]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - kernel/patches/grsecurity-3.0-3.15.6-201407232200.patch
Merge remote-tracking branch 'ms/pdns'
[people/ms/ipfire-3.x.git] / kernel / patches / grsecurity-3.0-3.15.6-201407232200.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 fefa023..06f4bb4 100644
291 --- a/Makefile
292 +++ b/Makefile
293 @@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
294
295 HOSTCC = gcc
296 HOSTCXX = g++
297 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
298 -HOSTCXXFLAGS = -O2
299 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
300 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
301 +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
302
303 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
304 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
305 @@ -438,8 +439,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
306 # Rules shared between *config targets and build targets
307
308 # Basic helpers built in scripts/
309 -PHONY += scripts_basic
310 -scripts_basic:
311 +PHONY += scripts_basic gcc-plugins
312 +scripts_basic: gcc-plugins
313 $(Q)$(MAKE) $(build)=scripts/basic
314 $(Q)rm -f .tmp_quiet_recordmcount
315
316 @@ -600,6 +601,72 @@ else
317 KBUILD_CFLAGS += -O2
318 endif
319
320 +ifndef DISABLE_PAX_PLUGINS
321 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
322 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
323 +else
324 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
325 +endif
326 +ifneq ($(PLUGINCC),)
327 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
328 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
329 +endif
330 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
331 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
332 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
333 +endif
334 +ifdef CONFIG_KALLOCSTAT_PLUGIN
335 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
336 +endif
337 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
338 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
339 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
340 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
341 +endif
342 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
343 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
344 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
345 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
346 +endif
347 +endif
348 +ifdef CONFIG_CHECKER_PLUGIN
349 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
350 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
351 +endif
352 +endif
353 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
354 +ifdef CONFIG_PAX_SIZE_OVERFLOW
355 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
356 +endif
357 +ifdef CONFIG_PAX_LATENT_ENTROPY
358 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
359 +endif
360 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
361 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
362 +endif
363 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
364 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
365 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
366 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
367 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
368 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
369 +ifeq ($(KBUILD_EXTMOD),)
370 +gcc-plugins:
371 + $(Q)$(MAKE) $(build)=tools/gcc
372 +else
373 +gcc-plugins: ;
374 +endif
375 +else
376 +gcc-plugins:
377 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
378 + $(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.))
379 +else
380 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
381 +endif
382 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
383 +endif
384 +endif
385 +
386 include $(srctree)/arch/$(SRCARCH)/Makefile
387
388 ifdef CONFIG_READABLE_ASM
389 @@ -816,7 +883,7 @@ export mod_sign_cmd
390
391
392 ifeq ($(KBUILD_EXTMOD),)
393 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
394 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
395
396 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
397 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
398 @@ -865,6 +932,8 @@ endif
399
400 # The actual objects are generated when descending,
401 # make sure no implicit rule kicks in
402 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
403 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
404 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
405
406 # Handle descending into subdirectories listed in $(vmlinux-dirs)
407 @@ -874,7 +943,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
408 # Error messages still appears in the original language
409
410 PHONY += $(vmlinux-dirs)
411 -$(vmlinux-dirs): prepare scripts
412 +$(vmlinux-dirs): gcc-plugins prepare scripts
413 $(Q)$(MAKE) $(build)=$@
414
415 define filechk_kernel.release
416 @@ -917,10 +986,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
417
418 archprepare: archheaders archscripts prepare1 scripts_basic
419
420 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
421 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
422 prepare0: archprepare FORCE
423 $(Q)$(MAKE) $(build)=.
424
425 # All the preparing..
426 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
427 prepare: prepare0
428
429 # Generate some files
430 @@ -1028,6 +1100,8 @@ all: modules
431 # using awk while concatenating to the final file.
432
433 PHONY += modules
434 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
435 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
436 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
437 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
438 @$(kecho) ' Building modules, stage 2.';
439 @@ -1043,7 +1117,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
440
441 # Target to prepare building external modules
442 PHONY += modules_prepare
443 -modules_prepare: prepare scripts
444 +modules_prepare: gcc-plugins prepare scripts
445
446 # Target to install modules
447 PHONY += modules_install
448 @@ -1109,7 +1183,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
449 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
450 signing_key.priv signing_key.x509 x509.genkey \
451 extra_certificates signing_key.x509.keyid \
452 - signing_key.x509.signer include/linux/version.h
453 + signing_key.x509.signer include/linux/version.h \
454 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
455 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
456 + tools/gcc/randomize_layout_seed.h
457
458 # clean - Delete most, but leave enough to build external modules
459 #
460 @@ -1148,7 +1225,7 @@ distclean: mrproper
461 @find $(srctree) $(RCS_FIND_IGNORE) \
462 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
463 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
464 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
465 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
466 -type f -print | xargs rm -f
467
468
469 @@ -1309,6 +1386,8 @@ PHONY += $(module-dirs) modules
470 $(module-dirs): crmodverdir $(objtree)/Module.symvers
471 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
472
473 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
474 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
475 modules: $(module-dirs)
476 @$(kecho) ' Building modules, stage 2.';
477 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
478 @@ -1448,17 +1527,21 @@ else
479 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
480 endif
481
482 -%.s: %.c prepare scripts FORCE
483 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
484 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
485 +%.s: %.c gcc-plugins prepare scripts FORCE
486 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
487 %.i: %.c prepare scripts FORCE
488 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
489 -%.o: %.c prepare scripts FORCE
490 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
491 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
492 +%.o: %.c gcc-plugins prepare scripts FORCE
493 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
494 %.lst: %.c prepare scripts FORCE
495 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
496 -%.s: %.S prepare scripts FORCE
497 +%.s: %.S gcc-plugins prepare scripts FORCE
498 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
499 -%.o: %.S prepare scripts FORCE
500 +%.o: %.S gcc-plugins prepare scripts FORCE
501 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
502 %.symtypes: %.c prepare scripts FORCE
503 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
504 @@ -1468,11 +1551,15 @@ endif
505 $(cmd_crmodverdir)
506 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
507 $(build)=$(build-dir)
508 -%/: prepare scripts FORCE
509 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
510 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
511 +%/: gcc-plugins prepare scripts FORCE
512 $(cmd_crmodverdir)
513 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
514 $(build)=$(build-dir)
515 -%.ko: prepare scripts FORCE
516 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
517 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
518 +%.ko: gcc-plugins prepare scripts FORCE
519 $(cmd_crmodverdir)
520 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
521 $(build)=$(build-dir) $(@:.ko=.o)
522 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
523 index 78b03ef..da28a51 100644
524 --- a/arch/alpha/include/asm/atomic.h
525 +++ b/arch/alpha/include/asm/atomic.h
526 @@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
527 #define atomic_dec(v) atomic_sub(1,(v))
528 #define atomic64_dec(v) atomic64_sub(1,(v))
529
530 +#define atomic64_read_unchecked(v) atomic64_read(v)
531 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
532 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
533 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
534 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
535 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
536 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
537 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
538 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
539 +
540 #define smp_mb__before_atomic_dec() smp_mb()
541 #define smp_mb__after_atomic_dec() smp_mb()
542 #define smp_mb__before_atomic_inc() smp_mb()
543 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
544 index ad368a9..fbe0f25 100644
545 --- a/arch/alpha/include/asm/cache.h
546 +++ b/arch/alpha/include/asm/cache.h
547 @@ -4,19 +4,19 @@
548 #ifndef __ARCH_ALPHA_CACHE_H
549 #define __ARCH_ALPHA_CACHE_H
550
551 +#include <linux/const.h>
552
553 /* Bytes per L1 (data) cache line. */
554 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
555 -# define L1_CACHE_BYTES 64
556 # define L1_CACHE_SHIFT 6
557 #else
558 /* Both EV4 and EV5 are write-through, read-allocate,
559 direct-mapped, physical.
560 */
561 -# define L1_CACHE_BYTES 32
562 # define L1_CACHE_SHIFT 5
563 #endif
564
565 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
566 #define SMP_CACHE_BYTES L1_CACHE_BYTES
567
568 #endif
569 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
570 index 968d999..d36b2df 100644
571 --- a/arch/alpha/include/asm/elf.h
572 +++ b/arch/alpha/include/asm/elf.h
573 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
574
575 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
576
577 +#ifdef CONFIG_PAX_ASLR
578 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
579 +
580 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
581 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
582 +#endif
583 +
584 /* $0 is set by ld.so to a pointer to a function which might be
585 registered using atexit. This provides a mean for the dynamic
586 linker to call DT_FINI functions for shared libraries that have
587 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
588 index aab14a0..b4fa3e7 100644
589 --- a/arch/alpha/include/asm/pgalloc.h
590 +++ b/arch/alpha/include/asm/pgalloc.h
591 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
592 pgd_set(pgd, pmd);
593 }
594
595 +static inline void
596 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
597 +{
598 + pgd_populate(mm, pgd, pmd);
599 +}
600 +
601 extern pgd_t *pgd_alloc(struct mm_struct *mm);
602
603 static inline void
604 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
605 index d8f9b7e..f6222fa 100644
606 --- a/arch/alpha/include/asm/pgtable.h
607 +++ b/arch/alpha/include/asm/pgtable.h
608 @@ -102,6 +102,17 @@ struct vm_area_struct;
609 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
610 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
611 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
612 +
613 +#ifdef CONFIG_PAX_PAGEEXEC
614 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
615 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
616 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
617 +#else
618 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
619 +# define PAGE_COPY_NOEXEC PAGE_COPY
620 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
621 +#endif
622 +
623 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
624
625 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
626 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
627 index 2fd00b7..cfd5069 100644
628 --- a/arch/alpha/kernel/module.c
629 +++ b/arch/alpha/kernel/module.c
630 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
631
632 /* The small sections were sorted to the end of the segment.
633 The following should definitely cover them. */
634 - gp = (u64)me->module_core + me->core_size - 0x8000;
635 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
636 got = sechdrs[me->arch.gotsecindex].sh_addr;
637
638 for (i = 0; i < n; i++) {
639 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
640 index 1402fcc..0b1abd2 100644
641 --- a/arch/alpha/kernel/osf_sys.c
642 +++ b/arch/alpha/kernel/osf_sys.c
643 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
644 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
645
646 static unsigned long
647 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
648 - unsigned long limit)
649 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
650 + unsigned long limit, unsigned long flags)
651 {
652 struct vm_unmapped_area_info info;
653 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
654
655 info.flags = 0;
656 info.length = len;
657 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
658 info.high_limit = limit;
659 info.align_mask = 0;
660 info.align_offset = 0;
661 + info.threadstack_offset = offset;
662 return vm_unmapped_area(&info);
663 }
664
665 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
666 merely specific addresses, but regions of memory -- perhaps
667 this feature should be incorporated into all ports? */
668
669 +#ifdef CONFIG_PAX_RANDMMAP
670 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
671 +#endif
672 +
673 if (addr) {
674 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
675 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
676 if (addr != (unsigned long) -ENOMEM)
677 return addr;
678 }
679
680 /* Next, try allocating at TASK_UNMAPPED_BASE. */
681 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
682 - len, limit);
683 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
684 +
685 if (addr != (unsigned long) -ENOMEM)
686 return addr;
687
688 /* Finally, try allocating in low memory. */
689 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
690 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
691
692 return addr;
693 }
694 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
695 index 98838a0..b304fb4 100644
696 --- a/arch/alpha/mm/fault.c
697 +++ b/arch/alpha/mm/fault.c
698 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
699 __reload_thread(pcb);
700 }
701
702 +#ifdef CONFIG_PAX_PAGEEXEC
703 +/*
704 + * PaX: decide what to do with offenders (regs->pc = fault address)
705 + *
706 + * returns 1 when task should be killed
707 + * 2 when patched PLT trampoline was detected
708 + * 3 when unpatched PLT trampoline was detected
709 + */
710 +static int pax_handle_fetch_fault(struct pt_regs *regs)
711 +{
712 +
713 +#ifdef CONFIG_PAX_EMUPLT
714 + int err;
715 +
716 + do { /* PaX: patched PLT emulation #1 */
717 + unsigned int ldah, ldq, jmp;
718 +
719 + err = get_user(ldah, (unsigned int *)regs->pc);
720 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
721 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
722 +
723 + if (err)
724 + break;
725 +
726 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
727 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
728 + jmp == 0x6BFB0000U)
729 + {
730 + unsigned long r27, addr;
731 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
732 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
733 +
734 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
735 + err = get_user(r27, (unsigned long *)addr);
736 + if (err)
737 + break;
738 +
739 + regs->r27 = r27;
740 + regs->pc = r27;
741 + return 2;
742 + }
743 + } while (0);
744 +
745 + do { /* PaX: patched PLT emulation #2 */
746 + unsigned int ldah, lda, br;
747 +
748 + err = get_user(ldah, (unsigned int *)regs->pc);
749 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
750 + err |= get_user(br, (unsigned int *)(regs->pc+8));
751 +
752 + if (err)
753 + break;
754 +
755 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
756 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
757 + (br & 0xFFE00000U) == 0xC3E00000U)
758 + {
759 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
760 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
761 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
762 +
763 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
764 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
765 + return 2;
766 + }
767 + } while (0);
768 +
769 + do { /* PaX: unpatched PLT emulation */
770 + unsigned int br;
771 +
772 + err = get_user(br, (unsigned int *)regs->pc);
773 +
774 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
775 + unsigned int br2, ldq, nop, jmp;
776 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
777 +
778 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
779 + err = get_user(br2, (unsigned int *)addr);
780 + err |= get_user(ldq, (unsigned int *)(addr+4));
781 + err |= get_user(nop, (unsigned int *)(addr+8));
782 + err |= get_user(jmp, (unsigned int *)(addr+12));
783 + err |= get_user(resolver, (unsigned long *)(addr+16));
784 +
785 + if (err)
786 + break;
787 +
788 + if (br2 == 0xC3600000U &&
789 + ldq == 0xA77B000CU &&
790 + nop == 0x47FF041FU &&
791 + jmp == 0x6B7B0000U)
792 + {
793 + regs->r28 = regs->pc+4;
794 + regs->r27 = addr+16;
795 + regs->pc = resolver;
796 + return 3;
797 + }
798 + }
799 + } while (0);
800 +#endif
801 +
802 + return 1;
803 +}
804 +
805 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
806 +{
807 + unsigned long i;
808 +
809 + printk(KERN_ERR "PAX: bytes at PC: ");
810 + for (i = 0; i < 5; i++) {
811 + unsigned int c;
812 + if (get_user(c, (unsigned int *)pc+i))
813 + printk(KERN_CONT "???????? ");
814 + else
815 + printk(KERN_CONT "%08x ", c);
816 + }
817 + printk("\n");
818 +}
819 +#endif
820
821 /*
822 * This routine handles page faults. It determines the address,
823 @@ -133,8 +251,29 @@ retry:
824 good_area:
825 si_code = SEGV_ACCERR;
826 if (cause < 0) {
827 - if (!(vma->vm_flags & VM_EXEC))
828 + if (!(vma->vm_flags & VM_EXEC)) {
829 +
830 +#ifdef CONFIG_PAX_PAGEEXEC
831 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
832 + goto bad_area;
833 +
834 + up_read(&mm->mmap_sem);
835 + switch (pax_handle_fetch_fault(regs)) {
836 +
837 +#ifdef CONFIG_PAX_EMUPLT
838 + case 2:
839 + case 3:
840 + return;
841 +#endif
842 +
843 + }
844 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
845 + do_group_exit(SIGKILL);
846 +#else
847 goto bad_area;
848 +#endif
849 +
850 + }
851 } else if (!cause) {
852 /* Allow reads even for write-only mappings */
853 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
854 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
855 index db3c541..a1acc89 100644
856 --- a/arch/arm/Kconfig
857 +++ b/arch/arm/Kconfig
858 @@ -1877,7 +1877,7 @@ config ALIGNMENT_TRAP
859
860 config UACCESS_WITH_MEMCPY
861 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
862 - depends on MMU
863 + depends on MMU && !PAX_MEMORY_UDEREF
864 default y if CPU_FEROCEON
865 help
866 Implement faster copy_to_user and clear_user methods for CPU
867 @@ -2141,6 +2141,7 @@ config XIP_PHYS_ADDR
868 config KEXEC
869 bool "Kexec system call (EXPERIMENTAL)"
870 depends on (!SMP || PM_SLEEP_SMP)
871 + depends on !GRKERNSEC_KMEM
872 help
873 kexec is a system call that implements the ability to shutdown your
874 current kernel, and to start another kernel. It is like a reboot
875 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
876 index 9a92fd7..3502a80 100644
877 --- a/arch/arm/include/asm/atomic.h
878 +++ b/arch/arm/include/asm/atomic.h
879 @@ -18,17 +18,35 @@
880 #include <asm/barrier.h>
881 #include <asm/cmpxchg.h>
882
883 +#ifdef CONFIG_GENERIC_ATOMIC64
884 +#include <asm-generic/atomic64.h>
885 +#endif
886 +
887 #define ATOMIC_INIT(i) { (i) }
888
889 #ifdef __KERNEL__
890
891 +#define _ASM_EXTABLE(from, to) \
892 +" .pushsection __ex_table,\"a\"\n"\
893 +" .align 3\n" \
894 +" .long " #from ", " #to"\n" \
895 +" .popsection"
896 +
897 /*
898 * On ARM, ordinary assignment (str instruction) doesn't clear the local
899 * strex/ldrex monitor on some implementations. The reason we can use it for
900 * atomic_set() is the clrex or dummy strex done on every exception return.
901 */
902 #define atomic_read(v) (*(volatile int *)&(v)->counter)
903 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
904 +{
905 + return v->counter;
906 +}
907 #define atomic_set(v,i) (((v)->counter) = (i))
908 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
909 +{
910 + v->counter = i;
911 +}
912
913 #if __LINUX_ARM_ARCH__ >= 6
914
915 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
916
917 prefetchw(&v->counter);
918 __asm__ __volatile__("@ atomic_add\n"
919 +"1: ldrex %1, [%3]\n"
920 +" adds %0, %1, %4\n"
921 +
922 +#ifdef CONFIG_PAX_REFCOUNT
923 +" bvc 3f\n"
924 +"2: bkpt 0xf103\n"
925 +"3:\n"
926 +#endif
927 +
928 +" strex %1, %0, [%3]\n"
929 +" teq %1, #0\n"
930 +" bne 1b"
931 +
932 +#ifdef CONFIG_PAX_REFCOUNT
933 +"\n4:\n"
934 + _ASM_EXTABLE(2b, 4b)
935 +#endif
936 +
937 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
938 + : "r" (&v->counter), "Ir" (i)
939 + : "cc");
940 +}
941 +
942 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
943 +{
944 + unsigned long tmp;
945 + int result;
946 +
947 + prefetchw(&v->counter);
948 + __asm__ __volatile__("@ atomic_add_unchecked\n"
949 "1: ldrex %0, [%3]\n"
950 " add %0, %0, %4\n"
951 " strex %1, %0, [%3]\n"
952 @@ -63,6 +111,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
953 prefetchw(&v->counter);
954
955 __asm__ __volatile__("@ atomic_add_return\n"
956 +"1: ldrex %1, [%3]\n"
957 +" adds %0, %1, %4\n"
958 +
959 +#ifdef CONFIG_PAX_REFCOUNT
960 +" bvc 3f\n"
961 +" mov %0, %1\n"
962 +"2: bkpt 0xf103\n"
963 +"3:\n"
964 +#endif
965 +
966 +" strex %1, %0, [%3]\n"
967 +" teq %1, #0\n"
968 +" bne 1b"
969 +
970 +#ifdef CONFIG_PAX_REFCOUNT
971 +"\n4:\n"
972 + _ASM_EXTABLE(2b, 4b)
973 +#endif
974 +
975 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
976 + : "r" (&v->counter), "Ir" (i)
977 + : "cc");
978 +
979 + smp_mb();
980 +
981 + return result;
982 +}
983 +
984 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
985 +{
986 + unsigned long tmp;
987 + int result;
988 +
989 + smp_mb();
990 + prefetchw(&v->counter);
991 +
992 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
993 "1: ldrex %0, [%3]\n"
994 " add %0, %0, %4\n"
995 " strex %1, %0, [%3]\n"
996 @@ -84,6 +169,36 @@ static inline void atomic_sub(int i, atomic_t *v)
997
998 prefetchw(&v->counter);
999 __asm__ __volatile__("@ atomic_sub\n"
1000 +"1: ldrex %1, [%3]\n"
1001 +" subs %0, %1, %4\n"
1002 +
1003 +#ifdef CONFIG_PAX_REFCOUNT
1004 +" bvc 3f\n"
1005 +"2: bkpt 0xf103\n"
1006 +"3:\n"
1007 +#endif
1008 +
1009 +" strex %1, %0, [%3]\n"
1010 +" teq %1, #0\n"
1011 +" bne 1b"
1012 +
1013 +#ifdef CONFIG_PAX_REFCOUNT
1014 +"\n4:\n"
1015 + _ASM_EXTABLE(2b, 4b)
1016 +#endif
1017 +
1018 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1019 + : "r" (&v->counter), "Ir" (i)
1020 + : "cc");
1021 +}
1022 +
1023 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1024 +{
1025 + unsigned long tmp;
1026 + int result;
1027 +
1028 + prefetchw(&v->counter);
1029 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1030 "1: ldrex %0, [%3]\n"
1031 " sub %0, %0, %4\n"
1032 " strex %1, %0, [%3]\n"
1033 @@ -103,11 +218,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1034 prefetchw(&v->counter);
1035
1036 __asm__ __volatile__("@ atomic_sub_return\n"
1037 -"1: ldrex %0, [%3]\n"
1038 -" sub %0, %0, %4\n"
1039 +"1: ldrex %1, [%3]\n"
1040 +" subs %0, %1, %4\n"
1041 +
1042 +#ifdef CONFIG_PAX_REFCOUNT
1043 +" bvc 3f\n"
1044 +" mov %0, %1\n"
1045 +"2: bkpt 0xf103\n"
1046 +"3:\n"
1047 +#endif
1048 +
1049 " strex %1, %0, [%3]\n"
1050 " teq %1, #0\n"
1051 " bne 1b"
1052 +
1053 +#ifdef CONFIG_PAX_REFCOUNT
1054 +"\n4:\n"
1055 + _ASM_EXTABLE(2b, 4b)
1056 +#endif
1057 +
1058 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1059 : "r" (&v->counter), "Ir" (i)
1060 : "cc");
1061 @@ -152,12 +281,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1062 __asm__ __volatile__ ("@ atomic_add_unless\n"
1063 "1: ldrex %0, [%4]\n"
1064 " teq %0, %5\n"
1065 -" beq 2f\n"
1066 -" add %1, %0, %6\n"
1067 +" beq 4f\n"
1068 +" adds %1, %0, %6\n"
1069 +
1070 +#ifdef CONFIG_PAX_REFCOUNT
1071 +" bvc 3f\n"
1072 +"2: bkpt 0xf103\n"
1073 +"3:\n"
1074 +#endif
1075 +
1076 " strex %2, %1, [%4]\n"
1077 " teq %2, #0\n"
1078 " bne 1b\n"
1079 -"2:"
1080 +"4:"
1081 +
1082 +#ifdef CONFIG_PAX_REFCOUNT
1083 + _ASM_EXTABLE(2b, 4b)
1084 +#endif
1085 +
1086 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1087 : "r" (&v->counter), "r" (u), "r" (a)
1088 : "cc");
1089 @@ -168,6 +309,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1090 return oldval;
1091 }
1092
1093 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1094 +{
1095 + unsigned long oldval, res;
1096 +
1097 + smp_mb();
1098 +
1099 + do {
1100 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1101 + "ldrex %1, [%3]\n"
1102 + "mov %0, #0\n"
1103 + "teq %1, %4\n"
1104 + "strexeq %0, %5, [%3]\n"
1105 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1106 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1107 + : "cc");
1108 + } while (res);
1109 +
1110 + smp_mb();
1111 +
1112 + return oldval;
1113 +}
1114 +
1115 #else /* ARM_ARCH_6 */
1116
1117 #ifdef CONFIG_SMP
1118 @@ -186,7 +349,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1119
1120 return val;
1121 }
1122 +
1123 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1124 +{
1125 + return atomic_add_return(i, v);
1126 +}
1127 +
1128 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1129 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1130 +{
1131 + (void) atomic_add_return(i, v);
1132 +}
1133
1134 static inline int atomic_sub_return(int i, atomic_t *v)
1135 {
1136 @@ -201,6 +374,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1137 return val;
1138 }
1139 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1140 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1141 +{
1142 + (void) atomic_sub_return(i, v);
1143 +}
1144
1145 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1146 {
1147 @@ -216,6 +393,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1148 return ret;
1149 }
1150
1151 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1152 +{
1153 + return atomic_cmpxchg(v, old, new);
1154 +}
1155 +
1156 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1157 {
1158 int c, old;
1159 @@ -229,13 +411,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1160 #endif /* __LINUX_ARM_ARCH__ */
1161
1162 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1163 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1164 +{
1165 + return xchg(&v->counter, new);
1166 +}
1167
1168 #define atomic_inc(v) atomic_add(1, v)
1169 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1170 +{
1171 + atomic_add_unchecked(1, v);
1172 +}
1173 #define atomic_dec(v) atomic_sub(1, v)
1174 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1175 +{
1176 + atomic_sub_unchecked(1, v);
1177 +}
1178
1179 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1180 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1181 +{
1182 + return atomic_add_return_unchecked(1, v) == 0;
1183 +}
1184 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1185 #define atomic_inc_return(v) (atomic_add_return(1, v))
1186 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1187 +{
1188 + return atomic_add_return_unchecked(1, v);
1189 +}
1190 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1191 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1192
1193 @@ -251,6 +453,14 @@ typedef struct {
1194 long long counter;
1195 } atomic64_t;
1196
1197 +#ifdef CONFIG_PAX_REFCOUNT
1198 +typedef struct {
1199 + long long counter;
1200 +} atomic64_unchecked_t;
1201 +#else
1202 +typedef atomic64_t atomic64_unchecked_t;
1203 +#endif
1204 +
1205 #define ATOMIC64_INIT(i) { (i) }
1206
1207 #ifdef CONFIG_ARM_LPAE
1208 @@ -267,6 +477,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1209 return result;
1210 }
1211
1212 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1213 +{
1214 + long long result;
1215 +
1216 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1217 +" ldrd %0, %H0, [%1]"
1218 + : "=&r" (result)
1219 + : "r" (&v->counter), "Qo" (v->counter)
1220 + );
1221 +
1222 + return result;
1223 +}
1224 +
1225 static inline void atomic64_set(atomic64_t *v, long long i)
1226 {
1227 __asm__ __volatile__("@ atomic64_set\n"
1228 @@ -275,6 +498,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1229 : "r" (&v->counter), "r" (i)
1230 );
1231 }
1232 +
1233 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1234 +{
1235 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1236 +" strd %2, %H2, [%1]"
1237 + : "=Qo" (v->counter)
1238 + : "r" (&v->counter), "r" (i)
1239 + );
1240 +}
1241 #else
1242 static inline long long atomic64_read(const atomic64_t *v)
1243 {
1244 @@ -289,6 +521,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1245 return result;
1246 }
1247
1248 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1249 +{
1250 + long long result;
1251 +
1252 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1253 +" ldrexd %0, %H0, [%1]"
1254 + : "=&r" (result)
1255 + : "r" (&v->counter), "Qo" (v->counter)
1256 + );
1257 +
1258 + return result;
1259 +}
1260 +
1261 static inline void atomic64_set(atomic64_t *v, long long i)
1262 {
1263 long long tmp;
1264 @@ -303,6 +548,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1265 : "r" (&v->counter), "r" (i)
1266 : "cc");
1267 }
1268 +
1269 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1270 +{
1271 + long long tmp;
1272 +
1273 + prefetchw(&v->counter);
1274 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1275 +"1: ldrexd %0, %H0, [%2]\n"
1276 +" strexd %0, %3, %H3, [%2]\n"
1277 +" teq %0, #0\n"
1278 +" bne 1b"
1279 + : "=&r" (tmp), "=Qo" (v->counter)
1280 + : "r" (&v->counter), "r" (i)
1281 + : "cc");
1282 +}
1283 #endif
1284
1285 static inline void atomic64_add(long long i, atomic64_t *v)
1286 @@ -314,6 +574,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1287 __asm__ __volatile__("@ atomic64_add\n"
1288 "1: ldrexd %0, %H0, [%3]\n"
1289 " adds %Q0, %Q0, %Q4\n"
1290 +" adcs %R0, %R0, %R4\n"
1291 +
1292 +#ifdef CONFIG_PAX_REFCOUNT
1293 +" bvc 3f\n"
1294 +"2: bkpt 0xf103\n"
1295 +"3:\n"
1296 +#endif
1297 +
1298 +" strexd %1, %0, %H0, [%3]\n"
1299 +" teq %1, #0\n"
1300 +" bne 1b"
1301 +
1302 +#ifdef CONFIG_PAX_REFCOUNT
1303 +"\n4:\n"
1304 + _ASM_EXTABLE(2b, 4b)
1305 +#endif
1306 +
1307 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1308 + : "r" (&v->counter), "r" (i)
1309 + : "cc");
1310 +}
1311 +
1312 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1313 +{
1314 + long long result;
1315 + unsigned long tmp;
1316 +
1317 + prefetchw(&v->counter);
1318 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1319 +"1: ldrexd %0, %H0, [%3]\n"
1320 +" adds %Q0, %Q0, %Q4\n"
1321 " adc %R0, %R0, %R4\n"
1322 " strexd %1, %0, %H0, [%3]\n"
1323 " teq %1, #0\n"
1324 @@ -334,6 +625,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1325 __asm__ __volatile__("@ atomic64_add_return\n"
1326 "1: ldrexd %0, %H0, [%3]\n"
1327 " adds %Q0, %Q0, %Q4\n"
1328 +" adcs %R0, %R0, %R4\n"
1329 +
1330 +#ifdef CONFIG_PAX_REFCOUNT
1331 +" bvc 3f\n"
1332 +" mov %0, %1\n"
1333 +" mov %H0, %H1\n"
1334 +"2: bkpt 0xf103\n"
1335 +"3:\n"
1336 +#endif
1337 +
1338 +" strexd %1, %0, %H0, [%3]\n"
1339 +" teq %1, #0\n"
1340 +" bne 1b"
1341 +
1342 +#ifdef CONFIG_PAX_REFCOUNT
1343 +"\n4:\n"
1344 + _ASM_EXTABLE(2b, 4b)
1345 +#endif
1346 +
1347 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1348 + : "r" (&v->counter), "r" (i)
1349 + : "cc");
1350 +
1351 + smp_mb();
1352 +
1353 + return result;
1354 +}
1355 +
1356 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1357 +{
1358 + long long result;
1359 + unsigned long tmp;
1360 +
1361 + smp_mb();
1362 +
1363 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1364 +"1: ldrexd %0, %H0, [%3]\n"
1365 +" adds %Q0, %Q0, %Q4\n"
1366 " adc %R0, %R0, %R4\n"
1367 " strexd %1, %0, %H0, [%3]\n"
1368 " teq %1, #0\n"
1369 @@ -356,6 +685,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1370 __asm__ __volatile__("@ atomic64_sub\n"
1371 "1: ldrexd %0, %H0, [%3]\n"
1372 " subs %Q0, %Q0, %Q4\n"
1373 +" sbcs %R0, %R0, %R4\n"
1374 +
1375 +#ifdef CONFIG_PAX_REFCOUNT
1376 +" bvc 3f\n"
1377 +"2: bkpt 0xf103\n"
1378 +"3:\n"
1379 +#endif
1380 +
1381 +" strexd %1, %0, %H0, [%3]\n"
1382 +" teq %1, #0\n"
1383 +" bne 1b"
1384 +
1385 +#ifdef CONFIG_PAX_REFCOUNT
1386 +"\n4:\n"
1387 + _ASM_EXTABLE(2b, 4b)
1388 +#endif
1389 +
1390 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1391 + : "r" (&v->counter), "r" (i)
1392 + : "cc");
1393 +}
1394 +
1395 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1396 +{
1397 + long long result;
1398 + unsigned long tmp;
1399 +
1400 + prefetchw(&v->counter);
1401 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1402 +"1: ldrexd %0, %H0, [%3]\n"
1403 +" subs %Q0, %Q0, %Q4\n"
1404 " sbc %R0, %R0, %R4\n"
1405 " strexd %1, %0, %H0, [%3]\n"
1406 " teq %1, #0\n"
1407 @@ -376,16 +736,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1408 __asm__ __volatile__("@ atomic64_sub_return\n"
1409 "1: ldrexd %0, %H0, [%3]\n"
1410 " subs %Q0, %Q0, %Q4\n"
1411 -" sbc %R0, %R0, %R4\n"
1412 +" sbcs %R0, %R0, %R4\n"
1413 +
1414 +#ifdef CONFIG_PAX_REFCOUNT
1415 +" bvc 3f\n"
1416 +" mov %0, %1\n"
1417 +" mov %H0, %H1\n"
1418 +"2: bkpt 0xf103\n"
1419 +"3:\n"
1420 +#endif
1421 +
1422 " strexd %1, %0, %H0, [%3]\n"
1423 " teq %1, #0\n"
1424 " bne 1b"
1425 +
1426 +#ifdef CONFIG_PAX_REFCOUNT
1427 +"\n4:\n"
1428 + _ASM_EXTABLE(2b, 4b)
1429 +#endif
1430 +
1431 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1432 : "r" (&v->counter), "r" (i)
1433 : "cc");
1434
1435 - smp_mb();
1436 -
1437 return result;
1438 }
1439
1440 @@ -415,6 +788,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1441 return oldval;
1442 }
1443
1444 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1445 + long long new)
1446 +{
1447 + long long oldval;
1448 + unsigned long res;
1449 +
1450 + smp_mb();
1451 +
1452 + do {
1453 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1454 + "ldrexd %1, %H1, [%3]\n"
1455 + "mov %0, #0\n"
1456 + "teq %1, %4\n"
1457 + "teqeq %H1, %H4\n"
1458 + "strexdeq %0, %5, %H5, [%3]"
1459 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1460 + : "r" (&ptr->counter), "r" (old), "r" (new)
1461 + : "cc");
1462 + } while (res);
1463 +
1464 + smp_mb();
1465 +
1466 + return oldval;
1467 +}
1468 +
1469 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1470 {
1471 long long result;
1472 @@ -440,21 +838,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1473 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1474 {
1475 long long result;
1476 - unsigned long tmp;
1477 + u64 tmp;
1478
1479 smp_mb();
1480 prefetchw(&v->counter);
1481
1482 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1483 -"1: ldrexd %0, %H0, [%3]\n"
1484 -" subs %Q0, %Q0, #1\n"
1485 -" sbc %R0, %R0, #0\n"
1486 +"1: ldrexd %1, %H1, [%3]\n"
1487 +" subs %Q0, %Q1, #1\n"
1488 +" sbcs %R0, %R1, #0\n"
1489 +
1490 +#ifdef CONFIG_PAX_REFCOUNT
1491 +" bvc 3f\n"
1492 +" mov %Q0, %Q1\n"
1493 +" mov %R0, %R1\n"
1494 +"2: bkpt 0xf103\n"
1495 +"3:\n"
1496 +#endif
1497 +
1498 " teq %R0, #0\n"
1499 -" bmi 2f\n"
1500 +" bmi 4f\n"
1501 " strexd %1, %0, %H0, [%3]\n"
1502 " teq %1, #0\n"
1503 " bne 1b\n"
1504 -"2:"
1505 +"4:\n"
1506 +
1507 +#ifdef CONFIG_PAX_REFCOUNT
1508 + _ASM_EXTABLE(2b, 4b)
1509 +#endif
1510 +
1511 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1512 : "r" (&v->counter)
1513 : "cc");
1514 @@ -478,13 +890,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1515 " teq %0, %5\n"
1516 " teqeq %H0, %H5\n"
1517 " moveq %1, #0\n"
1518 -" beq 2f\n"
1519 +" beq 4f\n"
1520 " adds %Q0, %Q0, %Q6\n"
1521 -" adc %R0, %R0, %R6\n"
1522 +" adcs %R0, %R0, %R6\n"
1523 +
1524 +#ifdef CONFIG_PAX_REFCOUNT
1525 +" bvc 3f\n"
1526 +"2: bkpt 0xf103\n"
1527 +"3:\n"
1528 +#endif
1529 +
1530 " strexd %2, %0, %H0, [%4]\n"
1531 " teq %2, #0\n"
1532 " bne 1b\n"
1533 -"2:"
1534 +"4:\n"
1535 +
1536 +#ifdef CONFIG_PAX_REFCOUNT
1537 + _ASM_EXTABLE(2b, 4b)
1538 +#endif
1539 +
1540 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1541 : "r" (&v->counter), "r" (u), "r" (a)
1542 : "cc");
1543 @@ -497,10 +921,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1544
1545 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1546 #define atomic64_inc(v) atomic64_add(1LL, (v))
1547 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1548 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1549 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1550 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1551 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1552 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1553 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1554 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1555 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1556 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1557 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1558 index 2f59f74..1594659 100644
1559 --- a/arch/arm/include/asm/barrier.h
1560 +++ b/arch/arm/include/asm/barrier.h
1561 @@ -63,7 +63,7 @@
1562 do { \
1563 compiletime_assert_atomic_type(*p); \
1564 smp_mb(); \
1565 - ACCESS_ONCE(*p) = (v); \
1566 + ACCESS_ONCE_RW(*p) = (v); \
1567 } while (0)
1568
1569 #define smp_load_acquire(p) \
1570 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1571 index 75fe66b..ba3dee4 100644
1572 --- a/arch/arm/include/asm/cache.h
1573 +++ b/arch/arm/include/asm/cache.h
1574 @@ -4,8 +4,10 @@
1575 #ifndef __ASMARM_CACHE_H
1576 #define __ASMARM_CACHE_H
1577
1578 +#include <linux/const.h>
1579 +
1580 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1581 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1582 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1583
1584 /*
1585 * Memory returned by kmalloc() may be used for DMA, so we must make
1586 @@ -24,5 +26,6 @@
1587 #endif
1588
1589 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1590 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1591
1592 #endif
1593 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1594 index 8b8b616..d973d24 100644
1595 --- a/arch/arm/include/asm/cacheflush.h
1596 +++ b/arch/arm/include/asm/cacheflush.h
1597 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1598 void (*dma_unmap_area)(const void *, size_t, int);
1599
1600 void (*dma_flush_range)(const void *, const void *);
1601 -};
1602 +} __no_const;
1603
1604 /*
1605 * Select the calling method
1606 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1607 index 5233151..87a71fa 100644
1608 --- a/arch/arm/include/asm/checksum.h
1609 +++ b/arch/arm/include/asm/checksum.h
1610 @@ -37,7 +37,19 @@ __wsum
1611 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1612
1613 __wsum
1614 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1615 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1616 +
1617 +static inline __wsum
1618 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1619 +{
1620 + __wsum ret;
1621 + pax_open_userland();
1622 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1623 + pax_close_userland();
1624 + return ret;
1625 +}
1626 +
1627 +
1628
1629 /*
1630 * Fold a partial checksum without adding pseudo headers
1631 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1632 index abb2c37..96db950 100644
1633 --- a/arch/arm/include/asm/cmpxchg.h
1634 +++ b/arch/arm/include/asm/cmpxchg.h
1635 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1636
1637 #define xchg(ptr,x) \
1638 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1639 +#define xchg_unchecked(ptr,x) \
1640 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1641
1642 #include <asm-generic/cmpxchg-local.h>
1643
1644 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1645 index 6ddbe44..b5e38b1 100644
1646 --- a/arch/arm/include/asm/domain.h
1647 +++ b/arch/arm/include/asm/domain.h
1648 @@ -48,18 +48,37 @@
1649 * Domain types
1650 */
1651 #define DOMAIN_NOACCESS 0
1652 -#define DOMAIN_CLIENT 1
1653 #ifdef CONFIG_CPU_USE_DOMAINS
1654 +#define DOMAIN_USERCLIENT 1
1655 +#define DOMAIN_KERNELCLIENT 1
1656 #define DOMAIN_MANAGER 3
1657 +#define DOMAIN_VECTORS DOMAIN_USER
1658 #else
1659 +
1660 +#ifdef CONFIG_PAX_KERNEXEC
1661 #define DOMAIN_MANAGER 1
1662 +#define DOMAIN_KERNEXEC 3
1663 +#else
1664 +#define DOMAIN_MANAGER 1
1665 +#endif
1666 +
1667 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1668 +#define DOMAIN_USERCLIENT 0
1669 +#define DOMAIN_UDEREF 1
1670 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1671 +#else
1672 +#define DOMAIN_USERCLIENT 1
1673 +#define DOMAIN_VECTORS DOMAIN_USER
1674 +#endif
1675 +#define DOMAIN_KERNELCLIENT 1
1676 +
1677 #endif
1678
1679 #define domain_val(dom,type) ((type) << (2*(dom)))
1680
1681 #ifndef __ASSEMBLY__
1682
1683 -#ifdef CONFIG_CPU_USE_DOMAINS
1684 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1685 static inline void set_domain(unsigned val)
1686 {
1687 asm volatile(
1688 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1689 isb();
1690 }
1691
1692 -#define modify_domain(dom,type) \
1693 - do { \
1694 - struct thread_info *thread = current_thread_info(); \
1695 - unsigned int domain = thread->cpu_domain; \
1696 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1697 - thread->cpu_domain = domain | domain_val(dom, type); \
1698 - set_domain(thread->cpu_domain); \
1699 - } while (0)
1700 -
1701 +extern void modify_domain(unsigned int dom, unsigned int type);
1702 #else
1703 static inline void set_domain(unsigned val) { }
1704 static inline void modify_domain(unsigned dom, unsigned type) { }
1705 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1706 index f4b46d3..abc9b2b 100644
1707 --- a/arch/arm/include/asm/elf.h
1708 +++ b/arch/arm/include/asm/elf.h
1709 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1710 the loader. We need to make sure that it is out of the way of the program
1711 that it will "exec", and that there is sufficient room for the brk. */
1712
1713 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1714 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1715 +
1716 +#ifdef CONFIG_PAX_ASLR
1717 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1718 +
1719 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1720 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1721 +#endif
1722
1723 /* When the program starts, a1 contains a pointer to a function to be
1724 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1725 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1726 extern void elf_set_personality(const struct elf32_hdr *);
1727 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1728
1729 -struct mm_struct;
1730 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1731 -#define arch_randomize_brk arch_randomize_brk
1732 -
1733 #ifdef CONFIG_MMU
1734 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1735 struct linux_binprm;
1736 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1737 index de53547..52b9a28 100644
1738 --- a/arch/arm/include/asm/fncpy.h
1739 +++ b/arch/arm/include/asm/fncpy.h
1740 @@ -81,7 +81,9 @@
1741 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1742 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1743 \
1744 + pax_open_kernel(); \
1745 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1746 + pax_close_kernel(); \
1747 flush_icache_range((unsigned long)(dest_buf), \
1748 (unsigned long)(dest_buf) + (size)); \
1749 \
1750 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1751 index 53e69da..3fdc896 100644
1752 --- a/arch/arm/include/asm/futex.h
1753 +++ b/arch/arm/include/asm/futex.h
1754 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1755 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1756 return -EFAULT;
1757
1758 + pax_open_userland();
1759 +
1760 smp_mb();
1761 /* Prefetching cannot fault */
1762 prefetchw(uaddr);
1763 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1764 : "cc", "memory");
1765 smp_mb();
1766
1767 + pax_close_userland();
1768 +
1769 *uval = val;
1770 return ret;
1771 }
1772 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1773 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1774 return -EFAULT;
1775
1776 + pax_open_userland();
1777 +
1778 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1779 "1: " TUSER(ldr) " %1, [%4]\n"
1780 " teq %1, %2\n"
1781 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1782 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1783 : "cc", "memory");
1784
1785 + pax_close_userland();
1786 +
1787 *uval = val;
1788 return ret;
1789 }
1790 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1791 return -EFAULT;
1792
1793 pagefault_disable(); /* implies preempt_disable() */
1794 + pax_open_userland();
1795
1796 switch (op) {
1797 case FUTEX_OP_SET:
1798 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1799 ret = -ENOSYS;
1800 }
1801
1802 + pax_close_userland();
1803 pagefault_enable(); /* subsumes preempt_enable() */
1804
1805 if (!ret) {
1806 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1807 index 83eb2f7..ed77159 100644
1808 --- a/arch/arm/include/asm/kmap_types.h
1809 +++ b/arch/arm/include/asm/kmap_types.h
1810 @@ -4,6 +4,6 @@
1811 /*
1812 * This is the "bare minimum". AIO seems to require this.
1813 */
1814 -#define KM_TYPE_NR 16
1815 +#define KM_TYPE_NR 17
1816
1817 #endif
1818 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1819 index 9e614a1..3302cca 100644
1820 --- a/arch/arm/include/asm/mach/dma.h
1821 +++ b/arch/arm/include/asm/mach/dma.h
1822 @@ -22,7 +22,7 @@ struct dma_ops {
1823 int (*residue)(unsigned int, dma_t *); /* optional */
1824 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1825 const char *type;
1826 -};
1827 +} __do_const;
1828
1829 struct dma_struct {
1830 void *addr; /* single DMA address */
1831 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1832 index f98c7f3..e5c626d 100644
1833 --- a/arch/arm/include/asm/mach/map.h
1834 +++ b/arch/arm/include/asm/mach/map.h
1835 @@ -23,17 +23,19 @@ struct map_desc {
1836
1837 /* types 0-3 are defined in asm/io.h */
1838 enum {
1839 - MT_UNCACHED = 4,
1840 - MT_CACHECLEAN,
1841 - MT_MINICLEAN,
1842 + MT_UNCACHED_RW = 4,
1843 + MT_CACHECLEAN_RO,
1844 + MT_MINICLEAN_RO,
1845 MT_LOW_VECTORS,
1846 MT_HIGH_VECTORS,
1847 - MT_MEMORY_RWX,
1848 + __MT_MEMORY_RWX,
1849 MT_MEMORY_RW,
1850 - MT_ROM,
1851 - MT_MEMORY_RWX_NONCACHED,
1852 + MT_MEMORY_RX,
1853 + MT_ROM_RX,
1854 + MT_MEMORY_RW_NONCACHED,
1855 + MT_MEMORY_RX_NONCACHED,
1856 MT_MEMORY_RW_DTCM,
1857 - MT_MEMORY_RWX_ITCM,
1858 + MT_MEMORY_RX_ITCM,
1859 MT_MEMORY_RW_SO,
1860 MT_MEMORY_DMA_READY,
1861 };
1862 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1863 index f94784f..9a09a4a 100644
1864 --- a/arch/arm/include/asm/outercache.h
1865 +++ b/arch/arm/include/asm/outercache.h
1866 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1867 #endif
1868 void (*set_debug)(unsigned long);
1869 void (*resume)(void);
1870 -};
1871 +} __no_const;
1872
1873 extern struct outer_cache_fns outer_cache;
1874
1875 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1876 index 4355f0e..cd9168e 100644
1877 --- a/arch/arm/include/asm/page.h
1878 +++ b/arch/arm/include/asm/page.h
1879 @@ -23,6 +23,7 @@
1880
1881 #else
1882
1883 +#include <linux/compiler.h>
1884 #include <asm/glue.h>
1885
1886 /*
1887 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1888 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1889 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1890 unsigned long vaddr, struct vm_area_struct *vma);
1891 -};
1892 +} __no_const;
1893
1894 #ifdef MULTI_USER
1895 extern struct cpu_user_fns cpu_user;
1896 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1897 index 78a7793..e3dc06c 100644
1898 --- a/arch/arm/include/asm/pgalloc.h
1899 +++ b/arch/arm/include/asm/pgalloc.h
1900 @@ -17,6 +17,7 @@
1901 #include <asm/processor.h>
1902 #include <asm/cacheflush.h>
1903 #include <asm/tlbflush.h>
1904 +#include <asm/system_info.h>
1905
1906 #define check_pgt_cache() do { } while (0)
1907
1908 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1909 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1910 }
1911
1912 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1913 +{
1914 + pud_populate(mm, pud, pmd);
1915 +}
1916 +
1917 #else /* !CONFIG_ARM_LPAE */
1918
1919 /*
1920 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1921 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1922 #define pmd_free(mm, pmd) do { } while (0)
1923 #define pud_populate(mm,pmd,pte) BUG()
1924 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1925
1926 #endif /* CONFIG_ARM_LPAE */
1927
1928 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1929 __free_page(pte);
1930 }
1931
1932 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1933 +{
1934 +#ifdef CONFIG_ARM_LPAE
1935 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1936 +#else
1937 + if (addr & SECTION_SIZE)
1938 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1939 + else
1940 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1941 +#endif
1942 + flush_pmd_entry(pmdp);
1943 +}
1944 +
1945 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1946 pmdval_t prot)
1947 {
1948 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1949 static inline void
1950 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1951 {
1952 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1953 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1954 }
1955 #define pmd_pgtable(pmd) pmd_page(pmd)
1956
1957 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1958 index 5cfba15..f415e1a 100644
1959 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1960 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1961 @@ -20,12 +20,15 @@
1962 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1963 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1964 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1965 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1966 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1967 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1968 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1969 +
1970 /*
1971 * - section
1972 */
1973 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1974 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1975 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1976 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1977 @@ -37,6 +40,7 @@
1978 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1979 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1980 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1981 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1982
1983 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1984 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1985 @@ -66,6 +70,7 @@
1986 * - extended small page/tiny page
1987 */
1988 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1989 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1990 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1991 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1992 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1993 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1994 index 219ac88..73ec32a 100644
1995 --- a/arch/arm/include/asm/pgtable-2level.h
1996 +++ b/arch/arm/include/asm/pgtable-2level.h
1997 @@ -126,6 +126,9 @@
1998 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1999 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
2000
2001 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
2002 +#define L_PTE_PXN (_AT(pteval_t, 0))
2003 +
2004 /*
2005 * These are the memory types, defined to be compatible with
2006 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
2007 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
2008 index 626989f..9d67a33 100644
2009 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
2010 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
2011 @@ -75,6 +75,7 @@
2012 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2013 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2014 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2015 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2016 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2017
2018 /*
2019 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2020 index 85c60ad..b0bbd7e 100644
2021 --- a/arch/arm/include/asm/pgtable-3level.h
2022 +++ b/arch/arm/include/asm/pgtable-3level.h
2023 @@ -82,6 +82,7 @@
2024 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
2025 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2026 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2027 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2028 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2029 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2030 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2031 @@ -95,6 +96,7 @@
2032 /*
2033 * To be used in assembly code with the upper page attributes.
2034 */
2035 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2036 #define L_PTE_XN_HIGH (1 << (54 - 32))
2037 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2038
2039 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2040 index 5478e5d..f5b5cb3 100644
2041 --- a/arch/arm/include/asm/pgtable.h
2042 +++ b/arch/arm/include/asm/pgtable.h
2043 @@ -33,6 +33,9 @@
2044 #include <asm/pgtable-2level.h>
2045 #endif
2046
2047 +#define ktla_ktva(addr) (addr)
2048 +#define ktva_ktla(addr) (addr)
2049 +
2050 /*
2051 * Just any arbitrary offset to the start of the vmalloc VM area: the
2052 * current 8MB value just means that there will be a 8MB "hole" after the
2053 @@ -48,6 +51,9 @@
2054 #define LIBRARY_TEXT_START 0x0c000000
2055
2056 #ifndef __ASSEMBLY__
2057 +extern pteval_t __supported_pte_mask;
2058 +extern pmdval_t __supported_pmd_mask;
2059 +
2060 extern void __pte_error(const char *file, int line, pte_t);
2061 extern void __pmd_error(const char *file, int line, pmd_t);
2062 extern void __pgd_error(const char *file, int line, pgd_t);
2063 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2064 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2065 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2066
2067 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2068 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2069 +
2070 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2071 +#include <asm/domain.h>
2072 +#include <linux/thread_info.h>
2073 +#include <linux/preempt.h>
2074 +
2075 +static inline int test_domain(int domain, int domaintype)
2076 +{
2077 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2078 +}
2079 +#endif
2080 +
2081 +#ifdef CONFIG_PAX_KERNEXEC
2082 +static inline unsigned long pax_open_kernel(void) {
2083 +#ifdef CONFIG_ARM_LPAE
2084 + /* TODO */
2085 +#else
2086 + preempt_disable();
2087 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2088 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2089 +#endif
2090 + return 0;
2091 +}
2092 +
2093 +static inline unsigned long pax_close_kernel(void) {
2094 +#ifdef CONFIG_ARM_LPAE
2095 + /* TODO */
2096 +#else
2097 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2098 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2099 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2100 + preempt_enable_no_resched();
2101 +#endif
2102 + return 0;
2103 +}
2104 +#else
2105 +static inline unsigned long pax_open_kernel(void) { return 0; }
2106 +static inline unsigned long pax_close_kernel(void) { return 0; }
2107 +#endif
2108 +
2109 /*
2110 * This is the lowest virtual address we can permit any user space
2111 * mapping to be mapped at. This is particularly important for
2112 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2113 /*
2114 * The pgprot_* and protection_map entries will be fixed up in runtime
2115 * to include the cachable and bufferable bits based on memory policy,
2116 - * as well as any architecture dependent bits like global/ASID and SMP
2117 - * shared mapping bits.
2118 + * as well as any architecture dependent bits like global/ASID, PXN,
2119 + * and SMP shared mapping bits.
2120 */
2121 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2122
2123 @@ -265,7 +313,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2124 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2125 {
2126 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2127 - L_PTE_NONE | L_PTE_VALID;
2128 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2129 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2130 return pte;
2131 }
2132 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2133 index c4ae171..ea0c0c2 100644
2134 --- a/arch/arm/include/asm/psci.h
2135 +++ b/arch/arm/include/asm/psci.h
2136 @@ -29,7 +29,7 @@ struct psci_operations {
2137 int (*cpu_off)(struct psci_power_state state);
2138 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2139 int (*migrate)(unsigned long cpuid);
2140 -};
2141 +} __no_const;
2142
2143 extern struct psci_operations psci_ops;
2144 extern struct smp_operations psci_smp_ops;
2145 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2146 index 2ec765c..beb1fe16 100644
2147 --- a/arch/arm/include/asm/smp.h
2148 +++ b/arch/arm/include/asm/smp.h
2149 @@ -113,7 +113,7 @@ struct smp_operations {
2150 int (*cpu_disable)(unsigned int cpu);
2151 #endif
2152 #endif
2153 -};
2154 +} __no_const;
2155
2156 struct of_cpu_method {
2157 const char *method;
2158 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2159 index f989d7c..e8aa7f0 100644
2160 --- a/arch/arm/include/asm/thread_info.h
2161 +++ b/arch/arm/include/asm/thread_info.h
2162 @@ -88,9 +88,9 @@ struct thread_info {
2163 .flags = 0, \
2164 .preempt_count = INIT_PREEMPT_COUNT, \
2165 .addr_limit = KERNEL_DS, \
2166 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2167 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2168 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2169 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2170 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2171 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2172 .restart_block = { \
2173 .fn = do_no_restart_syscall, \
2174 }, \
2175 @@ -158,7 +158,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2176 #define TIF_SYSCALL_AUDIT 9
2177 #define TIF_SYSCALL_TRACEPOINT 10
2178 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2179 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2180 +/* within 8 bits of TIF_SYSCALL_TRACE
2181 + * to meet flexible second operand requirements
2182 + */
2183 +#define TIF_GRSEC_SETXID 12
2184 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2185 #define TIF_USING_IWMMXT 17
2186 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2187 #define TIF_RESTORE_SIGMASK 20
2188 @@ -172,10 +176,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2189 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2190 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2191 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2192 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2193
2194 /* Checks for any syscall work in entry-common.S */
2195 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2196 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2197 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2198
2199 /*
2200 * Change these and you break ASM code in entry-common.S
2201 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2202 index 75d9579..b5b40e4 100644
2203 --- a/arch/arm/include/asm/uaccess.h
2204 +++ b/arch/arm/include/asm/uaccess.h
2205 @@ -18,6 +18,7 @@
2206 #include <asm/domain.h>
2207 #include <asm/unified.h>
2208 #include <asm/compiler.h>
2209 +#include <asm/pgtable.h>
2210
2211 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2212 #include <asm-generic/uaccess-unaligned.h>
2213 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2214 static inline void set_fs(mm_segment_t fs)
2215 {
2216 current_thread_info()->addr_limit = fs;
2217 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2218 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2219 }
2220
2221 #define segment_eq(a,b) ((a) == (b))
2222
2223 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2224 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2225 +
2226 +static inline void pax_open_userland(void)
2227 +{
2228 +
2229 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2230 + if (segment_eq(get_fs(), USER_DS)) {
2231 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2232 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2233 + }
2234 +#endif
2235 +
2236 +}
2237 +
2238 +static inline void pax_close_userland(void)
2239 +{
2240 +
2241 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2242 + if (segment_eq(get_fs(), USER_DS)) {
2243 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2244 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2245 + }
2246 +#endif
2247 +
2248 +}
2249 +
2250 #define __addr_ok(addr) ({ \
2251 unsigned long flag; \
2252 __asm__("cmp %2, %0; movlo %0, #0" \
2253 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2254
2255 #define get_user(x,p) \
2256 ({ \
2257 + int __e; \
2258 might_fault(); \
2259 - __get_user_check(x,p); \
2260 + pax_open_userland(); \
2261 + __e = __get_user_check(x,p); \
2262 + pax_close_userland(); \
2263 + __e; \
2264 })
2265
2266 extern int __put_user_1(void *, unsigned int);
2267 @@ -196,8 +228,12 @@ extern int __put_user_8(void *, unsigned long long);
2268
2269 #define put_user(x,p) \
2270 ({ \
2271 + int __e; \
2272 might_fault(); \
2273 - __put_user_check(x,p); \
2274 + pax_open_userland(); \
2275 + __e = __put_user_check(x,p); \
2276 + pax_close_userland(); \
2277 + __e; \
2278 })
2279
2280 #else /* CONFIG_MMU */
2281 @@ -221,6 +257,7 @@ static inline void set_fs(mm_segment_t fs)
2282
2283 #endif /* CONFIG_MMU */
2284
2285 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2286 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2287
2288 #define user_addr_max() \
2289 @@ -238,13 +275,17 @@ static inline void set_fs(mm_segment_t fs)
2290 #define __get_user(x,ptr) \
2291 ({ \
2292 long __gu_err = 0; \
2293 + pax_open_userland(); \
2294 __get_user_err((x),(ptr),__gu_err); \
2295 + pax_close_userland(); \
2296 __gu_err; \
2297 })
2298
2299 #define __get_user_error(x,ptr,err) \
2300 ({ \
2301 + pax_open_userland(); \
2302 __get_user_err((x),(ptr),err); \
2303 + pax_close_userland(); \
2304 (void) 0; \
2305 })
2306
2307 @@ -320,13 +361,17 @@ do { \
2308 #define __put_user(x,ptr) \
2309 ({ \
2310 long __pu_err = 0; \
2311 + pax_open_userland(); \
2312 __put_user_err((x),(ptr),__pu_err); \
2313 + pax_close_userland(); \
2314 __pu_err; \
2315 })
2316
2317 #define __put_user_error(x,ptr,err) \
2318 ({ \
2319 + pax_open_userland(); \
2320 __put_user_err((x),(ptr),err); \
2321 + pax_close_userland(); \
2322 (void) 0; \
2323 })
2324
2325 @@ -426,11 +471,44 @@ do { \
2326
2327
2328 #ifdef CONFIG_MMU
2329 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2330 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2331 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2332 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2333 +
2334 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2335 +{
2336 + unsigned long ret;
2337 +
2338 + check_object_size(to, n, false);
2339 + pax_open_userland();
2340 + ret = ___copy_from_user(to, from, n);
2341 + pax_close_userland();
2342 + return ret;
2343 +}
2344 +
2345 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2346 +{
2347 + unsigned long ret;
2348 +
2349 + check_object_size(from, n, true);
2350 + pax_open_userland();
2351 + ret = ___copy_to_user(to, from, n);
2352 + pax_close_userland();
2353 + return ret;
2354 +}
2355 +
2356 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, 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(void __user *addr, unsigned long n);
2359 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2360 +
2361 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2362 +{
2363 + unsigned long ret;
2364 + pax_open_userland();
2365 + ret = ___clear_user(addr, n);
2366 + pax_close_userland();
2367 + return ret;
2368 +}
2369 +
2370 #else
2371 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2372 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2373 @@ -439,6 +517,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2374
2375 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2376 {
2377 + if ((long)n < 0)
2378 + return n;
2379 +
2380 if (access_ok(VERIFY_READ, from, n))
2381 n = __copy_from_user(to, from, n);
2382 else /* security hole - plug it */
2383 @@ -448,6 +529,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2384
2385 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2386 {
2387 + if ((long)n < 0)
2388 + return n;
2389 +
2390 if (access_ok(VERIFY_WRITE, to, n))
2391 n = __copy_to_user(to, from, n);
2392 return n;
2393 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2394 index 5af0ed1..cea83883 100644
2395 --- a/arch/arm/include/uapi/asm/ptrace.h
2396 +++ b/arch/arm/include/uapi/asm/ptrace.h
2397 @@ -92,7 +92,7 @@
2398 * ARMv7 groups of PSR bits
2399 */
2400 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2401 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2402 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2403 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2404 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2405
2406 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2407 index f7b450f..f5364c5 100644
2408 --- a/arch/arm/kernel/armksyms.c
2409 +++ b/arch/arm/kernel/armksyms.c
2410 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2411
2412 /* networking */
2413 EXPORT_SYMBOL(csum_partial);
2414 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2415 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2416 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2417 EXPORT_SYMBOL(__csum_ipv6_magic);
2418
2419 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2420 #ifdef CONFIG_MMU
2421 EXPORT_SYMBOL(copy_page);
2422
2423 -EXPORT_SYMBOL(__copy_from_user);
2424 -EXPORT_SYMBOL(__copy_to_user);
2425 -EXPORT_SYMBOL(__clear_user);
2426 +EXPORT_SYMBOL(___copy_from_user);
2427 +EXPORT_SYMBOL(___copy_to_user);
2428 +EXPORT_SYMBOL(___clear_user);
2429
2430 EXPORT_SYMBOL(__get_user_1);
2431 EXPORT_SYMBOL(__get_user_2);
2432 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2433 index 1879e8d..5602dd4 100644
2434 --- a/arch/arm/kernel/entry-armv.S
2435 +++ b/arch/arm/kernel/entry-armv.S
2436 @@ -47,6 +47,87 @@
2437 9997:
2438 .endm
2439
2440 + .macro pax_enter_kernel
2441 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2442 + @ make aligned space for saved DACR
2443 + sub sp, sp, #8
2444 + @ save regs
2445 + stmdb sp!, {r1, r2}
2446 + @ read DACR from cpu_domain into r1
2447 + mov r2, sp
2448 + @ assume 8K pages, since we have to split the immediate in two
2449 + bic r2, r2, #(0x1fc0)
2450 + bic r2, r2, #(0x3f)
2451 + ldr r1, [r2, #TI_CPU_DOMAIN]
2452 + @ store old DACR on stack
2453 + str r1, [sp, #8]
2454 +#ifdef CONFIG_PAX_KERNEXEC
2455 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2456 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2457 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2458 +#endif
2459 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2460 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2461 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2462 +#endif
2463 + @ write r1 to current_thread_info()->cpu_domain
2464 + str r1, [r2, #TI_CPU_DOMAIN]
2465 + @ write r1 to DACR
2466 + mcr p15, 0, r1, c3, c0, 0
2467 + @ instruction sync
2468 + instr_sync
2469 + @ restore regs
2470 + ldmia sp!, {r1, r2}
2471 +#endif
2472 + .endm
2473 +
2474 + .macro pax_open_userland
2475 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2476 + @ save regs
2477 + stmdb sp!, {r0, r1}
2478 + @ read DACR from cpu_domain into r1
2479 + mov r0, sp
2480 + @ assume 8K pages, since we have to split the immediate in two
2481 + bic r0, r0, #(0x1fc0)
2482 + bic r0, r0, #(0x3f)
2483 + ldr r1, [r0, #TI_CPU_DOMAIN]
2484 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2485 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2486 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2487 + @ write r1 to current_thread_info()->cpu_domain
2488 + str r1, [r0, #TI_CPU_DOMAIN]
2489 + @ write r1 to DACR
2490 + mcr p15, 0, r1, c3, c0, 0
2491 + @ instruction sync
2492 + instr_sync
2493 + @ restore regs
2494 + ldmia sp!, {r0, r1}
2495 +#endif
2496 + .endm
2497 +
2498 + .macro pax_close_userland
2499 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2500 + @ save regs
2501 + stmdb sp!, {r0, r1}
2502 + @ read DACR from cpu_domain into r1
2503 + mov r0, sp
2504 + @ assume 8K pages, since we have to split the immediate in two
2505 + bic r0, r0, #(0x1fc0)
2506 + bic r0, r0, #(0x3f)
2507 + ldr r1, [r0, #TI_CPU_DOMAIN]
2508 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2509 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2510 + @ write r1 to current_thread_info()->cpu_domain
2511 + str r1, [r0, #TI_CPU_DOMAIN]
2512 + @ write r1 to DACR
2513 + mcr p15, 0, r1, c3, c0, 0
2514 + @ instruction sync
2515 + instr_sync
2516 + @ restore regs
2517 + ldmia sp!, {r0, r1}
2518 +#endif
2519 + .endm
2520 +
2521 .macro pabt_helper
2522 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2523 #ifdef MULTI_PABORT
2524 @@ -89,11 +170,15 @@
2525 * Invalid mode handlers
2526 */
2527 .macro inv_entry, reason
2528 +
2529 + pax_enter_kernel
2530 +
2531 sub sp, sp, #S_FRAME_SIZE
2532 ARM( stmib sp, {r1 - lr} )
2533 THUMB( stmia sp, {r0 - r12} )
2534 THUMB( str sp, [sp, #S_SP] )
2535 THUMB( str lr, [sp, #S_LR] )
2536 +
2537 mov r1, #\reason
2538 .endm
2539
2540 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2541 .macro svc_entry, stack_hole=0
2542 UNWIND(.fnstart )
2543 UNWIND(.save {r0 - pc} )
2544 +
2545 + pax_enter_kernel
2546 +
2547 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2548 +
2549 #ifdef CONFIG_THUMB2_KERNEL
2550 SPFIX( str r0, [sp] ) @ temporarily saved
2551 SPFIX( mov r0, sp )
2552 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2553 ldmia r0, {r3 - r5}
2554 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2555 mov r6, #-1 @ "" "" "" ""
2556 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2557 + @ offset sp by 8 as done in pax_enter_kernel
2558 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2559 +#else
2560 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2561 +#endif
2562 SPFIX( addeq r2, r2, #4 )
2563 str r3, [sp, #-4]! @ save the "real" r0 copied
2564 @ from the exception stack
2565 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2566 .macro usr_entry
2567 UNWIND(.fnstart )
2568 UNWIND(.cantunwind ) @ don't unwind the user space
2569 +
2570 + pax_enter_kernel_user
2571 +
2572 sub sp, sp, #S_FRAME_SIZE
2573 ARM( stmib sp, {r1 - r12} )
2574 THUMB( stmia sp, {r0 - r12} )
2575 @@ -416,7 +513,9 @@ __und_usr:
2576 tst r3, #PSR_T_BIT @ Thumb mode?
2577 bne __und_usr_thumb
2578 sub r4, r2, #4 @ ARM instr at LR - 4
2579 + pax_open_userland
2580 1: ldrt r0, [r4]
2581 + pax_close_userland
2582 ARM_BE8(rev r0, r0) @ little endian instruction
2583
2584 @ r0 = 32-bit ARM instruction which caused the exception
2585 @@ -450,11 +549,15 @@ __und_usr_thumb:
2586 */
2587 .arch armv6t2
2588 #endif
2589 + pax_open_userland
2590 2: ldrht r5, [r4]
2591 + pax_close_userland
2592 ARM_BE8(rev16 r5, r5) @ little endian instruction
2593 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2594 blo __und_usr_fault_16 @ 16bit undefined instruction
2595 + pax_open_userland
2596 3: ldrht r0, [r2]
2597 + pax_close_userland
2598 ARM_BE8(rev16 r0, r0) @ little endian instruction
2599 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2600 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2601 @@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2602 */
2603 .pushsection .fixup, "ax"
2604 .align 2
2605 -4: mov pc, r9
2606 +4: pax_close_userland
2607 + mov pc, r9
2608 .popsection
2609 .pushsection __ex_table,"a"
2610 .long 1b, 4b
2611 @@ -694,7 +798,7 @@ ENTRY(__switch_to)
2612 THUMB( str lr, [ip], #4 )
2613 ldr r4, [r2, #TI_TP_VALUE]
2614 ldr r5, [r2, #TI_TP_VALUE + 4]
2615 -#ifdef CONFIG_CPU_USE_DOMAINS
2616 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2617 ldr r6, [r2, #TI_CPU_DOMAIN]
2618 #endif
2619 switch_tls r1, r4, r5, r3, r7
2620 @@ -703,7 +807,7 @@ ENTRY(__switch_to)
2621 ldr r8, =__stack_chk_guard
2622 ldr r7, [r7, #TSK_STACK_CANARY]
2623 #endif
2624 -#ifdef CONFIG_CPU_USE_DOMAINS
2625 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2626 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2627 #endif
2628 mov r5, r0
2629 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2630 index a2dcafd..1048b5a 100644
2631 --- a/arch/arm/kernel/entry-common.S
2632 +++ b/arch/arm/kernel/entry-common.S
2633 @@ -10,18 +10,46 @@
2634
2635 #include <asm/unistd.h>
2636 #include <asm/ftrace.h>
2637 +#include <asm/domain.h>
2638 #include <asm/unwind.h>
2639
2640 +#include "entry-header.S"
2641 +
2642 #ifdef CONFIG_NEED_RET_TO_USER
2643 #include <mach/entry-macro.S>
2644 #else
2645 .macro arch_ret_to_user, tmp1, tmp2
2646 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2647 + @ save regs
2648 + stmdb sp!, {r1, r2}
2649 + @ read DACR from cpu_domain into r1
2650 + mov r2, sp
2651 + @ assume 8K pages, since we have to split the immediate in two
2652 + bic r2, r2, #(0x1fc0)
2653 + bic r2, r2, #(0x3f)
2654 + ldr r1, [r2, #TI_CPU_DOMAIN]
2655 +#ifdef CONFIG_PAX_KERNEXEC
2656 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2657 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2658 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2659 +#endif
2660 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2661 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2662 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2663 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2664 +#endif
2665 + @ write r1 to current_thread_info()->cpu_domain
2666 + str r1, [r2, #TI_CPU_DOMAIN]
2667 + @ write r1 to DACR
2668 + mcr p15, 0, r1, c3, c0, 0
2669 + @ instruction sync
2670 + instr_sync
2671 + @ restore regs
2672 + ldmia sp!, {r1, r2}
2673 +#endif
2674 .endm
2675 #endif
2676
2677 -#include "entry-header.S"
2678 -
2679 -
2680 .align 5
2681 /*
2682 * This is the fast syscall return path. We do as little as
2683 @@ -411,6 +439,12 @@ ENTRY(vector_swi)
2684 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2685 #endif
2686
2687 + /*
2688 + * do this here to avoid a performance hit of wrapping the code above
2689 + * that directly dereferences userland to parse the SWI instruction
2690 + */
2691 + pax_enter_kernel_user
2692 +
2693 adr tbl, sys_call_table @ load syscall table pointer
2694
2695 #if defined(CONFIG_OABI_COMPAT)
2696 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2697 index efb208d..d34bd02 100644
2698 --- a/arch/arm/kernel/entry-header.S
2699 +++ b/arch/arm/kernel/entry-header.S
2700 @@ -188,6 +188,60 @@
2701 msr cpsr_c, \rtemp @ switch back to the SVC mode
2702 .endm
2703
2704 + .macro pax_enter_kernel_user
2705 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2706 + @ save regs
2707 + stmdb sp!, {r0, r1}
2708 + @ read DACR from cpu_domain into r1
2709 + mov r0, sp
2710 + @ assume 8K pages, since we have to split the immediate in two
2711 + bic r0, r0, #(0x1fc0)
2712 + bic r0, r0, #(0x3f)
2713 + ldr r1, [r0, #TI_CPU_DOMAIN]
2714 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2715 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2716 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2717 +#endif
2718 +#ifdef CONFIG_PAX_KERNEXEC
2719 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2720 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2721 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2722 +#endif
2723 + @ write r1 to current_thread_info()->cpu_domain
2724 + str r1, [r0, #TI_CPU_DOMAIN]
2725 + @ write r1 to DACR
2726 + mcr p15, 0, r1, c3, c0, 0
2727 + @ instruction sync
2728 + instr_sync
2729 + @ restore regs
2730 + ldmia sp!, {r0, r1}
2731 +#endif
2732 + .endm
2733 +
2734 + .macro pax_exit_kernel
2735 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2736 + @ save regs
2737 + stmdb sp!, {r0, r1}
2738 + @ read old DACR from stack into r1
2739 + ldr r1, [sp, #(8 + S_SP)]
2740 + sub r1, r1, #8
2741 + ldr r1, [r1]
2742 +
2743 + @ write r1 to current_thread_info()->cpu_domain
2744 + mov r0, sp
2745 + @ assume 8K pages, since we have to split the immediate in two
2746 + bic r0, r0, #(0x1fc0)
2747 + bic r0, r0, #(0x3f)
2748 + str r1, [r0, #TI_CPU_DOMAIN]
2749 + @ write r1 to DACR
2750 + mcr p15, 0, r1, c3, c0, 0
2751 + @ instruction sync
2752 + instr_sync
2753 + @ restore regs
2754 + ldmia sp!, {r0, r1}
2755 +#endif
2756 + .endm
2757 +
2758 #ifndef CONFIG_THUMB2_KERNEL
2759 .macro svc_exit, rpsr, irq = 0
2760 .if \irq != 0
2761 @@ -207,6 +261,9 @@
2762 blne trace_hardirqs_off
2763 #endif
2764 .endif
2765 +
2766 + pax_exit_kernel
2767 +
2768 msr spsr_cxsf, \rpsr
2769 #if defined(CONFIG_CPU_V6)
2770 ldr r0, [sp]
2771 @@ -265,6 +322,9 @@
2772 blne trace_hardirqs_off
2773 #endif
2774 .endif
2775 +
2776 + pax_exit_kernel
2777 +
2778 ldr lr, [sp, #S_SP] @ top of the stack
2779 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2780 clrex @ clear the exclusive monitor
2781 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2782 index 918875d..cd5fa27 100644
2783 --- a/arch/arm/kernel/fiq.c
2784 +++ b/arch/arm/kernel/fiq.c
2785 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2786 void *base = vectors_page;
2787 unsigned offset = FIQ_OFFSET;
2788
2789 + pax_open_kernel();
2790 memcpy(base + offset, start, length);
2791 + pax_close_kernel();
2792 +
2793 if (!cache_is_vipt_nonaliasing())
2794 flush_icache_range((unsigned long)base + offset, offset +
2795 length);
2796 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2797 index 591d6e4..8322a26 100644
2798 --- a/arch/arm/kernel/head.S
2799 +++ b/arch/arm/kernel/head.S
2800 @@ -437,7 +437,7 @@ __enable_mmu:
2801 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2802 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2803 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2804 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2805 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2806 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2807 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2808 #endif
2809 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2810 index 45e4781..8eac93d 100644
2811 --- a/arch/arm/kernel/module.c
2812 +++ b/arch/arm/kernel/module.c
2813 @@ -38,12 +38,39 @@
2814 #endif
2815
2816 #ifdef CONFIG_MMU
2817 -void *module_alloc(unsigned long size)
2818 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2819 {
2820 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2821 + return NULL;
2822 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2823 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2824 + GFP_KERNEL, prot, NUMA_NO_NODE,
2825 __builtin_return_address(0));
2826 }
2827 +
2828 +void *module_alloc(unsigned long size)
2829 +{
2830 +
2831 +#ifdef CONFIG_PAX_KERNEXEC
2832 + return __module_alloc(size, PAGE_KERNEL);
2833 +#else
2834 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2835 +#endif
2836 +
2837 +}
2838 +
2839 +#ifdef CONFIG_PAX_KERNEXEC
2840 +void module_free_exec(struct module *mod, void *module_region)
2841 +{
2842 + module_free(mod, module_region);
2843 +}
2844 +EXPORT_SYMBOL(module_free_exec);
2845 +
2846 +void *module_alloc_exec(unsigned long size)
2847 +{
2848 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2849 +}
2850 +EXPORT_SYMBOL(module_alloc_exec);
2851 +#endif
2852 #endif
2853
2854 int
2855 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2856 index 07314af..c46655c 100644
2857 --- a/arch/arm/kernel/patch.c
2858 +++ b/arch/arm/kernel/patch.c
2859 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2860 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2861 int size;
2862
2863 + pax_open_kernel();
2864 if (thumb2 && __opcode_is_thumb16(insn)) {
2865 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2866 size = sizeof(u16);
2867 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2868 *(u32 *)addr = insn;
2869 size = sizeof(u32);
2870 }
2871 + pax_close_kernel();
2872
2873 flush_icache_range((uintptr_t)(addr),
2874 (uintptr_t)(addr) + size);
2875 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2876 index 81ef686..f4130b8 100644
2877 --- a/arch/arm/kernel/process.c
2878 +++ b/arch/arm/kernel/process.c
2879 @@ -212,6 +212,7 @@ void machine_power_off(void)
2880
2881 if (pm_power_off)
2882 pm_power_off();
2883 + BUG();
2884 }
2885
2886 /*
2887 @@ -225,7 +226,7 @@ void machine_power_off(void)
2888 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2889 * to use. Implementing such co-ordination would be essentially impossible.
2890 */
2891 -void machine_restart(char *cmd)
2892 +__noreturn void machine_restart(char *cmd)
2893 {
2894 local_irq_disable();
2895 smp_send_stop();
2896 @@ -248,8 +249,8 @@ void __show_regs(struct pt_regs *regs)
2897
2898 show_regs_print_info(KERN_DEFAULT);
2899
2900 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2901 - print_symbol("LR is at %s\n", regs->ARM_lr);
2902 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2903 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2904 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2905 "sp : %08lx ip : %08lx fp : %08lx\n",
2906 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2907 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2908 return 0;
2909 }
2910
2911 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2912 -{
2913 - unsigned long range_end = mm->brk + 0x02000000;
2914 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2915 -}
2916 -
2917 #ifdef CONFIG_MMU
2918 #ifdef CONFIG_KUSER_HELPERS
2919 /*
2920 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2921
2922 static int __init gate_vma_init(void)
2923 {
2924 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2925 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2926 return 0;
2927 }
2928 arch_initcall(gate_vma_init);
2929 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2930
2931 const char *arch_vma_name(struct vm_area_struct *vma)
2932 {
2933 - return is_gate_vma(vma) ? "[vectors]" :
2934 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2935 - "[sigpage]" : NULL;
2936 + return is_gate_vma(vma) ? "[vectors]" : NULL;
2937 }
2938
2939 -static struct page *signal_page;
2940 -extern struct page *get_signal_page(void);
2941 -
2942 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2943 {
2944 struct mm_struct *mm = current->mm;
2945 - unsigned long addr;
2946 - int ret;
2947 -
2948 - if (!signal_page)
2949 - signal_page = get_signal_page();
2950 - if (!signal_page)
2951 - return -ENOMEM;
2952
2953 down_write(&mm->mmap_sem);
2954 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2955 - if (IS_ERR_VALUE(addr)) {
2956 - ret = addr;
2957 - goto up_fail;
2958 - }
2959 -
2960 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
2961 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2962 - &signal_page);
2963 -
2964 - if (ret == 0)
2965 - mm->context.sigpage = addr;
2966 -
2967 - up_fail:
2968 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2969 up_write(&mm->mmap_sem);
2970 - return ret;
2971 + return 0;
2972 }
2973 #endif
2974 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2975 index 4693188..4596c5e 100644
2976 --- a/arch/arm/kernel/psci.c
2977 +++ b/arch/arm/kernel/psci.c
2978 @@ -24,7 +24,7 @@
2979 #include <asm/opcodes-virt.h>
2980 #include <asm/psci.h>
2981
2982 -struct psci_operations psci_ops;
2983 +struct psci_operations psci_ops __read_only;
2984
2985 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2986
2987 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2988 index 0dd3b79..b67388e 100644
2989 --- a/arch/arm/kernel/ptrace.c
2990 +++ b/arch/arm/kernel/ptrace.c
2991 @@ -908,7 +908,7 @@ enum ptrace_syscall_dir {
2992 PTRACE_SYSCALL_EXIT,
2993 };
2994
2995 -static int tracehook_report_syscall(struct pt_regs *regs,
2996 +static void tracehook_report_syscall(struct pt_regs *regs,
2997 enum ptrace_syscall_dir dir)
2998 {
2999 unsigned long ip;
3000 @@ -926,19 +926,29 @@ static int tracehook_report_syscall(struct pt_regs *regs,
3001 current_thread_info()->syscall = -1;
3002
3003 regs->ARM_ip = ip;
3004 - return current_thread_info()->syscall;
3005 }
3006
3007 +#ifdef CONFIG_GRKERNSEC_SETXID
3008 +extern void gr_delayed_cred_worker(void);
3009 +#endif
3010 +
3011 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3012 {
3013 current_thread_info()->syscall = scno;
3014
3015 +#ifdef CONFIG_GRKERNSEC_SETXID
3016 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3017 + gr_delayed_cred_worker();
3018 +#endif
3019 +
3020 /* Do the secure computing check first; failures should be fast. */
3021 if (secure_computing(scno) == -1)
3022 return -1;
3023
3024 if (test_thread_flag(TIF_SYSCALL_TRACE))
3025 - scno = tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
3026 + tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
3027 +
3028 + scno = current_thread_info()->syscall;
3029
3030 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
3031 trace_sys_enter(regs, scno);
3032 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3033 index 50e198c..a8b5f49 100644
3034 --- a/arch/arm/kernel/setup.c
3035 +++ b/arch/arm/kernel/setup.c
3036 @@ -103,21 +103,23 @@ EXPORT_SYMBOL(elf_hwcap);
3037 unsigned int elf_hwcap2 __read_mostly;
3038 EXPORT_SYMBOL(elf_hwcap2);
3039
3040 +pteval_t __supported_pte_mask __read_only;
3041 +pmdval_t __supported_pmd_mask __read_only;
3042
3043 #ifdef MULTI_CPU
3044 -struct processor processor __read_mostly;
3045 +struct processor processor __read_only;
3046 #endif
3047 #ifdef MULTI_TLB
3048 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3049 +struct cpu_tlb_fns cpu_tlb __read_only;
3050 #endif
3051 #ifdef MULTI_USER
3052 -struct cpu_user_fns cpu_user __read_mostly;
3053 +struct cpu_user_fns cpu_user __read_only;
3054 #endif
3055 #ifdef MULTI_CACHE
3056 -struct cpu_cache_fns cpu_cache __read_mostly;
3057 +struct cpu_cache_fns cpu_cache __read_only;
3058 #endif
3059 #ifdef CONFIG_OUTER_CACHE
3060 -struct outer_cache_fns outer_cache __read_mostly;
3061 +struct outer_cache_fns outer_cache __read_only;
3062 EXPORT_SYMBOL(outer_cache);
3063 #endif
3064
3065 @@ -250,9 +252,13 @@ static int __get_cpu_architecture(void)
3066 asm("mrc p15, 0, %0, c0, c1, 4"
3067 : "=r" (mmfr0));
3068 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3069 - (mmfr0 & 0x000000f0) >= 0x00000030)
3070 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3071 cpu_arch = CPU_ARCH_ARMv7;
3072 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3073 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3074 + __supported_pte_mask |= L_PTE_PXN;
3075 + __supported_pmd_mask |= PMD_PXNTABLE;
3076 + }
3077 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3078 (mmfr0 & 0x000000f0) == 0x00000020)
3079 cpu_arch = CPU_ARCH_ARMv6;
3080 else
3081 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3082 index bd19834..e4d8c66 100644
3083 --- a/arch/arm/kernel/signal.c
3084 +++ b/arch/arm/kernel/signal.c
3085 @@ -24,8 +24,6 @@
3086
3087 extern const unsigned long sigreturn_codes[7];
3088
3089 -static unsigned long signal_return_offset;
3090 -
3091 #ifdef CONFIG_CRUNCH
3092 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3093 {
3094 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3095 * except when the MPU has protected the vectors
3096 * page from PL0
3097 */
3098 - retcode = mm->context.sigpage + signal_return_offset +
3099 - (idx << 2) + thumb;
3100 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3101 } else
3102 #endif
3103 {
3104 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3105 } while (thread_flags & _TIF_WORK_MASK);
3106 return 0;
3107 }
3108 -
3109 -struct page *get_signal_page(void)
3110 -{
3111 - unsigned long ptr;
3112 - unsigned offset;
3113 - struct page *page;
3114 - void *addr;
3115 -
3116 - page = alloc_pages(GFP_KERNEL, 0);
3117 -
3118 - if (!page)
3119 - return NULL;
3120 -
3121 - addr = page_address(page);
3122 -
3123 - /* Give the signal return code some randomness */
3124 - offset = 0x200 + (get_random_int() & 0x7fc);
3125 - signal_return_offset = offset;
3126 -
3127 - /*
3128 - * Copy signal return handlers into the vector page, and
3129 - * set sigreturn to be a pointer to these.
3130 - */
3131 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3132 -
3133 - ptr = (unsigned long)addr + offset;
3134 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3135 -
3136 - return page;
3137 -}
3138 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3139 index 7c4fada..8581286 100644
3140 --- a/arch/arm/kernel/smp.c
3141 +++ b/arch/arm/kernel/smp.c
3142 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3143
3144 static DECLARE_COMPLETION(cpu_running);
3145
3146 -static struct smp_operations smp_ops;
3147 +static struct smp_operations smp_ops __read_only;
3148
3149 void __init smp_set_ops(struct smp_operations *ops)
3150 {
3151 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3152 index 7a3be1d..b00c7de 100644
3153 --- a/arch/arm/kernel/tcm.c
3154 +++ b/arch/arm/kernel/tcm.c
3155 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3156 .virtual = ITCM_OFFSET,
3157 .pfn = __phys_to_pfn(ITCM_OFFSET),
3158 .length = 0,
3159 - .type = MT_MEMORY_RWX_ITCM,
3160 + .type = MT_MEMORY_RX_ITCM,
3161 }
3162 };
3163
3164 @@ -267,7 +267,9 @@ no_dtcm:
3165 start = &__sitcm_text;
3166 end = &__eitcm_text;
3167 ram = &__itcm_start;
3168 + pax_open_kernel();
3169 memcpy(start, ram, itcm_code_sz);
3170 + pax_close_kernel();
3171 pr_debug("CPU ITCM: copied code from %p - %p\n",
3172 start, end);
3173 itcm_present = true;
3174 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3175 index abd2fc0..895dbb6 100644
3176 --- a/arch/arm/kernel/traps.c
3177 +++ b/arch/arm/kernel/traps.c
3178 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3179 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3180 {
3181 #ifdef CONFIG_KALLSYMS
3182 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3183 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3184 #else
3185 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3186 #endif
3187 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3188 static int die_owner = -1;
3189 static unsigned int die_nest_count;
3190
3191 +extern void gr_handle_kernel_exploit(void);
3192 +
3193 static unsigned long oops_begin(void)
3194 {
3195 int cpu;
3196 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3197 panic("Fatal exception in interrupt");
3198 if (panic_on_oops)
3199 panic("Fatal exception");
3200 +
3201 + gr_handle_kernel_exploit();
3202 +
3203 if (signr)
3204 do_exit(signr);
3205 }
3206 @@ -643,7 +648,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3207 * The user helper at 0xffff0fe0 must be used instead.
3208 * (see entry-armv.S for details)
3209 */
3210 + pax_open_kernel();
3211 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3212 + pax_close_kernel();
3213 }
3214 return 0;
3215
3216 @@ -900,7 +907,11 @@ void __init early_trap_init(void *vectors_base)
3217 kuser_init(vectors_base);
3218
3219 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3220 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3221 +
3222 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3223 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3224 +#endif
3225 +
3226 #else /* ifndef CONFIG_CPU_V7M */
3227 /*
3228 * on V7-M there is no need to copy the vector table to a dedicated
3229 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3230 index 7bcee5c..e2f3249 100644
3231 --- a/arch/arm/kernel/vmlinux.lds.S
3232 +++ b/arch/arm/kernel/vmlinux.lds.S
3233 @@ -8,7 +8,11 @@
3234 #include <asm/thread_info.h>
3235 #include <asm/memory.h>
3236 #include <asm/page.h>
3237 -
3238 +
3239 +#ifdef CONFIG_PAX_KERNEXEC
3240 +#include <asm/pgtable.h>
3241 +#endif
3242 +
3243 #define PROC_INFO \
3244 . = ALIGN(4); \
3245 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3246 @@ -34,7 +38,7 @@
3247 #endif
3248
3249 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3250 - defined(CONFIG_GENERIC_BUG)
3251 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3252 #define ARM_EXIT_KEEP(x) x
3253 #define ARM_EXIT_DISCARD(x)
3254 #else
3255 @@ -90,6 +94,11 @@ SECTIONS
3256 _text = .;
3257 HEAD_TEXT
3258 }
3259 +
3260 +#ifdef CONFIG_PAX_KERNEXEC
3261 + . = ALIGN(1<<SECTION_SHIFT);
3262 +#endif
3263 +
3264 .text : { /* Real text segment */
3265 _stext = .; /* Text and read-only data */
3266 __exception_text_start = .;
3267 @@ -112,6 +121,8 @@ SECTIONS
3268 ARM_CPU_KEEP(PROC_INFO)
3269 }
3270
3271 + _etext = .; /* End of text section */
3272 +
3273 RO_DATA(PAGE_SIZE)
3274
3275 . = ALIGN(4);
3276 @@ -142,7 +153,9 @@ SECTIONS
3277
3278 NOTES
3279
3280 - _etext = .; /* End of text and rodata section */
3281 +#ifdef CONFIG_PAX_KERNEXEC
3282 + . = ALIGN(1<<SECTION_SHIFT);
3283 +#endif
3284
3285 #ifndef CONFIG_XIP_KERNEL
3286 . = ALIGN(PAGE_SIZE);
3287 @@ -220,6 +233,11 @@ SECTIONS
3288 . = PAGE_OFFSET + TEXT_OFFSET;
3289 #else
3290 __init_end = .;
3291 +
3292 +#ifdef CONFIG_PAX_KERNEXEC
3293 + . = ALIGN(1<<SECTION_SHIFT);
3294 +#endif
3295 +
3296 . = ALIGN(THREAD_SIZE);
3297 __data_loc = .;
3298 #endif
3299 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3300 index f0e50a0..8d5d36c 100644
3301 --- a/arch/arm/kvm/arm.c
3302 +++ b/arch/arm/kvm/arm.c
3303 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3304 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3305
3306 /* The VMID used in the VTTBR */
3307 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3308 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3309 static u8 kvm_next_vmid;
3310 static DEFINE_SPINLOCK(kvm_vmid_lock);
3311
3312 @@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3313 */
3314 static bool need_new_vmid_gen(struct kvm *kvm)
3315 {
3316 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3317 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3318 }
3319
3320 /**
3321 @@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3322
3323 /* First user of a new VMID generation? */
3324 if (unlikely(kvm_next_vmid == 0)) {
3325 - atomic64_inc(&kvm_vmid_gen);
3326 + atomic64_inc_unchecked(&kvm_vmid_gen);
3327 kvm_next_vmid = 1;
3328
3329 /*
3330 @@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3331 kvm_call_hyp(__kvm_flush_vm_context);
3332 }
3333
3334 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3335 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3336 kvm->arch.vmid = kvm_next_vmid;
3337 kvm_next_vmid++;
3338
3339 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3340 index 14a0d98..7771a7d 100644
3341 --- a/arch/arm/lib/clear_user.S
3342 +++ b/arch/arm/lib/clear_user.S
3343 @@ -12,14 +12,14 @@
3344
3345 .text
3346
3347 -/* Prototype: int __clear_user(void *addr, size_t sz)
3348 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3349 * Purpose : clear some user memory
3350 * Params : addr - user memory address to clear
3351 * : sz - number of bytes to clear
3352 * Returns : number of bytes NOT cleared
3353 */
3354 ENTRY(__clear_user_std)
3355 -WEAK(__clear_user)
3356 +WEAK(___clear_user)
3357 stmfd sp!, {r1, lr}
3358 mov r2, #0
3359 cmp r1, #4
3360 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3361 USER( strnebt r2, [r0])
3362 mov r0, #0
3363 ldmfd sp!, {r1, pc}
3364 -ENDPROC(__clear_user)
3365 +ENDPROC(___clear_user)
3366 ENDPROC(__clear_user_std)
3367
3368 .pushsection .fixup,"ax"
3369 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3370 index 66a477a..bee61d3 100644
3371 --- a/arch/arm/lib/copy_from_user.S
3372 +++ b/arch/arm/lib/copy_from_user.S
3373 @@ -16,7 +16,7 @@
3374 /*
3375 * Prototype:
3376 *
3377 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3378 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3379 *
3380 * Purpose:
3381 *
3382 @@ -84,11 +84,11 @@
3383
3384 .text
3385
3386 -ENTRY(__copy_from_user)
3387 +ENTRY(___copy_from_user)
3388
3389 #include "copy_template.S"
3390
3391 -ENDPROC(__copy_from_user)
3392 +ENDPROC(___copy_from_user)
3393
3394 .pushsection .fixup,"ax"
3395 .align 0
3396 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3397 index 6ee2f67..d1cce76 100644
3398 --- a/arch/arm/lib/copy_page.S
3399 +++ b/arch/arm/lib/copy_page.S
3400 @@ -10,6 +10,7 @@
3401 * ASM optimised string functions
3402 */
3403 #include <linux/linkage.h>
3404 +#include <linux/const.h>
3405 #include <asm/assembler.h>
3406 #include <asm/asm-offsets.h>
3407 #include <asm/cache.h>
3408 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3409 index d066df6..df28194 100644
3410 --- a/arch/arm/lib/copy_to_user.S
3411 +++ b/arch/arm/lib/copy_to_user.S
3412 @@ -16,7 +16,7 @@
3413 /*
3414 * Prototype:
3415 *
3416 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3417 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3418 *
3419 * Purpose:
3420 *
3421 @@ -88,11 +88,11 @@
3422 .text
3423
3424 ENTRY(__copy_to_user_std)
3425 -WEAK(__copy_to_user)
3426 +WEAK(___copy_to_user)
3427
3428 #include "copy_template.S"
3429
3430 -ENDPROC(__copy_to_user)
3431 +ENDPROC(___copy_to_user)
3432 ENDPROC(__copy_to_user_std)
3433
3434 .pushsection .fixup,"ax"
3435 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3436 index 7d08b43..f7ca7ea 100644
3437 --- a/arch/arm/lib/csumpartialcopyuser.S
3438 +++ b/arch/arm/lib/csumpartialcopyuser.S
3439 @@ -57,8 +57,8 @@
3440 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3441 */
3442
3443 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3444 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3445 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3446 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3447
3448 #include "csumpartialcopygeneric.S"
3449
3450 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3451 index 5306de3..aed6d03 100644
3452 --- a/arch/arm/lib/delay.c
3453 +++ b/arch/arm/lib/delay.c
3454 @@ -28,7 +28,7 @@
3455 /*
3456 * Default to the loop-based delay implementation.
3457 */
3458 -struct arm_delay_ops arm_delay_ops = {
3459 +struct arm_delay_ops arm_delay_ops __read_only = {
3460 .delay = __loop_delay,
3461 .const_udelay = __loop_const_udelay,
3462 .udelay = __loop_udelay,
3463 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3464 index 3e58d71..029817c 100644
3465 --- a/arch/arm/lib/uaccess_with_memcpy.c
3466 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3467 @@ -136,7 +136,7 @@ out:
3468 }
3469
3470 unsigned long
3471 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3472 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3473 {
3474 /*
3475 * This test is stubbed out of the main function above to keep
3476 @@ -190,7 +190,7 @@ out:
3477 return n;
3478 }
3479
3480 -unsigned long __clear_user(void __user *addr, unsigned long n)
3481 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3482 {
3483 /* See rational for this in __copy_to_user() above. */
3484 if (n < 64)
3485 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3486 index f7a07a5..258e1f7 100644
3487 --- a/arch/arm/mach-at91/setup.c
3488 +++ b/arch/arm/mach-at91/setup.c
3489 @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3490
3491 desc->pfn = __phys_to_pfn(base);
3492 desc->length = length;
3493 - desc->type = MT_MEMORY_RWX_NONCACHED;
3494 + desc->type = MT_MEMORY_RW_NONCACHED;
3495
3496 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3497 base, length, desc->virtual);
3498 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3499 index 255f33a..507b157 100644
3500 --- a/arch/arm/mach-kirkwood/common.c
3501 +++ b/arch/arm/mach-kirkwood/common.c
3502 @@ -157,7 +157,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3503 clk_gate_ops.disable(hw);
3504 }
3505
3506 -static struct clk_ops clk_gate_fn_ops;
3507 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3508 +{
3509 + return clk_gate_ops.is_enabled(hw);
3510 +}
3511 +
3512 +static struct clk_ops clk_gate_fn_ops = {
3513 + .enable = clk_gate_fn_enable,
3514 + .disable = clk_gate_fn_disable,
3515 + .is_enabled = clk_gate_fn_is_enabled,
3516 +};
3517
3518 static struct clk __init *clk_register_gate_fn(struct device *dev,
3519 const char *name,
3520 @@ -191,14 +200,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3521 gate_fn->fn_en = fn_en;
3522 gate_fn->fn_dis = fn_dis;
3523
3524 - /* ops is the gate ops, but with our enable/disable functions */
3525 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3526 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3527 - clk_gate_fn_ops = clk_gate_ops;
3528 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3529 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3530 - }
3531 -
3532 clk = clk_register(dev, &gate_fn->gate.hw);
3533
3534 if (IS_ERR(clk))
3535 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3536 index aead77a..a2253fa 100644
3537 --- a/arch/arm/mach-omap2/board-n8x0.c
3538 +++ b/arch/arm/mach-omap2/board-n8x0.c
3539 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3540 }
3541 #endif
3542
3543 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3544 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3545 .late_init = n8x0_menelaus_late_init,
3546 };
3547
3548 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3549 index 9fe8c94..c014a4d 100644
3550 --- a/arch/arm/mach-omap2/gpmc.c
3551 +++ b/arch/arm/mach-omap2/gpmc.c
3552 @@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3553 };
3554
3555 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3556 -static struct irq_chip gpmc_irq_chip;
3557 static int gpmc_irq_start;
3558
3559 static struct resource gpmc_mem_root;
3560 @@ -727,6 +726,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3561
3562 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3563
3564 +static struct irq_chip gpmc_irq_chip = {
3565 + .name = "gpmc",
3566 + .irq_startup = gpmc_irq_noop_ret,
3567 + .irq_enable = gpmc_irq_enable,
3568 + .irq_disable = gpmc_irq_disable,
3569 + .irq_shutdown = gpmc_irq_noop,
3570 + .irq_ack = gpmc_irq_noop,
3571 + .irq_mask = gpmc_irq_noop,
3572 + .irq_unmask = gpmc_irq_noop,
3573 +
3574 +};
3575 +
3576 static int gpmc_setup_irq(void)
3577 {
3578 int i;
3579 @@ -741,15 +752,6 @@ static int gpmc_setup_irq(void)
3580 return gpmc_irq_start;
3581 }
3582
3583 - gpmc_irq_chip.name = "gpmc";
3584 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3585 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3586 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3587 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3588 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3589 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3590 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3591 -
3592 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3593 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3594
3595 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3596 index 667915d..2ee1219 100644
3597 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3598 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3599 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3600 int (*finish_suspend)(unsigned long cpu_state);
3601 void (*resume)(void);
3602 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3603 -};
3604 +} __no_const;
3605
3606 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3607 static struct powerdomain *mpuss_pd;
3608 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3609 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3610 {}
3611
3612 -struct cpu_pm_ops omap_pm_ops = {
3613 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3614 .finish_suspend = default_finish_suspend,
3615 .resume = dummy_cpu_resume,
3616 .scu_prepare = dummy_scu_prepare,
3617 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3618 index 693fe48..c15ea73 100644
3619 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3620 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3621 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3622 return NOTIFY_OK;
3623 }
3624
3625 -static struct notifier_block __refdata irq_hotplug_notifier = {
3626 +static struct notifier_block irq_hotplug_notifier = {
3627 .notifier_call = irq_cpu_hotplug_notify,
3628 };
3629
3630 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3631 index 01ef59d..32ae28a8 100644
3632 --- a/arch/arm/mach-omap2/omap_device.c
3633 +++ b/arch/arm/mach-omap2/omap_device.c
3634 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3635 struct platform_device __init *omap_device_build(const char *pdev_name,
3636 int pdev_id,
3637 struct omap_hwmod *oh,
3638 - void *pdata, int pdata_len)
3639 + const void *pdata, int pdata_len)
3640 {
3641 struct omap_hwmod *ohs[] = { oh };
3642
3643 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3644 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3645 int pdev_id,
3646 struct omap_hwmod **ohs,
3647 - int oh_cnt, void *pdata,
3648 + int oh_cnt, const void *pdata,
3649 int pdata_len)
3650 {
3651 int ret = -ENOMEM;
3652 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3653 index 78c02b3..c94109a 100644
3654 --- a/arch/arm/mach-omap2/omap_device.h
3655 +++ b/arch/arm/mach-omap2/omap_device.h
3656 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3657 /* Core code interface */
3658
3659 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3660 - struct omap_hwmod *oh, void *pdata,
3661 + struct omap_hwmod *oh, const void *pdata,
3662 int pdata_len);
3663
3664 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3665 struct omap_hwmod **oh, int oh_cnt,
3666 - void *pdata, int pdata_len);
3667 + const void *pdata, int pdata_len);
3668
3669 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3670 struct omap_hwmod **ohs, int oh_cnt);
3671 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3672 index 66c60fe..c78950d 100644
3673 --- a/arch/arm/mach-omap2/omap_hwmod.c
3674 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3675 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3676 int (*init_clkdm)(struct omap_hwmod *oh);
3677 void (*update_context_lost)(struct omap_hwmod *oh);
3678 int (*get_context_lost)(struct omap_hwmod *oh);
3679 -};
3680 +} __no_const;
3681
3682 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3683 -static struct omap_hwmod_soc_ops soc_ops;
3684 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3685
3686 /* omap_hwmod_list contains all registered struct omap_hwmods */
3687 static LIST_HEAD(omap_hwmod_list);
3688 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3689 index 95fee54..cfa9cf1 100644
3690 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3691 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3692 @@ -10,6 +10,7 @@
3693
3694 #include <linux/kernel.h>
3695 #include <linux/init.h>
3696 +#include <asm/pgtable.h>
3697
3698 #include "powerdomain.h"
3699
3700 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3701
3702 void __init am43xx_powerdomains_init(void)
3703 {
3704 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3705 + pax_open_kernel();
3706 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3707 + pax_close_kernel();
3708 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3709 pwrdm_register_pwrdms(powerdomains_am43xx);
3710 pwrdm_complete_init();
3711 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3712 index d15c7bb..b2d1f0c 100644
3713 --- a/arch/arm/mach-omap2/wd_timer.c
3714 +++ b/arch/arm/mach-omap2/wd_timer.c
3715 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3716 struct omap_hwmod *oh;
3717 char *oh_name = "wd_timer2";
3718 char *dev_name = "omap_wdt";
3719 - struct omap_wd_timer_platform_data pdata;
3720 + static struct omap_wd_timer_platform_data pdata = {
3721 + .read_reset_sources = prm_read_reset_sources
3722 + };
3723
3724 if (!cpu_class_is_omap2() || of_have_populated_dt())
3725 return 0;
3726 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3727 return -EINVAL;
3728 }
3729
3730 - pdata.read_reset_sources = prm_read_reset_sources;
3731 -
3732 pdev = omap_device_build(dev_name, id, oh, &pdata,
3733 sizeof(struct omap_wd_timer_platform_data));
3734 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3735 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3736 index b82dcae..44ee5b6 100644
3737 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3738 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3739 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3740 bool entered_lp2 = false;
3741
3742 if (tegra_pending_sgi())
3743 - ACCESS_ONCE(abort_flag) = true;
3744 + ACCESS_ONCE_RW(abort_flag) = true;
3745
3746 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3747
3748 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3749 index 2dea8b5..6499da2 100644
3750 --- a/arch/arm/mach-ux500/setup.h
3751 +++ b/arch/arm/mach-ux500/setup.h
3752 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3753 .type = MT_DEVICE, \
3754 }
3755
3756 -#define __MEM_DEV_DESC(x, sz) { \
3757 - .virtual = IO_ADDRESS(x), \
3758 - .pfn = __phys_to_pfn(x), \
3759 - .length = sz, \
3760 - .type = MT_MEMORY_RWX, \
3761 -}
3762 -
3763 extern struct smp_operations ux500_smp_ops;
3764 extern void ux500_cpu_die(unsigned int cpu);
3765
3766 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3767 index 5bf7c3c..571e67e 100644
3768 --- a/arch/arm/mm/Kconfig
3769 +++ b/arch/arm/mm/Kconfig
3770 @@ -446,6 +446,7 @@ config CPU_32v5
3771
3772 config CPU_32v6
3773 bool
3774 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3775 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3776
3777 config CPU_32v6K
3778 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
3779
3780 config CPU_USE_DOMAINS
3781 bool
3782 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3783 help
3784 This option enables or disables the use of domain switching
3785 via the set_fs() function.
3786 @@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3787 config KUSER_HELPERS
3788 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3789 default y
3790 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3791 help
3792 Warning: disabling this option may break user programs.
3793
3794 @@ -811,7 +814,7 @@ config KUSER_HELPERS
3795 See Documentation/arm/kernel_user_helpers.txt for details.
3796
3797 However, the fixed address nature of these helpers can be used
3798 - by ROP (return orientated programming) authors when creating
3799 + by ROP (Return Oriented Programming) authors when creating
3800 exploits.
3801
3802 If all of the binaries and libraries which run on your platform
3803 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3804 index 9240364..a2b8cf3 100644
3805 --- a/arch/arm/mm/alignment.c
3806 +++ b/arch/arm/mm/alignment.c
3807 @@ -212,10 +212,12 @@ union offset_union {
3808 #define __get16_unaligned_check(ins,val,addr) \
3809 do { \
3810 unsigned int err = 0, v, a = addr; \
3811 + pax_open_userland(); \
3812 __get8_unaligned_check(ins,v,a,err); \
3813 val = v << ((BE) ? 8 : 0); \
3814 __get8_unaligned_check(ins,v,a,err); \
3815 val |= v << ((BE) ? 0 : 8); \
3816 + pax_close_userland(); \
3817 if (err) \
3818 goto fault; \
3819 } while (0)
3820 @@ -229,6 +231,7 @@ union offset_union {
3821 #define __get32_unaligned_check(ins,val,addr) \
3822 do { \
3823 unsigned int err = 0, v, a = addr; \
3824 + pax_open_userland(); \
3825 __get8_unaligned_check(ins,v,a,err); \
3826 val = v << ((BE) ? 24 : 0); \
3827 __get8_unaligned_check(ins,v,a,err); \
3828 @@ -237,6 +240,7 @@ union offset_union {
3829 val |= v << ((BE) ? 8 : 16); \
3830 __get8_unaligned_check(ins,v,a,err); \
3831 val |= v << ((BE) ? 0 : 24); \
3832 + pax_close_userland(); \
3833 if (err) \
3834 goto fault; \
3835 } while (0)
3836 @@ -250,6 +254,7 @@ union offset_union {
3837 #define __put16_unaligned_check(ins,val,addr) \
3838 do { \
3839 unsigned int err = 0, v = val, a = addr; \
3840 + pax_open_userland(); \
3841 __asm__( FIRST_BYTE_16 \
3842 ARM( "1: "ins" %1, [%2], #1\n" ) \
3843 THUMB( "1: "ins" %1, [%2]\n" ) \
3844 @@ -269,6 +274,7 @@ union offset_union {
3845 " .popsection\n" \
3846 : "=r" (err), "=&r" (v), "=&r" (a) \
3847 : "0" (err), "1" (v), "2" (a)); \
3848 + pax_close_userland(); \
3849 if (err) \
3850 goto fault; \
3851 } while (0)
3852 @@ -282,6 +288,7 @@ union offset_union {
3853 #define __put32_unaligned_check(ins,val,addr) \
3854 do { \
3855 unsigned int err = 0, v = val, a = addr; \
3856 + pax_open_userland(); \
3857 __asm__( FIRST_BYTE_32 \
3858 ARM( "1: "ins" %1, [%2], #1\n" ) \
3859 THUMB( "1: "ins" %1, [%2]\n" ) \
3860 @@ -311,6 +318,7 @@ union offset_union {
3861 " .popsection\n" \
3862 : "=r" (err), "=&r" (v), "=&r" (a) \
3863 : "0" (err), "1" (v), "2" (a)); \
3864 + pax_close_userland(); \
3865 if (err) \
3866 goto fault; \
3867 } while (0)
3868 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3869 index 7abde2c..9df495f 100644
3870 --- a/arch/arm/mm/cache-l2x0.c
3871 +++ b/arch/arm/mm/cache-l2x0.c
3872 @@ -46,7 +46,7 @@ struct l2x0_of_data {
3873 void (*setup)(const struct device_node *, u32 *, u32 *);
3874 void (*save)(void);
3875 struct outer_cache_fns outer_cache;
3876 -};
3877 +} __do_const;
3878
3879 static bool of_init = false;
3880
3881 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3882 index 6eb97b3..ac509f6 100644
3883 --- a/arch/arm/mm/context.c
3884 +++ b/arch/arm/mm/context.c
3885 @@ -43,7 +43,7 @@
3886 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3887
3888 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3889 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3890 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3891 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3892
3893 static DEFINE_PER_CPU(atomic64_t, active_asids);
3894 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3895 {
3896 static u32 cur_idx = 1;
3897 u64 asid = atomic64_read(&mm->context.id);
3898 - u64 generation = atomic64_read(&asid_generation);
3899 + u64 generation = atomic64_read_unchecked(&asid_generation);
3900
3901 if (asid != 0 && is_reserved_asid(asid)) {
3902 /*
3903 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3904 */
3905 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3906 if (asid == NUM_USER_ASIDS) {
3907 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3908 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3909 &asid_generation);
3910 flush_context(cpu);
3911 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3912 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3913 cpu_set_reserved_ttbr0();
3914
3915 asid = atomic64_read(&mm->context.id);
3916 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3917 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3918 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3919 goto switch_mm_fastpath;
3920
3921 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3922 /* Check that our ASID belongs to the current generation. */
3923 asid = atomic64_read(&mm->context.id);
3924 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3925 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3926 asid = new_context(mm, cpu);
3927 atomic64_set(&mm->context.id, asid);
3928 }
3929 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3930 index eb8830a..5360ce7 100644
3931 --- a/arch/arm/mm/fault.c
3932 +++ b/arch/arm/mm/fault.c
3933 @@ -25,6 +25,7 @@
3934 #include <asm/system_misc.h>
3935 #include <asm/system_info.h>
3936 #include <asm/tlbflush.h>
3937 +#include <asm/sections.h>
3938
3939 #include "fault.h"
3940
3941 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3942 if (fixup_exception(regs))
3943 return;
3944
3945 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3946 + if (addr < TASK_SIZE) {
3947 + if (current->signal->curr_ip)
3948 + 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),
3949 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3950 + else
3951 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3952 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3953 + }
3954 +#endif
3955 +
3956 +#ifdef CONFIG_PAX_KERNEXEC
3957 + if ((fsr & FSR_WRITE) &&
3958 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3959 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3960 + {
3961 + if (current->signal->curr_ip)
3962 + 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),
3963 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3964 + else
3965 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3966 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3967 + }
3968 +#endif
3969 +
3970 /*
3971 * No handler, we'll have to terminate things with extreme prejudice.
3972 */
3973 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3974 }
3975 #endif
3976
3977 +#ifdef CONFIG_PAX_PAGEEXEC
3978 + if (fsr & FSR_LNX_PF) {
3979 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3980 + do_group_exit(SIGKILL);
3981 + }
3982 +#endif
3983 +
3984 tsk->thread.address = addr;
3985 tsk->thread.error_code = fsr;
3986 tsk->thread.trap_no = 14;
3987 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3988 }
3989 #endif /* CONFIG_MMU */
3990
3991 +#ifdef CONFIG_PAX_PAGEEXEC
3992 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3993 +{
3994 + long i;
3995 +
3996 + printk(KERN_ERR "PAX: bytes at PC: ");
3997 + for (i = 0; i < 20; i++) {
3998 + unsigned char c;
3999 + if (get_user(c, (__force unsigned char __user *)pc+i))
4000 + printk(KERN_CONT "?? ");
4001 + else
4002 + printk(KERN_CONT "%02x ", c);
4003 + }
4004 + printk("\n");
4005 +
4006 + printk(KERN_ERR "PAX: bytes at SP-4: ");
4007 + for (i = -1; i < 20; i++) {
4008 + unsigned long c;
4009 + if (get_user(c, (__force unsigned long __user *)sp+i))
4010 + printk(KERN_CONT "???????? ");
4011 + else
4012 + printk(KERN_CONT "%08lx ", c);
4013 + }
4014 + printk("\n");
4015 +}
4016 +#endif
4017 +
4018 /*
4019 * First Level Translation Fault Handler
4020 *
4021 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4022 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4023 struct siginfo info;
4024
4025 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4026 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4027 + if (current->signal->curr_ip)
4028 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4029 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4030 + else
4031 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4032 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4033 + goto die;
4034 + }
4035 +#endif
4036 +
4037 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4038 return;
4039
4040 +die:
4041 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4042 inf->name, fsr, addr);
4043
4044 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4045 ifsr_info[nr].name = name;
4046 }
4047
4048 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4049 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4050 +
4051 asmlinkage void __exception
4052 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4053 {
4054 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4055 struct siginfo info;
4056 + unsigned long pc = instruction_pointer(regs);
4057 +
4058 + if (user_mode(regs)) {
4059 + unsigned long sigpage = current->mm->context.sigpage;
4060 +
4061 + if (sigpage <= pc && pc < sigpage + 7*4) {
4062 + if (pc < sigpage + 3*4)
4063 + sys_sigreturn(regs);
4064 + else
4065 + sys_rt_sigreturn(regs);
4066 + return;
4067 + }
4068 + if (pc == 0xffff0f60UL) {
4069 + /*
4070 + * PaX: __kuser_cmpxchg64 emulation
4071 + */
4072 + // TODO
4073 + //regs->ARM_pc = regs->ARM_lr;
4074 + //return;
4075 + }
4076 + if (pc == 0xffff0fa0UL) {
4077 + /*
4078 + * PaX: __kuser_memory_barrier emulation
4079 + */
4080 + // dmb(); implied by the exception
4081 + regs->ARM_pc = regs->ARM_lr;
4082 + return;
4083 + }
4084 + if (pc == 0xffff0fc0UL) {
4085 + /*
4086 + * PaX: __kuser_cmpxchg emulation
4087 + */
4088 + // TODO
4089 + //long new;
4090 + //int op;
4091 +
4092 + //op = FUTEX_OP_SET << 28;
4093 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4094 + //regs->ARM_r0 = old != new;
4095 + //regs->ARM_pc = regs->ARM_lr;
4096 + //return;
4097 + }
4098 + if (pc == 0xffff0fe0UL) {
4099 + /*
4100 + * PaX: __kuser_get_tls emulation
4101 + */
4102 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4103 + regs->ARM_pc = regs->ARM_lr;
4104 + return;
4105 + }
4106 + }
4107 +
4108 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4109 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4110 + if (current->signal->curr_ip)
4111 + 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),
4112 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4113 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4114 + else
4115 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4116 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4117 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4118 + goto die;
4119 + }
4120 +#endif
4121 +
4122 +#ifdef CONFIG_PAX_REFCOUNT
4123 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4124 + unsigned int bkpt;
4125 +
4126 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4127 + current->thread.error_code = ifsr;
4128 + current->thread.trap_no = 0;
4129 + pax_report_refcount_overflow(regs);
4130 + fixup_exception(regs);
4131 + return;
4132 + }
4133 + }
4134 +#endif
4135
4136 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4137 return;
4138
4139 +die:
4140 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4141 inf->name, ifsr, addr);
4142
4143 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4144 index cf08bdf..772656c 100644
4145 --- a/arch/arm/mm/fault.h
4146 +++ b/arch/arm/mm/fault.h
4147 @@ -3,6 +3,7 @@
4148
4149 /*
4150 * Fault status register encodings. We steal bit 31 for our own purposes.
4151 + * Set when the FSR value is from an instruction fault.
4152 */
4153 #define FSR_LNX_PF (1 << 31)
4154 #define FSR_WRITE (1 << 11)
4155 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4156 }
4157 #endif
4158
4159 +/* valid for LPAE and !LPAE */
4160 +static inline int is_xn_fault(unsigned int fsr)
4161 +{
4162 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4163 +}
4164 +
4165 +static inline int is_domain_fault(unsigned int fsr)
4166 +{
4167 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4168 +}
4169 +
4170 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4171 unsigned long search_exception_table(unsigned long addr);
4172
4173 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4174 index 2a77ba8..68e6a7a 100644
4175 --- a/arch/arm/mm/init.c
4176 +++ b/arch/arm/mm/init.c
4177 @@ -30,6 +30,8 @@
4178 #include <asm/setup.h>
4179 #include <asm/tlb.h>
4180 #include <asm/fixmap.h>
4181 +#include <asm/system_info.h>
4182 +#include <asm/cp15.h>
4183
4184 #include <asm/mach/arch.h>
4185 #include <asm/mach/map.h>
4186 @@ -627,7 +629,46 @@ void free_initmem(void)
4187 {
4188 #ifdef CONFIG_HAVE_TCM
4189 extern char __tcm_start, __tcm_end;
4190 +#endif
4191
4192 +#ifdef CONFIG_PAX_KERNEXEC
4193 + unsigned long addr;
4194 + pgd_t *pgd;
4195 + pud_t *pud;
4196 + pmd_t *pmd;
4197 + int cpu_arch = cpu_architecture();
4198 + unsigned int cr = get_cr();
4199 +
4200 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4201 + /* make pages tables, etc before .text NX */
4202 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4203 + pgd = pgd_offset_k(addr);
4204 + pud = pud_offset(pgd, addr);
4205 + pmd = pmd_offset(pud, addr);
4206 + __section_update(pmd, addr, PMD_SECT_XN);
4207 + }
4208 + /* make init NX */
4209 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4210 + pgd = pgd_offset_k(addr);
4211 + pud = pud_offset(pgd, addr);
4212 + pmd = pmd_offset(pud, addr);
4213 + __section_update(pmd, addr, PMD_SECT_XN);
4214 + }
4215 + /* make kernel code/rodata RX */
4216 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4217 + pgd = pgd_offset_k(addr);
4218 + pud = pud_offset(pgd, addr);
4219 + pmd = pmd_offset(pud, addr);
4220 +#ifdef CONFIG_ARM_LPAE
4221 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4222 +#else
4223 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4224 +#endif
4225 + }
4226 + }
4227 +#endif
4228 +
4229 +#ifdef CONFIG_HAVE_TCM
4230 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4231 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4232 #endif
4233 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4234 index f9c32ba..8540068 100644
4235 --- a/arch/arm/mm/ioremap.c
4236 +++ b/arch/arm/mm/ioremap.c
4237 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4238 unsigned int mtype;
4239
4240 if (cached)
4241 - mtype = MT_MEMORY_RWX;
4242 + mtype = MT_MEMORY_RX;
4243 else
4244 - mtype = MT_MEMORY_RWX_NONCACHED;
4245 + mtype = MT_MEMORY_RX_NONCACHED;
4246
4247 return __arm_ioremap_caller(phys_addr, size, mtype,
4248 __builtin_return_address(0));
4249 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4250 index 5e85ed3..b10a7ed 100644
4251 --- a/arch/arm/mm/mmap.c
4252 +++ b/arch/arm/mm/mmap.c
4253 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4254 struct vm_area_struct *vma;
4255 int do_align = 0;
4256 int aliasing = cache_is_vipt_aliasing();
4257 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4258 struct vm_unmapped_area_info info;
4259
4260 /*
4261 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4262 if (len > TASK_SIZE)
4263 return -ENOMEM;
4264
4265 +#ifdef CONFIG_PAX_RANDMMAP
4266 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4267 +#endif
4268 +
4269 if (addr) {
4270 if (do_align)
4271 addr = COLOUR_ALIGN(addr, pgoff);
4272 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4273 addr = PAGE_ALIGN(addr);
4274
4275 vma = find_vma(mm, addr);
4276 - if (TASK_SIZE - len >= addr &&
4277 - (!vma || addr + len <= vma->vm_start))
4278 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4279 return addr;
4280 }
4281
4282 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4283 info.high_limit = TASK_SIZE;
4284 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4285 info.align_offset = pgoff << PAGE_SHIFT;
4286 + info.threadstack_offset = offset;
4287 return vm_unmapped_area(&info);
4288 }
4289
4290 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4291 unsigned long addr = addr0;
4292 int do_align = 0;
4293 int aliasing = cache_is_vipt_aliasing();
4294 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4295 struct vm_unmapped_area_info info;
4296
4297 /*
4298 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4299 return addr;
4300 }
4301
4302 +#ifdef CONFIG_PAX_RANDMMAP
4303 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4304 +#endif
4305 +
4306 /* requesting a specific address */
4307 if (addr) {
4308 if (do_align)
4309 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4310 else
4311 addr = PAGE_ALIGN(addr);
4312 vma = find_vma(mm, addr);
4313 - if (TASK_SIZE - len >= addr &&
4314 - (!vma || addr + len <= vma->vm_start))
4315 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4316 return addr;
4317 }
4318
4319 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4320 info.high_limit = mm->mmap_base;
4321 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4322 info.align_offset = pgoff << PAGE_SHIFT;
4323 + info.threadstack_offset = offset;
4324 addr = vm_unmapped_area(&info);
4325
4326 /*
4327 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4328 {
4329 unsigned long random_factor = 0UL;
4330
4331 +#ifdef CONFIG_PAX_RANDMMAP
4332 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4333 +#endif
4334 +
4335 /* 8 bits of randomness in 20 address space bits */
4336 if ((current->flags & PF_RANDOMIZE) &&
4337 !(current->personality & ADDR_NO_RANDOMIZE))
4338 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4339
4340 if (mmap_is_legacy()) {
4341 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4342 +
4343 +#ifdef CONFIG_PAX_RANDMMAP
4344 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4345 + mm->mmap_base += mm->delta_mmap;
4346 +#endif
4347 +
4348 mm->get_unmapped_area = arch_get_unmapped_area;
4349 } else {
4350 mm->mmap_base = mmap_base(random_factor);
4351 +
4352 +#ifdef CONFIG_PAX_RANDMMAP
4353 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4354 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4355 +#endif
4356 +
4357 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4358 }
4359 }
4360 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4361 index b68c6b2..f66c492 100644
4362 --- a/arch/arm/mm/mmu.c
4363 +++ b/arch/arm/mm/mmu.c
4364 @@ -39,6 +39,22 @@
4365 #include "mm.h"
4366 #include "tcm.h"
4367
4368 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4369 +void modify_domain(unsigned int dom, unsigned int type)
4370 +{
4371 + struct thread_info *thread = current_thread_info();
4372 + unsigned int domain = thread->cpu_domain;
4373 + /*
4374 + * DOMAIN_MANAGER might be defined to some other value,
4375 + * use the arch-defined constant
4376 + */
4377 + domain &= ~domain_val(dom, 3);
4378 + thread->cpu_domain = domain | domain_val(dom, type);
4379 + set_domain(thread->cpu_domain);
4380 +}
4381 +EXPORT_SYMBOL(modify_domain);
4382 +#endif
4383 +
4384 /*
4385 * empty_zero_page is a special page that is used for
4386 * zero-initialized data and COW.
4387 @@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4388 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4389 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4390
4391 -static struct mem_type mem_types[] = {
4392 +#ifdef CONFIG_PAX_KERNEXEC
4393 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4394 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4395 +#else
4396 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4397 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4398 +#endif
4399 +
4400 +static struct mem_type mem_types[] __read_only = {
4401 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4402 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4403 L_PTE_SHARED,
4404 @@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4405 .prot_sect = PROT_SECT_DEVICE,
4406 .domain = DOMAIN_IO,
4407 },
4408 - [MT_UNCACHED] = {
4409 + [MT_UNCACHED_RW] = {
4410 .prot_pte = PROT_PTE_DEVICE,
4411 .prot_l1 = PMD_TYPE_TABLE,
4412 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4413 .domain = DOMAIN_IO,
4414 },
4415 - [MT_CACHECLEAN] = {
4416 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4417 + [MT_CACHECLEAN_RO] = {
4418 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4419 .domain = DOMAIN_KERNEL,
4420 },
4421 #ifndef CONFIG_ARM_LPAE
4422 - [MT_MINICLEAN] = {
4423 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4424 + [MT_MINICLEAN_RO] = {
4425 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4426 .domain = DOMAIN_KERNEL,
4427 },
4428 #endif
4429 @@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4430 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4431 L_PTE_RDONLY,
4432 .prot_l1 = PMD_TYPE_TABLE,
4433 - .domain = DOMAIN_USER,
4434 + .domain = DOMAIN_VECTORS,
4435 },
4436 [MT_HIGH_VECTORS] = {
4437 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4438 L_PTE_USER | L_PTE_RDONLY,
4439 .prot_l1 = PMD_TYPE_TABLE,
4440 - .domain = DOMAIN_USER,
4441 + .domain = DOMAIN_VECTORS,
4442 },
4443 - [MT_MEMORY_RWX] = {
4444 + [__MT_MEMORY_RWX] = {
4445 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4446 .prot_l1 = PMD_TYPE_TABLE,
4447 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4448 @@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4449 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4450 .domain = DOMAIN_KERNEL,
4451 },
4452 - [MT_ROM] = {
4453 - .prot_sect = PMD_TYPE_SECT,
4454 + [MT_MEMORY_RX] = {
4455 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4456 + .prot_l1 = PMD_TYPE_TABLE,
4457 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4458 + .domain = DOMAIN_KERNEL,
4459 + },
4460 + [MT_ROM_RX] = {
4461 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4462 .domain = DOMAIN_KERNEL,
4463 },
4464 - [MT_MEMORY_RWX_NONCACHED] = {
4465 + [MT_MEMORY_RW_NONCACHED] = {
4466 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4467 L_PTE_MT_BUFFERABLE,
4468 .prot_l1 = PMD_TYPE_TABLE,
4469 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4470 .domain = DOMAIN_KERNEL,
4471 },
4472 + [MT_MEMORY_RX_NONCACHED] = {
4473 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4474 + L_PTE_MT_BUFFERABLE,
4475 + .prot_l1 = PMD_TYPE_TABLE,
4476 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4477 + .domain = DOMAIN_KERNEL,
4478 + },
4479 [MT_MEMORY_RW_DTCM] = {
4480 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4481 L_PTE_XN,
4482 @@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4483 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4484 .domain = DOMAIN_KERNEL,
4485 },
4486 - [MT_MEMORY_RWX_ITCM] = {
4487 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4488 + [MT_MEMORY_RX_ITCM] = {
4489 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4490 .prot_l1 = PMD_TYPE_TABLE,
4491 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4492 .domain = DOMAIN_KERNEL,
4493 },
4494 [MT_MEMORY_RW_SO] = {
4495 @@ -534,9 +572,14 @@ static void __init build_mem_type_table(void)
4496 * Mark cache clean areas and XIP ROM read only
4497 * from SVC mode and no access from userspace.
4498 */
4499 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4500 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4501 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4502 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4503 +#ifdef CONFIG_PAX_KERNEXEC
4504 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4505 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4506 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4507 +#endif
4508 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4509 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4510 #endif
4511
4512 if (is_smp()) {
4513 @@ -552,13 +595,17 @@ static void __init build_mem_type_table(void)
4514 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4515 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4516 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4517 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4518 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4519 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4520 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4521 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4522 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4523 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4524 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4525 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4526 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4527 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4528 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4529 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4530 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4531 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4532 }
4533 }
4534
4535 @@ -569,15 +616,20 @@ static void __init build_mem_type_table(void)
4536 if (cpu_arch >= CPU_ARCH_ARMv6) {
4537 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4538 /* Non-cacheable Normal is XCB = 001 */
4539 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4540 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4541 + PMD_SECT_BUFFERED;
4542 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4543 PMD_SECT_BUFFERED;
4544 } else {
4545 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4546 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4547 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4548 + PMD_SECT_TEX(1);
4549 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4550 PMD_SECT_TEX(1);
4551 }
4552 } else {
4553 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4554 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4555 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4556 }
4557
4558 #ifdef CONFIG_ARM_LPAE
4559 @@ -593,6 +645,8 @@ static void __init build_mem_type_table(void)
4560 vecs_pgprot |= PTE_EXT_AF;
4561 #endif
4562
4563 + user_pgprot |= __supported_pte_mask;
4564 +
4565 for (i = 0; i < 16; i++) {
4566 pteval_t v = pgprot_val(protection_map[i]);
4567 protection_map[i] = __pgprot(v | user_pgprot);
4568 @@ -610,21 +664,24 @@ static void __init build_mem_type_table(void)
4569
4570 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4571 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4572 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4573 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4574 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4575 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4576 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4577 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4578 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4579 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4580 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4581 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4582 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4583 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4584 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4585 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4586
4587 switch (cp->pmd) {
4588 case PMD_SECT_WT:
4589 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4590 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4591 break;
4592 case PMD_SECT_WB:
4593 case PMD_SECT_WBWA:
4594 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4595 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4596 break;
4597 }
4598 pr_info("Memory policy: %sData cache %s\n",
4599 @@ -842,7 +899,7 @@ static void __init create_mapping(struct map_desc *md)
4600 return;
4601 }
4602
4603 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4604 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4605 md->virtual >= PAGE_OFFSET &&
4606 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4607 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4608 @@ -1257,18 +1314,15 @@ void __init arm_mm_memblock_reserve(void)
4609 * called function. This means you can't use any function or debugging
4610 * method which may touch any device, otherwise the kernel _will_ crash.
4611 */
4612 +
4613 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4614 +
4615 static void __init devicemaps_init(const struct machine_desc *mdesc)
4616 {
4617 struct map_desc map;
4618 unsigned long addr;
4619 - void *vectors;
4620
4621 - /*
4622 - * Allocate the vector page early.
4623 - */
4624 - vectors = early_alloc(PAGE_SIZE * 2);
4625 -
4626 - early_trap_init(vectors);
4627 + early_trap_init(&vectors);
4628
4629 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4630 pmd_clear(pmd_off_k(addr));
4631 @@ -1281,7 +1335,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4632 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4633 map.virtual = MODULES_VADDR;
4634 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4635 - map.type = MT_ROM;
4636 + map.type = MT_ROM_RX;
4637 create_mapping(&map);
4638 #endif
4639
4640 @@ -1292,14 +1346,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4641 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4642 map.virtual = FLUSH_BASE;
4643 map.length = SZ_1M;
4644 - map.type = MT_CACHECLEAN;
4645 + map.type = MT_CACHECLEAN_RO;
4646 create_mapping(&map);
4647 #endif
4648 #ifdef FLUSH_BASE_MINICACHE
4649 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4650 map.virtual = FLUSH_BASE_MINICACHE;
4651 map.length = SZ_1M;
4652 - map.type = MT_MINICLEAN;
4653 + map.type = MT_MINICLEAN_RO;
4654 create_mapping(&map);
4655 #endif
4656
4657 @@ -1308,7 +1362,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4658 * location (0xffff0000). If we aren't using high-vectors, also
4659 * create a mapping at the low-vectors virtual address.
4660 */
4661 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4662 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4663 map.virtual = 0xffff0000;
4664 map.length = PAGE_SIZE;
4665 #ifdef CONFIG_KUSER_HELPERS
4666 @@ -1365,8 +1419,10 @@ static void __init kmap_init(void)
4667 static void __init map_lowmem(void)
4668 {
4669 struct memblock_region *reg;
4670 +#ifndef CONFIG_PAX_KERNEXEC
4671 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4672 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4673 +#endif
4674
4675 /* Map all the lowmem memory banks. */
4676 for_each_memblock(memory, reg) {
4677 @@ -1379,11 +1435,48 @@ static void __init map_lowmem(void)
4678 if (start >= end)
4679 break;
4680
4681 +#ifdef CONFIG_PAX_KERNEXEC
4682 + map.pfn = __phys_to_pfn(start);
4683 + map.virtual = __phys_to_virt(start);
4684 + map.length = end - start;
4685 +
4686 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4687 + struct map_desc kernel;
4688 + struct map_desc initmap;
4689 +
4690 + /* when freeing initmem we will make this RW */
4691 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4692 + initmap.virtual = (unsigned long)__init_begin;
4693 + initmap.length = _sdata - __init_begin;
4694 + initmap.type = __MT_MEMORY_RWX;
4695 + create_mapping(&initmap);
4696 +
4697 + /* when freeing initmem we will make this RX */
4698 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4699 + kernel.virtual = (unsigned long)_stext;
4700 + kernel.length = __init_begin - _stext;
4701 + kernel.type = __MT_MEMORY_RWX;
4702 + create_mapping(&kernel);
4703 +
4704 + if (map.virtual < (unsigned long)_stext) {
4705 + map.length = (unsigned long)_stext - map.virtual;
4706 + map.type = __MT_MEMORY_RWX;
4707 + create_mapping(&map);
4708 + }
4709 +
4710 + map.pfn = __phys_to_pfn(__pa(_sdata));
4711 + map.virtual = (unsigned long)_sdata;
4712 + map.length = end - __pa(_sdata);
4713 + }
4714 +
4715 + map.type = MT_MEMORY_RW;
4716 + create_mapping(&map);
4717 +#else
4718 if (end < kernel_x_start || start >= kernel_x_end) {
4719 map.pfn = __phys_to_pfn(start);
4720 map.virtual = __phys_to_virt(start);
4721 map.length = end - start;
4722 - map.type = MT_MEMORY_RWX;
4723 + map.type = __MT_MEMORY_RWX;
4724
4725 create_mapping(&map);
4726 } else {
4727 @@ -1400,7 +1493,7 @@ static void __init map_lowmem(void)
4728 map.pfn = __phys_to_pfn(kernel_x_start);
4729 map.virtual = __phys_to_virt(kernel_x_start);
4730 map.length = kernel_x_end - kernel_x_start;
4731 - map.type = MT_MEMORY_RWX;
4732 + map.type = __MT_MEMORY_RWX;
4733
4734 create_mapping(&map);
4735
4736 @@ -1413,6 +1506,7 @@ static void __init map_lowmem(void)
4737 create_mapping(&map);
4738 }
4739 }
4740 +#endif
4741 }
4742 }
4743
4744 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4745 index 5b217f4..c23f40e 100644
4746 --- a/arch/arm/plat-iop/setup.c
4747 +++ b/arch/arm/plat-iop/setup.c
4748 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4749 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4750 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4751 .length = IOP3XX_PERIPHERAL_SIZE,
4752 - .type = MT_UNCACHED,
4753 + .type = MT_UNCACHED_RW,
4754 },
4755 };
4756
4757 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4758 index a5bc92d..0bb4730 100644
4759 --- a/arch/arm/plat-omap/sram.c
4760 +++ b/arch/arm/plat-omap/sram.c
4761 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4762 * Looks like we need to preserve some bootloader code at the
4763 * beginning of SRAM for jumping to flash for reboot to work...
4764 */
4765 + pax_open_kernel();
4766 memset_io(omap_sram_base + omap_sram_skip, 0,
4767 omap_sram_size - omap_sram_skip);
4768 + pax_close_kernel();
4769 }
4770 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4771 index ce6d763..cfea917 100644
4772 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4773 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4774 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4775 int (*started)(unsigned ch);
4776 int (*flush)(unsigned ch);
4777 int (*stop)(unsigned ch);
4778 -};
4779 +} __no_const;
4780
4781 extern void *samsung_dmadev_get_ops(void);
4782 extern void *s3c_dma_get_ops(void);
4783 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4784 index 66eb764..b529b84 100644
4785 --- a/arch/arm64/include/asm/barrier.h
4786 +++ b/arch/arm64/include/asm/barrier.h
4787 @@ -41,7 +41,7 @@
4788 do { \
4789 compiletime_assert_atomic_type(*p); \
4790 smp_mb(); \
4791 - ACCESS_ONCE(*p) = (v); \
4792 + ACCESS_ONCE_RW(*p) = (v); \
4793 } while (0)
4794
4795 #define smp_load_acquire(p) \
4796 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4797 index 3bf8f4e..5dd5491 100644
4798 --- a/arch/arm64/include/asm/uaccess.h
4799 +++ b/arch/arm64/include/asm/uaccess.h
4800 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4801 flag; \
4802 })
4803
4804 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4805 #define access_ok(type, addr, size) __range_ok(addr, size)
4806 #define user_addr_max get_fs
4807
4808 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4809 index c3a58a1..78fbf54 100644
4810 --- a/arch/avr32/include/asm/cache.h
4811 +++ b/arch/avr32/include/asm/cache.h
4812 @@ -1,8 +1,10 @@
4813 #ifndef __ASM_AVR32_CACHE_H
4814 #define __ASM_AVR32_CACHE_H
4815
4816 +#include <linux/const.h>
4817 +
4818 #define L1_CACHE_SHIFT 5
4819 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4820 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4821
4822 /*
4823 * Memory returned by kmalloc() may be used for DMA, so we must make
4824 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4825 index d232888..87c8df1 100644
4826 --- a/arch/avr32/include/asm/elf.h
4827 +++ b/arch/avr32/include/asm/elf.h
4828 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4829 the loader. We need to make sure that it is out of the way of the program
4830 that it will "exec", and that there is sufficient room for the brk. */
4831
4832 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4833 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4834
4835 +#ifdef CONFIG_PAX_ASLR
4836 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4837 +
4838 +#define PAX_DELTA_MMAP_LEN 15
4839 +#define PAX_DELTA_STACK_LEN 15
4840 +#endif
4841
4842 /* This yields a mask that user programs can use to figure out what
4843 instruction set this CPU supports. This could be done in user space,
4844 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4845 index 479330b..53717a8 100644
4846 --- a/arch/avr32/include/asm/kmap_types.h
4847 +++ b/arch/avr32/include/asm/kmap_types.h
4848 @@ -2,9 +2,9 @@
4849 #define __ASM_AVR32_KMAP_TYPES_H
4850
4851 #ifdef CONFIG_DEBUG_HIGHMEM
4852 -# define KM_TYPE_NR 29
4853 +# define KM_TYPE_NR 30
4854 #else
4855 -# define KM_TYPE_NR 14
4856 +# define KM_TYPE_NR 15
4857 #endif
4858
4859 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4860 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4861 index 0eca933..eb78c7b 100644
4862 --- a/arch/avr32/mm/fault.c
4863 +++ b/arch/avr32/mm/fault.c
4864 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4865
4866 int exception_trace = 1;
4867
4868 +#ifdef CONFIG_PAX_PAGEEXEC
4869 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4870 +{
4871 + unsigned long i;
4872 +
4873 + printk(KERN_ERR "PAX: bytes at PC: ");
4874 + for (i = 0; i < 20; i++) {
4875 + unsigned char c;
4876 + if (get_user(c, (unsigned char *)pc+i))
4877 + printk(KERN_CONT "???????? ");
4878 + else
4879 + printk(KERN_CONT "%02x ", c);
4880 + }
4881 + printk("\n");
4882 +}
4883 +#endif
4884 +
4885 /*
4886 * This routine handles page faults. It determines the address and the
4887 * problem, and then passes it off to one of the appropriate routines.
4888 @@ -176,6 +193,16 @@ bad_area:
4889 up_read(&mm->mmap_sem);
4890
4891 if (user_mode(regs)) {
4892 +
4893 +#ifdef CONFIG_PAX_PAGEEXEC
4894 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4895 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4896 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4897 + do_group_exit(SIGKILL);
4898 + }
4899 + }
4900 +#endif
4901 +
4902 if (exception_trace && printk_ratelimit())
4903 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4904 "sp %08lx ecr %lu\n",
4905 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4906 index 568885a..f8008df 100644
4907 --- a/arch/blackfin/include/asm/cache.h
4908 +++ b/arch/blackfin/include/asm/cache.h
4909 @@ -7,6 +7,7 @@
4910 #ifndef __ARCH_BLACKFIN_CACHE_H
4911 #define __ARCH_BLACKFIN_CACHE_H
4912
4913 +#include <linux/const.h>
4914 #include <linux/linkage.h> /* for asmlinkage */
4915
4916 /*
4917 @@ -14,7 +15,7 @@
4918 * Blackfin loads 32 bytes for cache
4919 */
4920 #define L1_CACHE_SHIFT 5
4921 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4922 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4923 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4924
4925 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4926 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4927 index aea2718..3639a60 100644
4928 --- a/arch/cris/include/arch-v10/arch/cache.h
4929 +++ b/arch/cris/include/arch-v10/arch/cache.h
4930 @@ -1,8 +1,9 @@
4931 #ifndef _ASM_ARCH_CACHE_H
4932 #define _ASM_ARCH_CACHE_H
4933
4934 +#include <linux/const.h>
4935 /* Etrax 100LX have 32-byte cache-lines. */
4936 -#define L1_CACHE_BYTES 32
4937 #define L1_CACHE_SHIFT 5
4938 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4939
4940 #endif /* _ASM_ARCH_CACHE_H */
4941 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4942 index 7caf25d..ee65ac5 100644
4943 --- a/arch/cris/include/arch-v32/arch/cache.h
4944 +++ b/arch/cris/include/arch-v32/arch/cache.h
4945 @@ -1,11 +1,12 @@
4946 #ifndef _ASM_CRIS_ARCH_CACHE_H
4947 #define _ASM_CRIS_ARCH_CACHE_H
4948
4949 +#include <linux/const.h>
4950 #include <arch/hwregs/dma.h>
4951
4952 /* A cache-line is 32 bytes. */
4953 -#define L1_CACHE_BYTES 32
4954 #define L1_CACHE_SHIFT 5
4955 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4956
4957 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4958
4959 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4960 index b86329d..6709906 100644
4961 --- a/arch/frv/include/asm/atomic.h
4962 +++ b/arch/frv/include/asm/atomic.h
4963 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4964 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4965 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4966
4967 +#define atomic64_read_unchecked(v) atomic64_read(v)
4968 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4969 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4970 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4971 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4972 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4973 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4974 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4975 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4976 +
4977 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4978 {
4979 int c, old;
4980 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4981 index 2797163..c2a401d 100644
4982 --- a/arch/frv/include/asm/cache.h
4983 +++ b/arch/frv/include/asm/cache.h
4984 @@ -12,10 +12,11 @@
4985 #ifndef __ASM_CACHE_H
4986 #define __ASM_CACHE_H
4987
4988 +#include <linux/const.h>
4989
4990 /* bytes per L1 cache line */
4991 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4992 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4993 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4994
4995 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4996 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4997 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4998 index 43901f2..0d8b865 100644
4999 --- a/arch/frv/include/asm/kmap_types.h
5000 +++ b/arch/frv/include/asm/kmap_types.h
5001 @@ -2,6 +2,6 @@
5002 #ifndef _ASM_KMAP_TYPES_H
5003 #define _ASM_KMAP_TYPES_H
5004
5005 -#define KM_TYPE_NR 17
5006 +#define KM_TYPE_NR 18
5007
5008 #endif
5009 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5010 index 836f147..4cf23f5 100644
5011 --- a/arch/frv/mm/elf-fdpic.c
5012 +++ b/arch/frv/mm/elf-fdpic.c
5013 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5014 {
5015 struct vm_area_struct *vma;
5016 struct vm_unmapped_area_info info;
5017 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5018
5019 if (len > TASK_SIZE)
5020 return -ENOMEM;
5021 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5022 if (addr) {
5023 addr = PAGE_ALIGN(addr);
5024 vma = find_vma(current->mm, addr);
5025 - if (TASK_SIZE - len >= addr &&
5026 - (!vma || addr + len <= vma->vm_start))
5027 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5028 goto success;
5029 }
5030
5031 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5032 info.high_limit = (current->mm->start_stack - 0x00200000);
5033 info.align_mask = 0;
5034 info.align_offset = 0;
5035 + info.threadstack_offset = offset;
5036 addr = vm_unmapped_area(&info);
5037 if (!(addr & ~PAGE_MASK))
5038 goto success;
5039 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5040 index f4ca594..adc72fd6 100644
5041 --- a/arch/hexagon/include/asm/cache.h
5042 +++ b/arch/hexagon/include/asm/cache.h
5043 @@ -21,9 +21,11 @@
5044 #ifndef __ASM_CACHE_H
5045 #define __ASM_CACHE_H
5046
5047 +#include <linux/const.h>
5048 +
5049 /* Bytes per L1 cache line */
5050 -#define L1_CACHE_SHIFT (5)
5051 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5052 +#define L1_CACHE_SHIFT 5
5053 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5054
5055 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5056 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5057 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5058 index 12c3afe..b1abab2 100644
5059 --- a/arch/ia64/Kconfig
5060 +++ b/arch/ia64/Kconfig
5061 @@ -546,6 +546,7 @@ source "drivers/sn/Kconfig"
5062 config KEXEC
5063 bool "kexec system call"
5064 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5065 + depends on !GRKERNSEC_KMEM
5066 help
5067 kexec is a system call that implements the ability to shutdown your
5068 current kernel, and to start another kernel. It is like a reboot
5069 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5070 index 6e6fe18..a6ae668 100644
5071 --- a/arch/ia64/include/asm/atomic.h
5072 +++ b/arch/ia64/include/asm/atomic.h
5073 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5074 #define atomic64_inc(v) atomic64_add(1, (v))
5075 #define atomic64_dec(v) atomic64_sub(1, (v))
5076
5077 +#define atomic64_read_unchecked(v) atomic64_read(v)
5078 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5079 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5080 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5081 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5082 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5083 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5084 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5085 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5086 +
5087 /* Atomic operations are already serializing */
5088 #define smp_mb__before_atomic_dec() barrier()
5089 #define smp_mb__after_atomic_dec() barrier()
5090 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5091 index d0a69aa..142f878 100644
5092 --- a/arch/ia64/include/asm/barrier.h
5093 +++ b/arch/ia64/include/asm/barrier.h
5094 @@ -64,7 +64,7 @@
5095 do { \
5096 compiletime_assert_atomic_type(*p); \
5097 barrier(); \
5098 - ACCESS_ONCE(*p) = (v); \
5099 + ACCESS_ONCE_RW(*p) = (v); \
5100 } while (0)
5101
5102 #define smp_load_acquire(p) \
5103 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5104 index 988254a..e1ee885 100644
5105 --- a/arch/ia64/include/asm/cache.h
5106 +++ b/arch/ia64/include/asm/cache.h
5107 @@ -1,6 +1,7 @@
5108 #ifndef _ASM_IA64_CACHE_H
5109 #define _ASM_IA64_CACHE_H
5110
5111 +#include <linux/const.h>
5112
5113 /*
5114 * Copyright (C) 1998-2000 Hewlett-Packard Co
5115 @@ -9,7 +10,7 @@
5116
5117 /* Bytes per L1 (data) cache line. */
5118 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5119 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5120 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5121
5122 #ifdef CONFIG_SMP
5123 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5124 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5125 index 5a83c5c..4d7f553 100644
5126 --- a/arch/ia64/include/asm/elf.h
5127 +++ b/arch/ia64/include/asm/elf.h
5128 @@ -42,6 +42,13 @@
5129 */
5130 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5131
5132 +#ifdef CONFIG_PAX_ASLR
5133 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5134 +
5135 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5136 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5137 +#endif
5138 +
5139 #define PT_IA_64_UNWIND 0x70000001
5140
5141 /* IA-64 relocations: */
5142 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5143 index 5767cdf..7462574 100644
5144 --- a/arch/ia64/include/asm/pgalloc.h
5145 +++ b/arch/ia64/include/asm/pgalloc.h
5146 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5147 pgd_val(*pgd_entry) = __pa(pud);
5148 }
5149
5150 +static inline void
5151 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5152 +{
5153 + pgd_populate(mm, pgd_entry, pud);
5154 +}
5155 +
5156 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5157 {
5158 return quicklist_alloc(0, GFP_KERNEL, NULL);
5159 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5160 pud_val(*pud_entry) = __pa(pmd);
5161 }
5162
5163 +static inline void
5164 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5165 +{
5166 + pud_populate(mm, pud_entry, pmd);
5167 +}
5168 +
5169 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5170 {
5171 return quicklist_alloc(0, GFP_KERNEL, NULL);
5172 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5173 index 7935115..c0eca6a 100644
5174 --- a/arch/ia64/include/asm/pgtable.h
5175 +++ b/arch/ia64/include/asm/pgtable.h
5176 @@ -12,7 +12,7 @@
5177 * David Mosberger-Tang <davidm@hpl.hp.com>
5178 */
5179
5180 -
5181 +#include <linux/const.h>
5182 #include <asm/mman.h>
5183 #include <asm/page.h>
5184 #include <asm/processor.h>
5185 @@ -142,6 +142,17 @@
5186 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5187 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5188 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5189 +
5190 +#ifdef CONFIG_PAX_PAGEEXEC
5191 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5192 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5193 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5194 +#else
5195 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5196 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5197 +# define PAGE_COPY_NOEXEC PAGE_COPY
5198 +#endif
5199 +
5200 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5201 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5202 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5203 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5204 index 45698cd..e8e2dbc 100644
5205 --- a/arch/ia64/include/asm/spinlock.h
5206 +++ b/arch/ia64/include/asm/spinlock.h
5207 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5208 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5209
5210 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5211 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5212 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5213 }
5214
5215 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5216 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5217 index 449c8c0..3d4b1e9 100644
5218 --- a/arch/ia64/include/asm/uaccess.h
5219 +++ b/arch/ia64/include/asm/uaccess.h
5220 @@ -70,6 +70,7 @@
5221 && ((segment).seg == KERNEL_DS.seg \
5222 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5223 })
5224 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5225 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5226
5227 /*
5228 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5229 static inline unsigned long
5230 __copy_to_user (void __user *to, const void *from, unsigned long count)
5231 {
5232 + if (count > INT_MAX)
5233 + return count;
5234 +
5235 + if (!__builtin_constant_p(count))
5236 + check_object_size(from, count, true);
5237 +
5238 return __copy_user(to, (__force void __user *) from, count);
5239 }
5240
5241 static inline unsigned long
5242 __copy_from_user (void *to, const void __user *from, unsigned long count)
5243 {
5244 + if (count > INT_MAX)
5245 + return count;
5246 +
5247 + if (!__builtin_constant_p(count))
5248 + check_object_size(to, count, false);
5249 +
5250 return __copy_user((__force void __user *) to, from, count);
5251 }
5252
5253 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5254 ({ \
5255 void __user *__cu_to = (to); \
5256 const void *__cu_from = (from); \
5257 - long __cu_len = (n); \
5258 + unsigned long __cu_len = (n); \
5259 \
5260 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5261 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5262 + if (!__builtin_constant_p(n)) \
5263 + check_object_size(__cu_from, __cu_len, true); \
5264 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5265 + } \
5266 __cu_len; \
5267 })
5268
5269 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5270 ({ \
5271 void *__cu_to = (to); \
5272 const void __user *__cu_from = (from); \
5273 - long __cu_len = (n); \
5274 + unsigned long __cu_len = (n); \
5275 \
5276 __chk_user_ptr(__cu_from); \
5277 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5278 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5279 + if (!__builtin_constant_p(n)) \
5280 + check_object_size(__cu_to, __cu_len, false); \
5281 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5282 + } \
5283 __cu_len; \
5284 })
5285
5286 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5287 index 24603be..948052d 100644
5288 --- a/arch/ia64/kernel/module.c
5289 +++ b/arch/ia64/kernel/module.c
5290 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5291 void
5292 module_free (struct module *mod, void *module_region)
5293 {
5294 - if (mod && mod->arch.init_unw_table &&
5295 - module_region == mod->module_init) {
5296 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5297 unw_remove_unwind_table(mod->arch.init_unw_table);
5298 mod->arch.init_unw_table = NULL;
5299 }
5300 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5301 }
5302
5303 static inline int
5304 +in_init_rx (const struct module *mod, uint64_t addr)
5305 +{
5306 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5307 +}
5308 +
5309 +static inline int
5310 +in_init_rw (const struct module *mod, uint64_t addr)
5311 +{
5312 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5313 +}
5314 +
5315 +static inline int
5316 in_init (const struct module *mod, uint64_t addr)
5317 {
5318 - return addr - (uint64_t) mod->module_init < mod->init_size;
5319 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5320 +}
5321 +
5322 +static inline int
5323 +in_core_rx (const struct module *mod, uint64_t addr)
5324 +{
5325 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5326 +}
5327 +
5328 +static inline int
5329 +in_core_rw (const struct module *mod, uint64_t addr)
5330 +{
5331 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5332 }
5333
5334 static inline int
5335 in_core (const struct module *mod, uint64_t addr)
5336 {
5337 - return addr - (uint64_t) mod->module_core < mod->core_size;
5338 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5339 }
5340
5341 static inline int
5342 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5343 break;
5344
5345 case RV_BDREL:
5346 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5347 + if (in_init_rx(mod, val))
5348 + val -= (uint64_t) mod->module_init_rx;
5349 + else if (in_init_rw(mod, val))
5350 + val -= (uint64_t) mod->module_init_rw;
5351 + else if (in_core_rx(mod, val))
5352 + val -= (uint64_t) mod->module_core_rx;
5353 + else if (in_core_rw(mod, val))
5354 + val -= (uint64_t) mod->module_core_rw;
5355 break;
5356
5357 case RV_LTV:
5358 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5359 * addresses have been selected...
5360 */
5361 uint64_t gp;
5362 - if (mod->core_size > MAX_LTOFF)
5363 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5364 /*
5365 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5366 * at the end of the module.
5367 */
5368 - gp = mod->core_size - MAX_LTOFF / 2;
5369 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5370 else
5371 - gp = mod->core_size / 2;
5372 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5373 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5374 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5375 mod->arch.gp = gp;
5376 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5377 }
5378 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5379 index c39c3cd..3c77738 100644
5380 --- a/arch/ia64/kernel/palinfo.c
5381 +++ b/arch/ia64/kernel/palinfo.c
5382 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5383 return NOTIFY_OK;
5384 }
5385
5386 -static struct notifier_block __refdata palinfo_cpu_notifier =
5387 +static struct notifier_block palinfo_cpu_notifier =
5388 {
5389 .notifier_call = palinfo_cpu_callback,
5390 .priority = 0,
5391 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5392 index 41e33f8..65180b2a 100644
5393 --- a/arch/ia64/kernel/sys_ia64.c
5394 +++ b/arch/ia64/kernel/sys_ia64.c
5395 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5396 unsigned long align_mask = 0;
5397 struct mm_struct *mm = current->mm;
5398 struct vm_unmapped_area_info info;
5399 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5400
5401 if (len > RGN_MAP_LIMIT)
5402 return -ENOMEM;
5403 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5404 if (REGION_NUMBER(addr) == RGN_HPAGE)
5405 addr = 0;
5406 #endif
5407 +
5408 +#ifdef CONFIG_PAX_RANDMMAP
5409 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5410 + addr = mm->free_area_cache;
5411 + else
5412 +#endif
5413 +
5414 if (!addr)
5415 addr = TASK_UNMAPPED_BASE;
5416
5417 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5418 info.high_limit = TASK_SIZE;
5419 info.align_mask = align_mask;
5420 info.align_offset = 0;
5421 + info.threadstack_offset = offset;
5422 return vm_unmapped_area(&info);
5423 }
5424
5425 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5426 index 84f8a52..7c76178 100644
5427 --- a/arch/ia64/kernel/vmlinux.lds.S
5428 +++ b/arch/ia64/kernel/vmlinux.lds.S
5429 @@ -192,7 +192,7 @@ SECTIONS {
5430 /* Per-cpu data: */
5431 . = ALIGN(PERCPU_PAGE_SIZE);
5432 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5433 - __phys_per_cpu_start = __per_cpu_load;
5434 + __phys_per_cpu_start = per_cpu_load;
5435 /*
5436 * ensure percpu data fits
5437 * into percpu page size
5438 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5439 index 7225dad..2a7c8256 100644
5440 --- a/arch/ia64/mm/fault.c
5441 +++ b/arch/ia64/mm/fault.c
5442 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5443 return pte_present(pte);
5444 }
5445
5446 +#ifdef CONFIG_PAX_PAGEEXEC
5447 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5448 +{
5449 + unsigned long i;
5450 +
5451 + printk(KERN_ERR "PAX: bytes at PC: ");
5452 + for (i = 0; i < 8; i++) {
5453 + unsigned int c;
5454 + if (get_user(c, (unsigned int *)pc+i))
5455 + printk(KERN_CONT "???????? ");
5456 + else
5457 + printk(KERN_CONT "%08x ", c);
5458 + }
5459 + printk("\n");
5460 +}
5461 +#endif
5462 +
5463 # define VM_READ_BIT 0
5464 # define VM_WRITE_BIT 1
5465 # define VM_EXEC_BIT 2
5466 @@ -151,8 +168,21 @@ retry:
5467 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5468 goto bad_area;
5469
5470 - if ((vma->vm_flags & mask) != mask)
5471 + if ((vma->vm_flags & mask) != mask) {
5472 +
5473 +#ifdef CONFIG_PAX_PAGEEXEC
5474 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5475 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5476 + goto bad_area;
5477 +
5478 + up_read(&mm->mmap_sem);
5479 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5480 + do_group_exit(SIGKILL);
5481 + }
5482 +#endif
5483 +
5484 goto bad_area;
5485 + }
5486
5487 /*
5488 * If for any reason at all we couldn't handle the fault, make
5489 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5490 index 76069c1..c2aa816 100644
5491 --- a/arch/ia64/mm/hugetlbpage.c
5492 +++ b/arch/ia64/mm/hugetlbpage.c
5493 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5494 unsigned long pgoff, unsigned long flags)
5495 {
5496 struct vm_unmapped_area_info info;
5497 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5498
5499 if (len > RGN_MAP_LIMIT)
5500 return -ENOMEM;
5501 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5502 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5503 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5504 info.align_offset = 0;
5505 + info.threadstack_offset = offset;
5506 return vm_unmapped_area(&info);
5507 }
5508
5509 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5510 index 25c3502..560dae7 100644
5511 --- a/arch/ia64/mm/init.c
5512 +++ b/arch/ia64/mm/init.c
5513 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5514 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5515 vma->vm_end = vma->vm_start + PAGE_SIZE;
5516 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5517 +
5518 +#ifdef CONFIG_PAX_PAGEEXEC
5519 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5520 + vma->vm_flags &= ~VM_EXEC;
5521 +
5522 +#ifdef CONFIG_PAX_MPROTECT
5523 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5524 + vma->vm_flags &= ~VM_MAYEXEC;
5525 +#endif
5526 +
5527 + }
5528 +#endif
5529 +
5530 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5531 down_write(&current->mm->mmap_sem);
5532 if (insert_vm_struct(current->mm, vma)) {
5533 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5534 index 40b3ee9..8c2c112 100644
5535 --- a/arch/m32r/include/asm/cache.h
5536 +++ b/arch/m32r/include/asm/cache.h
5537 @@ -1,8 +1,10 @@
5538 #ifndef _ASM_M32R_CACHE_H
5539 #define _ASM_M32R_CACHE_H
5540
5541 +#include <linux/const.h>
5542 +
5543 /* L1 cache line size */
5544 #define L1_CACHE_SHIFT 4
5545 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5546 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5547
5548 #endif /* _ASM_M32R_CACHE_H */
5549 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5550 index 82abd15..d95ae5d 100644
5551 --- a/arch/m32r/lib/usercopy.c
5552 +++ b/arch/m32r/lib/usercopy.c
5553 @@ -14,6 +14,9 @@
5554 unsigned long
5555 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5556 {
5557 + if ((long)n < 0)
5558 + return n;
5559 +
5560 prefetch(from);
5561 if (access_ok(VERIFY_WRITE, to, n))
5562 __copy_user(to,from,n);
5563 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5564 unsigned long
5565 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5566 {
5567 + if ((long)n < 0)
5568 + return n;
5569 +
5570 prefetchw(to);
5571 if (access_ok(VERIFY_READ, from, n))
5572 __copy_user_zeroing(to,from,n);
5573 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5574 index 0395c51..5f26031 100644
5575 --- a/arch/m68k/include/asm/cache.h
5576 +++ b/arch/m68k/include/asm/cache.h
5577 @@ -4,9 +4,11 @@
5578 #ifndef __ARCH_M68K_CACHE_H
5579 #define __ARCH_M68K_CACHE_H
5580
5581 +#include <linux/const.h>
5582 +
5583 /* bytes per L1 cache line */
5584 #define L1_CACHE_SHIFT 4
5585 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5586 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5587
5588 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5589
5590 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5591 index 2d6f0de..de5f5ac 100644
5592 --- a/arch/metag/include/asm/barrier.h
5593 +++ b/arch/metag/include/asm/barrier.h
5594 @@ -89,7 +89,7 @@ static inline void fence(void)
5595 do { \
5596 compiletime_assert_atomic_type(*p); \
5597 smp_mb(); \
5598 - ACCESS_ONCE(*p) = (v); \
5599 + ACCESS_ONCE_RW(*p) = (v); \
5600 } while (0)
5601
5602 #define smp_load_acquire(p) \
5603 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5604 index 3c52fa6..11b2ad8 100644
5605 --- a/arch/metag/mm/hugetlbpage.c
5606 +++ b/arch/metag/mm/hugetlbpage.c
5607 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5608 info.high_limit = TASK_SIZE;
5609 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5610 info.align_offset = 0;
5611 + info.threadstack_offset = 0;
5612 return vm_unmapped_area(&info);
5613 }
5614
5615 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5616 index 4efe96a..60e8699 100644
5617 --- a/arch/microblaze/include/asm/cache.h
5618 +++ b/arch/microblaze/include/asm/cache.h
5619 @@ -13,11 +13,12 @@
5620 #ifndef _ASM_MICROBLAZE_CACHE_H
5621 #define _ASM_MICROBLAZE_CACHE_H
5622
5623 +#include <linux/const.h>
5624 #include <asm/registers.h>
5625
5626 #define L1_CACHE_SHIFT 5
5627 /* word-granular cache in microblaze */
5628 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5629 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5630
5631 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5632
5633 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5634 index 5cd695f..9a24ad0 100644
5635 --- a/arch/mips/Kconfig
5636 +++ b/arch/mips/Kconfig
5637 @@ -2395,6 +2395,7 @@ source "kernel/Kconfig.preempt"
5638
5639 config KEXEC
5640 bool "Kexec system call"
5641 + depends on !GRKERNSEC_KMEM
5642 help
5643 kexec is a system call that implements the ability to shutdown your
5644 current kernel, and to start another kernel. It is like a reboot
5645 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5646 index 02f2444..506969c 100644
5647 --- a/arch/mips/cavium-octeon/dma-octeon.c
5648 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5649 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5650 if (dma_release_from_coherent(dev, order, vaddr))
5651 return;
5652
5653 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5654 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5655 }
5656
5657 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5658 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5659 index e8eb3d5..2e665d1 100644
5660 --- a/arch/mips/include/asm/atomic.h
5661 +++ b/arch/mips/include/asm/atomic.h
5662 @@ -21,15 +21,39 @@
5663 #include <asm/cmpxchg.h>
5664 #include <asm/war.h>
5665
5666 +#ifdef CONFIG_GENERIC_ATOMIC64
5667 +#include <asm-generic/atomic64.h>
5668 +#endif
5669 +
5670 #define ATOMIC_INIT(i) { (i) }
5671
5672 +#ifdef CONFIG_64BIT
5673 +#define _ASM_EXTABLE(from, to) \
5674 +" .section __ex_table,\"a\"\n" \
5675 +" .dword " #from ", " #to"\n" \
5676 +" .previous\n"
5677 +#else
5678 +#define _ASM_EXTABLE(from, to) \
5679 +" .section __ex_table,\"a\"\n" \
5680 +" .word " #from ", " #to"\n" \
5681 +" .previous\n"
5682 +#endif
5683 +
5684 /*
5685 * atomic_read - read atomic variable
5686 * @v: pointer of type atomic_t
5687 *
5688 * Atomically reads the value of @v.
5689 */
5690 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5691 +static inline int atomic_read(const atomic_t *v)
5692 +{
5693 + return (*(volatile const int *) &v->counter);
5694 +}
5695 +
5696 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5697 +{
5698 + return (*(volatile const int *) &v->counter);
5699 +}
5700
5701 /*
5702 * atomic_set - set atomic variable
5703 @@ -38,7 +62,15 @@
5704 *
5705 * Atomically sets the value of @v to @i.
5706 */
5707 -#define atomic_set(v, i) ((v)->counter = (i))
5708 +static inline void atomic_set(atomic_t *v, int i)
5709 +{
5710 + v->counter = i;
5711 +}
5712 +
5713 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5714 +{
5715 + v->counter = i;
5716 +}
5717
5718 /*
5719 * atomic_add - add integer to atomic variable
5720 @@ -47,7 +79,67 @@
5721 *
5722 * Atomically adds @i to @v.
5723 */
5724 -static __inline__ void atomic_add(int i, atomic_t * v)
5725 +static __inline__ void atomic_add(int i, atomic_t *v)
5726 +{
5727 + int temp;
5728 +
5729 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5730 + __asm__ __volatile__(
5731 + " .set mips3 \n"
5732 + "1: ll %0, %1 # atomic_add \n"
5733 +#ifdef CONFIG_PAX_REFCOUNT
5734 + /* Exception on overflow. */
5735 + "2: add %0, %2 \n"
5736 +#else
5737 + " addu %0, %2 \n"
5738 +#endif
5739 + " sc %0, %1 \n"
5740 + " beqzl %0, 1b \n"
5741 +#ifdef CONFIG_PAX_REFCOUNT
5742 + "3: \n"
5743 + _ASM_EXTABLE(2b, 3b)
5744 +#endif
5745 + " .set mips0 \n"
5746 + : "=&r" (temp), "+m" (v->counter)
5747 + : "Ir" (i));
5748 + } else if (kernel_uses_llsc) {
5749 + __asm__ __volatile__(
5750 + " .set mips3 \n"
5751 + "1: ll %0, %1 # atomic_add \n"
5752 +#ifdef CONFIG_PAX_REFCOUNT
5753 + /* Exception on overflow. */
5754 + "2: add %0, %2 \n"
5755 +#else
5756 + " addu %0, %2 \n"
5757 +#endif
5758 + " sc %0, %1 \n"
5759 + " beqz %0, 1b \n"
5760 +#ifdef CONFIG_PAX_REFCOUNT
5761 + "3: \n"
5762 + _ASM_EXTABLE(2b, 3b)
5763 +#endif
5764 + " .set mips0 \n"
5765 + : "=&r" (temp), "+m" (v->counter)
5766 + : "Ir" (i));
5767 + } else {
5768 + unsigned long flags;
5769 +
5770 + raw_local_irq_save(flags);
5771 + __asm__ __volatile__(
5772 +#ifdef CONFIG_PAX_REFCOUNT
5773 + /* Exception on overflow. */
5774 + "1: add %0, %1 \n"
5775 + "2: \n"
5776 + _ASM_EXTABLE(1b, 2b)
5777 +#else
5778 + " addu %0, %1 \n"
5779 +#endif
5780 + : "+r" (v->counter) : "Ir" (i));
5781 + raw_local_irq_restore(flags);
5782 + }
5783 +}
5784 +
5785 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5786 {
5787 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5788 int temp;
5789 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5790 *
5791 * Atomically subtracts @i from @v.
5792 */
5793 -static __inline__ void atomic_sub(int i, atomic_t * v)
5794 +static __inline__ void atomic_sub(int i, atomic_t *v)
5795 +{
5796 + int temp;
5797 +
5798 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5799 + __asm__ __volatile__(
5800 + " .set mips3 \n"
5801 + "1: ll %0, %1 # atomic64_sub \n"
5802 +#ifdef CONFIG_PAX_REFCOUNT
5803 + /* Exception on overflow. */
5804 + "2: sub %0, %2 \n"
5805 +#else
5806 + " subu %0, %2 \n"
5807 +#endif
5808 + " sc %0, %1 \n"
5809 + " beqzl %0, 1b \n"
5810 +#ifdef CONFIG_PAX_REFCOUNT
5811 + "3: \n"
5812 + _ASM_EXTABLE(2b, 3b)
5813 +#endif
5814 + " .set mips0 \n"
5815 + : "=&r" (temp), "+m" (v->counter)
5816 + : "Ir" (i));
5817 + } else if (kernel_uses_llsc) {
5818 + __asm__ __volatile__(
5819 + " .set mips3 \n"
5820 + "1: ll %0, %1 # atomic64_sub \n"
5821 +#ifdef CONFIG_PAX_REFCOUNT
5822 + /* Exception on overflow. */
5823 + "2: sub %0, %2 \n"
5824 +#else
5825 + " subu %0, %2 \n"
5826 +#endif
5827 + " sc %0, %1 \n"
5828 + " beqz %0, 1b \n"
5829 +#ifdef CONFIG_PAX_REFCOUNT
5830 + "3: \n"
5831 + _ASM_EXTABLE(2b, 3b)
5832 +#endif
5833 + " .set mips0 \n"
5834 + : "=&r" (temp), "+m" (v->counter)
5835 + : "Ir" (i));
5836 + } else {
5837 + unsigned long flags;
5838 +
5839 + raw_local_irq_save(flags);
5840 + __asm__ __volatile__(
5841 +#ifdef CONFIG_PAX_REFCOUNT
5842 + /* Exception on overflow. */
5843 + "1: sub %0, %1 \n"
5844 + "2: \n"
5845 + _ASM_EXTABLE(1b, 2b)
5846 +#else
5847 + " subu %0, %1 \n"
5848 +#endif
5849 + : "+r" (v->counter) : "Ir" (i));
5850 + raw_local_irq_restore(flags);
5851 + }
5852 +}
5853 +
5854 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5855 {
5856 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5857 int temp;
5858 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5859 /*
5860 * Same as above, but return the result value
5861 */
5862 -static __inline__ int atomic_add_return(int i, atomic_t * v)
5863 +static __inline__ int atomic_add_return(int i, atomic_t *v)
5864 +{
5865 + int result;
5866 + int temp;
5867 +
5868 + smp_mb__before_llsc();
5869 +
5870 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5871 + __asm__ __volatile__(
5872 + " .set mips3 \n"
5873 + "1: ll %1, %2 # atomic_add_return \n"
5874 +#ifdef CONFIG_PAX_REFCOUNT
5875 + "2: add %0, %1, %3 \n"
5876 +#else
5877 + " addu %0, %1, %3 \n"
5878 +#endif
5879 + " sc %0, %2 \n"
5880 + " beqzl %0, 1b \n"
5881 +#ifdef CONFIG_PAX_REFCOUNT
5882 + " b 4f \n"
5883 + " .set noreorder \n"
5884 + "3: b 5f \n"
5885 + " move %0, %1 \n"
5886 + " .set reorder \n"
5887 + _ASM_EXTABLE(2b, 3b)
5888 +#endif
5889 + "4: addu %0, %1, %3 \n"
5890 +#ifdef CONFIG_PAX_REFCOUNT
5891 + "5: \n"
5892 +#endif
5893 + " .set mips0 \n"
5894 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5895 + : "Ir" (i));
5896 + } else if (kernel_uses_llsc) {
5897 + __asm__ __volatile__(
5898 + " .set mips3 \n"
5899 + "1: ll %1, %2 # atomic_add_return \n"
5900 +#ifdef CONFIG_PAX_REFCOUNT
5901 + "2: add %0, %1, %3 \n"
5902 +#else
5903 + " addu %0, %1, %3 \n"
5904 +#endif
5905 + " sc %0, %2 \n"
5906 + " bnez %0, 4f \n"
5907 + " b 1b \n"
5908 +#ifdef CONFIG_PAX_REFCOUNT
5909 + " .set noreorder \n"
5910 + "3: b 5f \n"
5911 + " move %0, %1 \n"
5912 + " .set reorder \n"
5913 + _ASM_EXTABLE(2b, 3b)
5914 +#endif
5915 + "4: addu %0, %1, %3 \n"
5916 +#ifdef CONFIG_PAX_REFCOUNT
5917 + "5: \n"
5918 +#endif
5919 + " .set mips0 \n"
5920 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5921 + : "Ir" (i));
5922 + } else {
5923 + unsigned long flags;
5924 +
5925 + raw_local_irq_save(flags);
5926 + __asm__ __volatile__(
5927 + " lw %0, %1 \n"
5928 +#ifdef CONFIG_PAX_REFCOUNT
5929 + /* Exception on overflow. */
5930 + "1: add %0, %2 \n"
5931 +#else
5932 + " addu %0, %2 \n"
5933 +#endif
5934 + " sw %0, %1 \n"
5935 +#ifdef CONFIG_PAX_REFCOUNT
5936 + /* Note: Dest reg is not modified on overflow */
5937 + "2: \n"
5938 + _ASM_EXTABLE(1b, 2b)
5939 +#endif
5940 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5941 + raw_local_irq_restore(flags);
5942 + }
5943 +
5944 + smp_llsc_mb();
5945 +
5946 + return result;
5947 +}
5948 +
5949 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5950 {
5951 int result;
5952
5953 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5954 return result;
5955 }
5956
5957 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
5958 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
5959 +{
5960 + int result;
5961 + int temp;
5962 +
5963 + smp_mb__before_llsc();
5964 +
5965 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5966 + __asm__ __volatile__(
5967 + " .set mips3 \n"
5968 + "1: ll %1, %2 # atomic_sub_return \n"
5969 +#ifdef CONFIG_PAX_REFCOUNT
5970 + "2: sub %0, %1, %3 \n"
5971 +#else
5972 + " subu %0, %1, %3 \n"
5973 +#endif
5974 + " sc %0, %2 \n"
5975 + " beqzl %0, 1b \n"
5976 +#ifdef CONFIG_PAX_REFCOUNT
5977 + " b 4f \n"
5978 + " .set noreorder \n"
5979 + "3: b 5f \n"
5980 + " move %0, %1 \n"
5981 + " .set reorder \n"
5982 + _ASM_EXTABLE(2b, 3b)
5983 +#endif
5984 + "4: subu %0, %1, %3 \n"
5985 +#ifdef CONFIG_PAX_REFCOUNT
5986 + "5: \n"
5987 +#endif
5988 + " .set mips0 \n"
5989 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5990 + : "Ir" (i), "m" (v->counter)
5991 + : "memory");
5992 + } else if (kernel_uses_llsc) {
5993 + __asm__ __volatile__(
5994 + " .set mips3 \n"
5995 + "1: ll %1, %2 # atomic_sub_return \n"
5996 +#ifdef CONFIG_PAX_REFCOUNT
5997 + "2: sub %0, %1, %3 \n"
5998 +#else
5999 + " subu %0, %1, %3 \n"
6000 +#endif
6001 + " sc %0, %2 \n"
6002 + " bnez %0, 4f \n"
6003 + " b 1b \n"
6004 +#ifdef CONFIG_PAX_REFCOUNT
6005 + " .set noreorder \n"
6006 + "3: b 5f \n"
6007 + " move %0, %1 \n"
6008 + " .set reorder \n"
6009 + _ASM_EXTABLE(2b, 3b)
6010 +#endif
6011 + "4: subu %0, %1, %3 \n"
6012 +#ifdef CONFIG_PAX_REFCOUNT
6013 + "5: \n"
6014 +#endif
6015 + " .set mips0 \n"
6016 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6017 + : "Ir" (i));
6018 + } else {
6019 + unsigned long flags;
6020 +
6021 + raw_local_irq_save(flags);
6022 + __asm__ __volatile__(
6023 + " lw %0, %1 \n"
6024 +#ifdef CONFIG_PAX_REFCOUNT
6025 + /* Exception on overflow. */
6026 + "1: sub %0, %2 \n"
6027 +#else
6028 + " subu %0, %2 \n"
6029 +#endif
6030 + " sw %0, %1 \n"
6031 +#ifdef CONFIG_PAX_REFCOUNT
6032 + /* Note: Dest reg is not modified on overflow */
6033 + "2: \n"
6034 + _ASM_EXTABLE(1b, 2b)
6035 +#endif
6036 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6037 + raw_local_irq_restore(flags);
6038 + }
6039 +
6040 + smp_llsc_mb();
6041 +
6042 + return result;
6043 +}
6044 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6045 {
6046 int result;
6047
6048 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6049 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6050 * The function returns the old value of @v minus @i.
6051 */
6052 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6053 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6054 {
6055 int result;
6056
6057 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6058 return result;
6059 }
6060
6061 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6062 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6063 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6064 +{
6065 + return cmpxchg(&v->counter, old, new);
6066 +}
6067 +
6068 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6069 + int new)
6070 +{
6071 + return cmpxchg(&(v->counter), old, new);
6072 +}
6073 +
6074 +static inline int atomic_xchg(atomic_t *v, int new)
6075 +{
6076 + return xchg(&v->counter, new);
6077 +}
6078 +
6079 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6080 +{
6081 + return xchg(&(v->counter), new);
6082 +}
6083
6084 /**
6085 * __atomic_add_unless - add unless the number is a given value
6086 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6087
6088 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6089 #define atomic_inc_return(v) atomic_add_return(1, (v))
6090 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6091 +{
6092 + return atomic_add_return_unchecked(1, v);
6093 +}
6094
6095 /*
6096 * atomic_sub_and_test - subtract value from variable and test result
6097 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6098 * other cases.
6099 */
6100 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6101 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6102 +{
6103 + return atomic_add_return_unchecked(1, v) == 0;
6104 +}
6105
6106 /*
6107 * atomic_dec_and_test - decrement by 1 and test
6108 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6109 * Atomically increments @v by 1.
6110 */
6111 #define atomic_inc(v) atomic_add(1, (v))
6112 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6113 +{
6114 + atomic_add_unchecked(1, v);
6115 +}
6116
6117 /*
6118 * atomic_dec - decrement and test
6119 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6120 * Atomically decrements @v by 1.
6121 */
6122 #define atomic_dec(v) atomic_sub(1, (v))
6123 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6124 +{
6125 + atomic_sub_unchecked(1, v);
6126 +}
6127
6128 /*
6129 * atomic_add_negative - add and test if negative
6130 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6131 * @v: pointer of type atomic64_t
6132 *
6133 */
6134 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6135 +static inline long atomic64_read(const atomic64_t *v)
6136 +{
6137 + return (*(volatile const long *) &v->counter);
6138 +}
6139 +
6140 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6141 +{
6142 + return (*(volatile const long *) &v->counter);
6143 +}
6144
6145 /*
6146 * atomic64_set - set atomic variable
6147 * @v: pointer of type atomic64_t
6148 * @i: required value
6149 */
6150 -#define atomic64_set(v, i) ((v)->counter = (i))
6151 +static inline void atomic64_set(atomic64_t *v, long i)
6152 +{
6153 + v->counter = i;
6154 +}
6155 +
6156 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6157 +{
6158 + v->counter = i;
6159 +}
6160
6161 /*
6162 * atomic64_add - add integer to atomic variable
6163 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6164 *
6165 * Atomically adds @i to @v.
6166 */
6167 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6168 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6169 +{
6170 + long temp;
6171 +
6172 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6173 + __asm__ __volatile__(
6174 + " .set mips3 \n"
6175 + "1: lld %0, %1 # atomic64_add \n"
6176 +#ifdef CONFIG_PAX_REFCOUNT
6177 + /* Exception on overflow. */
6178 + "2: dadd %0, %2 \n"
6179 +#else
6180 + " daddu %0, %2 \n"
6181 +#endif
6182 + " scd %0, %1 \n"
6183 + " beqzl %0, 1b \n"
6184 +#ifdef CONFIG_PAX_REFCOUNT
6185 + "3: \n"
6186 + _ASM_EXTABLE(2b, 3b)
6187 +#endif
6188 + " .set mips0 \n"
6189 + : "=&r" (temp), "+m" (v->counter)
6190 + : "Ir" (i));
6191 + } else if (kernel_uses_llsc) {
6192 + __asm__ __volatile__(
6193 + " .set mips3 \n"
6194 + "1: lld %0, %1 # atomic64_add \n"
6195 +#ifdef CONFIG_PAX_REFCOUNT
6196 + /* Exception on overflow. */
6197 + "2: dadd %0, %2 \n"
6198 +#else
6199 + " daddu %0, %2 \n"
6200 +#endif
6201 + " scd %0, %1 \n"
6202 + " beqz %0, 1b \n"
6203 +#ifdef CONFIG_PAX_REFCOUNT
6204 + "3: \n"
6205 + _ASM_EXTABLE(2b, 3b)
6206 +#endif
6207 + " .set mips0 \n"
6208 + : "=&r" (temp), "+m" (v->counter)
6209 + : "Ir" (i));
6210 + } else {
6211 + unsigned long flags;
6212 +
6213 + raw_local_irq_save(flags);
6214 + __asm__ __volatile__(
6215 +#ifdef CONFIG_PAX_REFCOUNT
6216 + /* Exception on overflow. */
6217 + "1: dadd %0, %1 \n"
6218 + "2: \n"
6219 + _ASM_EXTABLE(1b, 2b)
6220 +#else
6221 + " daddu %0, %1 \n"
6222 +#endif
6223 + : "+r" (v->counter) : "Ir" (i));
6224 + raw_local_irq_restore(flags);
6225 + }
6226 +}
6227 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6228 {
6229 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6230 long temp;
6231 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6232 *
6233 * Atomically subtracts @i from @v.
6234 */
6235 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6236 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6237 +{
6238 + long temp;
6239 +
6240 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6241 + __asm__ __volatile__(
6242 + " .set mips3 \n"
6243 + "1: lld %0, %1 # atomic64_sub \n"
6244 +#ifdef CONFIG_PAX_REFCOUNT
6245 + /* Exception on overflow. */
6246 + "2: dsub %0, %2 \n"
6247 +#else
6248 + " dsubu %0, %2 \n"
6249 +#endif
6250 + " scd %0, %1 \n"
6251 + " beqzl %0, 1b \n"
6252 +#ifdef CONFIG_PAX_REFCOUNT
6253 + "3: \n"
6254 + _ASM_EXTABLE(2b, 3b)
6255 +#endif
6256 + " .set mips0 \n"
6257 + : "=&r" (temp), "+m" (v->counter)
6258 + : "Ir" (i));
6259 + } else if (kernel_uses_llsc) {
6260 + __asm__ __volatile__(
6261 + " .set mips3 \n"
6262 + "1: lld %0, %1 # atomic64_sub \n"
6263 +#ifdef CONFIG_PAX_REFCOUNT
6264 + /* Exception on overflow. */
6265 + "2: dsub %0, %2 \n"
6266 +#else
6267 + " dsubu %0, %2 \n"
6268 +#endif
6269 + " scd %0, %1 \n"
6270 + " beqz %0, 1b \n"
6271 +#ifdef CONFIG_PAX_REFCOUNT
6272 + "3: \n"
6273 + _ASM_EXTABLE(2b, 3b)
6274 +#endif
6275 + " .set mips0 \n"
6276 + : "=&r" (temp), "+m" (v->counter)
6277 + : "Ir" (i));
6278 + } else {
6279 + unsigned long flags;
6280 +
6281 + raw_local_irq_save(flags);
6282 + __asm__ __volatile__(
6283 +#ifdef CONFIG_PAX_REFCOUNT
6284 + /* Exception on overflow. */
6285 + "1: dsub %0, %1 \n"
6286 + "2: \n"
6287 + _ASM_EXTABLE(1b, 2b)
6288 +#else
6289 + " dsubu %0, %1 \n"
6290 +#endif
6291 + : "+r" (v->counter) : "Ir" (i));
6292 + raw_local_irq_restore(flags);
6293 + }
6294 +}
6295 +
6296 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6297 {
6298 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6299 long temp;
6300 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6301 /*
6302 * Same as above, but return the result value
6303 */
6304 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6305 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6306 +{
6307 + long result;
6308 + long temp;
6309 +
6310 + smp_mb__before_llsc();
6311 +
6312 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6313 + __asm__ __volatile__(
6314 + " .set mips3 \n"
6315 + "1: lld %1, %2 # atomic64_add_return \n"
6316 +#ifdef CONFIG_PAX_REFCOUNT
6317 + "2: dadd %0, %1, %3 \n"
6318 +#else
6319 + " daddu %0, %1, %3 \n"
6320 +#endif
6321 + " scd %0, %2 \n"
6322 + " beqzl %0, 1b \n"
6323 +#ifdef CONFIG_PAX_REFCOUNT
6324 + " b 4f \n"
6325 + " .set noreorder \n"
6326 + "3: b 5f \n"
6327 + " move %0, %1 \n"
6328 + " .set reorder \n"
6329 + _ASM_EXTABLE(2b, 3b)
6330 +#endif
6331 + "4: daddu %0, %1, %3 \n"
6332 +#ifdef CONFIG_PAX_REFCOUNT
6333 + "5: \n"
6334 +#endif
6335 + " .set mips0 \n"
6336 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6337 + : "Ir" (i));
6338 + } else if (kernel_uses_llsc) {
6339 + __asm__ __volatile__(
6340 + " .set mips3 \n"
6341 + "1: lld %1, %2 # atomic64_add_return \n"
6342 +#ifdef CONFIG_PAX_REFCOUNT
6343 + "2: dadd %0, %1, %3 \n"
6344 +#else
6345 + " daddu %0, %1, %3 \n"
6346 +#endif
6347 + " scd %0, %2 \n"
6348 + " bnez %0, 4f \n"
6349 + " b 1b \n"
6350 +#ifdef CONFIG_PAX_REFCOUNT
6351 + " .set noreorder \n"
6352 + "3: b 5f \n"
6353 + " move %0, %1 \n"
6354 + " .set reorder \n"
6355 + _ASM_EXTABLE(2b, 3b)
6356 +#endif
6357 + "4: daddu %0, %1, %3 \n"
6358 +#ifdef CONFIG_PAX_REFCOUNT
6359 + "5: \n"
6360 +#endif
6361 + " .set mips0 \n"
6362 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6363 + : "Ir" (i), "m" (v->counter)
6364 + : "memory");
6365 + } else {
6366 + unsigned long flags;
6367 +
6368 + raw_local_irq_save(flags);
6369 + __asm__ __volatile__(
6370 + " ld %0, %1 \n"
6371 +#ifdef CONFIG_PAX_REFCOUNT
6372 + /* Exception on overflow. */
6373 + "1: dadd %0, %2 \n"
6374 +#else
6375 + " daddu %0, %2 \n"
6376 +#endif
6377 + " sd %0, %1 \n"
6378 +#ifdef CONFIG_PAX_REFCOUNT
6379 + /* Note: Dest reg is not modified on overflow */
6380 + "2: \n"
6381 + _ASM_EXTABLE(1b, 2b)
6382 +#endif
6383 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6384 + raw_local_irq_restore(flags);
6385 + }
6386 +
6387 + smp_llsc_mb();
6388 +
6389 + return result;
6390 +}
6391 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6392 {
6393 long result;
6394
6395 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6396 return result;
6397 }
6398
6399 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6400 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6401 +{
6402 + long result;
6403 + long temp;
6404 +
6405 + smp_mb__before_llsc();
6406 +
6407 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6408 + long temp;
6409 +
6410 + __asm__ __volatile__(
6411 + " .set mips3 \n"
6412 + "1: lld %1, %2 # atomic64_sub_return \n"
6413 +#ifdef CONFIG_PAX_REFCOUNT
6414 + "2: dsub %0, %1, %3 \n"
6415 +#else
6416 + " dsubu %0, %1, %3 \n"
6417 +#endif
6418 + " scd %0, %2 \n"
6419 + " beqzl %0, 1b \n"
6420 +#ifdef CONFIG_PAX_REFCOUNT
6421 + " b 4f \n"
6422 + " .set noreorder \n"
6423 + "3: b 5f \n"
6424 + " move %0, %1 \n"
6425 + " .set reorder \n"
6426 + _ASM_EXTABLE(2b, 3b)
6427 +#endif
6428 + "4: dsubu %0, %1, %3 \n"
6429 +#ifdef CONFIG_PAX_REFCOUNT
6430 + "5: \n"
6431 +#endif
6432 + " .set mips0 \n"
6433 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6434 + : "Ir" (i), "m" (v->counter)
6435 + : "memory");
6436 + } else if (kernel_uses_llsc) {
6437 + __asm__ __volatile__(
6438 + " .set mips3 \n"
6439 + "1: lld %1, %2 # atomic64_sub_return \n"
6440 +#ifdef CONFIG_PAX_REFCOUNT
6441 + "2: dsub %0, %1, %3 \n"
6442 +#else
6443 + " dsubu %0, %1, %3 \n"
6444 +#endif
6445 + " scd %0, %2 \n"
6446 + " bnez %0, 4f \n"
6447 + " b 1b \n"
6448 +#ifdef CONFIG_PAX_REFCOUNT
6449 + " .set noreorder \n"
6450 + "3: b 5f \n"
6451 + " move %0, %1 \n"
6452 + " .set reorder \n"
6453 + _ASM_EXTABLE(2b, 3b)
6454 +#endif
6455 + "4: dsubu %0, %1, %3 \n"
6456 +#ifdef CONFIG_PAX_REFCOUNT
6457 + "5: \n"
6458 +#endif
6459 + " .set mips0 \n"
6460 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6461 + : "Ir" (i), "m" (v->counter)
6462 + : "memory");
6463 + } else {
6464 + unsigned long flags;
6465 +
6466 + raw_local_irq_save(flags);
6467 + __asm__ __volatile__(
6468 + " ld %0, %1 \n"
6469 +#ifdef CONFIG_PAX_REFCOUNT
6470 + /* Exception on overflow. */
6471 + "1: dsub %0, %2 \n"
6472 +#else
6473 + " dsubu %0, %2 \n"
6474 +#endif
6475 + " sd %0, %1 \n"
6476 +#ifdef CONFIG_PAX_REFCOUNT
6477 + /* Note: Dest reg is not modified on overflow */
6478 + "2: \n"
6479 + _ASM_EXTABLE(1b, 2b)
6480 +#endif
6481 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6482 + raw_local_irq_restore(flags);
6483 + }
6484 +
6485 + smp_llsc_mb();
6486 +
6487 + return result;
6488 +}
6489 +
6490 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6491 {
6492 long result;
6493
6494 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6495 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6496 * The function returns the old value of @v minus @i.
6497 */
6498 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6499 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6500 {
6501 long result;
6502
6503 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6504 return result;
6505 }
6506
6507 -#define atomic64_cmpxchg(v, o, n) \
6508 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6509 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6510 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6511 +{
6512 + return cmpxchg(&v->counter, old, new);
6513 +}
6514 +
6515 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6516 + long new)
6517 +{
6518 + return cmpxchg(&(v->counter), old, new);
6519 +}
6520 +
6521 +static inline long atomic64_xchg(atomic64_t *v, long new)
6522 +{
6523 + return xchg(&v->counter, new);
6524 +}
6525 +
6526 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6527 +{
6528 + return xchg(&(v->counter), new);
6529 +}
6530
6531 /**
6532 * atomic64_add_unless - add unless the number is a given value
6533 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6534
6535 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6536 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6537 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6538
6539 /*
6540 * atomic64_sub_and_test - subtract value from variable and test result
6541 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6542 * other cases.
6543 */
6544 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6545 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6546
6547 /*
6548 * atomic64_dec_and_test - decrement by 1 and test
6549 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6550 * Atomically increments @v by 1.
6551 */
6552 #define atomic64_inc(v) atomic64_add(1, (v))
6553 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6554
6555 /*
6556 * atomic64_dec - decrement and test
6557 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6558 * Atomically decrements @v by 1.
6559 */
6560 #define atomic64_dec(v) atomic64_sub(1, (v))
6561 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6562
6563 /*
6564 * atomic64_add_negative - add and test if negative
6565 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6566 index e1aa4e4..670b68b 100644
6567 --- a/arch/mips/include/asm/barrier.h
6568 +++ b/arch/mips/include/asm/barrier.h
6569 @@ -184,7 +184,7 @@
6570 do { \
6571 compiletime_assert_atomic_type(*p); \
6572 smp_mb(); \
6573 - ACCESS_ONCE(*p) = (v); \
6574 + ACCESS_ONCE_RW(*p) = (v); \
6575 } while (0)
6576
6577 #define smp_load_acquire(p) \
6578 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6579 index b4db69f..8f3b093 100644
6580 --- a/arch/mips/include/asm/cache.h
6581 +++ b/arch/mips/include/asm/cache.h
6582 @@ -9,10 +9,11 @@
6583 #ifndef _ASM_CACHE_H
6584 #define _ASM_CACHE_H
6585
6586 +#include <linux/const.h>
6587 #include <kmalloc.h>
6588
6589 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6590 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6591 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6592
6593 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6594 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6595 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6596 index d414405..6bb4ba2 100644
6597 --- a/arch/mips/include/asm/elf.h
6598 +++ b/arch/mips/include/asm/elf.h
6599 @@ -398,13 +398,16 @@ extern const char *__elf_platform;
6600 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6601 #endif
6602
6603 +#ifdef CONFIG_PAX_ASLR
6604 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6605 +
6606 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6607 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6608 +#endif
6609 +
6610 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6611 struct linux_binprm;
6612 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6613 int uses_interp);
6614
6615 -struct mm_struct;
6616 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6617 -#define arch_randomize_brk arch_randomize_brk
6618 -
6619 #endif /* _ASM_ELF_H */
6620 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6621 index c1f6afa..38cc6e9 100644
6622 --- a/arch/mips/include/asm/exec.h
6623 +++ b/arch/mips/include/asm/exec.h
6624 @@ -12,6 +12,6 @@
6625 #ifndef _ASM_EXEC_H
6626 #define _ASM_EXEC_H
6627
6628 -extern unsigned long arch_align_stack(unsigned long sp);
6629 +#define arch_align_stack(x) ((x) & ~0xfUL)
6630
6631 #endif /* _ASM_EXEC_H */
6632 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6633 index 9e8ef59..1139d6b 100644
6634 --- a/arch/mips/include/asm/hw_irq.h
6635 +++ b/arch/mips/include/asm/hw_irq.h
6636 @@ -10,7 +10,7 @@
6637
6638 #include <linux/atomic.h>
6639
6640 -extern atomic_t irq_err_count;
6641 +extern atomic_unchecked_t irq_err_count;
6642
6643 /*
6644 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6645 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6646 index 46dfc3c..a16b13a 100644
6647 --- a/arch/mips/include/asm/local.h
6648 +++ b/arch/mips/include/asm/local.h
6649 @@ -12,15 +12,25 @@ typedef struct
6650 atomic_long_t a;
6651 } local_t;
6652
6653 +typedef struct {
6654 + atomic_long_unchecked_t a;
6655 +} local_unchecked_t;
6656 +
6657 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6658
6659 #define local_read(l) atomic_long_read(&(l)->a)
6660 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6661 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6662 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6663
6664 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6665 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6666 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6667 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6668 #define local_inc(l) atomic_long_inc(&(l)->a)
6669 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6670 #define local_dec(l) atomic_long_dec(&(l)->a)
6671 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6672
6673 /*
6674 * Same as above, but return the result value
6675 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6676 return result;
6677 }
6678
6679 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6680 +{
6681 + unsigned long result;
6682 +
6683 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6684 + unsigned long temp;
6685 +
6686 + __asm__ __volatile__(
6687 + " .set mips3 \n"
6688 + "1:" __LL "%1, %2 # local_add_return \n"
6689 + " addu %0, %1, %3 \n"
6690 + __SC "%0, %2 \n"
6691 + " beqzl %0, 1b \n"
6692 + " addu %0, %1, %3 \n"
6693 + " .set mips0 \n"
6694 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6695 + : "Ir" (i), "m" (l->a.counter)
6696 + : "memory");
6697 + } else if (kernel_uses_llsc) {
6698 + unsigned long temp;
6699 +
6700 + __asm__ __volatile__(
6701 + " .set mips3 \n"
6702 + "1:" __LL "%1, %2 # local_add_return \n"
6703 + " addu %0, %1, %3 \n"
6704 + __SC "%0, %2 \n"
6705 + " beqz %0, 1b \n"
6706 + " addu %0, %1, %3 \n"
6707 + " .set mips0 \n"
6708 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6709 + : "Ir" (i), "m" (l->a.counter)
6710 + : "memory");
6711 + } else {
6712 + unsigned long flags;
6713 +
6714 + local_irq_save(flags);
6715 + result = l->a.counter;
6716 + result += i;
6717 + l->a.counter = result;
6718 + local_irq_restore(flags);
6719 + }
6720 +
6721 + return result;
6722 +}
6723 +
6724 static __inline__ long local_sub_return(long i, local_t * l)
6725 {
6726 unsigned long result;
6727 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6728
6729 #define local_cmpxchg(l, o, n) \
6730 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6731 +#define local_cmpxchg_unchecked(l, o, n) \
6732 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6733 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6734
6735 /**
6736 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6737 index 5699ec3..95def83 100644
6738 --- a/arch/mips/include/asm/page.h
6739 +++ b/arch/mips/include/asm/page.h
6740 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6741 #ifdef CONFIG_CPU_MIPS32
6742 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6743 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6744 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6745 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6746 #else
6747 typedef struct { unsigned long long pte; } pte_t;
6748 #define pte_val(x) ((x).pte)
6749 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6750 index b336037..5b874cc 100644
6751 --- a/arch/mips/include/asm/pgalloc.h
6752 +++ b/arch/mips/include/asm/pgalloc.h
6753 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6754 {
6755 set_pud(pud, __pud((unsigned long)pmd));
6756 }
6757 +
6758 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6759 +{
6760 + pud_populate(mm, pud, pmd);
6761 +}
6762 #endif
6763
6764 /*
6765 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6766 index 008324d..f67c239 100644
6767 --- a/arch/mips/include/asm/pgtable.h
6768 +++ b/arch/mips/include/asm/pgtable.h
6769 @@ -20,6 +20,9 @@
6770 #include <asm/io.h>
6771 #include <asm/pgtable-bits.h>
6772
6773 +#define ktla_ktva(addr) (addr)
6774 +#define ktva_ktla(addr) (addr)
6775 +
6776 struct mm_struct;
6777 struct vm_area_struct;
6778
6779 diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6780 index 25da651..ae2a259 100644
6781 --- a/arch/mips/include/asm/smtc_proc.h
6782 +++ b/arch/mips/include/asm/smtc_proc.h
6783 @@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6784
6785 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6786
6787 -extern atomic_t smtc_fpu_recoveries;
6788 +extern atomic_unchecked_t smtc_fpu_recoveries;
6789
6790 #endif /* __ASM_SMTC_PROC_H */
6791 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6792 index d2d961d..a674df0 100644
6793 --- a/arch/mips/include/asm/thread_info.h
6794 +++ b/arch/mips/include/asm/thread_info.h
6795 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6796 #define TIF_SECCOMP 4 /* secure computing */
6797 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6798 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6799 +/* li takes a 32bit immediate */
6800 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6801 +
6802 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6803 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6804 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6805 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6806 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6807 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6808 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6809 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6810
6811 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6812 _TIF_SYSCALL_AUDIT | \
6813 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6814 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6815 + _TIF_GRSEC_SETXID)
6816
6817 /* work to do in syscall_trace_leave() */
6818 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6819 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6820 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6821
6822 /* work to do on interrupt/exception return */
6823 #define _TIF_WORK_MASK \
6824 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6825 /* work to do on any return to u-space */
6826 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6827 _TIF_WORK_SYSCALL_EXIT | \
6828 - _TIF_SYSCALL_TRACEPOINT)
6829 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6830
6831 /*
6832 * We stash processor id into a COP0 register to retrieve it fast
6833 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6834 index a109510..94ee3f6 100644
6835 --- a/arch/mips/include/asm/uaccess.h
6836 +++ b/arch/mips/include/asm/uaccess.h
6837 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
6838 __ok == 0; \
6839 })
6840
6841 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6842 #define access_ok(type, addr, size) \
6843 likely(__access_ok((addr), (size), __access_mask))
6844
6845 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6846 index 1188e00..41cf144 100644
6847 --- a/arch/mips/kernel/binfmt_elfn32.c
6848 +++ b/arch/mips/kernel/binfmt_elfn32.c
6849 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6850 #undef ELF_ET_DYN_BASE
6851 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6852
6853 +#ifdef CONFIG_PAX_ASLR
6854 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6855 +
6856 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6857 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6858 +#endif
6859 +
6860 #include <asm/processor.h>
6861 #include <linux/module.h>
6862 #include <linux/elfcore.h>
6863 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6864 index 7faf5f2..f3d3cf4 100644
6865 --- a/arch/mips/kernel/binfmt_elfo32.c
6866 +++ b/arch/mips/kernel/binfmt_elfo32.c
6867 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6868 #undef ELF_ET_DYN_BASE
6869 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6870
6871 +#ifdef CONFIG_PAX_ASLR
6872 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6873 +
6874 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6875 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6876 +#endif
6877 +
6878 #include <asm/processor.h>
6879
6880 /*
6881 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6882 index 2b91fe8..fe4f6b4 100644
6883 --- a/arch/mips/kernel/i8259.c
6884 +++ b/arch/mips/kernel/i8259.c
6885 @@ -205,7 +205,7 @@ spurious_8259A_irq:
6886 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6887 spurious_irq_mask |= irqmask;
6888 }
6889 - atomic_inc(&irq_err_count);
6890 + atomic_inc_unchecked(&irq_err_count);
6891 /*
6892 * Theoretically we do not have to handle this IRQ,
6893 * but in Linux this does not cause problems and is
6894 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6895 index 44a1f79..2bd6aa3 100644
6896 --- a/arch/mips/kernel/irq-gt641xx.c
6897 +++ b/arch/mips/kernel/irq-gt641xx.c
6898 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6899 }
6900 }
6901
6902 - atomic_inc(&irq_err_count);
6903 + atomic_inc_unchecked(&irq_err_count);
6904 }
6905
6906 void __init gt641xx_irq_init(void)
6907 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6908 index d1fea7a..2e591b0 100644
6909 --- a/arch/mips/kernel/irq.c
6910 +++ b/arch/mips/kernel/irq.c
6911 @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6912 printk("unexpected IRQ # %d\n", irq);
6913 }
6914
6915 -atomic_t irq_err_count;
6916 +atomic_unchecked_t irq_err_count;
6917
6918 int arch_show_interrupts(struct seq_file *p, int prec)
6919 {
6920 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6921 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6922 return 0;
6923 }
6924
6925 asmlinkage void spurious_interrupt(void)
6926 {
6927 - atomic_inc(&irq_err_count);
6928 + atomic_inc_unchecked(&irq_err_count);
6929 }
6930
6931 void __init init_IRQ(void)
6932 @@ -110,7 +110,10 @@ void __init init_IRQ(void)
6933 #endif
6934 }
6935
6936 +
6937 #ifdef DEBUG_STACKOVERFLOW
6938 +extern void gr_handle_kernel_exploit(void);
6939 +
6940 static inline void check_stack_overflow(void)
6941 {
6942 unsigned long sp;
6943 @@ -126,6 +129,7 @@ static inline void check_stack_overflow(void)
6944 printk("do_IRQ: stack overflow: %ld\n",
6945 sp - sizeof(struct thread_info));
6946 dump_stack();
6947 + gr_handle_kernel_exploit();
6948 }
6949 }
6950 #else
6951 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6952 index 60e39dc..b4829bf 100644
6953 --- a/arch/mips/kernel/process.c
6954 +++ b/arch/mips/kernel/process.c
6955 @@ -579,15 +579,3 @@ unsigned long get_wchan(struct task_struct *task)
6956 out:
6957 return pc;
6958 }
6959 -
6960 -/*
6961 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6962 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6963 - */
6964 -unsigned long arch_align_stack(unsigned long sp)
6965 -{
6966 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6967 - sp -= get_random_int() & ~PAGE_MASK;
6968 -
6969 - return sp & ALMASK;
6970 -}
6971 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6972 index f639ccd..e4b110d 100644
6973 --- a/arch/mips/kernel/ptrace.c
6974 +++ b/arch/mips/kernel/ptrace.c
6975 @@ -630,6 +630,10 @@ long arch_ptrace(struct task_struct *child, long request,
6976 return ret;
6977 }
6978
6979 +#ifdef CONFIG_GRKERNSEC_SETXID
6980 +extern void gr_delayed_cred_worker(void);
6981 +#endif
6982 +
6983 /*
6984 * Notification of system call entry/exit
6985 * - triggered by current->work.syscall_trace
6986 @@ -646,6 +650,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
6987 tracehook_report_syscall_entry(regs))
6988 ret = -1;
6989
6990 +#ifdef CONFIG_GRKERNSEC_SETXID
6991 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6992 + gr_delayed_cred_worker();
6993 +#endif
6994 +
6995 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6996 trace_sys_enter(regs, regs->regs[2]);
6997
6998 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6999 index 07fc524..b9d7f28 100644
7000 --- a/arch/mips/kernel/reset.c
7001 +++ b/arch/mips/kernel/reset.c
7002 @@ -13,6 +13,7 @@
7003 #include <linux/reboot.h>
7004
7005 #include <asm/reboot.h>
7006 +#include <asm/bug.h>
7007
7008 /*
7009 * Urgs ... Too many MIPS machines to handle this in a generic way.
7010 @@ -29,16 +30,19 @@ void machine_restart(char *command)
7011 {
7012 if (_machine_restart)
7013 _machine_restart(command);
7014 + BUG();
7015 }
7016
7017 void machine_halt(void)
7018 {
7019 if (_machine_halt)
7020 _machine_halt();
7021 + BUG();
7022 }
7023
7024 void machine_power_off(void)
7025 {
7026 if (pm_power_off)
7027 pm_power_off();
7028 + BUG();
7029 }
7030 diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
7031 index 38635a9..3fcd5e0 100644
7032 --- a/arch/mips/kernel/smtc-proc.c
7033 +++ b/arch/mips/kernel/smtc-proc.c
7034 @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
7035
7036 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
7037
7038 -atomic_t smtc_fpu_recoveries;
7039 +atomic_unchecked_t smtc_fpu_recoveries;
7040
7041 static int smtc_proc_show(struct seq_file *m, void *v)
7042 {
7043 @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
7044 for(i = 0; i < NR_CPUS; i++)
7045 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
7046 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
7047 - atomic_read(&smtc_fpu_recoveries));
7048 + atomic_read_unchecked(&smtc_fpu_recoveries));
7049 return 0;
7050 }
7051
7052 @@ -73,7 +73,7 @@ void init_smtc_stats(void)
7053 smtc_cpu_stats[i].selfipis = 0;
7054 }
7055
7056 - atomic_set(&smtc_fpu_recoveries, 0);
7057 + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
7058
7059 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
7060 }
7061 diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
7062 index c1681d6..9f881d1 100644
7063 --- a/arch/mips/kernel/smtc.c
7064 +++ b/arch/mips/kernel/smtc.c
7065 @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
7066 }
7067 smtc_ipi_qdump();
7068 printk("%d Recoveries of \"stolen\" FPU\n",
7069 - atomic_read(&smtc_fpu_recoveries));
7070 + atomic_read_unchecked(&smtc_fpu_recoveries));
7071 }
7072
7073
7074 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7075 index c24ad5f..9983ab2 100644
7076 --- a/arch/mips/kernel/sync-r4k.c
7077 +++ b/arch/mips/kernel/sync-r4k.c
7078 @@ -20,8 +20,8 @@
7079 #include <asm/mipsregs.h>
7080
7081 static atomic_t count_start_flag = ATOMIC_INIT(0);
7082 -static atomic_t count_count_start = ATOMIC_INIT(0);
7083 -static atomic_t count_count_stop = ATOMIC_INIT(0);
7084 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7085 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7086 static atomic_t count_reference = ATOMIC_INIT(0);
7087
7088 #define COUNTON 100
7089 @@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
7090
7091 for (i = 0; i < NR_LOOPS; i++) {
7092 /* slaves loop on '!= 2' */
7093 - while (atomic_read(&count_count_start) != 1)
7094 + while (atomic_read_unchecked(&count_count_start) != 1)
7095 mb();
7096 - atomic_set(&count_count_stop, 0);
7097 + atomic_set_unchecked(&count_count_stop, 0);
7098 smp_wmb();
7099
7100 /* this lets the slaves write their count register */
7101 - atomic_inc(&count_count_start);
7102 + atomic_inc_unchecked(&count_count_start);
7103
7104 /*
7105 * Everyone initialises count in the last loop:
7106 @@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
7107 /*
7108 * Wait for all slaves to leave the synchronization point:
7109 */
7110 - while (atomic_read(&count_count_stop) != 1)
7111 + while (atomic_read_unchecked(&count_count_stop) != 1)
7112 mb();
7113 - atomic_set(&count_count_start, 0);
7114 + atomic_set_unchecked(&count_count_start, 0);
7115 smp_wmb();
7116 - atomic_inc(&count_count_stop);
7117 + atomic_inc_unchecked(&count_count_stop);
7118 }
7119 /* Arrange for an interrupt in a short while */
7120 write_c0_compare(read_c0_count() + COUNTON);
7121 @@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
7122 initcount = atomic_read(&count_reference);
7123
7124 for (i = 0; i < NR_LOOPS; i++) {
7125 - atomic_inc(&count_count_start);
7126 - while (atomic_read(&count_count_start) != 2)
7127 + atomic_inc_unchecked(&count_count_start);
7128 + while (atomic_read_unchecked(&count_count_start) != 2)
7129 mb();
7130
7131 /*
7132 @@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
7133 if (i == NR_LOOPS-1)
7134 write_c0_count(initcount);
7135
7136 - atomic_inc(&count_count_stop);
7137 - while (atomic_read(&count_count_stop) != 2)
7138 + atomic_inc_unchecked(&count_count_stop);
7139 + while (atomic_read_unchecked(&count_count_stop) != 2)
7140 mb();
7141 }
7142 /* Arrange for an interrupt in a short while */
7143 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7144 index 8119ac2..b229939 100644
7145 --- a/arch/mips/kernel/traps.c
7146 +++ b/arch/mips/kernel/traps.c
7147 @@ -695,7 +695,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7148 siginfo_t info;
7149
7150 prev_state = exception_enter();
7151 - die_if_kernel("Integer overflow", regs);
7152 + if (unlikely(!user_mode(regs))) {
7153 +
7154 +#ifdef CONFIG_PAX_REFCOUNT
7155 + if (fixup_exception(regs)) {
7156 + pax_report_refcount_overflow(regs);
7157 + exception_exit(prev_state);
7158 + return;
7159 + }
7160 +#endif
7161 +
7162 + die("Integer overflow", regs);
7163 + }
7164
7165 info.si_code = FPE_INTOVF;
7166 info.si_signo = SIGFPE;
7167 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7168 index becc42b..9e43d4b 100644
7169 --- a/arch/mips/mm/fault.c
7170 +++ b/arch/mips/mm/fault.c
7171 @@ -28,6 +28,23 @@
7172 #include <asm/highmem.h> /* For VMALLOC_END */
7173 #include <linux/kdebug.h>
7174
7175 +#ifdef CONFIG_PAX_PAGEEXEC
7176 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7177 +{
7178 + unsigned long i;
7179 +
7180 + printk(KERN_ERR "PAX: bytes at PC: ");
7181 + for (i = 0; i < 5; i++) {
7182 + unsigned int c;
7183 + if (get_user(c, (unsigned int *)pc+i))
7184 + printk(KERN_CONT "???????? ");
7185 + else
7186 + printk(KERN_CONT "%08x ", c);
7187 + }
7188 + printk("\n");
7189 +}
7190 +#endif
7191 +
7192 /*
7193 * This routine handles page faults. It determines the address,
7194 * and the problem, and then passes it off to one of the appropriate
7195 @@ -199,6 +216,14 @@ bad_area:
7196 bad_area_nosemaphore:
7197 /* User mode accesses just cause a SIGSEGV */
7198 if (user_mode(regs)) {
7199 +
7200 +#ifdef CONFIG_PAX_PAGEEXEC
7201 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7202 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7203 + do_group_exit(SIGKILL);
7204 + }
7205 +#endif
7206 +
7207 tsk->thread.cp0_badvaddr = address;
7208 tsk->thread.error_code = write;
7209 #if 0
7210 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7211 index f1baadd..5472dca 100644
7212 --- a/arch/mips/mm/mmap.c
7213 +++ b/arch/mips/mm/mmap.c
7214 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7215 struct vm_area_struct *vma;
7216 unsigned long addr = addr0;
7217 int do_color_align;
7218 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7219 struct vm_unmapped_area_info info;
7220
7221 if (unlikely(len > TASK_SIZE))
7222 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7223 do_color_align = 1;
7224
7225 /* requesting a specific address */
7226 +
7227 +#ifdef CONFIG_PAX_RANDMMAP
7228 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7229 +#endif
7230 +
7231 if (addr) {
7232 if (do_color_align)
7233 addr = COLOUR_ALIGN(addr, pgoff);
7234 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7235 addr = PAGE_ALIGN(addr);
7236
7237 vma = find_vma(mm, addr);
7238 - if (TASK_SIZE - len >= addr &&
7239 - (!vma || addr + len <= vma->vm_start))
7240 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7241 return addr;
7242 }
7243
7244 info.length = len;
7245 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7246 info.align_offset = pgoff << PAGE_SHIFT;
7247 + info.threadstack_offset = offset;
7248
7249 if (dir == DOWN) {
7250 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7251 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7252 {
7253 unsigned long random_factor = 0UL;
7254
7255 +#ifdef CONFIG_PAX_RANDMMAP
7256 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7257 +#endif
7258 +
7259 if (current->flags & PF_RANDOMIZE) {
7260 random_factor = get_random_int();
7261 random_factor = random_factor << PAGE_SHIFT;
7262 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7263
7264 if (mmap_is_legacy()) {
7265 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7266 +
7267 +#ifdef CONFIG_PAX_RANDMMAP
7268 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7269 + mm->mmap_base += mm->delta_mmap;
7270 +#endif
7271 +
7272 mm->get_unmapped_area = arch_get_unmapped_area;
7273 } else {
7274 mm->mmap_base = mmap_base(random_factor);
7275 +
7276 +#ifdef CONFIG_PAX_RANDMMAP
7277 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7278 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7279 +#endif
7280 +
7281 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7282 }
7283 }
7284
7285 -static inline unsigned long brk_rnd(void)
7286 -{
7287 - unsigned long rnd = get_random_int();
7288 -
7289 - rnd = rnd << PAGE_SHIFT;
7290 - /* 8MB for 32bit, 256MB for 64bit */
7291 - if (TASK_IS_32BIT_ADDR)
7292 - rnd = rnd & 0x7ffffful;
7293 - else
7294 - rnd = rnd & 0xffffffful;
7295 -
7296 - return rnd;
7297 -}
7298 -
7299 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7300 -{
7301 - unsigned long base = mm->brk;
7302 - unsigned long ret;
7303 -
7304 - ret = PAGE_ALIGN(base + brk_rnd());
7305 -
7306 - if (ret < mm->brk)
7307 - return mm->brk;
7308 -
7309 - return ret;
7310 -}
7311 -
7312 int __virt_addr_valid(const volatile void *kaddr)
7313 {
7314 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7315 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7316 index 59cccd9..f39ac2f 100644
7317 --- a/arch/mips/pci/pci-octeon.c
7318 +++ b/arch/mips/pci/pci-octeon.c
7319 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7320
7321
7322 static struct pci_ops octeon_pci_ops = {
7323 - octeon_read_config,
7324 - octeon_write_config,
7325 + .read = octeon_read_config,
7326 + .write = octeon_write_config,
7327 };
7328
7329 static struct resource octeon_pci_mem_resource = {
7330 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7331 index 5e36c33..eb4a17b 100644
7332 --- a/arch/mips/pci/pcie-octeon.c
7333 +++ b/arch/mips/pci/pcie-octeon.c
7334 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7335 }
7336
7337 static struct pci_ops octeon_pcie0_ops = {
7338 - octeon_pcie0_read_config,
7339 - octeon_pcie0_write_config,
7340 + .read = octeon_pcie0_read_config,
7341 + .write = octeon_pcie0_write_config,
7342 };
7343
7344 static struct resource octeon_pcie0_mem_resource = {
7345 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7346 };
7347
7348 static struct pci_ops octeon_pcie1_ops = {
7349 - octeon_pcie1_read_config,
7350 - octeon_pcie1_write_config,
7351 + .read = octeon_pcie1_read_config,
7352 + .write = octeon_pcie1_write_config,
7353 };
7354
7355 static struct resource octeon_pcie1_mem_resource = {
7356 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7357 };
7358
7359 static struct pci_ops octeon_dummy_ops = {
7360 - octeon_dummy_read_config,
7361 - octeon_dummy_write_config,
7362 + .read = octeon_dummy_read_config,
7363 + .write = octeon_dummy_write_config,
7364 };
7365
7366 static struct resource octeon_dummy_mem_resource = {
7367 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7368 index a2358b4..7cead4f 100644
7369 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7370 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7371 @@ -187,9 +187,9 @@ void
7372 cont_nmi_dump(void)
7373 {
7374 #ifndef REAL_NMI_SIGNAL
7375 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7376 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7377
7378 - atomic_inc(&nmied_cpus);
7379 + atomic_inc_unchecked(&nmied_cpus);
7380 #endif
7381 /*
7382 * Only allow 1 cpu to proceed
7383 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7384 udelay(10000);
7385 }
7386 #else
7387 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7388 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7389 #endif
7390
7391 /*
7392 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7393 index a046b30..6799527 100644
7394 --- a/arch/mips/sni/rm200.c
7395 +++ b/arch/mips/sni/rm200.c
7396 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7397 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7398 spurious_irq_mask |= irqmask;
7399 }
7400 - atomic_inc(&irq_err_count);
7401 + atomic_inc_unchecked(&irq_err_count);
7402 /*
7403 * Theoretically we do not have to handle this IRQ,
7404 * but in Linux this does not cause problems and is
7405 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7406 index 41e873b..34d33a7 100644
7407 --- a/arch/mips/vr41xx/common/icu.c
7408 +++ b/arch/mips/vr41xx/common/icu.c
7409 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7410
7411 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7412
7413 - atomic_inc(&irq_err_count);
7414 + atomic_inc_unchecked(&irq_err_count);
7415
7416 return -1;
7417 }
7418 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7419 index ae0e4ee..e8f0692 100644
7420 --- a/arch/mips/vr41xx/common/irq.c
7421 +++ b/arch/mips/vr41xx/common/irq.c
7422 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7423 irq_cascade_t *cascade;
7424
7425 if (irq >= NR_IRQS) {
7426 - atomic_inc(&irq_err_count);
7427 + atomic_inc_unchecked(&irq_err_count);
7428 return;
7429 }
7430
7431 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7432 ret = cascade->get_irq(irq);
7433 irq = ret;
7434 if (ret < 0)
7435 - atomic_inc(&irq_err_count);
7436 + atomic_inc_unchecked(&irq_err_count);
7437 else
7438 irq_dispatch(irq);
7439 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7440 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7441 index 967d144..db12197 100644
7442 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7443 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7444 @@ -11,12 +11,14 @@
7445 #ifndef _ASM_PROC_CACHE_H
7446 #define _ASM_PROC_CACHE_H
7447
7448 +#include <linux/const.h>
7449 +
7450 /* L1 cache */
7451
7452 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7453 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7454 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7455 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7456 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7457 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7458
7459 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7460 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7461 index bcb5df2..84fabd2 100644
7462 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7463 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7464 @@ -16,13 +16,15 @@
7465 #ifndef _ASM_PROC_CACHE_H
7466 #define _ASM_PROC_CACHE_H
7467
7468 +#include <linux/const.h>
7469 +
7470 /*
7471 * L1 cache
7472 */
7473 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7474 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7475 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7476 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7477 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7478 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7479
7480 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7481 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7482 index 4ce7a01..449202a 100644
7483 --- a/arch/openrisc/include/asm/cache.h
7484 +++ b/arch/openrisc/include/asm/cache.h
7485 @@ -19,11 +19,13 @@
7486 #ifndef __ASM_OPENRISC_CACHE_H
7487 #define __ASM_OPENRISC_CACHE_H
7488
7489 +#include <linux/const.h>
7490 +
7491 /* FIXME: How can we replace these with values from the CPU...
7492 * they shouldn't be hard-coded!
7493 */
7494
7495 -#define L1_CACHE_BYTES 16
7496 #define L1_CACHE_SHIFT 4
7497 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7498
7499 #endif /* __ASM_OPENRISC_CACHE_H */
7500 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7501 index 472886c..00e7df9 100644
7502 --- a/arch/parisc/include/asm/atomic.h
7503 +++ b/arch/parisc/include/asm/atomic.h
7504 @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7505 return dec;
7506 }
7507
7508 +#define atomic64_read_unchecked(v) atomic64_read(v)
7509 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7510 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7511 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7512 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7513 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7514 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7515 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7516 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7517 +
7518 #endif /* !CONFIG_64BIT */
7519
7520
7521 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7522 index 47f11c7..3420df2 100644
7523 --- a/arch/parisc/include/asm/cache.h
7524 +++ b/arch/parisc/include/asm/cache.h
7525 @@ -5,6 +5,7 @@
7526 #ifndef __ARCH_PARISC_CACHE_H
7527 #define __ARCH_PARISC_CACHE_H
7528
7529 +#include <linux/const.h>
7530
7531 /*
7532 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7533 @@ -15,13 +16,13 @@
7534 * just ruin performance.
7535 */
7536 #ifdef CONFIG_PA20
7537 -#define L1_CACHE_BYTES 64
7538 #define L1_CACHE_SHIFT 6
7539 #else
7540 -#define L1_CACHE_BYTES 32
7541 #define L1_CACHE_SHIFT 5
7542 #endif
7543
7544 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7545 +
7546 #ifndef __ASSEMBLY__
7547
7548 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7549 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7550 index 3391d06..c23a2cc 100644
7551 --- a/arch/parisc/include/asm/elf.h
7552 +++ b/arch/parisc/include/asm/elf.h
7553 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7554
7555 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7556
7557 +#ifdef CONFIG_PAX_ASLR
7558 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7559 +
7560 +#define PAX_DELTA_MMAP_LEN 16
7561 +#define PAX_DELTA_STACK_LEN 16
7562 +#endif
7563 +
7564 /* This yields a mask that user programs can use to figure out what
7565 instruction set this CPU supports. This could be done in user space,
7566 but it's not easy, and we've already done it here. */
7567 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7568 index f213f5b..0af3e8e 100644
7569 --- a/arch/parisc/include/asm/pgalloc.h
7570 +++ b/arch/parisc/include/asm/pgalloc.h
7571 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7572 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7573 }
7574
7575 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7576 +{
7577 + pgd_populate(mm, pgd, pmd);
7578 +}
7579 +
7580 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7581 {
7582 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7583 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7584 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7585 #define pmd_free(mm, x) do { } while (0)
7586 #define pgd_populate(mm, pmd, pte) BUG()
7587 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7588
7589 #endif
7590
7591 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7592 index 22b89d1..ce34230 100644
7593 --- a/arch/parisc/include/asm/pgtable.h
7594 +++ b/arch/parisc/include/asm/pgtable.h
7595 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7596 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7597 #define PAGE_COPY PAGE_EXECREAD
7598 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7599 +
7600 +#ifdef CONFIG_PAX_PAGEEXEC
7601 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7602 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7603 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7604 +#else
7605 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7606 +# define PAGE_COPY_NOEXEC PAGE_COPY
7607 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7608 +#endif
7609 +
7610 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7611 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7612 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7613 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7614 index 4006964..fcb3cc2 100644
7615 --- a/arch/parisc/include/asm/uaccess.h
7616 +++ b/arch/parisc/include/asm/uaccess.h
7617 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7618 const void __user *from,
7619 unsigned long n)
7620 {
7621 - int sz = __compiletime_object_size(to);
7622 + size_t sz = __compiletime_object_size(to);
7623 int ret = -EFAULT;
7624
7625 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7626 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7627 ret = __copy_from_user(to, from, n);
7628 else
7629 copy_from_user_overflow();
7630 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7631 index 50dfafc..b9fc230 100644
7632 --- a/arch/parisc/kernel/module.c
7633 +++ b/arch/parisc/kernel/module.c
7634 @@ -98,16 +98,38 @@
7635
7636 /* three functions to determine where in the module core
7637 * or init pieces the location is */
7638 +static inline int in_init_rx(struct module *me, void *loc)
7639 +{
7640 + return (loc >= me->module_init_rx &&
7641 + loc < (me->module_init_rx + me->init_size_rx));
7642 +}
7643 +
7644 +static inline int in_init_rw(struct module *me, void *loc)
7645 +{
7646 + return (loc >= me->module_init_rw &&
7647 + loc < (me->module_init_rw + me->init_size_rw));
7648 +}
7649 +
7650 static inline int in_init(struct module *me, void *loc)
7651 {
7652 - return (loc >= me->module_init &&
7653 - loc <= (me->module_init + me->init_size));
7654 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7655 +}
7656 +
7657 +static inline int in_core_rx(struct module *me, void *loc)
7658 +{
7659 + return (loc >= me->module_core_rx &&
7660 + loc < (me->module_core_rx + me->core_size_rx));
7661 +}
7662 +
7663 +static inline int in_core_rw(struct module *me, void *loc)
7664 +{
7665 + return (loc >= me->module_core_rw &&
7666 + loc < (me->module_core_rw + me->core_size_rw));
7667 }
7668
7669 static inline int in_core(struct module *me, void *loc)
7670 {
7671 - return (loc >= me->module_core &&
7672 - loc <= (me->module_core + me->core_size));
7673 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7674 }
7675
7676 static inline int in_local(struct module *me, void *loc)
7677 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7678 }
7679
7680 /* align things a bit */
7681 - me->core_size = ALIGN(me->core_size, 16);
7682 - me->arch.got_offset = me->core_size;
7683 - me->core_size += gots * sizeof(struct got_entry);
7684 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7685 + me->arch.got_offset = me->core_size_rw;
7686 + me->core_size_rw += gots * sizeof(struct got_entry);
7687
7688 - me->core_size = ALIGN(me->core_size, 16);
7689 - me->arch.fdesc_offset = me->core_size;
7690 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7691 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7692 + me->arch.fdesc_offset = me->core_size_rw;
7693 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7694
7695 me->arch.got_max = gots;
7696 me->arch.fdesc_max = fdescs;
7697 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7698
7699 BUG_ON(value == 0);
7700
7701 - got = me->module_core + me->arch.got_offset;
7702 + got = me->module_core_rw + me->arch.got_offset;
7703 for (i = 0; got[i].addr; i++)
7704 if (got[i].addr == value)
7705 goto out;
7706 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7707 #ifdef CONFIG_64BIT
7708 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7709 {
7710 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7711 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7712
7713 if (!value) {
7714 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7715 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7716
7717 /* Create new one */
7718 fdesc->addr = value;
7719 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7720 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7721 return (Elf_Addr)fdesc;
7722 }
7723 #endif /* CONFIG_64BIT */
7724 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7725
7726 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7727 end = table + sechdrs[me->arch.unwind_section].sh_size;
7728 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7729 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7730
7731 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7732 me->arch.unwind_section, table, end, gp);
7733 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7734 index e1ffea2..46ed66e 100644
7735 --- a/arch/parisc/kernel/sys_parisc.c
7736 +++ b/arch/parisc/kernel/sys_parisc.c
7737 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7738 unsigned long task_size = TASK_SIZE;
7739 int do_color_align, last_mmap;
7740 struct vm_unmapped_area_info info;
7741 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7742
7743 if (len > task_size)
7744 return -ENOMEM;
7745 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7746 goto found_addr;
7747 }
7748
7749 +#ifdef CONFIG_PAX_RANDMMAP
7750 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7751 +#endif
7752 +
7753 if (addr) {
7754 if (do_color_align && last_mmap)
7755 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7756 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7757 info.high_limit = mmap_upper_limit();
7758 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7759 info.align_offset = shared_align_offset(last_mmap, pgoff);
7760 + info.threadstack_offset = offset;
7761 addr = vm_unmapped_area(&info);
7762
7763 found_addr:
7764 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7765 unsigned long addr = addr0;
7766 int do_color_align, last_mmap;
7767 struct vm_unmapped_area_info info;
7768 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7769
7770 #ifdef CONFIG_64BIT
7771 /* This should only ever run for 32-bit processes. */
7772 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7773 }
7774
7775 /* requesting a specific address */
7776 +#ifdef CONFIG_PAX_RANDMMAP
7777 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7778 +#endif
7779 +
7780 if (addr) {
7781 if (do_color_align && last_mmap)
7782 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7783 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7784 info.high_limit = mm->mmap_base;
7785 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7786 info.align_offset = shared_align_offset(last_mmap, pgoff);
7787 + info.threadstack_offset = offset;
7788 addr = vm_unmapped_area(&info);
7789 if (!(addr & ~PAGE_MASK))
7790 goto found_addr;
7791 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7792 mm->mmap_legacy_base = mmap_legacy_base();
7793 mm->mmap_base = mmap_upper_limit();
7794
7795 +#ifdef CONFIG_PAX_RANDMMAP
7796 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7797 + mm->mmap_legacy_base += mm->delta_mmap;
7798 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7799 + }
7800 +#endif
7801 +
7802 if (mmap_is_legacy()) {
7803 mm->mmap_base = mm->mmap_legacy_base;
7804 mm->get_unmapped_area = arch_get_unmapped_area;
7805 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7806 index 47ee620..1107387 100644
7807 --- a/arch/parisc/kernel/traps.c
7808 +++ b/arch/parisc/kernel/traps.c
7809 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7810
7811 down_read(&current->mm->mmap_sem);
7812 vma = find_vma(current->mm,regs->iaoq[0]);
7813 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7814 - && (vma->vm_flags & VM_EXEC)) {
7815 -
7816 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7817 fault_address = regs->iaoq[0];
7818 fault_space = regs->iasq[0];
7819
7820 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7821 index 3ca9c11..d163ef7 100644
7822 --- a/arch/parisc/mm/fault.c
7823 +++ b/arch/parisc/mm/fault.c
7824 @@ -15,6 +15,7 @@
7825 #include <linux/sched.h>
7826 #include <linux/interrupt.h>
7827 #include <linux/module.h>
7828 +#include <linux/unistd.h>
7829
7830 #include <asm/uaccess.h>
7831 #include <asm/traps.h>
7832 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7833 static unsigned long
7834 parisc_acctyp(unsigned long code, unsigned int inst)
7835 {
7836 - if (code == 6 || code == 16)
7837 + if (code == 6 || code == 7 || code == 16)
7838 return VM_EXEC;
7839
7840 switch (inst & 0xf0000000) {
7841 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7842 }
7843 #endif
7844
7845 +#ifdef CONFIG_PAX_PAGEEXEC
7846 +/*
7847 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7848 + *
7849 + * returns 1 when task should be killed
7850 + * 2 when rt_sigreturn trampoline was detected
7851 + * 3 when unpatched PLT trampoline was detected
7852 + */
7853 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7854 +{
7855 +
7856 +#ifdef CONFIG_PAX_EMUPLT
7857 + int err;
7858 +
7859 + do { /* PaX: unpatched PLT emulation */
7860 + unsigned int bl, depwi;
7861 +
7862 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7863 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7864 +
7865 + if (err)
7866 + break;
7867 +
7868 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7869 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7870 +
7871 + err = get_user(ldw, (unsigned int *)addr);
7872 + err |= get_user(bv, (unsigned int *)(addr+4));
7873 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7874 +
7875 + if (err)
7876 + break;
7877 +
7878 + if (ldw == 0x0E801096U &&
7879 + bv == 0xEAC0C000U &&
7880 + ldw2 == 0x0E881095U)
7881 + {
7882 + unsigned int resolver, map;
7883 +
7884 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7885 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7886 + if (err)
7887 + break;
7888 +
7889 + regs->gr[20] = instruction_pointer(regs)+8;
7890 + regs->gr[21] = map;
7891 + regs->gr[22] = resolver;
7892 + regs->iaoq[0] = resolver | 3UL;
7893 + regs->iaoq[1] = regs->iaoq[0] + 4;
7894 + return 3;
7895 + }
7896 + }
7897 + } while (0);
7898 +#endif
7899 +
7900 +#ifdef CONFIG_PAX_EMUTRAMP
7901 +
7902 +#ifndef CONFIG_PAX_EMUSIGRT
7903 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7904 + return 1;
7905 +#endif
7906 +
7907 + do { /* PaX: rt_sigreturn emulation */
7908 + unsigned int ldi1, ldi2, bel, nop;
7909 +
7910 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7911 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7912 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7913 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7914 +
7915 + if (err)
7916 + break;
7917 +
7918 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7919 + ldi2 == 0x3414015AU &&
7920 + bel == 0xE4008200U &&
7921 + nop == 0x08000240U)
7922 + {
7923 + regs->gr[25] = (ldi1 & 2) >> 1;
7924 + regs->gr[20] = __NR_rt_sigreturn;
7925 + regs->gr[31] = regs->iaoq[1] + 16;
7926 + regs->sr[0] = regs->iasq[1];
7927 + regs->iaoq[0] = 0x100UL;
7928 + regs->iaoq[1] = regs->iaoq[0] + 4;
7929 + regs->iasq[0] = regs->sr[2];
7930 + regs->iasq[1] = regs->sr[2];
7931 + return 2;
7932 + }
7933 + } while (0);
7934 +#endif
7935 +
7936 + return 1;
7937 +}
7938 +
7939 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7940 +{
7941 + unsigned long i;
7942 +
7943 + printk(KERN_ERR "PAX: bytes at PC: ");
7944 + for (i = 0; i < 5; i++) {
7945 + unsigned int c;
7946 + if (get_user(c, (unsigned int *)pc+i))
7947 + printk(KERN_CONT "???????? ");
7948 + else
7949 + printk(KERN_CONT "%08x ", c);
7950 + }
7951 + printk("\n");
7952 +}
7953 +#endif
7954 +
7955 int fixup_exception(struct pt_regs *regs)
7956 {
7957 const struct exception_table_entry *fix;
7958 @@ -234,8 +345,33 @@ retry:
7959
7960 good_area:
7961
7962 - if ((vma->vm_flags & acc_type) != acc_type)
7963 + if ((vma->vm_flags & acc_type) != acc_type) {
7964 +
7965 +#ifdef CONFIG_PAX_PAGEEXEC
7966 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7967 + (address & ~3UL) == instruction_pointer(regs))
7968 + {
7969 + up_read(&mm->mmap_sem);
7970 + switch (pax_handle_fetch_fault(regs)) {
7971 +
7972 +#ifdef CONFIG_PAX_EMUPLT
7973 + case 3:
7974 + return;
7975 +#endif
7976 +
7977 +#ifdef CONFIG_PAX_EMUTRAMP
7978 + case 2:
7979 + return;
7980 +#endif
7981 +
7982 + }
7983 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7984 + do_group_exit(SIGKILL);
7985 + }
7986 +#endif
7987 +
7988 goto bad_area;
7989 + }
7990
7991 /*
7992 * If for any reason at all we couldn't handle the fault, make
7993 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7994 index c95c4b8..d831f81 100644
7995 --- a/arch/powerpc/Kconfig
7996 +++ b/arch/powerpc/Kconfig
7997 @@ -397,6 +397,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7998 config KEXEC
7999 bool "kexec system call"
8000 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8001 + depends on !GRKERNSEC_KMEM
8002 help
8003 kexec is a system call that implements the ability to shutdown your
8004 current kernel, and to start another kernel. It is like a reboot
8005 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8006 index e3b1d41..8e81edf 100644
8007 --- a/arch/powerpc/include/asm/atomic.h
8008 +++ b/arch/powerpc/include/asm/atomic.h
8009 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
8010 return t1;
8011 }
8012
8013 +#define atomic64_read_unchecked(v) atomic64_read(v)
8014 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8015 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8016 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8017 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8018 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8019 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8020 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8021 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8022 +
8023 #endif /* __powerpc64__ */
8024
8025 #endif /* __KERNEL__ */
8026 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8027 index f89da80..7f5b05a 100644
8028 --- a/arch/powerpc/include/asm/barrier.h
8029 +++ b/arch/powerpc/include/asm/barrier.h
8030 @@ -73,7 +73,7 @@
8031 do { \
8032 compiletime_assert_atomic_type(*p); \
8033 __lwsync(); \
8034 - ACCESS_ONCE(*p) = (v); \
8035 + ACCESS_ONCE_RW(*p) = (v); \
8036 } while (0)
8037
8038 #define smp_load_acquire(p) \
8039 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8040 index ed0afc1..0332825 100644
8041 --- a/arch/powerpc/include/asm/cache.h
8042 +++ b/arch/powerpc/include/asm/cache.h
8043 @@ -3,6 +3,7 @@
8044
8045 #ifdef __KERNEL__
8046
8047 +#include <linux/const.h>
8048
8049 /* bytes per L1 cache line */
8050 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8051 @@ -22,7 +23,7 @@
8052 #define L1_CACHE_SHIFT 7
8053 #endif
8054
8055 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8056 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8057
8058 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8059
8060 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8061 index 935b5e7..7001d2d 100644
8062 --- a/arch/powerpc/include/asm/elf.h
8063 +++ b/arch/powerpc/include/asm/elf.h
8064 @@ -28,8 +28,19 @@
8065 the loader. We need to make sure that it is out of the way of the program
8066 that it will "exec", and that there is sufficient room for the brk. */
8067
8068 -extern unsigned long randomize_et_dyn(unsigned long base);
8069 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8070 +#define ELF_ET_DYN_BASE (0x20000000)
8071 +
8072 +#ifdef CONFIG_PAX_ASLR
8073 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8074 +
8075 +#ifdef __powerpc64__
8076 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8077 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8078 +#else
8079 +#define PAX_DELTA_MMAP_LEN 15
8080 +#define PAX_DELTA_STACK_LEN 15
8081 +#endif
8082 +#endif
8083
8084 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8085
8086 @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8087 (0x7ff >> (PAGE_SHIFT - 12)) : \
8088 (0x3ffff >> (PAGE_SHIFT - 12)))
8089
8090 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8091 -#define arch_randomize_brk arch_randomize_brk
8092 -
8093 -
8094 #ifdef CONFIG_SPU_BASE
8095 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8096 #define NT_SPU 1
8097 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8098 index 8196e9c..d83a9f3 100644
8099 --- a/arch/powerpc/include/asm/exec.h
8100 +++ b/arch/powerpc/include/asm/exec.h
8101 @@ -4,6 +4,6 @@
8102 #ifndef _ASM_POWERPC_EXEC_H
8103 #define _ASM_POWERPC_EXEC_H
8104
8105 -extern unsigned long arch_align_stack(unsigned long sp);
8106 +#define arch_align_stack(x) ((x) & ~0xfUL)
8107
8108 #endif /* _ASM_POWERPC_EXEC_H */
8109 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8110 index 5acabbd..7ea14fa 100644
8111 --- a/arch/powerpc/include/asm/kmap_types.h
8112 +++ b/arch/powerpc/include/asm/kmap_types.h
8113 @@ -10,7 +10,7 @@
8114 * 2 of the License, or (at your option) any later version.
8115 */
8116
8117 -#define KM_TYPE_NR 16
8118 +#define KM_TYPE_NR 17
8119
8120 #endif /* __KERNEL__ */
8121 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8122 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8123 index b8da913..60b608a 100644
8124 --- a/arch/powerpc/include/asm/local.h
8125 +++ b/arch/powerpc/include/asm/local.h
8126 @@ -9,15 +9,26 @@ typedef struct
8127 atomic_long_t a;
8128 } local_t;
8129
8130 +typedef struct
8131 +{
8132 + atomic_long_unchecked_t a;
8133 +} local_unchecked_t;
8134 +
8135 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8136
8137 #define local_read(l) atomic_long_read(&(l)->a)
8138 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8139 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8140 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8141
8142 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8143 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8144 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8145 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8146 #define local_inc(l) atomic_long_inc(&(l)->a)
8147 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8148 #define local_dec(l) atomic_long_dec(&(l)->a)
8149 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8150
8151 static __inline__ long local_add_return(long a, local_t *l)
8152 {
8153 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8154
8155 return t;
8156 }
8157 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8158
8159 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8160
8161 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8162
8163 return t;
8164 }
8165 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8166
8167 static __inline__ long local_inc_return(local_t *l)
8168 {
8169 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8170
8171 #define local_cmpxchg(l, o, n) \
8172 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8173 +#define local_cmpxchg_unchecked(l, o, n) \
8174 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8175 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8176
8177 /**
8178 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8179 index 8565c25..2865190 100644
8180 --- a/arch/powerpc/include/asm/mman.h
8181 +++ b/arch/powerpc/include/asm/mman.h
8182 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8183 }
8184 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8185
8186 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8187 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8188 {
8189 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8190 }
8191 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8192 index 32e4e21..62afb12 100644
8193 --- a/arch/powerpc/include/asm/page.h
8194 +++ b/arch/powerpc/include/asm/page.h
8195 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8196 * and needs to be executable. This means the whole heap ends
8197 * up being executable.
8198 */
8199 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8200 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8201 +#define VM_DATA_DEFAULT_FLAGS32 \
8202 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8203 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8204
8205 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8206 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8207 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8208 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8209 #endif
8210
8211 +#define ktla_ktva(addr) (addr)
8212 +#define ktva_ktla(addr) (addr)
8213 +
8214 #ifndef CONFIG_PPC_BOOK3S_64
8215 /*
8216 * Use the top bit of the higher-level page table entries to indicate whether
8217 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8218 index 88693ce..ac6f9ab 100644
8219 --- a/arch/powerpc/include/asm/page_64.h
8220 +++ b/arch/powerpc/include/asm/page_64.h
8221 @@ -153,15 +153,18 @@ do { \
8222 * stack by default, so in the absence of a PT_GNU_STACK program header
8223 * we turn execute permission off.
8224 */
8225 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8226 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8227 +#define VM_STACK_DEFAULT_FLAGS32 \
8228 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8229 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8230
8231 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8232 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8233
8234 +#ifndef CONFIG_PAX_PAGEEXEC
8235 #define VM_STACK_DEFAULT_FLAGS \
8236 (is_32bit_task() ? \
8237 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8238 +#endif
8239
8240 #include <asm-generic/getorder.h>
8241
8242 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8243 index 4b0be20..c15a27d 100644
8244 --- a/arch/powerpc/include/asm/pgalloc-64.h
8245 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8246 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8247 #ifndef CONFIG_PPC_64K_PAGES
8248
8249 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8250 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8251
8252 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8253 {
8254 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8255 pud_set(pud, (unsigned long)pmd);
8256 }
8257
8258 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8259 +{
8260 + pud_populate(mm, pud, pmd);
8261 +}
8262 +
8263 #define pmd_populate(mm, pmd, pte_page) \
8264 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8265 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8266 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8267 #endif
8268
8269 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8270 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8271
8272 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8273 pte_t *pte)
8274 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8275 index 3ebb188..e17dddf 100644
8276 --- a/arch/powerpc/include/asm/pgtable.h
8277 +++ b/arch/powerpc/include/asm/pgtable.h
8278 @@ -2,6 +2,7 @@
8279 #define _ASM_POWERPC_PGTABLE_H
8280 #ifdef __KERNEL__
8281
8282 +#include <linux/const.h>
8283 #ifndef __ASSEMBLY__
8284 #include <linux/mmdebug.h>
8285 #include <asm/processor.h> /* For TASK_SIZE */
8286 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8287 index 4aad413..85d86bf 100644
8288 --- a/arch/powerpc/include/asm/pte-hash32.h
8289 +++ b/arch/powerpc/include/asm/pte-hash32.h
8290 @@ -21,6 +21,7 @@
8291 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8292 #define _PAGE_USER 0x004 /* usermode access allowed */
8293 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8294 +#define _PAGE_EXEC _PAGE_GUARDED
8295 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8296 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8297 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8298 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8299 index e5d2e0b..9ac74b1 100644
8300 --- a/arch/powerpc/include/asm/reg.h
8301 +++ b/arch/powerpc/include/asm/reg.h
8302 @@ -249,6 +249,7 @@
8303 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8304 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8305 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8306 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8307 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8308 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8309 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8310 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8311 index ff51046..b982dd4 100644
8312 --- a/arch/powerpc/include/asm/smp.h
8313 +++ b/arch/powerpc/include/asm/smp.h
8314 @@ -51,7 +51,7 @@ struct smp_ops_t {
8315 int (*cpu_disable)(void);
8316 void (*cpu_die)(unsigned int nr);
8317 int (*cpu_bootable)(unsigned int nr);
8318 -};
8319 +} __no_const;
8320
8321 extern void smp_send_debugger_break(void);
8322 extern void start_secondary_resume(void);
8323 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8324 index b034ecd..af7e31f 100644
8325 --- a/arch/powerpc/include/asm/thread_info.h
8326 +++ b/arch/powerpc/include/asm/thread_info.h
8327 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8328 #if defined(CONFIG_PPC64)
8329 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8330 #endif
8331 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8332 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8333
8334 /* as above, but as bit values */
8335 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8336 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8337 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8338 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8339 #define _TIF_NOHZ (1<<TIF_NOHZ)
8340 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8341 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8342 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8343 - _TIF_NOHZ)
8344 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8345
8346 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8347 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8348 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8349 index 9485b43..3bd3c16 100644
8350 --- a/arch/powerpc/include/asm/uaccess.h
8351 +++ b/arch/powerpc/include/asm/uaccess.h
8352 @@ -58,6 +58,7 @@
8353
8354 #endif
8355
8356 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8357 #define access_ok(type, addr, size) \
8358 (__chk_user_ptr(addr), \
8359 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8360 @@ -318,52 +319,6 @@ do { \
8361 extern unsigned long __copy_tofrom_user(void __user *to,
8362 const void __user *from, unsigned long size);
8363
8364 -#ifndef __powerpc64__
8365 -
8366 -static inline unsigned long copy_from_user(void *to,
8367 - const void __user *from, unsigned long n)
8368 -{
8369 - unsigned long over;
8370 -
8371 - if (access_ok(VERIFY_READ, from, n))
8372 - return __copy_tofrom_user((__force void __user *)to, from, n);
8373 - if ((unsigned long)from < TASK_SIZE) {
8374 - over = (unsigned long)from + n - TASK_SIZE;
8375 - return __copy_tofrom_user((__force void __user *)to, from,
8376 - n - over) + over;
8377 - }
8378 - return n;
8379 -}
8380 -
8381 -static inline unsigned long copy_to_user(void __user *to,
8382 - const void *from, unsigned long n)
8383 -{
8384 - unsigned long over;
8385 -
8386 - if (access_ok(VERIFY_WRITE, to, n))
8387 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8388 - if ((unsigned long)to < TASK_SIZE) {
8389 - over = (unsigned long)to + n - TASK_SIZE;
8390 - return __copy_tofrom_user(to, (__force void __user *)from,
8391 - n - over) + over;
8392 - }
8393 - return n;
8394 -}
8395 -
8396 -#else /* __powerpc64__ */
8397 -
8398 -#define __copy_in_user(to, from, size) \
8399 - __copy_tofrom_user((to), (from), (size))
8400 -
8401 -extern unsigned long copy_from_user(void *to, const void __user *from,
8402 - unsigned long n);
8403 -extern unsigned long copy_to_user(void __user *to, const void *from,
8404 - unsigned long n);
8405 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8406 - unsigned long n);
8407 -
8408 -#endif /* __powerpc64__ */
8409 -
8410 static inline unsigned long __copy_from_user_inatomic(void *to,
8411 const void __user *from, unsigned long n)
8412 {
8413 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8414 if (ret == 0)
8415 return 0;
8416 }
8417 +
8418 + if (!__builtin_constant_p(n))
8419 + check_object_size(to, n, false);
8420 +
8421 return __copy_tofrom_user((__force void __user *)to, from, n);
8422 }
8423
8424 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8425 if (ret == 0)
8426 return 0;
8427 }
8428 +
8429 + if (!__builtin_constant_p(n))
8430 + check_object_size(from, n, true);
8431 +
8432 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8433 }
8434
8435 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8436 return __copy_to_user_inatomic(to, from, size);
8437 }
8438
8439 +#ifndef __powerpc64__
8440 +
8441 +static inline unsigned long __must_check copy_from_user(void *to,
8442 + const void __user *from, unsigned long n)
8443 +{
8444 + unsigned long over;
8445 +
8446 + if ((long)n < 0)
8447 + return n;
8448 +
8449 + if (access_ok(VERIFY_READ, from, n)) {
8450 + if (!__builtin_constant_p(n))
8451 + check_object_size(to, n, false);
8452 + return __copy_tofrom_user((__force void __user *)to, from, n);
8453 + }
8454 + if ((unsigned long)from < TASK_SIZE) {
8455 + over = (unsigned long)from + n - TASK_SIZE;
8456 + if (!__builtin_constant_p(n - over))
8457 + check_object_size(to, n - over, false);
8458 + return __copy_tofrom_user((__force void __user *)to, from,
8459 + n - over) + over;
8460 + }
8461 + return n;
8462 +}
8463 +
8464 +static inline unsigned long __must_check copy_to_user(void __user *to,
8465 + const void *from, unsigned long n)
8466 +{
8467 + unsigned long over;
8468 +
8469 + if ((long)n < 0)
8470 + return n;
8471 +
8472 + if (access_ok(VERIFY_WRITE, to, n)) {
8473 + if (!__builtin_constant_p(n))
8474 + check_object_size(from, n, true);
8475 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8476 + }
8477 + if ((unsigned long)to < TASK_SIZE) {
8478 + over = (unsigned long)to + n - TASK_SIZE;
8479 + if (!__builtin_constant_p(n))
8480 + check_object_size(from, n - over, true);
8481 + return __copy_tofrom_user(to, (__force void __user *)from,
8482 + n - over) + over;
8483 + }
8484 + return n;
8485 +}
8486 +
8487 +#else /* __powerpc64__ */
8488 +
8489 +#define __copy_in_user(to, from, size) \
8490 + __copy_tofrom_user((to), (from), (size))
8491 +
8492 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8493 +{
8494 + if ((long)n < 0 || n > INT_MAX)
8495 + return n;
8496 +
8497 + if (!__builtin_constant_p(n))
8498 + check_object_size(to, n, false);
8499 +
8500 + if (likely(access_ok(VERIFY_READ, from, n)))
8501 + n = __copy_from_user(to, from, n);
8502 + else
8503 + memset(to, 0, n);
8504 + return n;
8505 +}
8506 +
8507 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8508 +{
8509 + if ((long)n < 0 || n > INT_MAX)
8510 + return n;
8511 +
8512 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8513 + if (!__builtin_constant_p(n))
8514 + check_object_size(from, n, true);
8515 + n = __copy_to_user(to, from, n);
8516 + }
8517 + return n;
8518 +}
8519 +
8520 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8521 + unsigned long n);
8522 +
8523 +#endif /* __powerpc64__ */
8524 +
8525 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8526
8527 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8528 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8529 index fcc9a89..07be2bb 100644
8530 --- a/arch/powerpc/kernel/Makefile
8531 +++ b/arch/powerpc/kernel/Makefile
8532 @@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8533 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8534 endif
8535
8536 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8537 +
8538 obj-y := cputable.o ptrace.o syscalls.o \
8539 irq.o align.o signal_32.o pmc.o vdso.o \
8540 process.o systbl.o idle.o \
8541 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8542 index c1bee3c..5b42583 100644
8543 --- a/arch/powerpc/kernel/exceptions-64e.S
8544 +++ b/arch/powerpc/kernel/exceptions-64e.S
8545 @@ -1010,6 +1010,7 @@ storage_fault_common:
8546 std r14,_DAR(r1)
8547 std r15,_DSISR(r1)
8548 addi r3,r1,STACK_FRAME_OVERHEAD
8549 + bl .save_nvgprs
8550 mr r4,r14
8551 mr r5,r15
8552 ld r14,PACA_EXGEN+EX_R14(r13)
8553 @@ -1018,8 +1019,7 @@ storage_fault_common:
8554 cmpdi r3,0
8555 bne- 1f
8556 b .ret_from_except_lite
8557 -1: bl .save_nvgprs
8558 - mr r5,r3
8559 +1: mr r5,r3
8560 addi r3,r1,STACK_FRAME_OVERHEAD
8561 ld r4,_DAR(r1)
8562 bl .bad_page_fault
8563 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8564 index 3afd391..18f9e36 100644
8565 --- a/arch/powerpc/kernel/exceptions-64s.S
8566 +++ b/arch/powerpc/kernel/exceptions-64s.S
8567 @@ -1587,10 +1587,10 @@ handle_page_fault:
8568 11: ld r4,_DAR(r1)
8569 ld r5,_DSISR(r1)
8570 addi r3,r1,STACK_FRAME_OVERHEAD
8571 + bl .save_nvgprs
8572 bl .do_page_fault
8573 cmpdi r3,0
8574 beq+ 12f
8575 - bl .save_nvgprs
8576 mr r5,r3
8577 addi r3,r1,STACK_FRAME_OVERHEAD
8578 lwz r4,_DAR(r1)
8579 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8580 index ca1cd74..6f0241a 100644
8581 --- a/arch/powerpc/kernel/irq.c
8582 +++ b/arch/powerpc/kernel/irq.c
8583 @@ -447,6 +447,8 @@ void migrate_irqs(void)
8584 }
8585 #endif
8586
8587 +extern void gr_handle_kernel_exploit(void);
8588 +
8589 static inline void check_stack_overflow(void)
8590 {
8591 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8592 @@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
8593 printk("do_IRQ: stack overflow: %ld\n",
8594 sp - sizeof(struct thread_info));
8595 dump_stack();
8596 + gr_handle_kernel_exploit();
8597 }
8598 #endif
8599 }
8600 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8601 index 6cff040..74ac5d1b 100644
8602 --- a/arch/powerpc/kernel/module_32.c
8603 +++ b/arch/powerpc/kernel/module_32.c
8604 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8605 me->arch.core_plt_section = i;
8606 }
8607 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8608 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8609 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8610 return -ENOEXEC;
8611 }
8612
8613 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8614
8615 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8616 /* Init, or core PLT? */
8617 - if (location >= mod->module_core
8618 - && location < mod->module_core + mod->core_size)
8619 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8620 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8621 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8622 - else
8623 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8624 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8625 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8626 + else {
8627 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8628 + return ~0UL;
8629 + }
8630
8631 /* Find this entry, or if that fails, the next avail. entry */
8632 while (entry->jump[0]) {
8633 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8634 }
8635 #ifdef CONFIG_DYNAMIC_FTRACE
8636 module->arch.tramp =
8637 - do_plt_call(module->module_core,
8638 + do_plt_call(module->module_core_rx,
8639 (unsigned long)ftrace_caller,
8640 sechdrs, module);
8641 #endif
8642 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8643 index 31d0215..206af70 100644
8644 --- a/arch/powerpc/kernel/process.c
8645 +++ b/arch/powerpc/kernel/process.c
8646 @@ -1031,8 +1031,8 @@ void show_regs(struct pt_regs * regs)
8647 * Lookup NIP late so we have the best change of getting the
8648 * above info out without failing
8649 */
8650 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8651 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8652 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8653 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8654 #endif
8655 show_stack(current, (unsigned long *) regs->gpr[1]);
8656 if (!user_mode(regs))
8657 @@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8658 newsp = stack[0];
8659 ip = stack[STACK_FRAME_LR_SAVE];
8660 if (!firstframe || ip != lr) {
8661 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8662 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8663 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8664 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8665 - printk(" (%pS)",
8666 + printk(" (%pA)",
8667 (void *)current->ret_stack[curr_frame].ret);
8668 curr_frame--;
8669 }
8670 @@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8671 struct pt_regs *regs = (struct pt_regs *)
8672 (sp + STACK_FRAME_OVERHEAD);
8673 lr = regs->link;
8674 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
8675 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
8676 regs->trap, (void *)regs->nip, (void *)lr);
8677 firstframe = 1;
8678 }
8679 @@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
8680 mtspr(SPRN_CTRLT, ctrl);
8681 }
8682 #endif /* CONFIG_PPC64 */
8683 -
8684 -unsigned long arch_align_stack(unsigned long sp)
8685 -{
8686 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8687 - sp -= get_random_int() & ~PAGE_MASK;
8688 - return sp & ~0xf;
8689 -}
8690 -
8691 -static inline unsigned long brk_rnd(void)
8692 -{
8693 - unsigned long rnd = 0;
8694 -
8695 - /* 8MB for 32bit, 1GB for 64bit */
8696 - if (is_32bit_task())
8697 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8698 - else
8699 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8700 -
8701 - return rnd << PAGE_SHIFT;
8702 -}
8703 -
8704 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8705 -{
8706 - unsigned long base = mm->brk;
8707 - unsigned long ret;
8708 -
8709 -#ifdef CONFIG_PPC_STD_MMU_64
8710 - /*
8711 - * If we are using 1TB segments and we are allowed to randomise
8712 - * the heap, we can put it above 1TB so it is backed by a 1TB
8713 - * segment. Otherwise the heap will be in the bottom 1TB
8714 - * which always uses 256MB segments and this may result in a
8715 - * performance penalty.
8716 - */
8717 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8718 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8719 -#endif
8720 -
8721 - ret = PAGE_ALIGN(base + brk_rnd());
8722 -
8723 - if (ret < mm->brk)
8724 - return mm->brk;
8725 -
8726 - return ret;
8727 -}
8728 -
8729 -unsigned long randomize_et_dyn(unsigned long base)
8730 -{
8731 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8732 -
8733 - if (ret < base)
8734 - return base;
8735 -
8736 - return ret;
8737 -}
8738 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8739 index 2e3d2bf..35df241 100644
8740 --- a/arch/powerpc/kernel/ptrace.c
8741 +++ b/arch/powerpc/kernel/ptrace.c
8742 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8743 return ret;
8744 }
8745
8746 +#ifdef CONFIG_GRKERNSEC_SETXID
8747 +extern void gr_delayed_cred_worker(void);
8748 +#endif
8749 +
8750 /*
8751 * We must return the syscall number to actually look up in the table.
8752 * This can be -1L to skip running any syscall at all.
8753 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8754
8755 secure_computing_strict(regs->gpr[0]);
8756
8757 +#ifdef CONFIG_GRKERNSEC_SETXID
8758 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8759 + gr_delayed_cred_worker();
8760 +#endif
8761 +
8762 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8763 tracehook_report_syscall_entry(regs))
8764 /*
8765 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8766 {
8767 int step;
8768
8769 +#ifdef CONFIG_GRKERNSEC_SETXID
8770 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8771 + gr_delayed_cred_worker();
8772 +#endif
8773 +
8774 audit_syscall_exit(regs);
8775
8776 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8777 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8778 index 4e47db6..6dcc96e 100644
8779 --- a/arch/powerpc/kernel/signal_32.c
8780 +++ b/arch/powerpc/kernel/signal_32.c
8781 @@ -1013,7 +1013,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8782 /* Save user registers on the stack */
8783 frame = &rt_sf->uc.uc_mcontext;
8784 addr = frame;
8785 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8786 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8787 sigret = 0;
8788 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8789 } else {
8790 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8791 index d501dc4..e5a0de0 100644
8792 --- a/arch/powerpc/kernel/signal_64.c
8793 +++ b/arch/powerpc/kernel/signal_64.c
8794 @@ -760,7 +760,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8795 current->thread.fp_state.fpscr = 0;
8796
8797 /* Set up to return from userspace. */
8798 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8799 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8800 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8801 } else {
8802 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8803 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8804 index 1bd7ca2..9b78c2f 100644
8805 --- a/arch/powerpc/kernel/traps.c
8806 +++ b/arch/powerpc/kernel/traps.c
8807 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8808 return flags;
8809 }
8810
8811 +extern void gr_handle_kernel_exploit(void);
8812 +
8813 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8814 int signr)
8815 {
8816 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8817 panic("Fatal exception in interrupt");
8818 if (panic_on_oops)
8819 panic("Fatal exception");
8820 +
8821 + gr_handle_kernel_exploit();
8822 +
8823 do_exit(signr);
8824 }
8825
8826 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8827 index ce74c33..0803371 100644
8828 --- a/arch/powerpc/kernel/vdso.c
8829 +++ b/arch/powerpc/kernel/vdso.c
8830 @@ -35,6 +35,7 @@
8831 #include <asm/vdso.h>
8832 #include <asm/vdso_datapage.h>
8833 #include <asm/setup.h>
8834 +#include <asm/mman.h>
8835
8836 #undef DEBUG
8837
8838 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8839 vdso_base = VDSO32_MBASE;
8840 #endif
8841
8842 - current->mm->context.vdso_base = 0;
8843 + current->mm->context.vdso_base = ~0UL;
8844
8845 /* vDSO has a problem and was disabled, just don't "enable" it for the
8846 * process
8847 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8848 vdso_base = get_unmapped_area(NULL, vdso_base,
8849 (vdso_pages << PAGE_SHIFT) +
8850 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8851 - 0, 0);
8852 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8853 if (IS_ERR_VALUE(vdso_base)) {
8854 rc = vdso_base;
8855 goto fail_mmapsem;
8856 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8857 index 3cf541a..ab2d825 100644
8858 --- a/arch/powerpc/kvm/powerpc.c
8859 +++ b/arch/powerpc/kvm/powerpc.c
8860 @@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8861 }
8862 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8863
8864 -int kvm_arch_init(void *opaque)
8865 +int kvm_arch_init(const void *opaque)
8866 {
8867 return 0;
8868 }
8869 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8870 index 5eea6f3..5d10396 100644
8871 --- a/arch/powerpc/lib/usercopy_64.c
8872 +++ b/arch/powerpc/lib/usercopy_64.c
8873 @@ -9,22 +9,6 @@
8874 #include <linux/module.h>
8875 #include <asm/uaccess.h>
8876
8877 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8878 -{
8879 - if (likely(access_ok(VERIFY_READ, from, n)))
8880 - n = __copy_from_user(to, from, n);
8881 - else
8882 - memset(to, 0, n);
8883 - return n;
8884 -}
8885 -
8886 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8887 -{
8888 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8889 - n = __copy_to_user(to, from, n);
8890 - return n;
8891 -}
8892 -
8893 unsigned long copy_in_user(void __user *to, const void __user *from,
8894 unsigned long n)
8895 {
8896 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8897 return n;
8898 }
8899
8900 -EXPORT_SYMBOL(copy_from_user);
8901 -EXPORT_SYMBOL(copy_to_user);
8902 EXPORT_SYMBOL(copy_in_user);
8903
8904 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8905 index 51ab9e7..7d3c78b 100644
8906 --- a/arch/powerpc/mm/fault.c
8907 +++ b/arch/powerpc/mm/fault.c
8908 @@ -33,6 +33,10 @@
8909 #include <linux/magic.h>
8910 #include <linux/ratelimit.h>
8911 #include <linux/context_tracking.h>
8912 +#include <linux/slab.h>
8913 +#include <linux/pagemap.h>
8914 +#include <linux/compiler.h>
8915 +#include <linux/unistd.h>
8916
8917 #include <asm/firmware.h>
8918 #include <asm/page.h>
8919 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8920 }
8921 #endif
8922
8923 +#ifdef CONFIG_PAX_PAGEEXEC
8924 +/*
8925 + * PaX: decide what to do with offenders (regs->nip = fault address)
8926 + *
8927 + * returns 1 when task should be killed
8928 + */
8929 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8930 +{
8931 + return 1;
8932 +}
8933 +
8934 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8935 +{
8936 + unsigned long i;
8937 +
8938 + printk(KERN_ERR "PAX: bytes at PC: ");
8939 + for (i = 0; i < 5; i++) {
8940 + unsigned int c;
8941 + if (get_user(c, (unsigned int __user *)pc+i))
8942 + printk(KERN_CONT "???????? ");
8943 + else
8944 + printk(KERN_CONT "%08x ", c);
8945 + }
8946 + printk("\n");
8947 +}
8948 +#endif
8949 +
8950 /*
8951 * Check whether the instruction at regs->nip is a store using
8952 * an update addressing form which will update r1.
8953 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8954 * indicate errors in DSISR but can validly be set in SRR1.
8955 */
8956 if (trap == 0x400)
8957 - error_code &= 0x48200000;
8958 + error_code &= 0x58200000;
8959 else
8960 is_write = error_code & DSISR_ISSTORE;
8961 #else
8962 @@ -378,7 +409,7 @@ good_area:
8963 * "undefined". Of those that can be set, this is the only
8964 * one which seems bad.
8965 */
8966 - if (error_code & 0x10000000)
8967 + if (error_code & DSISR_GUARDED)
8968 /* Guarded storage error. */
8969 goto bad_area;
8970 #endif /* CONFIG_8xx */
8971 @@ -393,7 +424,7 @@ good_area:
8972 * processors use the same I/D cache coherency mechanism
8973 * as embedded.
8974 */
8975 - if (error_code & DSISR_PROTFAULT)
8976 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8977 goto bad_area;
8978 #endif /* CONFIG_PPC_STD_MMU */
8979
8980 @@ -483,6 +514,23 @@ bad_area:
8981 bad_area_nosemaphore:
8982 /* User mode accesses cause a SIGSEGV */
8983 if (user_mode(regs)) {
8984 +
8985 +#ifdef CONFIG_PAX_PAGEEXEC
8986 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8987 +#ifdef CONFIG_PPC_STD_MMU
8988 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8989 +#else
8990 + if (is_exec && regs->nip == address) {
8991 +#endif
8992 + switch (pax_handle_fetch_fault(regs)) {
8993 + }
8994 +
8995 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8996 + do_group_exit(SIGKILL);
8997 + }
8998 + }
8999 +#endif
9000 +
9001 _exception(SIGSEGV, regs, code, address);
9002 goto bail;
9003 }
9004 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9005 index cb8bdbe..cde4bc7 100644
9006 --- a/arch/powerpc/mm/mmap.c
9007 +++ b/arch/powerpc/mm/mmap.c
9008 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9009 return sysctl_legacy_va_layout;
9010 }
9011
9012 -static unsigned long mmap_rnd(void)
9013 +static unsigned long mmap_rnd(struct mm_struct *mm)
9014 {
9015 unsigned long rnd = 0;
9016
9017 +#ifdef CONFIG_PAX_RANDMMAP
9018 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9019 +#endif
9020 +
9021 if (current->flags & PF_RANDOMIZE) {
9022 /* 8MB for 32bit, 1GB for 64bit */
9023 if (is_32bit_task())
9024 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9025 return rnd << PAGE_SHIFT;
9026 }
9027
9028 -static inline unsigned long mmap_base(void)
9029 +static inline unsigned long mmap_base(struct mm_struct *mm)
9030 {
9031 unsigned long gap = rlimit(RLIMIT_STACK);
9032
9033 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9034 else if (gap > MAX_GAP)
9035 gap = MAX_GAP;
9036
9037 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9038 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9039 }
9040
9041 /*
9042 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9043 */
9044 if (mmap_is_legacy()) {
9045 mm->mmap_base = TASK_UNMAPPED_BASE;
9046 +
9047 +#ifdef CONFIG_PAX_RANDMMAP
9048 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9049 + mm->mmap_base += mm->delta_mmap;
9050 +#endif
9051 +
9052 mm->get_unmapped_area = arch_get_unmapped_area;
9053 } else {
9054 - mm->mmap_base = mmap_base();
9055 + mm->mmap_base = mmap_base(mm);
9056 +
9057 +#ifdef CONFIG_PAX_RANDMMAP
9058 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9059 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9060 +#endif
9061 +
9062 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9063 }
9064 }
9065 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9066 index b0c75cc..ef7fb93 100644
9067 --- a/arch/powerpc/mm/slice.c
9068 +++ b/arch/powerpc/mm/slice.c
9069 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9070 if ((mm->task_size - len) < addr)
9071 return 0;
9072 vma = find_vma(mm, addr);
9073 - return (!vma || (addr + len) <= vma->vm_start);
9074 + return check_heap_stack_gap(vma, addr, len, 0);
9075 }
9076
9077 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9078 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9079 info.align_offset = 0;
9080
9081 addr = TASK_UNMAPPED_BASE;
9082 +
9083 +#ifdef CONFIG_PAX_RANDMMAP
9084 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9085 + addr += mm->delta_mmap;
9086 +#endif
9087 +
9088 while (addr < TASK_SIZE) {
9089 info.low_limit = addr;
9090 if (!slice_scan_available(addr, available, 1, &addr))
9091 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9092 if (fixed && addr > (mm->task_size - len))
9093 return -ENOMEM;
9094
9095 +#ifdef CONFIG_PAX_RANDMMAP
9096 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9097 + addr = 0;
9098 +#endif
9099 +
9100 /* If hint, make sure it matches our alignment restrictions */
9101 if (!fixed && addr) {
9102 addr = _ALIGN_UP(addr, 1ul << pshift);
9103 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9104 index 4278acf..67fd0e6 100644
9105 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9106 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9107 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9108 }
9109
9110 static struct pci_ops scc_pciex_pci_ops = {
9111 - scc_pciex_read_config,
9112 - scc_pciex_write_config,
9113 + .read = scc_pciex_read_config,
9114 + .write = scc_pciex_write_config,
9115 };
9116
9117 static void pciex_clear_intr_all(unsigned int __iomem *base)
9118 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9119 index 9098692..3d54cd1 100644
9120 --- a/arch/powerpc/platforms/cell/spufs/file.c
9121 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9122 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9123 return VM_FAULT_NOPAGE;
9124 }
9125
9126 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9127 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9128 unsigned long address,
9129 - void *buf, int len, int write)
9130 + void *buf, size_t len, int write)
9131 {
9132 struct spu_context *ctx = vma->vm_file->private_data;
9133 unsigned long offset = address - vma->vm_start;
9134 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9135 index 1d47061..0714963 100644
9136 --- a/arch/s390/include/asm/atomic.h
9137 +++ b/arch/s390/include/asm/atomic.h
9138 @@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9139 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9140 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9141
9142 +#define atomic64_read_unchecked(v) atomic64_read(v)
9143 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9144 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9145 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9146 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9147 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9148 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9149 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9150 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9151 +
9152 #define smp_mb__before_atomic_dec() smp_mb()
9153 #define smp_mb__after_atomic_dec() smp_mb()
9154 #define smp_mb__before_atomic_inc() smp_mb()
9155 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9156 index 578680f..0eb3b11 100644
9157 --- a/arch/s390/include/asm/barrier.h
9158 +++ b/arch/s390/include/asm/barrier.h
9159 @@ -36,7 +36,7 @@
9160 do { \
9161 compiletime_assert_atomic_type(*p); \
9162 barrier(); \
9163 - ACCESS_ONCE(*p) = (v); \
9164 + ACCESS_ONCE_RW(*p) = (v); \
9165 } while (0)
9166
9167 #define smp_load_acquire(p) \
9168 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9169 index 4d7ccac..d03d0ad 100644
9170 --- a/arch/s390/include/asm/cache.h
9171 +++ b/arch/s390/include/asm/cache.h
9172 @@ -9,8 +9,10 @@
9173 #ifndef __ARCH_S390_CACHE_H
9174 #define __ARCH_S390_CACHE_H
9175
9176 -#define L1_CACHE_BYTES 256
9177 +#include <linux/const.h>
9178 +
9179 #define L1_CACHE_SHIFT 8
9180 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9181 #define NET_SKB_PAD 32
9182
9183 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9184 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9185 index 78f4f87..598ce39 100644
9186 --- a/arch/s390/include/asm/elf.h
9187 +++ b/arch/s390/include/asm/elf.h
9188 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9189 the loader. We need to make sure that it is out of the way of the program
9190 that it will "exec", and that there is sufficient room for the brk. */
9191
9192 -extern unsigned long randomize_et_dyn(unsigned long base);
9193 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9194 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9195 +
9196 +#ifdef CONFIG_PAX_ASLR
9197 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9198 +
9199 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9200 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9201 +#endif
9202
9203 /* This yields a mask that user programs can use to figure out what
9204 instruction set this CPU supports. */
9205 @@ -222,9 +228,6 @@ struct linux_binprm;
9206 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9207 int arch_setup_additional_pages(struct linux_binprm *, int);
9208
9209 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9210 -#define arch_randomize_brk arch_randomize_brk
9211 -
9212 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9213
9214 #endif
9215 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9216 index c4a93d6..4d2a9b4 100644
9217 --- a/arch/s390/include/asm/exec.h
9218 +++ b/arch/s390/include/asm/exec.h
9219 @@ -7,6 +7,6 @@
9220 #ifndef __ASM_EXEC_H
9221 #define __ASM_EXEC_H
9222
9223 -extern unsigned long arch_align_stack(unsigned long sp);
9224 +#define arch_align_stack(x) ((x) & ~0xfUL)
9225
9226 #endif /* __ASM_EXEC_H */
9227 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9228 index 1be64a1..086839d1 100644
9229 --- a/arch/s390/include/asm/uaccess.h
9230 +++ b/arch/s390/include/asm/uaccess.h
9231 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9232 __range_ok((unsigned long)(addr), (size)); \
9233 })
9234
9235 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9236 #define access_ok(type, addr, size) __access_ok(addr, size)
9237
9238 /*
9239 @@ -245,6 +246,10 @@ static inline unsigned long __must_check
9240 copy_to_user(void __user *to, const void *from, unsigned long n)
9241 {
9242 might_fault();
9243 +
9244 + if ((long)n < 0)
9245 + return n;
9246 +
9247 return __copy_to_user(to, from, n);
9248 }
9249
9250 @@ -273,10 +278,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9251 static inline unsigned long __must_check
9252 copy_from_user(void *to, const void __user *from, unsigned long n)
9253 {
9254 - unsigned int sz = __compiletime_object_size(to);
9255 + size_t sz = __compiletime_object_size(to);
9256
9257 might_fault();
9258 - if (unlikely(sz != -1 && sz < n)) {
9259 +
9260 + if ((long)n < 0)
9261 + return n;
9262 +
9263 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9264 copy_from_user_overflow();
9265 return n;
9266 }
9267 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9268 index b89b591..fd9609d 100644
9269 --- a/arch/s390/kernel/module.c
9270 +++ b/arch/s390/kernel/module.c
9271 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9272
9273 /* Increase core size by size of got & plt and set start
9274 offsets for got and plt. */
9275 - me->core_size = ALIGN(me->core_size, 4);
9276 - me->arch.got_offset = me->core_size;
9277 - me->core_size += me->arch.got_size;
9278 - me->arch.plt_offset = me->core_size;
9279 - me->core_size += me->arch.plt_size;
9280 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9281 + me->arch.got_offset = me->core_size_rw;
9282 + me->core_size_rw += me->arch.got_size;
9283 + me->arch.plt_offset = me->core_size_rx;
9284 + me->core_size_rx += me->arch.plt_size;
9285 return 0;
9286 }
9287
9288 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9289 if (info->got_initialized == 0) {
9290 Elf_Addr *gotent;
9291
9292 - gotent = me->module_core + me->arch.got_offset +
9293 + gotent = me->module_core_rw + me->arch.got_offset +
9294 info->got_offset;
9295 *gotent = val;
9296 info->got_initialized = 1;
9297 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9298 rc = apply_rela_bits(loc, val, 0, 64, 0);
9299 else if (r_type == R_390_GOTENT ||
9300 r_type == R_390_GOTPLTENT) {
9301 - val += (Elf_Addr) me->module_core - loc;
9302 + val += (Elf_Addr) me->module_core_rw - loc;
9303 rc = apply_rela_bits(loc, val, 1, 32, 1);
9304 }
9305 break;
9306 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9307 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9308 if (info->plt_initialized == 0) {
9309 unsigned int *ip;
9310 - ip = me->module_core + me->arch.plt_offset +
9311 + ip = me->module_core_rx + me->arch.plt_offset +
9312 info->plt_offset;
9313 #ifndef CONFIG_64BIT
9314 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9315 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9316 val - loc + 0xffffUL < 0x1ffffeUL) ||
9317 (r_type == R_390_PLT32DBL &&
9318 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9319 - val = (Elf_Addr) me->module_core +
9320 + val = (Elf_Addr) me->module_core_rx +
9321 me->arch.plt_offset +
9322 info->plt_offset;
9323 val += rela->r_addend - loc;
9324 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9325 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9326 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9327 val = val + rela->r_addend -
9328 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9329 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9330 if (r_type == R_390_GOTOFF16)
9331 rc = apply_rela_bits(loc, val, 0, 16, 0);
9332 else if (r_type == R_390_GOTOFF32)
9333 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9334 break;
9335 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9336 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9337 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9338 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9339 rela->r_addend - loc;
9340 if (r_type == R_390_GOTPC)
9341 rc = apply_rela_bits(loc, val, 1, 32, 0);
9342 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9343 index dd14532..1dfc145 100644
9344 --- a/arch/s390/kernel/process.c
9345 +++ b/arch/s390/kernel/process.c
9346 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9347 }
9348 return 0;
9349 }
9350 -
9351 -unsigned long arch_align_stack(unsigned long sp)
9352 -{
9353 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9354 - sp -= get_random_int() & ~PAGE_MASK;
9355 - return sp & ~0xf;
9356 -}
9357 -
9358 -static inline unsigned long brk_rnd(void)
9359 -{
9360 - /* 8MB for 32bit, 1GB for 64bit */
9361 - if (is_32bit_task())
9362 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9363 - else
9364 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9365 -}
9366 -
9367 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9368 -{
9369 - unsigned long ret;
9370 -
9371 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9372 - return (ret > mm->brk) ? ret : mm->brk;
9373 -}
9374 -
9375 -unsigned long randomize_et_dyn(unsigned long base)
9376 -{
9377 - unsigned long ret;
9378 -
9379 - if (!(current->flags & PF_RANDOMIZE))
9380 - return base;
9381 - ret = PAGE_ALIGN(base + brk_rnd());
9382 - return (ret > base) ? ret : base;
9383 -}
9384 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9385 index 9b436c2..54fbf0a 100644
9386 --- a/arch/s390/mm/mmap.c
9387 +++ b/arch/s390/mm/mmap.c
9388 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9389 */
9390 if (mmap_is_legacy()) {
9391 mm->mmap_base = mmap_base_legacy();
9392 +
9393 +#ifdef CONFIG_PAX_RANDMMAP
9394 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9395 + mm->mmap_base += mm->delta_mmap;
9396 +#endif
9397 +
9398 mm->get_unmapped_area = arch_get_unmapped_area;
9399 } else {
9400 mm->mmap_base = mmap_base();
9401 +
9402 +#ifdef CONFIG_PAX_RANDMMAP
9403 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9404 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9405 +#endif
9406 +
9407 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9408 }
9409 }
9410 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9411 */
9412 if (mmap_is_legacy()) {
9413 mm->mmap_base = mmap_base_legacy();
9414 +
9415 +#ifdef CONFIG_PAX_RANDMMAP
9416 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9417 + mm->mmap_base += mm->delta_mmap;
9418 +#endif
9419 +
9420 mm->get_unmapped_area = s390_get_unmapped_area;
9421 } else {
9422 mm->mmap_base = mmap_base();
9423 +
9424 +#ifdef CONFIG_PAX_RANDMMAP
9425 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9426 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9427 +#endif
9428 +
9429 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9430 }
9431 }
9432 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9433 index ae3d59f..f65f075 100644
9434 --- a/arch/score/include/asm/cache.h
9435 +++ b/arch/score/include/asm/cache.h
9436 @@ -1,7 +1,9 @@
9437 #ifndef _ASM_SCORE_CACHE_H
9438 #define _ASM_SCORE_CACHE_H
9439
9440 +#include <linux/const.h>
9441 +
9442 #define L1_CACHE_SHIFT 4
9443 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9444 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9445
9446 #endif /* _ASM_SCORE_CACHE_H */
9447 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9448 index f9f3cd5..58ff438 100644
9449 --- a/arch/score/include/asm/exec.h
9450 +++ b/arch/score/include/asm/exec.h
9451 @@ -1,6 +1,6 @@
9452 #ifndef _ASM_SCORE_EXEC_H
9453 #define _ASM_SCORE_EXEC_H
9454
9455 -extern unsigned long arch_align_stack(unsigned long sp);
9456 +#define arch_align_stack(x) (x)
9457
9458 #endif /* _ASM_SCORE_EXEC_H */
9459 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9460 index a1519ad3..e8ac1ff 100644
9461 --- a/arch/score/kernel/process.c
9462 +++ b/arch/score/kernel/process.c
9463 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9464
9465 return task_pt_regs(task)->cp0_epc;
9466 }
9467 -
9468 -unsigned long arch_align_stack(unsigned long sp)
9469 -{
9470 - return sp;
9471 -}
9472 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9473 index ef9e555..331bd29 100644
9474 --- a/arch/sh/include/asm/cache.h
9475 +++ b/arch/sh/include/asm/cache.h
9476 @@ -9,10 +9,11 @@
9477 #define __ASM_SH_CACHE_H
9478 #ifdef __KERNEL__
9479
9480 +#include <linux/const.h>
9481 #include <linux/init.h>
9482 #include <cpu/cache.h>
9483
9484 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9485 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9486
9487 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9488
9489 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9490 index 6777177..cb5e44f 100644
9491 --- a/arch/sh/mm/mmap.c
9492 +++ b/arch/sh/mm/mmap.c
9493 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9494 struct mm_struct *mm = current->mm;
9495 struct vm_area_struct *vma;
9496 int do_colour_align;
9497 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9498 struct vm_unmapped_area_info info;
9499
9500 if (flags & MAP_FIXED) {
9501 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9502 if (filp || (flags & MAP_SHARED))
9503 do_colour_align = 1;
9504
9505 +#ifdef CONFIG_PAX_RANDMMAP
9506 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9507 +#endif
9508 +
9509 if (addr) {
9510 if (do_colour_align)
9511 addr = COLOUR_ALIGN(addr, pgoff);
9512 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9513 addr = PAGE_ALIGN(addr);
9514
9515 vma = find_vma(mm, addr);
9516 - if (TASK_SIZE - len >= addr &&
9517 - (!vma || addr + len <= vma->vm_start))
9518 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9519 return addr;
9520 }
9521
9522 info.flags = 0;
9523 info.length = len;
9524 - info.low_limit = TASK_UNMAPPED_BASE;
9525 + info.low_limit = mm->mmap_base;
9526 info.high_limit = TASK_SIZE;
9527 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9528 info.align_offset = pgoff << PAGE_SHIFT;
9529 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9530 struct mm_struct *mm = current->mm;
9531 unsigned long addr = addr0;
9532 int do_colour_align;
9533 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9534 struct vm_unmapped_area_info info;
9535
9536 if (flags & MAP_FIXED) {
9537 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9538 if (filp || (flags & MAP_SHARED))
9539 do_colour_align = 1;
9540
9541 +#ifdef CONFIG_PAX_RANDMMAP
9542 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9543 +#endif
9544 +
9545 /* requesting a specific address */
9546 if (addr) {
9547 if (do_colour_align)
9548 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9549 addr = PAGE_ALIGN(addr);
9550
9551 vma = find_vma(mm, addr);
9552 - if (TASK_SIZE - len >= addr &&
9553 - (!vma || addr + len <= vma->vm_start))
9554 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9555 return addr;
9556 }
9557
9558 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9559 VM_BUG_ON(addr != -ENOMEM);
9560 info.flags = 0;
9561 info.low_limit = TASK_UNMAPPED_BASE;
9562 +
9563 +#ifdef CONFIG_PAX_RANDMMAP
9564 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9565 + info.low_limit += mm->delta_mmap;
9566 +#endif
9567 +
9568 info.high_limit = TASK_SIZE;
9569 addr = vm_unmapped_area(&info);
9570 }
9571 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9572 index be56a24..443328f 100644
9573 --- a/arch/sparc/include/asm/atomic_64.h
9574 +++ b/arch/sparc/include/asm/atomic_64.h
9575 @@ -14,18 +14,40 @@
9576 #define ATOMIC64_INIT(i) { (i) }
9577
9578 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9579 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9580 +{
9581 + return v->counter;
9582 +}
9583 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9584 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9585 +{
9586 + return v->counter;
9587 +}
9588
9589 #define atomic_set(v, i) (((v)->counter) = i)
9590 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9591 +{
9592 + v->counter = i;
9593 +}
9594 #define atomic64_set(v, i) (((v)->counter) = i)
9595 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9596 +{
9597 + v->counter = i;
9598 +}
9599
9600 extern void atomic_add(int, atomic_t *);
9601 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9602 extern void atomic64_add(long, atomic64_t *);
9603 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9604 extern void atomic_sub(int, atomic_t *);
9605 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9606 extern void atomic64_sub(long, atomic64_t *);
9607 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9608
9609 extern int atomic_add_ret(int, atomic_t *);
9610 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9611 extern long atomic64_add_ret(long, atomic64_t *);
9612 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9613 extern int atomic_sub_ret(int, atomic_t *);
9614 extern long atomic64_sub_ret(long, atomic64_t *);
9615
9616 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9617 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9618
9619 #define atomic_inc_return(v) atomic_add_ret(1, v)
9620 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9621 +{
9622 + return atomic_add_ret_unchecked(1, v);
9623 +}
9624 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9625 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9626 +{
9627 + return atomic64_add_ret_unchecked(1, v);
9628 +}
9629
9630 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9631 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9632
9633 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9634 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9635 +{
9636 + return atomic_add_ret_unchecked(i, v);
9637 +}
9638 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9639 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9640 +{
9641 + return atomic64_add_ret_unchecked(i, v);
9642 +}
9643
9644 /*
9645 * atomic_inc_and_test - increment and test
9646 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9647 * other cases.
9648 */
9649 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9650 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9651 +{
9652 + return atomic_inc_return_unchecked(v) == 0;
9653 +}
9654 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9655
9656 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9657 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9658 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9659
9660 #define atomic_inc(v) atomic_add(1, v)
9661 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9662 +{
9663 + atomic_add_unchecked(1, v);
9664 +}
9665 #define atomic64_inc(v) atomic64_add(1, v)
9666 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9667 +{
9668 + atomic64_add_unchecked(1, v);
9669 +}
9670
9671 #define atomic_dec(v) atomic_sub(1, v)
9672 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9673 +{
9674 + atomic_sub_unchecked(1, v);
9675 +}
9676 #define atomic64_dec(v) atomic64_sub(1, v)
9677 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9678 +{
9679 + atomic64_sub_unchecked(1, v);
9680 +}
9681
9682 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9683 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9684
9685 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9686 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9687 +{
9688 + return cmpxchg(&v->counter, old, new);
9689 +}
9690 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9691 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9692 +{
9693 + return xchg(&v->counter, new);
9694 +}
9695
9696 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9697 {
9698 - int c, old;
9699 + int c, old, new;
9700 c = atomic_read(v);
9701 for (;;) {
9702 - if (unlikely(c == (u)))
9703 + if (unlikely(c == u))
9704 break;
9705 - old = atomic_cmpxchg((v), c, c + (a));
9706 +
9707 + asm volatile("addcc %2, %0, %0\n"
9708 +
9709 +#ifdef CONFIG_PAX_REFCOUNT
9710 + "tvs %%icc, 6\n"
9711 +#endif
9712 +
9713 + : "=r" (new)
9714 + : "0" (c), "ir" (a)
9715 + : "cc");
9716 +
9717 + old = atomic_cmpxchg(v, c, new);
9718 if (likely(old == c))
9719 break;
9720 c = old;
9721 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9722 #define atomic64_cmpxchg(v, o, n) \
9723 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9724 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9725 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9726 +{
9727 + return xchg(&v->counter, new);
9728 +}
9729
9730 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9731 {
9732 - long c, old;
9733 + long c, old, new;
9734 c = atomic64_read(v);
9735 for (;;) {
9736 - if (unlikely(c == (u)))
9737 + if (unlikely(c == u))
9738 break;
9739 - old = atomic64_cmpxchg((v), c, c + (a));
9740 +
9741 + asm volatile("addcc %2, %0, %0\n"
9742 +
9743 +#ifdef CONFIG_PAX_REFCOUNT
9744 + "tvs %%xcc, 6\n"
9745 +#endif
9746 +
9747 + : "=r" (new)
9748 + : "0" (c), "ir" (a)
9749 + : "cc");
9750 +
9751 + old = atomic64_cmpxchg(v, c, new);
9752 if (likely(old == c))
9753 break;
9754 c = old;
9755 }
9756 - return c != (u);
9757 + return c != u;
9758 }
9759
9760 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9761 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
9762 index b5aad96..99d7465 100644
9763 --- a/arch/sparc/include/asm/barrier_64.h
9764 +++ b/arch/sparc/include/asm/barrier_64.h
9765 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
9766 do { \
9767 compiletime_assert_atomic_type(*p); \
9768 barrier(); \
9769 - ACCESS_ONCE(*p) = (v); \
9770 + ACCESS_ONCE_RW(*p) = (v); \
9771 } while (0)
9772
9773 #define smp_load_acquire(p) \
9774 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9775 index 5bb6991..5c2132e 100644
9776 --- a/arch/sparc/include/asm/cache.h
9777 +++ b/arch/sparc/include/asm/cache.h
9778 @@ -7,10 +7,12 @@
9779 #ifndef _SPARC_CACHE_H
9780 #define _SPARC_CACHE_H
9781
9782 +#include <linux/const.h>
9783 +
9784 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9785
9786 #define L1_CACHE_SHIFT 5
9787 -#define L1_CACHE_BYTES 32
9788 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9789
9790 #ifdef CONFIG_SPARC32
9791 #define SMP_CACHE_BYTES_SHIFT 5
9792 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9793 index a24e41f..47677ff 100644
9794 --- a/arch/sparc/include/asm/elf_32.h
9795 +++ b/arch/sparc/include/asm/elf_32.h
9796 @@ -114,6 +114,13 @@ typedef struct {
9797
9798 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9799
9800 +#ifdef CONFIG_PAX_ASLR
9801 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9802 +
9803 +#define PAX_DELTA_MMAP_LEN 16
9804 +#define PAX_DELTA_STACK_LEN 16
9805 +#endif
9806 +
9807 /* This yields a mask that user programs can use to figure out what
9808 instruction set this cpu supports. This can NOT be done in userspace
9809 on Sparc. */
9810 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9811 index 370ca1e..d4f4a98 100644
9812 --- a/arch/sparc/include/asm/elf_64.h
9813 +++ b/arch/sparc/include/asm/elf_64.h
9814 @@ -189,6 +189,13 @@ typedef struct {
9815 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9816 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9817
9818 +#ifdef CONFIG_PAX_ASLR
9819 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9820 +
9821 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9822 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9823 +#endif
9824 +
9825 extern unsigned long sparc64_elf_hwcap;
9826 #define ELF_HWCAP sparc64_elf_hwcap
9827
9828 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9829 index 9b1c36d..209298b 100644
9830 --- a/arch/sparc/include/asm/pgalloc_32.h
9831 +++ b/arch/sparc/include/asm/pgalloc_32.h
9832 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9833 }
9834
9835 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9836 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9837
9838 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9839 unsigned long address)
9840 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9841 index bcfe063..b333142 100644
9842 --- a/arch/sparc/include/asm/pgalloc_64.h
9843 +++ b/arch/sparc/include/asm/pgalloc_64.h
9844 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9845 }
9846
9847 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9848 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9849
9850 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9851 {
9852 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9853 index 59ba6f6..4518128 100644
9854 --- a/arch/sparc/include/asm/pgtable.h
9855 +++ b/arch/sparc/include/asm/pgtable.h
9856 @@ -5,4 +5,8 @@
9857 #else
9858 #include <asm/pgtable_32.h>
9859 #endif
9860 +
9861 +#define ktla_ktva(addr) (addr)
9862 +#define ktva_ktla(addr) (addr)
9863 +
9864 #endif
9865 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9866 index 502f632..da1917f 100644
9867 --- a/arch/sparc/include/asm/pgtable_32.h
9868 +++ b/arch/sparc/include/asm/pgtable_32.h
9869 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9870 #define PAGE_SHARED SRMMU_PAGE_SHARED
9871 #define PAGE_COPY SRMMU_PAGE_COPY
9872 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9873 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9874 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9875 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9876 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9877
9878 /* Top-level page directory - dummy used by init-mm.
9879 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9880
9881 /* xwr */
9882 #define __P000 PAGE_NONE
9883 -#define __P001 PAGE_READONLY
9884 -#define __P010 PAGE_COPY
9885 -#define __P011 PAGE_COPY
9886 +#define __P001 PAGE_READONLY_NOEXEC
9887 +#define __P010 PAGE_COPY_NOEXEC
9888 +#define __P011 PAGE_COPY_NOEXEC
9889 #define __P100 PAGE_READONLY
9890 #define __P101 PAGE_READONLY
9891 #define __P110 PAGE_COPY
9892 #define __P111 PAGE_COPY
9893
9894 #define __S000 PAGE_NONE
9895 -#define __S001 PAGE_READONLY
9896 -#define __S010 PAGE_SHARED
9897 -#define __S011 PAGE_SHARED
9898 +#define __S001 PAGE_READONLY_NOEXEC
9899 +#define __S010 PAGE_SHARED_NOEXEC
9900 +#define __S011 PAGE_SHARED_NOEXEC
9901 #define __S100 PAGE_READONLY
9902 #define __S101 PAGE_READONLY
9903 #define __S110 PAGE_SHARED
9904 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9905 index 79da178..c2eede8 100644
9906 --- a/arch/sparc/include/asm/pgtsrmmu.h
9907 +++ b/arch/sparc/include/asm/pgtsrmmu.h
9908 @@ -115,6 +115,11 @@
9909 SRMMU_EXEC | SRMMU_REF)
9910 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9911 SRMMU_EXEC | SRMMU_REF)
9912 +
9913 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9914 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9915 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9916 +
9917 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9918 SRMMU_DIRTY | SRMMU_REF)
9919
9920 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9921 index 9689176..63c18ea 100644
9922 --- a/arch/sparc/include/asm/spinlock_64.h
9923 +++ b/arch/sparc/include/asm/spinlock_64.h
9924 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9925
9926 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9927
9928 -static void inline arch_read_lock(arch_rwlock_t *lock)
9929 +static inline void arch_read_lock(arch_rwlock_t *lock)
9930 {
9931 unsigned long tmp1, tmp2;
9932
9933 __asm__ __volatile__ (
9934 "1: ldsw [%2], %0\n"
9935 " brlz,pn %0, 2f\n"
9936 -"4: add %0, 1, %1\n"
9937 +"4: addcc %0, 1, %1\n"
9938 +
9939 +#ifdef CONFIG_PAX_REFCOUNT
9940 +" tvs %%icc, 6\n"
9941 +#endif
9942 +
9943 " cas [%2], %0, %1\n"
9944 " cmp %0, %1\n"
9945 " bne,pn %%icc, 1b\n"
9946 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9947 " .previous"
9948 : "=&r" (tmp1), "=&r" (tmp2)
9949 : "r" (lock)
9950 - : "memory");
9951 + : "memory", "cc");
9952 }
9953
9954 -static int inline arch_read_trylock(arch_rwlock_t *lock)
9955 +static inline int arch_read_trylock(arch_rwlock_t *lock)
9956 {
9957 int tmp1, tmp2;
9958
9959 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9960 "1: ldsw [%2], %0\n"
9961 " brlz,a,pn %0, 2f\n"
9962 " mov 0, %0\n"
9963 -" add %0, 1, %1\n"
9964 +" addcc %0, 1, %1\n"
9965 +
9966 +#ifdef CONFIG_PAX_REFCOUNT
9967 +" tvs %%icc, 6\n"
9968 +#endif
9969 +
9970 " cas [%2], %0, %1\n"
9971 " cmp %0, %1\n"
9972 " bne,pn %%icc, 1b\n"
9973 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9974 return tmp1;
9975 }
9976
9977 -static void inline arch_read_unlock(arch_rwlock_t *lock)
9978 +static inline void arch_read_unlock(arch_rwlock_t *lock)
9979 {
9980 unsigned long tmp1, tmp2;
9981
9982 __asm__ __volatile__(
9983 "1: lduw [%2], %0\n"
9984 -" sub %0, 1, %1\n"
9985 +" subcc %0, 1, %1\n"
9986 +
9987 +#ifdef CONFIG_PAX_REFCOUNT
9988 +" tvs %%icc, 6\n"
9989 +#endif
9990 +
9991 " cas [%2], %0, %1\n"
9992 " cmp %0, %1\n"
9993 " bne,pn %%xcc, 1b\n"
9994 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9995 : "memory");
9996 }
9997
9998 -static void inline arch_write_lock(arch_rwlock_t *lock)
9999 +static inline void arch_write_lock(arch_rwlock_t *lock)
10000 {
10001 unsigned long mask, tmp1, tmp2;
10002
10003 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10004 : "memory");
10005 }
10006
10007 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10008 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10009 {
10010 __asm__ __volatile__(
10011 " stw %%g0, [%0]"
10012 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10013 : "memory");
10014 }
10015
10016 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10017 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10018 {
10019 unsigned long mask, tmp1, tmp2, result;
10020
10021 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10022 index 96efa7a..16858bf 100644
10023 --- a/arch/sparc/include/asm/thread_info_32.h
10024 +++ b/arch/sparc/include/asm/thread_info_32.h
10025 @@ -49,6 +49,8 @@ struct thread_info {
10026 unsigned long w_saved;
10027
10028 struct restart_block restart_block;
10029 +
10030 + unsigned long lowest_stack;
10031 };
10032
10033 /*
10034 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10035 index a5f01ac..703b554 100644
10036 --- a/arch/sparc/include/asm/thread_info_64.h
10037 +++ b/arch/sparc/include/asm/thread_info_64.h
10038 @@ -63,6 +63,8 @@ struct thread_info {
10039 struct pt_regs *kern_una_regs;
10040 unsigned int kern_una_insn;
10041
10042 + unsigned long lowest_stack;
10043 +
10044 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10045 };
10046
10047 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10048 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10049 /* flag bit 4 is available */
10050 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10051 -/* flag bit 6 is available */
10052 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10053 #define TIF_32BIT 7 /* 32-bit binary */
10054 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10055 #define TIF_SECCOMP 9 /* secure computing */
10056 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10057 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10058 +
10059 /* NOTE: Thread flags >= 12 should be ones we have no interest
10060 * in using in assembly, else we can't use the mask as
10061 * an immediate value in instructions such as andcc.
10062 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10063 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10064 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10065 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10066 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10067
10068 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10069 _TIF_DO_NOTIFY_RESUME_MASK | \
10070 _TIF_NEED_RESCHED)
10071 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10072
10073 +#define _TIF_WORK_SYSCALL \
10074 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10075 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10076 +
10077 +
10078 /*
10079 * Thread-synchronous status.
10080 *
10081 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10082 index 0167d26..767bb0c 100644
10083 --- a/arch/sparc/include/asm/uaccess.h
10084 +++ b/arch/sparc/include/asm/uaccess.h
10085 @@ -1,5 +1,6 @@
10086 #ifndef ___ASM_SPARC_UACCESS_H
10087 #define ___ASM_SPARC_UACCESS_H
10088 +
10089 #if defined(__sparc__) && defined(__arch64__)
10090 #include <asm/uaccess_64.h>
10091 #else
10092 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10093 index 53a28dd..50c38c3 100644
10094 --- a/arch/sparc/include/asm/uaccess_32.h
10095 +++ b/arch/sparc/include/asm/uaccess_32.h
10096 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
10097
10098 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10099 {
10100 - if (n && __access_ok((unsigned long) to, n))
10101 + if ((long)n < 0)
10102 + return n;
10103 +
10104 + if (n && __access_ok((unsigned long) to, n)) {
10105 + if (!__builtin_constant_p(n))
10106 + check_object_size(from, n, true);
10107 return __copy_user(to, (__force void __user *) from, n);
10108 - else
10109 + } else
10110 return n;
10111 }
10112
10113 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10114 {
10115 + if ((long)n < 0)
10116 + return n;
10117 +
10118 + if (!__builtin_constant_p(n))
10119 + check_object_size(from, n, true);
10120 +
10121 return __copy_user(to, (__force void __user *) from, n);
10122 }
10123
10124 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10125 {
10126 - if (n && __access_ok((unsigned long) from, n))
10127 + if ((long)n < 0)
10128 + return n;
10129 +
10130 + if (n && __access_ok((unsigned long) from, n)) {
10131 + if (!__builtin_constant_p(n))
10132 + check_object_size(to, n, false);
10133 return __copy_user((__force void __user *) to, from, n);
10134 - else
10135 + } else
10136 return n;
10137 }
10138
10139 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10140 {
10141 + if ((long)n < 0)
10142 + return n;
10143 +
10144 return __copy_user((__force void __user *) to, from, n);
10145 }
10146
10147 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10148 index ad7e178..c9e7423 100644
10149 --- a/arch/sparc/include/asm/uaccess_64.h
10150 +++ b/arch/sparc/include/asm/uaccess_64.h
10151 @@ -10,6 +10,7 @@
10152 #include <linux/compiler.h>
10153 #include <linux/string.h>
10154 #include <linux/thread_info.h>
10155 +#include <linux/kernel.h>
10156 #include <asm/asi.h>
10157 #include <asm/spitfire.h>
10158 #include <asm-generic/uaccess-unaligned.h>
10159 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10160 static inline unsigned long __must_check
10161 copy_from_user(void *to, const void __user *from, unsigned long size)
10162 {
10163 - unsigned long ret = ___copy_from_user(to, from, size);
10164 + unsigned long ret;
10165
10166 + if ((long)size < 0 || size > INT_MAX)
10167 + return size;
10168 +
10169 + if (!__builtin_constant_p(size))
10170 + check_object_size(to, size, false);
10171 +
10172 + ret = ___copy_from_user(to, from, size);
10173 if (unlikely(ret))
10174 ret = copy_from_user_fixup(to, from, size);
10175
10176 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10177 static inline unsigned long __must_check
10178 copy_to_user(void __user *to, const void *from, unsigned long size)
10179 {
10180 - unsigned long ret = ___copy_to_user(to, from, size);
10181 + unsigned long ret;
10182
10183 + if ((long)size < 0 || size > INT_MAX)
10184 + return size;
10185 +
10186 + if (!__builtin_constant_p(size))
10187 + check_object_size(from, size, true);
10188 +
10189 + ret = ___copy_to_user(to, from, size);
10190 if (unlikely(ret))
10191 ret = copy_to_user_fixup(to, from, size);
10192 return ret;
10193 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10194 index d15cc17..d0ae796 100644
10195 --- a/arch/sparc/kernel/Makefile
10196 +++ b/arch/sparc/kernel/Makefile
10197 @@ -4,7 +4,7 @@
10198 #
10199
10200 asflags-y := -ansi
10201 -ccflags-y := -Werror
10202 +#ccflags-y := -Werror
10203
10204 extra-y := head_$(BITS).o
10205
10206 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10207 index 510baec..9ff2607 100644
10208 --- a/arch/sparc/kernel/process_32.c
10209 +++ b/arch/sparc/kernel/process_32.c
10210 @@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10211
10212 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10213 r->psr, r->pc, r->npc, r->y, print_tainted());
10214 - printk("PC: <%pS>\n", (void *) r->pc);
10215 + printk("PC: <%pA>\n", (void *) r->pc);
10216 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10217 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10218 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10219 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10220 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10221 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10222 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10223 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10224
10225 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10226 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10227 @@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10228 rw = (struct reg_window32 *) fp;
10229 pc = rw->ins[7];
10230 printk("[%08lx : ", pc);
10231 - printk("%pS ] ", (void *) pc);
10232 + printk("%pA ] ", (void *) pc);
10233 fp = rw->ins[6];
10234 } while (++count < 16);
10235 printk("\n");
10236 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10237 index d7b4967..2edf827 100644
10238 --- a/arch/sparc/kernel/process_64.c
10239 +++ b/arch/sparc/kernel/process_64.c
10240 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10241 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10242 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10243 if (regs->tstate & TSTATE_PRIV)
10244 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10245 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10246 }
10247
10248 void show_regs(struct pt_regs *regs)
10249 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10250
10251 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10252 regs->tpc, regs->tnpc, regs->y, print_tainted());
10253 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10254 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10255 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10256 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10257 regs->u_regs[3]);
10258 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10259 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10260 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10261 regs->u_regs[15]);
10262 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10263 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10264 show_regwindow(regs);
10265 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10266 }
10267 @@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10268 ((tp && tp->task) ? tp->task->pid : -1));
10269
10270 if (gp->tstate & TSTATE_PRIV) {
10271 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10272 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10273 (void *) gp->tpc,
10274 (void *) gp->o7,
10275 (void *) gp->i7,
10276 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10277 index 79cc0d1..ec62734 100644
10278 --- a/arch/sparc/kernel/prom_common.c
10279 +++ b/arch/sparc/kernel/prom_common.c
10280 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10281
10282 unsigned int prom_early_allocated __initdata;
10283
10284 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10285 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10286 .nextprop = prom_common_nextprop,
10287 .getproplen = prom_getproplen,
10288 .getproperty = prom_getproperty,
10289 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10290 index c13c9f2..d572c34 100644
10291 --- a/arch/sparc/kernel/ptrace_64.c
10292 +++ b/arch/sparc/kernel/ptrace_64.c
10293 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10294 return ret;
10295 }
10296
10297 +#ifdef CONFIG_GRKERNSEC_SETXID
10298 +extern void gr_delayed_cred_worker(void);
10299 +#endif
10300 +
10301 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10302 {
10303 int ret = 0;
10304 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10305 if (test_thread_flag(TIF_NOHZ))
10306 user_exit();
10307
10308 +#ifdef CONFIG_GRKERNSEC_SETXID
10309 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10310 + gr_delayed_cred_worker();
10311 +#endif
10312 +
10313 if (test_thread_flag(TIF_SYSCALL_TRACE))
10314 ret = tracehook_report_syscall_entry(regs);
10315
10316 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10317 if (test_thread_flag(TIF_NOHZ))
10318 user_exit();
10319
10320 +#ifdef CONFIG_GRKERNSEC_SETXID
10321 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10322 + gr_delayed_cred_worker();
10323 +#endif
10324 +
10325 audit_syscall_exit(regs);
10326
10327 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10328 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10329 index 745a363..b5566b1 100644
10330 --- a/arch/sparc/kernel/smp_64.c
10331 +++ b/arch/sparc/kernel/smp_64.c
10332 @@ -868,8 +868,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10333 extern unsigned long xcall_flush_dcache_page_spitfire;
10334
10335 #ifdef CONFIG_DEBUG_DCFLUSH
10336 -extern atomic_t dcpage_flushes;
10337 -extern atomic_t dcpage_flushes_xcall;
10338 +extern atomic_unchecked_t dcpage_flushes;
10339 +extern atomic_unchecked_t dcpage_flushes_xcall;
10340 #endif
10341
10342 static inline void __local_flush_dcache_page(struct page *page)
10343 @@ -893,7 +893,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10344 return;
10345
10346 #ifdef CONFIG_DEBUG_DCFLUSH
10347 - atomic_inc(&dcpage_flushes);
10348 + atomic_inc_unchecked(&dcpage_flushes);
10349 #endif
10350
10351 this_cpu = get_cpu();
10352 @@ -917,7 +917,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10353 xcall_deliver(data0, __pa(pg_addr),
10354 (u64) pg_addr, cpumask_of(cpu));
10355 #ifdef CONFIG_DEBUG_DCFLUSH
10356 - atomic_inc(&dcpage_flushes_xcall);
10357 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10358 #endif
10359 }
10360 }
10361 @@ -936,7 +936,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10362 preempt_disable();
10363
10364 #ifdef CONFIG_DEBUG_DCFLUSH
10365 - atomic_inc(&dcpage_flushes);
10366 + atomic_inc_unchecked(&dcpage_flushes);
10367 #endif
10368 data0 = 0;
10369 pg_addr = page_address(page);
10370 @@ -953,7 +953,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10371 xcall_deliver(data0, __pa(pg_addr),
10372 (u64) pg_addr, cpu_online_mask);
10373 #ifdef CONFIG_DEBUG_DCFLUSH
10374 - atomic_inc(&dcpage_flushes_xcall);
10375 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10376 #endif
10377 }
10378 __local_flush_dcache_page(page);
10379 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10380 index 3a8d184..49498a8 100644
10381 --- a/arch/sparc/kernel/sys_sparc_32.c
10382 +++ b/arch/sparc/kernel/sys_sparc_32.c
10383 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10384 if (len > TASK_SIZE - PAGE_SIZE)
10385 return -ENOMEM;
10386 if (!addr)
10387 - addr = TASK_UNMAPPED_BASE;
10388 + addr = current->mm->mmap_base;
10389
10390 info.flags = 0;
10391 info.length = len;
10392 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10393 index beb0b5a..5a153f7 100644
10394 --- a/arch/sparc/kernel/sys_sparc_64.c
10395 +++ b/arch/sparc/kernel/sys_sparc_64.c
10396 @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10397 struct vm_area_struct * vma;
10398 unsigned long task_size = TASK_SIZE;
10399 int do_color_align;
10400 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10401 struct vm_unmapped_area_info info;
10402
10403 if (flags & MAP_FIXED) {
10404 /* We do not accept a shared mapping if it would violate
10405 * cache aliasing constraints.
10406 */
10407 - if ((flags & MAP_SHARED) &&
10408 + if ((filp || (flags & MAP_SHARED)) &&
10409 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10410 return -EINVAL;
10411 return addr;
10412 @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10413 if (filp || (flags & MAP_SHARED))
10414 do_color_align = 1;
10415
10416 +#ifdef CONFIG_PAX_RANDMMAP
10417 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10418 +#endif
10419 +
10420 if (addr) {
10421 if (do_color_align)
10422 addr = COLOR_ALIGN(addr, pgoff);
10423 @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10424 addr = PAGE_ALIGN(addr);
10425
10426 vma = find_vma(mm, addr);
10427 - if (task_size - len >= addr &&
10428 - (!vma || addr + len <= vma->vm_start))
10429 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10430 return addr;
10431 }
10432
10433 info.flags = 0;
10434 info.length = len;
10435 - info.low_limit = TASK_UNMAPPED_BASE;
10436 + info.low_limit = mm->mmap_base;
10437 info.high_limit = min(task_size, VA_EXCLUDE_START);
10438 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10439 info.align_offset = pgoff << PAGE_SHIFT;
10440 + info.threadstack_offset = offset;
10441 addr = vm_unmapped_area(&info);
10442
10443 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10444 VM_BUG_ON(addr != -ENOMEM);
10445 info.low_limit = VA_EXCLUDE_END;
10446 +
10447 +#ifdef CONFIG_PAX_RANDMMAP
10448 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10449 + info.low_limit += mm->delta_mmap;
10450 +#endif
10451 +
10452 info.high_limit = task_size;
10453 addr = vm_unmapped_area(&info);
10454 }
10455 @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10456 unsigned long task_size = STACK_TOP32;
10457 unsigned long addr = addr0;
10458 int do_color_align;
10459 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10460 struct vm_unmapped_area_info info;
10461
10462 /* This should only ever run for 32-bit processes. */
10463 @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10464 /* We do not accept a shared mapping if it would violate
10465 * cache aliasing constraints.
10466 */
10467 - if ((flags & MAP_SHARED) &&
10468 + if ((filp || (flags & MAP_SHARED)) &&
10469 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10470 return -EINVAL;
10471 return addr;
10472 @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10473 if (filp || (flags & MAP_SHARED))
10474 do_color_align = 1;
10475
10476 +#ifdef CONFIG_PAX_RANDMMAP
10477 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10478 +#endif
10479 +
10480 /* requesting a specific address */
10481 if (addr) {
10482 if (do_color_align)
10483 @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10484 addr = PAGE_ALIGN(addr);
10485
10486 vma = find_vma(mm, addr);
10487 - if (task_size - len >= addr &&
10488 - (!vma || addr + len <= vma->vm_start))
10489 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10490 return addr;
10491 }
10492
10493 @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10494 info.high_limit = mm->mmap_base;
10495 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10496 info.align_offset = pgoff << PAGE_SHIFT;
10497 + info.threadstack_offset = offset;
10498 addr = vm_unmapped_area(&info);
10499
10500 /*
10501 @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10502 VM_BUG_ON(addr != -ENOMEM);
10503 info.flags = 0;
10504 info.low_limit = TASK_UNMAPPED_BASE;
10505 +
10506 +#ifdef CONFIG_PAX_RANDMMAP
10507 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10508 + info.low_limit += mm->delta_mmap;
10509 +#endif
10510 +
10511 info.high_limit = STACK_TOP32;
10512 addr = vm_unmapped_area(&info);
10513 }
10514 @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10515 EXPORT_SYMBOL(get_fb_unmapped_area);
10516
10517 /* Essentially the same as PowerPC. */
10518 -static unsigned long mmap_rnd(void)
10519 +static unsigned long mmap_rnd(struct mm_struct *mm)
10520 {
10521 unsigned long rnd = 0UL;
10522
10523 +#ifdef CONFIG_PAX_RANDMMAP
10524 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10525 +#endif
10526 +
10527 if (current->flags & PF_RANDOMIZE) {
10528 unsigned long val = get_random_int();
10529 if (test_thread_flag(TIF_32BIT))
10530 @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10531
10532 void arch_pick_mmap_layout(struct mm_struct *mm)
10533 {
10534 - unsigned long random_factor = mmap_rnd();
10535 + unsigned long random_factor = mmap_rnd(mm);
10536 unsigned long gap;
10537
10538 /*
10539 @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10540 gap == RLIM_INFINITY ||
10541 sysctl_legacy_va_layout) {
10542 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10543 +
10544 +#ifdef CONFIG_PAX_RANDMMAP
10545 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10546 + mm->mmap_base += mm->delta_mmap;
10547 +#endif
10548 +
10549 mm->get_unmapped_area = arch_get_unmapped_area;
10550 } else {
10551 /* We know it's 32-bit */
10552 @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10553 gap = (task_size / 6 * 5);
10554
10555 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10556 +
10557 +#ifdef CONFIG_PAX_RANDMMAP
10558 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10559 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10560 +#endif
10561 +
10562 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10563 }
10564 }
10565 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10566 index 33a17e7..d87fb1f 100644
10567 --- a/arch/sparc/kernel/syscalls.S
10568 +++ b/arch/sparc/kernel/syscalls.S
10569 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10570 #endif
10571 .align 32
10572 1: ldx [%g6 + TI_FLAGS], %l5
10573 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10574 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10575 be,pt %icc, rtrap
10576 nop
10577 call syscall_trace_leave
10578 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10579
10580 srl %i3, 0, %o3 ! IEU0
10581 srl %i2, 0, %o2 ! IEU0 Group
10582 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10583 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10584 bne,pn %icc, linux_syscall_trace32 ! CTI
10585 mov %i0, %l5 ! IEU1
10586 5: call %l7 ! CTI Group brk forced
10587 @@ -208,7 +208,7 @@ linux_sparc_syscall:
10588
10589 mov %i3, %o3 ! IEU1
10590 mov %i4, %o4 ! IEU0 Group
10591 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10592 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10593 bne,pn %icc, linux_syscall_trace ! CTI Group
10594 mov %i0, %l5 ! IEU0
10595 2: call %l7 ! CTI Group brk forced
10596 @@ -223,7 +223,7 @@ ret_sys_call:
10597
10598 cmp %o0, -ERESTART_RESTARTBLOCK
10599 bgeu,pn %xcc, 1f
10600 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10601 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10602 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10603
10604 2:
10605 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10606 index 6629829..036032d 100644
10607 --- a/arch/sparc/kernel/traps_32.c
10608 +++ b/arch/sparc/kernel/traps_32.c
10609 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10610 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10611 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10612
10613 +extern void gr_handle_kernel_exploit(void);
10614 +
10615 void die_if_kernel(char *str, struct pt_regs *regs)
10616 {
10617 static int die_counter;
10618 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10619 count++ < 30 &&
10620 (((unsigned long) rw) >= PAGE_OFFSET) &&
10621 !(((unsigned long) rw) & 0x7)) {
10622 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10623 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10624 (void *) rw->ins[7]);
10625 rw = (struct reg_window32 *)rw->ins[6];
10626 }
10627 }
10628 printk("Instruction DUMP:");
10629 instruction_dump ((unsigned long *) regs->pc);
10630 - if(regs->psr & PSR_PS)
10631 + if(regs->psr & PSR_PS) {
10632 + gr_handle_kernel_exploit();
10633 do_exit(SIGKILL);
10634 + }
10635 do_exit(SIGSEGV);
10636 }
10637
10638 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10639 index 4ced92f..965eeed 100644
10640 --- a/arch/sparc/kernel/traps_64.c
10641 +++ b/arch/sparc/kernel/traps_64.c
10642 @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10643 i + 1,
10644 p->trapstack[i].tstate, p->trapstack[i].tpc,
10645 p->trapstack[i].tnpc, p->trapstack[i].tt);
10646 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10647 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10648 }
10649 }
10650
10651 @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10652
10653 lvl -= 0x100;
10654 if (regs->tstate & TSTATE_PRIV) {
10655 +
10656 +#ifdef CONFIG_PAX_REFCOUNT
10657 + if (lvl == 6)
10658 + pax_report_refcount_overflow(regs);
10659 +#endif
10660 +
10661 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10662 die_if_kernel(buffer, regs);
10663 }
10664 @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10665 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10666 {
10667 char buffer[32];
10668 -
10669 +
10670 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10671 0, lvl, SIGTRAP) == NOTIFY_STOP)
10672 return;
10673
10674 +#ifdef CONFIG_PAX_REFCOUNT
10675 + if (lvl == 6)
10676 + pax_report_refcount_overflow(regs);
10677 +#endif
10678 +
10679 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10680
10681 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10682 @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10683 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10684 printk("%s" "ERROR(%d): ",
10685 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10686 - printk("TPC<%pS>\n", (void *) regs->tpc);
10687 + printk("TPC<%pA>\n", (void *) regs->tpc);
10688 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10689 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10690 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10691 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10692 smp_processor_id(),
10693 (type & 0x1) ? 'I' : 'D',
10694 regs->tpc);
10695 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10696 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10697 panic("Irrecoverable Cheetah+ parity error.");
10698 }
10699
10700 @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10701 smp_processor_id(),
10702 (type & 0x1) ? 'I' : 'D',
10703 regs->tpc);
10704 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10705 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10706 }
10707
10708 struct sun4v_error_entry {
10709 @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10710 /*0x38*/u64 reserved_5;
10711 };
10712
10713 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10714 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10715 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10716 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10717
10718 static const char *sun4v_err_type_to_str(u8 type)
10719 {
10720 @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10721 }
10722
10723 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10724 - int cpu, const char *pfx, atomic_t *ocnt)
10725 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10726 {
10727 u64 *raw_ptr = (u64 *) ent;
10728 u32 attrs;
10729 @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10730
10731 show_regs(regs);
10732
10733 - if ((cnt = atomic_read(ocnt)) != 0) {
10734 - atomic_set(ocnt, 0);
10735 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10736 + atomic_set_unchecked(ocnt, 0);
10737 wmb();
10738 printk("%s: Queue overflowed %d times.\n",
10739 pfx, cnt);
10740 @@ -2046,7 +2057,7 @@ out:
10741 */
10742 void sun4v_resum_overflow(struct pt_regs *regs)
10743 {
10744 - atomic_inc(&sun4v_resum_oflow_cnt);
10745 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10746 }
10747
10748 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10749 @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10750 /* XXX Actually even this can make not that much sense. Perhaps
10751 * XXX we should just pull the plug and panic directly from here?
10752 */
10753 - atomic_inc(&sun4v_nonresum_oflow_cnt);
10754 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10755 }
10756
10757 unsigned long sun4v_err_itlb_vaddr;
10758 @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10759
10760 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10761 regs->tpc, tl);
10762 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10763 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10764 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10765 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10766 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10767 (void *) regs->u_regs[UREG_I7]);
10768 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10769 "pte[%lx] error[%lx]\n",
10770 @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10771
10772 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10773 regs->tpc, tl);
10774 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10775 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10776 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10777 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10778 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10779 (void *) regs->u_regs[UREG_I7]);
10780 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10781 "pte[%lx] error[%lx]\n",
10782 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10783 fp = (unsigned long)sf->fp + STACK_BIAS;
10784 }
10785
10786 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10787 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10788 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10789 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10790 int index = tsk->curr_ret_stack;
10791 if (tsk->ret_stack && index >= graph) {
10792 pc = tsk->ret_stack[index - graph].ret;
10793 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10794 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10795 graph++;
10796 }
10797 }
10798 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10799 return (struct reg_window *) (fp + STACK_BIAS);
10800 }
10801
10802 +extern void gr_handle_kernel_exploit(void);
10803 +
10804 void die_if_kernel(char *str, struct pt_regs *regs)
10805 {
10806 static int die_counter;
10807 @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10808 while (rw &&
10809 count++ < 30 &&
10810 kstack_valid(tp, (unsigned long) rw)) {
10811 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
10812 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
10813 (void *) rw->ins[7]);
10814
10815 rw = kernel_stack_up(rw);
10816 @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10817 }
10818 user_instruction_dump ((unsigned int __user *) regs->tpc);
10819 }
10820 - if (regs->tstate & TSTATE_PRIV)
10821 + if (regs->tstate & TSTATE_PRIV) {
10822 + gr_handle_kernel_exploit();
10823 do_exit(SIGKILL);
10824 + }
10825 do_exit(SIGSEGV);
10826 }
10827 EXPORT_SYMBOL(die_if_kernel);
10828 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10829 index 35ab8b6..9046547 100644
10830 --- a/arch/sparc/kernel/unaligned_64.c
10831 +++ b/arch/sparc/kernel/unaligned_64.c
10832 @@ -295,7 +295,7 @@ static void log_unaligned(struct pt_regs *regs)
10833 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10834
10835 if (__ratelimit(&ratelimit)) {
10836 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
10837 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
10838 regs->tpc, (void *) regs->tpc);
10839 }
10840 }
10841 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10842 index dbe119b..089c7c1 100644
10843 --- a/arch/sparc/lib/Makefile
10844 +++ b/arch/sparc/lib/Makefile
10845 @@ -2,7 +2,7 @@
10846 #
10847
10848 asflags-y := -ansi -DST_DIV0=0x02
10849 -ccflags-y := -Werror
10850 +#ccflags-y := -Werror
10851
10852 lib-$(CONFIG_SPARC32) += ashrdi3.o
10853 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10854 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10855 index 85c233d..68500e0 100644
10856 --- a/arch/sparc/lib/atomic_64.S
10857 +++ b/arch/sparc/lib/atomic_64.S
10858 @@ -17,7 +17,12 @@
10859 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10860 BACKOFF_SETUP(%o2)
10861 1: lduw [%o1], %g1
10862 - add %g1, %o0, %g7
10863 + addcc %g1, %o0, %g7
10864 +
10865 +#ifdef CONFIG_PAX_REFCOUNT
10866 + tvs %icc, 6
10867 +#endif
10868 +
10869 cas [%o1], %g1, %g7
10870 cmp %g1, %g7
10871 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10872 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10873 2: BACKOFF_SPIN(%o2, %o3, 1b)
10874 ENDPROC(atomic_add)
10875
10876 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10877 + BACKOFF_SETUP(%o2)
10878 +1: lduw [%o1], %g1
10879 + add %g1, %o0, %g7
10880 + cas [%o1], %g1, %g7
10881 + cmp %g1, %g7
10882 + bne,pn %icc, 2f
10883 + nop
10884 + retl
10885 + nop
10886 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10887 +ENDPROC(atomic_add_unchecked)
10888 +
10889 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10890 BACKOFF_SETUP(%o2)
10891 1: lduw [%o1], %g1
10892 - sub %g1, %o0, %g7
10893 + subcc %g1, %o0, %g7
10894 +
10895 +#ifdef CONFIG_PAX_REFCOUNT
10896 + tvs %icc, 6
10897 +#endif
10898 +
10899 cas [%o1], %g1, %g7
10900 cmp %g1, %g7
10901 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10902 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10903 2: BACKOFF_SPIN(%o2, %o3, 1b)
10904 ENDPROC(atomic_sub)
10905
10906 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10907 + BACKOFF_SETUP(%o2)
10908 +1: lduw [%o1], %g1
10909 + sub %g1, %o0, %g7
10910 + cas [%o1], %g1, %g7
10911 + cmp %g1, %g7
10912 + bne,pn %icc, 2f
10913 + nop
10914 + retl
10915 + nop
10916 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10917 +ENDPROC(atomic_sub_unchecked)
10918 +
10919 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10920 BACKOFF_SETUP(%o2)
10921 1: lduw [%o1], %g1
10922 - add %g1, %o0, %g7
10923 + addcc %g1, %o0, %g7
10924 +
10925 +#ifdef CONFIG_PAX_REFCOUNT
10926 + tvs %icc, 6
10927 +#endif
10928 +
10929 cas [%o1], %g1, %g7
10930 cmp %g1, %g7
10931 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10932 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10933 2: BACKOFF_SPIN(%o2, %o3, 1b)
10934 ENDPROC(atomic_add_ret)
10935
10936 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10937 + BACKOFF_SETUP(%o2)
10938 +1: lduw [%o1], %g1
10939 + addcc %g1, %o0, %g7
10940 + cas [%o1], %g1, %g7
10941 + cmp %g1, %g7
10942 + bne,pn %icc, 2f
10943 + add %g7, %o0, %g7
10944 + sra %g7, 0, %o0
10945 + retl
10946 + nop
10947 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10948 +ENDPROC(atomic_add_ret_unchecked)
10949 +
10950 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10951 BACKOFF_SETUP(%o2)
10952 1: lduw [%o1], %g1
10953 - sub %g1, %o0, %g7
10954 + subcc %g1, %o0, %g7
10955 +
10956 +#ifdef CONFIG_PAX_REFCOUNT
10957 + tvs %icc, 6
10958 +#endif
10959 +
10960 cas [%o1], %g1, %g7
10961 cmp %g1, %g7
10962 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10963 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10964 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10965 BACKOFF_SETUP(%o2)
10966 1: ldx [%o1], %g1
10967 - add %g1, %o0, %g7
10968 + addcc %g1, %o0, %g7
10969 +
10970 +#ifdef CONFIG_PAX_REFCOUNT
10971 + tvs %xcc, 6
10972 +#endif
10973 +
10974 casx [%o1], %g1, %g7
10975 cmp %g1, %g7
10976 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10977 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10978 2: BACKOFF_SPIN(%o2, %o3, 1b)
10979 ENDPROC(atomic64_add)
10980
10981 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10982 + BACKOFF_SETUP(%o2)
10983 +1: ldx [%o1], %g1
10984 + addcc %g1, %o0, %g7
10985 + casx [%o1], %g1, %g7
10986 + cmp %g1, %g7
10987 + bne,pn %xcc, 2f
10988 + nop
10989 + retl
10990 + nop
10991 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10992 +ENDPROC(atomic64_add_unchecked)
10993 +
10994 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10995 BACKOFF_SETUP(%o2)
10996 1: ldx [%o1], %g1
10997 - sub %g1, %o0, %g7
10998 + subcc %g1, %o0, %g7
10999 +
11000 +#ifdef CONFIG_PAX_REFCOUNT
11001 + tvs %xcc, 6
11002 +#endif
11003 +
11004 casx [%o1], %g1, %g7
11005 cmp %g1, %g7
11006 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11007 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11008 2: BACKOFF_SPIN(%o2, %o3, 1b)
11009 ENDPROC(atomic64_sub)
11010
11011 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11012 + BACKOFF_SETUP(%o2)
11013 +1: ldx [%o1], %g1
11014 + subcc %g1, %o0, %g7
11015 + casx [%o1], %g1, %g7
11016 + cmp %g1, %g7
11017 + bne,pn %xcc, 2f
11018 + nop
11019 + retl
11020 + nop
11021 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11022 +ENDPROC(atomic64_sub_unchecked)
11023 +
11024 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11025 BACKOFF_SETUP(%o2)
11026 1: ldx [%o1], %g1
11027 - add %g1, %o0, %g7
11028 + addcc %g1, %o0, %g7
11029 +
11030 +#ifdef CONFIG_PAX_REFCOUNT
11031 + tvs %xcc, 6
11032 +#endif
11033 +
11034 casx [%o1], %g1, %g7
11035 cmp %g1, %g7
11036 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11037 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11038 2: BACKOFF_SPIN(%o2, %o3, 1b)
11039 ENDPROC(atomic64_add_ret)
11040
11041 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11042 + BACKOFF_SETUP(%o2)
11043 +1: ldx [%o1], %g1
11044 + addcc %g1, %o0, %g7
11045 + casx [%o1], %g1, %g7
11046 + cmp %g1, %g7
11047 + bne,pn %xcc, 2f
11048 + add %g7, %o0, %g7
11049 + mov %g7, %o0
11050 + retl
11051 + nop
11052 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11053 +ENDPROC(atomic64_add_ret_unchecked)
11054 +
11055 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11056 BACKOFF_SETUP(%o2)
11057 1: ldx [%o1], %g1
11058 - sub %g1, %o0, %g7
11059 + subcc %g1, %o0, %g7
11060 +
11061 +#ifdef CONFIG_PAX_REFCOUNT
11062 + tvs %xcc, 6
11063 +#endif
11064 +
11065 casx [%o1], %g1, %g7
11066 cmp %g1, %g7
11067 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11068 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11069 index 323335b..ed85ea2 100644
11070 --- a/arch/sparc/lib/ksyms.c
11071 +++ b/arch/sparc/lib/ksyms.c
11072 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11073
11074 /* Atomic counter implementation. */
11075 EXPORT_SYMBOL(atomic_add);
11076 +EXPORT_SYMBOL(atomic_add_unchecked);
11077 EXPORT_SYMBOL(atomic_add_ret);
11078 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
11079 EXPORT_SYMBOL(atomic_sub);
11080 +EXPORT_SYMBOL(atomic_sub_unchecked);
11081 EXPORT_SYMBOL(atomic_sub_ret);
11082 EXPORT_SYMBOL(atomic64_add);
11083 +EXPORT_SYMBOL(atomic64_add_unchecked);
11084 EXPORT_SYMBOL(atomic64_add_ret);
11085 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11086 EXPORT_SYMBOL(atomic64_sub);
11087 +EXPORT_SYMBOL(atomic64_sub_unchecked);
11088 EXPORT_SYMBOL(atomic64_sub_ret);
11089 EXPORT_SYMBOL(atomic64_dec_if_positive);
11090
11091 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11092 index 30c3ecc..736f015 100644
11093 --- a/arch/sparc/mm/Makefile
11094 +++ b/arch/sparc/mm/Makefile
11095 @@ -2,7 +2,7 @@
11096 #
11097
11098 asflags-y := -ansi
11099 -ccflags-y := -Werror
11100 +#ccflags-y := -Werror
11101
11102 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11103 obj-y += fault_$(BITS).o
11104 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11105 index 59dbd46..1dd7f5e 100644
11106 --- a/arch/sparc/mm/fault_32.c
11107 +++ b/arch/sparc/mm/fault_32.c
11108 @@ -21,6 +21,9 @@
11109 #include <linux/perf_event.h>
11110 #include <linux/interrupt.h>
11111 #include <linux/kdebug.h>
11112 +#include <linux/slab.h>
11113 +#include <linux/pagemap.h>
11114 +#include <linux/compiler.h>
11115
11116 #include <asm/page.h>
11117 #include <asm/pgtable.h>
11118 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11119 return safe_compute_effective_address(regs, insn);
11120 }
11121
11122 +#ifdef CONFIG_PAX_PAGEEXEC
11123 +#ifdef CONFIG_PAX_DLRESOLVE
11124 +static void pax_emuplt_close(struct vm_area_struct *vma)
11125 +{
11126 + vma->vm_mm->call_dl_resolve = 0UL;
11127 +}
11128 +
11129 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11130 +{
11131 + unsigned int *kaddr;
11132 +
11133 + vmf->page = alloc_page(GFP_HIGHUSER);
11134 + if (!vmf->page)
11135 + return VM_FAULT_OOM;
11136 +
11137 + kaddr = kmap(vmf->page);
11138 + memset(kaddr, 0, PAGE_SIZE);
11139 + kaddr[0] = 0x9DE3BFA8U; /* save */
11140 + flush_dcache_page(vmf->page);
11141 + kunmap(vmf->page);
11142 + return VM_FAULT_MAJOR;
11143 +}
11144 +
11145 +static const struct vm_operations_struct pax_vm_ops = {
11146 + .close = pax_emuplt_close,
11147 + .fault = pax_emuplt_fault
11148 +};
11149 +
11150 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11151 +{
11152 + int ret;
11153 +
11154 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11155 + vma->vm_mm = current->mm;
11156 + vma->vm_start = addr;
11157 + vma->vm_end = addr + PAGE_SIZE;
11158 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11159 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11160 + vma->vm_ops = &pax_vm_ops;
11161 +
11162 + ret = insert_vm_struct(current->mm, vma);
11163 + if (ret)
11164 + return ret;
11165 +
11166 + ++current->mm->total_vm;
11167 + return 0;
11168 +}
11169 +#endif
11170 +
11171 +/*
11172 + * PaX: decide what to do with offenders (regs->pc = fault address)
11173 + *
11174 + * returns 1 when task should be killed
11175 + * 2 when patched PLT trampoline was detected
11176 + * 3 when unpatched PLT trampoline was detected
11177 + */
11178 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11179 +{
11180 +
11181 +#ifdef CONFIG_PAX_EMUPLT
11182 + int err;
11183 +
11184 + do { /* PaX: patched PLT emulation #1 */
11185 + unsigned int sethi1, sethi2, jmpl;
11186 +
11187 + err = get_user(sethi1, (unsigned int *)regs->pc);
11188 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11189 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11190 +
11191 + if (err)
11192 + break;
11193 +
11194 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11195 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11196 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11197 + {
11198 + unsigned int addr;
11199 +
11200 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11201 + addr = regs->u_regs[UREG_G1];
11202 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11203 + regs->pc = addr;
11204 + regs->npc = addr+4;
11205 + return 2;
11206 + }
11207 + } while (0);
11208 +
11209 + do { /* PaX: patched PLT emulation #2 */
11210 + unsigned int ba;
11211 +
11212 + err = get_user(ba, (unsigned int *)regs->pc);
11213 +
11214 + if (err)
11215 + break;
11216 +
11217 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11218 + unsigned int addr;
11219 +
11220 + if ((ba & 0xFFC00000U) == 0x30800000U)
11221 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11222 + else
11223 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11224 + regs->pc = addr;
11225 + regs->npc = addr+4;
11226 + return 2;
11227 + }
11228 + } while (0);
11229 +
11230 + do { /* PaX: patched PLT emulation #3 */
11231 + unsigned int sethi, bajmpl, nop;
11232 +
11233 + err = get_user(sethi, (unsigned int *)regs->pc);
11234 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11235 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11236 +
11237 + if (err)
11238 + break;
11239 +
11240 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11241 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11242 + nop == 0x01000000U)
11243 + {
11244 + unsigned int addr;
11245 +
11246 + addr = (sethi & 0x003FFFFFU) << 10;
11247 + regs->u_regs[UREG_G1] = addr;
11248 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11249 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11250 + else
11251 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11252 + regs->pc = addr;
11253 + regs->npc = addr+4;
11254 + return 2;
11255 + }
11256 + } while (0);
11257 +
11258 + do { /* PaX: unpatched PLT emulation step 1 */
11259 + unsigned int sethi, ba, nop;
11260 +
11261 + err = get_user(sethi, (unsigned int *)regs->pc);
11262 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11263 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11264 +
11265 + if (err)
11266 + break;
11267 +
11268 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11269 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11270 + nop == 0x01000000U)
11271 + {
11272 + unsigned int addr, save, call;
11273 +
11274 + if ((ba & 0xFFC00000U) == 0x30800000U)
11275 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11276 + else
11277 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11278 +
11279 + err = get_user(save, (unsigned int *)addr);
11280 + err |= get_user(call, (unsigned int *)(addr+4));
11281 + err |= get_user(nop, (unsigned int *)(addr+8));
11282 + if (err)
11283 + break;
11284 +
11285 +#ifdef CONFIG_PAX_DLRESOLVE
11286 + if (save == 0x9DE3BFA8U &&
11287 + (call & 0xC0000000U) == 0x40000000U &&
11288 + nop == 0x01000000U)
11289 + {
11290 + struct vm_area_struct *vma;
11291 + unsigned long call_dl_resolve;
11292 +
11293 + down_read(&current->mm->mmap_sem);
11294 + call_dl_resolve = current->mm->call_dl_resolve;
11295 + up_read(&current->mm->mmap_sem);
11296 + if (likely(call_dl_resolve))
11297 + goto emulate;
11298 +
11299 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11300 +
11301 + down_write(&current->mm->mmap_sem);
11302 + if (current->mm->call_dl_resolve) {
11303 + call_dl_resolve = current->mm->call_dl_resolve;
11304 + up_write(&current->mm->mmap_sem);
11305 + if (vma)
11306 + kmem_cache_free(vm_area_cachep, vma);
11307 + goto emulate;
11308 + }
11309 +
11310 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11311 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11312 + up_write(&current->mm->mmap_sem);
11313 + if (vma)
11314 + kmem_cache_free(vm_area_cachep, vma);
11315 + return 1;
11316 + }
11317 +
11318 + if (pax_insert_vma(vma, call_dl_resolve)) {
11319 + up_write(&current->mm->mmap_sem);
11320 + kmem_cache_free(vm_area_cachep, vma);
11321 + return 1;
11322 + }
11323 +
11324 + current->mm->call_dl_resolve = call_dl_resolve;
11325 + up_write(&current->mm->mmap_sem);
11326 +
11327 +emulate:
11328 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11329 + regs->pc = call_dl_resolve;
11330 + regs->npc = addr+4;
11331 + return 3;
11332 + }
11333 +#endif
11334 +
11335 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11336 + if ((save & 0xFFC00000U) == 0x05000000U &&
11337 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11338 + nop == 0x01000000U)
11339 + {
11340 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11341 + regs->u_regs[UREG_G2] = addr + 4;
11342 + addr = (save & 0x003FFFFFU) << 10;
11343 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11344 + regs->pc = addr;
11345 + regs->npc = addr+4;
11346 + return 3;
11347 + }
11348 + }
11349 + } while (0);
11350 +
11351 + do { /* PaX: unpatched PLT emulation step 2 */
11352 + unsigned int save, call, nop;
11353 +
11354 + err = get_user(save, (unsigned int *)(regs->pc-4));
11355 + err |= get_user(call, (unsigned int *)regs->pc);
11356 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11357 + if (err)
11358 + break;
11359 +
11360 + if (save == 0x9DE3BFA8U &&
11361 + (call & 0xC0000000U) == 0x40000000U &&
11362 + nop == 0x01000000U)
11363 + {
11364 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11365 +
11366 + regs->u_regs[UREG_RETPC] = regs->pc;
11367 + regs->pc = dl_resolve;
11368 + regs->npc = dl_resolve+4;
11369 + return 3;
11370 + }
11371 + } while (0);
11372 +#endif
11373 +
11374 + return 1;
11375 +}
11376 +
11377 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11378 +{
11379 + unsigned long i;
11380 +
11381 + printk(KERN_ERR "PAX: bytes at PC: ");
11382 + for (i = 0; i < 8; i++) {
11383 + unsigned int c;
11384 + if (get_user(c, (unsigned int *)pc+i))
11385 + printk(KERN_CONT "???????? ");
11386 + else
11387 + printk(KERN_CONT "%08x ", c);
11388 + }
11389 + printk("\n");
11390 +}
11391 +#endif
11392 +
11393 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11394 int text_fault)
11395 {
11396 @@ -229,6 +503,24 @@ good_area:
11397 if (!(vma->vm_flags & VM_WRITE))
11398 goto bad_area;
11399 } else {
11400 +
11401 +#ifdef CONFIG_PAX_PAGEEXEC
11402 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11403 + up_read(&mm->mmap_sem);
11404 + switch (pax_handle_fetch_fault(regs)) {
11405 +
11406 +#ifdef CONFIG_PAX_EMUPLT
11407 + case 2:
11408 + case 3:
11409 + return;
11410 +#endif
11411 +
11412 + }
11413 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11414 + do_group_exit(SIGKILL);
11415 + }
11416 +#endif
11417 +
11418 /* Allow reads even for write-only mappings */
11419 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11420 goto bad_area;
11421 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11422 index 4ced3fc..234f1e4 100644
11423 --- a/arch/sparc/mm/fault_64.c
11424 +++ b/arch/sparc/mm/fault_64.c
11425 @@ -22,6 +22,9 @@
11426 #include <linux/kdebug.h>
11427 #include <linux/percpu.h>
11428 #include <linux/context_tracking.h>
11429 +#include <linux/slab.h>
11430 +#include <linux/pagemap.h>
11431 +#include <linux/compiler.h>
11432
11433 #include <asm/page.h>
11434 #include <asm/pgtable.h>
11435 @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11436 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11437 regs->tpc);
11438 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11439 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11440 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11441 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11442 dump_stack();
11443 unhandled_fault(regs->tpc, current, regs);
11444 @@ -281,6 +284,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11445 show_regs(regs);
11446 }
11447
11448 +#ifdef CONFIG_PAX_PAGEEXEC
11449 +#ifdef CONFIG_PAX_DLRESOLVE
11450 +static void pax_emuplt_close(struct vm_area_struct *vma)
11451 +{
11452 + vma->vm_mm->call_dl_resolve = 0UL;
11453 +}
11454 +
11455 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11456 +{
11457 + unsigned int *kaddr;
11458 +
11459 + vmf->page = alloc_page(GFP_HIGHUSER);
11460 + if (!vmf->page)
11461 + return VM_FAULT_OOM;
11462 +
11463 + kaddr = kmap(vmf->page);
11464 + memset(kaddr, 0, PAGE_SIZE);
11465 + kaddr[0] = 0x9DE3BFA8U; /* save */
11466 + flush_dcache_page(vmf->page);
11467 + kunmap(vmf->page);
11468 + return VM_FAULT_MAJOR;
11469 +}
11470 +
11471 +static const struct vm_operations_struct pax_vm_ops = {
11472 + .close = pax_emuplt_close,
11473 + .fault = pax_emuplt_fault
11474 +};
11475 +
11476 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11477 +{
11478 + int ret;
11479 +
11480 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11481 + vma->vm_mm = current->mm;
11482 + vma->vm_start = addr;
11483 + vma->vm_end = addr + PAGE_SIZE;
11484 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11485 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11486 + vma->vm_ops = &pax_vm_ops;
11487 +
11488 + ret = insert_vm_struct(current->mm, vma);
11489 + if (ret)
11490 + return ret;
11491 +
11492 + ++current->mm->total_vm;
11493 + return 0;
11494 +}
11495 +#endif
11496 +
11497 +/*
11498 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11499 + *
11500 + * returns 1 when task should be killed
11501 + * 2 when patched PLT trampoline was detected
11502 + * 3 when unpatched PLT trampoline was detected
11503 + */
11504 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11505 +{
11506 +
11507 +#ifdef CONFIG_PAX_EMUPLT
11508 + int err;
11509 +
11510 + do { /* PaX: patched PLT emulation #1 */
11511 + unsigned int sethi1, sethi2, jmpl;
11512 +
11513 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11514 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11515 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11516 +
11517 + if (err)
11518 + break;
11519 +
11520 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11521 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11522 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11523 + {
11524 + unsigned long addr;
11525 +
11526 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11527 + addr = regs->u_regs[UREG_G1];
11528 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11529 +
11530 + if (test_thread_flag(TIF_32BIT))
11531 + addr &= 0xFFFFFFFFUL;
11532 +
11533 + regs->tpc = addr;
11534 + regs->tnpc = addr+4;
11535 + return 2;
11536 + }
11537 + } while (0);
11538 +
11539 + do { /* PaX: patched PLT emulation #2 */
11540 + unsigned int ba;
11541 +
11542 + err = get_user(ba, (unsigned int *)regs->tpc);
11543 +
11544 + if (err)
11545 + break;
11546 +
11547 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11548 + unsigned long addr;
11549 +
11550 + if ((ba & 0xFFC00000U) == 0x30800000U)
11551 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11552 + else
11553 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11554 +
11555 + if (test_thread_flag(TIF_32BIT))
11556 + addr &= 0xFFFFFFFFUL;
11557 +
11558 + regs->tpc = addr;
11559 + regs->tnpc = addr+4;
11560 + return 2;
11561 + }
11562 + } while (0);
11563 +
11564 + do { /* PaX: patched PLT emulation #3 */
11565 + unsigned int sethi, bajmpl, nop;
11566 +
11567 + err = get_user(sethi, (unsigned int *)regs->tpc);
11568 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11569 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11570 +
11571 + if (err)
11572 + break;
11573 +
11574 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11575 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11576 + nop == 0x01000000U)
11577 + {
11578 + unsigned long addr;
11579 +
11580 + addr = (sethi & 0x003FFFFFU) << 10;
11581 + regs->u_regs[UREG_G1] = addr;
11582 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11583 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11584 + else
11585 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11586 +
11587 + if (test_thread_flag(TIF_32BIT))
11588 + addr &= 0xFFFFFFFFUL;
11589 +
11590 + regs->tpc = addr;
11591 + regs->tnpc = addr+4;
11592 + return 2;
11593 + }
11594 + } while (0);
11595 +
11596 + do { /* PaX: patched PLT emulation #4 */
11597 + unsigned int sethi, mov1, call, mov2;
11598 +
11599 + err = get_user(sethi, (unsigned int *)regs->tpc);
11600 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11601 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11602 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11603 +
11604 + if (err)
11605 + break;
11606 +
11607 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11608 + mov1 == 0x8210000FU &&
11609 + (call & 0xC0000000U) == 0x40000000U &&
11610 + mov2 == 0x9E100001U)
11611 + {
11612 + unsigned long addr;
11613 +
11614 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11615 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11616 +
11617 + if (test_thread_flag(TIF_32BIT))
11618 + addr &= 0xFFFFFFFFUL;
11619 +
11620 + regs->tpc = addr;
11621 + regs->tnpc = addr+4;
11622 + return 2;
11623 + }
11624 + } while (0);
11625 +
11626 + do { /* PaX: patched PLT emulation #5 */
11627 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11628 +
11629 + err = get_user(sethi, (unsigned int *)regs->tpc);
11630 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11631 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11632 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11633 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11634 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11635 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11636 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11637 +
11638 + if (err)
11639 + break;
11640 +
11641 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11642 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11643 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11644 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11645 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11646 + sllx == 0x83287020U &&
11647 + jmpl == 0x81C04005U &&
11648 + nop == 0x01000000U)
11649 + {
11650 + unsigned long addr;
11651 +
11652 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11653 + regs->u_regs[UREG_G1] <<= 32;
11654 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11655 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11656 + regs->tpc = addr;
11657 + regs->tnpc = addr+4;
11658 + return 2;
11659 + }
11660 + } while (0);
11661 +
11662 + do { /* PaX: patched PLT emulation #6 */
11663 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11664 +
11665 + err = get_user(sethi, (unsigned int *)regs->tpc);
11666 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11667 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11668 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11669 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11670 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11671 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11672 +
11673 + if (err)
11674 + break;
11675 +
11676 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11677 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11678 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11679 + sllx == 0x83287020U &&
11680 + (or & 0xFFFFE000U) == 0x8A116000U &&
11681 + jmpl == 0x81C04005U &&
11682 + nop == 0x01000000U)
11683 + {
11684 + unsigned long addr;
11685 +
11686 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11687 + regs->u_regs[UREG_G1] <<= 32;
11688 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11689 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11690 + regs->tpc = addr;
11691 + regs->tnpc = addr+4;
11692 + return 2;
11693 + }
11694 + } while (0);
11695 +
11696 + do { /* PaX: unpatched PLT emulation step 1 */
11697 + unsigned int sethi, ba, nop;
11698 +
11699 + err = get_user(sethi, (unsigned int *)regs->tpc);
11700 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11701 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11702 +
11703 + if (err)
11704 + break;
11705 +
11706 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11707 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11708 + nop == 0x01000000U)
11709 + {
11710 + unsigned long addr;
11711 + unsigned int save, call;
11712 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11713 +
11714 + if ((ba & 0xFFC00000U) == 0x30800000U)
11715 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11716 + else
11717 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11718 +
11719 + if (test_thread_flag(TIF_32BIT))
11720 + addr &= 0xFFFFFFFFUL;
11721 +
11722 + err = get_user(save, (unsigned int *)addr);
11723 + err |= get_user(call, (unsigned int *)(addr+4));
11724 + err |= get_user(nop, (unsigned int *)(addr+8));
11725 + if (err)
11726 + break;
11727 +
11728 +#ifdef CONFIG_PAX_DLRESOLVE
11729 + if (save == 0x9DE3BFA8U &&
11730 + (call & 0xC0000000U) == 0x40000000U &&
11731 + nop == 0x01000000U)
11732 + {
11733 + struct vm_area_struct *vma;
11734 + unsigned long call_dl_resolve;
11735 +
11736 + down_read(&current->mm->mmap_sem);
11737 + call_dl_resolve = current->mm->call_dl_resolve;
11738 + up_read(&current->mm->mmap_sem);
11739 + if (likely(call_dl_resolve))
11740 + goto emulate;
11741 +
11742 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11743 +
11744 + down_write(&current->mm->mmap_sem);
11745 + if (current->mm->call_dl_resolve) {
11746 + call_dl_resolve = current->mm->call_dl_resolve;
11747 + up_write(&current->mm->mmap_sem);
11748 + if (vma)
11749 + kmem_cache_free(vm_area_cachep, vma);
11750 + goto emulate;
11751 + }
11752 +
11753 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11754 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11755 + up_write(&current->mm->mmap_sem);
11756 + if (vma)
11757 + kmem_cache_free(vm_area_cachep, vma);
11758 + return 1;
11759 + }
11760 +
11761 + if (pax_insert_vma(vma, call_dl_resolve)) {
11762 + up_write(&current->mm->mmap_sem);
11763 + kmem_cache_free(vm_area_cachep, vma);
11764 + return 1;
11765 + }
11766 +
11767 + current->mm->call_dl_resolve = call_dl_resolve;
11768 + up_write(&current->mm->mmap_sem);
11769 +
11770 +emulate:
11771 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11772 + regs->tpc = call_dl_resolve;
11773 + regs->tnpc = addr+4;
11774 + return 3;
11775 + }
11776 +#endif
11777 +
11778 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11779 + if ((save & 0xFFC00000U) == 0x05000000U &&
11780 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11781 + nop == 0x01000000U)
11782 + {
11783 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11784 + regs->u_regs[UREG_G2] = addr + 4;
11785 + addr = (save & 0x003FFFFFU) << 10;
11786 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11787 +
11788 + if (test_thread_flag(TIF_32BIT))
11789 + addr &= 0xFFFFFFFFUL;
11790 +
11791 + regs->tpc = addr;
11792 + regs->tnpc = addr+4;
11793 + return 3;
11794 + }
11795 +
11796 + /* PaX: 64-bit PLT stub */
11797 + err = get_user(sethi1, (unsigned int *)addr);
11798 + err |= get_user(sethi2, (unsigned int *)(addr+4));
11799 + err |= get_user(or1, (unsigned int *)(addr+8));
11800 + err |= get_user(or2, (unsigned int *)(addr+12));
11801 + err |= get_user(sllx, (unsigned int *)(addr+16));
11802 + err |= get_user(add, (unsigned int *)(addr+20));
11803 + err |= get_user(jmpl, (unsigned int *)(addr+24));
11804 + err |= get_user(nop, (unsigned int *)(addr+28));
11805 + if (err)
11806 + break;
11807 +
11808 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11809 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11810 + (or1 & 0xFFFFE000U) == 0x88112000U &&
11811 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11812 + sllx == 0x89293020U &&
11813 + add == 0x8A010005U &&
11814 + jmpl == 0x89C14000U &&
11815 + nop == 0x01000000U)
11816 + {
11817 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11818 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11819 + regs->u_regs[UREG_G4] <<= 32;
11820 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11821 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11822 + regs->u_regs[UREG_G4] = addr + 24;
11823 + addr = regs->u_regs[UREG_G5];
11824 + regs->tpc = addr;
11825 + regs->tnpc = addr+4;
11826 + return 3;
11827 + }
11828 + }
11829 + } while (0);
11830 +
11831 +#ifdef CONFIG_PAX_DLRESOLVE
11832 + do { /* PaX: unpatched PLT emulation step 2 */
11833 + unsigned int save, call, nop;
11834 +
11835 + err = get_user(save, (unsigned int *)(regs->tpc-4));
11836 + err |= get_user(call, (unsigned int *)regs->tpc);
11837 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11838 + if (err)
11839 + break;
11840 +
11841 + if (save == 0x9DE3BFA8U &&
11842 + (call & 0xC0000000U) == 0x40000000U &&
11843 + nop == 0x01000000U)
11844 + {
11845 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11846 +
11847 + if (test_thread_flag(TIF_32BIT))
11848 + dl_resolve &= 0xFFFFFFFFUL;
11849 +
11850 + regs->u_regs[UREG_RETPC] = regs->tpc;
11851 + regs->tpc = dl_resolve;
11852 + regs->tnpc = dl_resolve+4;
11853 + return 3;
11854 + }
11855 + } while (0);
11856 +#endif
11857 +
11858 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11859 + unsigned int sethi, ba, nop;
11860 +
11861 + err = get_user(sethi, (unsigned int *)regs->tpc);
11862 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11863 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11864 +
11865 + if (err)
11866 + break;
11867 +
11868 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11869 + (ba & 0xFFF00000U) == 0x30600000U &&
11870 + nop == 0x01000000U)
11871 + {
11872 + unsigned long addr;
11873 +
11874 + addr = (sethi & 0x003FFFFFU) << 10;
11875 + regs->u_regs[UREG_G1] = addr;
11876 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11877 +
11878 + if (test_thread_flag(TIF_32BIT))
11879 + addr &= 0xFFFFFFFFUL;
11880 +
11881 + regs->tpc = addr;
11882 + regs->tnpc = addr+4;
11883 + return 2;
11884 + }
11885 + } while (0);
11886 +
11887 +#endif
11888 +
11889 + return 1;
11890 +}
11891 +
11892 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11893 +{
11894 + unsigned long i;
11895 +
11896 + printk(KERN_ERR "PAX: bytes at PC: ");
11897 + for (i = 0; i < 8; i++) {
11898 + unsigned int c;
11899 + if (get_user(c, (unsigned int *)pc+i))
11900 + printk(KERN_CONT "???????? ");
11901 + else
11902 + printk(KERN_CONT "%08x ", c);
11903 + }
11904 + printk("\n");
11905 +}
11906 +#endif
11907 +
11908 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11909 {
11910 enum ctx_state prev_state = exception_enter();
11911 @@ -352,6 +815,29 @@ retry:
11912 if (!vma)
11913 goto bad_area;
11914
11915 +#ifdef CONFIG_PAX_PAGEEXEC
11916 + /* PaX: detect ITLB misses on non-exec pages */
11917 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11918 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11919 + {
11920 + if (address != regs->tpc)
11921 + goto good_area;
11922 +
11923 + up_read(&mm->mmap_sem);
11924 + switch (pax_handle_fetch_fault(regs)) {
11925 +
11926 +#ifdef CONFIG_PAX_EMUPLT
11927 + case 2:
11928 + case 3:
11929 + return;
11930 +#endif
11931 +
11932 + }
11933 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11934 + do_group_exit(SIGKILL);
11935 + }
11936 +#endif
11937 +
11938 /* Pure DTLB misses do not tell us whether the fault causing
11939 * load/store/atomic was a write or not, it only says that there
11940 * was no match. So in such a case we (carefully) read the
11941 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11942 index d329537..2c3746a 100644
11943 --- a/arch/sparc/mm/hugetlbpage.c
11944 +++ b/arch/sparc/mm/hugetlbpage.c
11945 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11946 unsigned long addr,
11947 unsigned long len,
11948 unsigned long pgoff,
11949 - unsigned long flags)
11950 + unsigned long flags,
11951 + unsigned long offset)
11952 {
11953 + struct mm_struct *mm = current->mm;
11954 unsigned long task_size = TASK_SIZE;
11955 struct vm_unmapped_area_info info;
11956
11957 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11958
11959 info.flags = 0;
11960 info.length = len;
11961 - info.low_limit = TASK_UNMAPPED_BASE;
11962 + info.low_limit = mm->mmap_base;
11963 info.high_limit = min(task_size, VA_EXCLUDE_START);
11964 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11965 info.align_offset = 0;
11966 + info.threadstack_offset = offset;
11967 addr = vm_unmapped_area(&info);
11968
11969 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11970 VM_BUG_ON(addr != -ENOMEM);
11971 info.low_limit = VA_EXCLUDE_END;
11972 +
11973 +#ifdef CONFIG_PAX_RANDMMAP
11974 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11975 + info.low_limit += mm->delta_mmap;
11976 +#endif
11977 +
11978 info.high_limit = task_size;
11979 addr = vm_unmapped_area(&info);
11980 }
11981 @@ -55,7 +64,8 @@ static unsigned long
11982 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11983 const unsigned long len,
11984 const unsigned long pgoff,
11985 - const unsigned long flags)
11986 + const unsigned long flags,
11987 + const unsigned long offset)
11988 {
11989 struct mm_struct *mm = current->mm;
11990 unsigned long addr = addr0;
11991 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11992 info.high_limit = mm->mmap_base;
11993 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11994 info.align_offset = 0;
11995 + info.threadstack_offset = offset;
11996 addr = vm_unmapped_area(&info);
11997
11998 /*
11999 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12000 VM_BUG_ON(addr != -ENOMEM);
12001 info.flags = 0;
12002 info.low_limit = TASK_UNMAPPED_BASE;
12003 +
12004 +#ifdef CONFIG_PAX_RANDMMAP
12005 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12006 + info.low_limit += mm->delta_mmap;
12007 +#endif
12008 +
12009 info.high_limit = STACK_TOP32;
12010 addr = vm_unmapped_area(&info);
12011 }
12012 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12013 struct mm_struct *mm = current->mm;
12014 struct vm_area_struct *vma;
12015 unsigned long task_size = TASK_SIZE;
12016 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12017
12018 if (test_thread_flag(TIF_32BIT))
12019 task_size = STACK_TOP32;
12020 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12021 return addr;
12022 }
12023
12024 +#ifdef CONFIG_PAX_RANDMMAP
12025 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12026 +#endif
12027 +
12028 if (addr) {
12029 addr = ALIGN(addr, HPAGE_SIZE);
12030 vma = find_vma(mm, addr);
12031 - if (task_size - len >= addr &&
12032 - (!vma || addr + len <= vma->vm_start))
12033 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12034 return addr;
12035 }
12036 if (mm->get_unmapped_area == arch_get_unmapped_area)
12037 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12038 - pgoff, flags);
12039 + pgoff, flags, offset);
12040 else
12041 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12042 - pgoff, flags);
12043 + pgoff, flags, offset);
12044 }
12045
12046 pte_t *huge_pte_alloc(struct mm_struct *mm,
12047 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12048 index ed3c969..42fe48d 100644
12049 --- a/arch/sparc/mm/init_64.c
12050 +++ b/arch/sparc/mm/init_64.c
12051 @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12052 int num_kernel_image_mappings;
12053
12054 #ifdef CONFIG_DEBUG_DCFLUSH
12055 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12056 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12057 #ifdef CONFIG_SMP
12058 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12059 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12060 #endif
12061 #endif
12062
12063 @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
12064 {
12065 BUG_ON(tlb_type == hypervisor);
12066 #ifdef CONFIG_DEBUG_DCFLUSH
12067 - atomic_inc(&dcpage_flushes);
12068 + atomic_inc_unchecked(&dcpage_flushes);
12069 #endif
12070
12071 #ifdef DCACHE_ALIASING_POSSIBLE
12072 @@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
12073
12074 #ifdef CONFIG_DEBUG_DCFLUSH
12075 seq_printf(m, "DCPageFlushes\t: %d\n",
12076 - atomic_read(&dcpage_flushes));
12077 + atomic_read_unchecked(&dcpage_flushes));
12078 #ifdef CONFIG_SMP
12079 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12080 - atomic_read(&dcpage_flushes_xcall));
12081 + atomic_read_unchecked(&dcpage_flushes_xcall));
12082 #endif /* CONFIG_SMP */
12083 #endif /* CONFIG_DEBUG_DCFLUSH */
12084 }
12085 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12086 index 85258ca..df97c79 100644
12087 --- a/arch/tile/Kconfig
12088 +++ b/arch/tile/Kconfig
12089 @@ -190,6 +190,7 @@ source "kernel/Kconfig.hz"
12090
12091 config KEXEC
12092 bool "kexec system call"
12093 + depends on !GRKERNSEC_KMEM
12094 ---help---
12095 kexec is a system call that implements the ability to shutdown your
12096 current kernel, and to start another kernel. It is like a reboot
12097 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12098 index ad220ee..2f537b3 100644
12099 --- a/arch/tile/include/asm/atomic_64.h
12100 +++ b/arch/tile/include/asm/atomic_64.h
12101 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12102
12103 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12104
12105 +#define atomic64_read_unchecked(v) atomic64_read(v)
12106 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12107 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12108 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12109 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12110 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
12111 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12112 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
12113 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12114 +
12115 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
12116 #define smp_mb__before_atomic_dec() smp_mb()
12117 #define smp_mb__after_atomic_dec() smp_mb()
12118 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12119 index 6160761..00cac88 100644
12120 --- a/arch/tile/include/asm/cache.h
12121 +++ b/arch/tile/include/asm/cache.h
12122 @@ -15,11 +15,12 @@
12123 #ifndef _ASM_TILE_CACHE_H
12124 #define _ASM_TILE_CACHE_H
12125
12126 +#include <linux/const.h>
12127 #include <arch/chip.h>
12128
12129 /* bytes per L1 data cache line */
12130 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12131 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12132 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12133
12134 /* bytes per L2 cache line */
12135 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12136 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12137 index b6cde32..c0cb736 100644
12138 --- a/arch/tile/include/asm/uaccess.h
12139 +++ b/arch/tile/include/asm/uaccess.h
12140 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12141 const void __user *from,
12142 unsigned long n)
12143 {
12144 - int sz = __compiletime_object_size(to);
12145 + size_t sz = __compiletime_object_size(to);
12146
12147 - if (likely(sz == -1 || sz >= n))
12148 + if (likely(sz == (size_t)-1 || sz >= n))
12149 n = _copy_from_user(to, from, n);
12150 else
12151 copy_from_user_overflow();
12152 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12153 index e514899..f8743c4 100644
12154 --- a/arch/tile/mm/hugetlbpage.c
12155 +++ b/arch/tile/mm/hugetlbpage.c
12156 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12157 info.high_limit = TASK_SIZE;
12158 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12159 info.align_offset = 0;
12160 + info.threadstack_offset = 0;
12161 return vm_unmapped_area(&info);
12162 }
12163
12164 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12165 info.high_limit = current->mm->mmap_base;
12166 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12167 info.align_offset = 0;
12168 + info.threadstack_offset = 0;
12169 addr = vm_unmapped_area(&info);
12170
12171 /*
12172 diff --git a/arch/um/Makefile b/arch/um/Makefile
12173 index 36e658a..71a5c5a 100644
12174 --- a/arch/um/Makefile
12175 +++ b/arch/um/Makefile
12176 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12177 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12178 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12179
12180 +ifdef CONSTIFY_PLUGIN
12181 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12182 +endif
12183 +
12184 #This will adjust *FLAGS accordingly to the platform.
12185 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12186
12187 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12188 index 19e1bdd..3665b77 100644
12189 --- a/arch/um/include/asm/cache.h
12190 +++ b/arch/um/include/asm/cache.h
12191 @@ -1,6 +1,7 @@
12192 #ifndef __UM_CACHE_H
12193 #define __UM_CACHE_H
12194
12195 +#include <linux/const.h>
12196
12197 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12198 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12199 @@ -12,6 +13,6 @@
12200 # define L1_CACHE_SHIFT 5
12201 #endif
12202
12203 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12204 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12205
12206 #endif
12207 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12208 index 2e0a6b1..a64d0f5 100644
12209 --- a/arch/um/include/asm/kmap_types.h
12210 +++ b/arch/um/include/asm/kmap_types.h
12211 @@ -8,6 +8,6 @@
12212
12213 /* No more #include "asm/arch/kmap_types.h" ! */
12214
12215 -#define KM_TYPE_NR 14
12216 +#define KM_TYPE_NR 15
12217
12218 #endif
12219 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12220 index 5ff53d9..5850cdf 100644
12221 --- a/arch/um/include/asm/page.h
12222 +++ b/arch/um/include/asm/page.h
12223 @@ -14,6 +14,9 @@
12224 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12225 #define PAGE_MASK (~(PAGE_SIZE-1))
12226
12227 +#define ktla_ktva(addr) (addr)
12228 +#define ktva_ktla(addr) (addr)
12229 +
12230 #ifndef __ASSEMBLY__
12231
12232 struct page;
12233 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12234 index 0032f92..cd151e0 100644
12235 --- a/arch/um/include/asm/pgtable-3level.h
12236 +++ b/arch/um/include/asm/pgtable-3level.h
12237 @@ -58,6 +58,7 @@
12238 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12239 #define pud_populate(mm, pud, pmd) \
12240 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12241 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12242
12243 #ifdef CONFIG_64BIT
12244 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12245 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12246 index f17bca8..48adb87 100644
12247 --- a/arch/um/kernel/process.c
12248 +++ b/arch/um/kernel/process.c
12249 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12250 return 2;
12251 }
12252
12253 -/*
12254 - * Only x86 and x86_64 have an arch_align_stack().
12255 - * All other arches have "#define arch_align_stack(x) (x)"
12256 - * in their asm/exec.h
12257 - * As this is included in UML from asm-um/system-generic.h,
12258 - * we can use it to behave as the subarch does.
12259 - */
12260 -#ifndef arch_align_stack
12261 -unsigned long arch_align_stack(unsigned long sp)
12262 -{
12263 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12264 - sp -= get_random_int() % 8192;
12265 - return sp & ~0xf;
12266 -}
12267 -#endif
12268 -
12269 unsigned long get_wchan(struct task_struct *p)
12270 {
12271 unsigned long stack_page, sp, ip;
12272 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12273 index ad8f795..2c7eec6 100644
12274 --- a/arch/unicore32/include/asm/cache.h
12275 +++ b/arch/unicore32/include/asm/cache.h
12276 @@ -12,8 +12,10 @@
12277 #ifndef __UNICORE_CACHE_H__
12278 #define __UNICORE_CACHE_H__
12279
12280 -#define L1_CACHE_SHIFT (5)
12281 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12282 +#include <linux/const.h>
12283 +
12284 +#define L1_CACHE_SHIFT 5
12285 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12286
12287 /*
12288 * Memory returned by kmalloc() may be used for DMA, so we must make
12289 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12290 index 6b8b429..7b21fe4 100644
12291 --- a/arch/x86/Kconfig
12292 +++ b/arch/x86/Kconfig
12293 @@ -127,7 +127,7 @@ config X86
12294 select RTC_LIB
12295 select HAVE_DEBUG_STACKOVERFLOW
12296 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12297 - select HAVE_CC_STACKPROTECTOR
12298 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12299 select GENERIC_CPU_AUTOPROBE
12300 select HAVE_ARCH_AUDITSYSCALL
12301
12302 @@ -251,7 +251,7 @@ config X86_HT
12303
12304 config X86_32_LAZY_GS
12305 def_bool y
12306 - depends on X86_32 && !CC_STACKPROTECTOR
12307 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12308
12309 config ARCH_HWEIGHT_CFLAGS
12310 string
12311 @@ -545,6 +545,7 @@ config SCHED_OMIT_FRAME_POINTER
12312
12313 menuconfig HYPERVISOR_GUEST
12314 bool "Linux guest support"
12315 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12316 ---help---
12317 Say Y here to enable options for running Linux under various hyper-
12318 visors. This option enables basic hypervisor detection and platform
12319 @@ -1054,6 +1055,7 @@ choice
12320
12321 config NOHIGHMEM
12322 bool "off"
12323 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12324 ---help---
12325 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12326 However, the address space of 32-bit x86 processors is only 4
12327 @@ -1090,6 +1092,7 @@ config NOHIGHMEM
12328
12329 config HIGHMEM4G
12330 bool "4GB"
12331 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12332 ---help---
12333 Select this if you have a 32-bit processor and between 1 and 4
12334 gigabytes of physical RAM.
12335 @@ -1142,7 +1145,7 @@ config PAGE_OFFSET
12336 hex
12337 default 0xB0000000 if VMSPLIT_3G_OPT
12338 default 0x80000000 if VMSPLIT_2G
12339 - default 0x78000000 if VMSPLIT_2G_OPT
12340 + default 0x70000000 if VMSPLIT_2G_OPT
12341 default 0x40000000 if VMSPLIT_1G
12342 default 0xC0000000
12343 depends on X86_32
12344 @@ -1555,6 +1558,7 @@ source kernel/Kconfig.hz
12345
12346 config KEXEC
12347 bool "kexec system call"
12348 + depends on !GRKERNSEC_KMEM
12349 ---help---
12350 kexec is a system call that implements the ability to shutdown your
12351 current kernel, and to start another kernel. It is like a reboot
12352 @@ -1706,7 +1710,9 @@ config X86_NEED_RELOCS
12353
12354 config PHYSICAL_ALIGN
12355 hex "Alignment value to which kernel should be aligned"
12356 - default "0x200000"
12357 + default "0x1000000"
12358 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12359 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12360 range 0x2000 0x1000000 if X86_32
12361 range 0x200000 0x1000000 if X86_64
12362 ---help---
12363 @@ -1789,6 +1795,7 @@ config COMPAT_VDSO
12364 def_bool n
12365 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12366 depends on X86_32 || IA32_EMULATION
12367 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12368 ---help---
12369 Certain buggy versions of glibc will crash if they are
12370 presented with a 32-bit vDSO that is not mapped at the address
12371 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12372 index 6983314..54ad7e8 100644
12373 --- a/arch/x86/Kconfig.cpu
12374 +++ b/arch/x86/Kconfig.cpu
12375 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12376
12377 config X86_F00F_BUG
12378 def_bool y
12379 - depends on M586MMX || M586TSC || M586 || M486
12380 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12381
12382 config X86_INVD_BUG
12383 def_bool y
12384 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12385
12386 config X86_ALIGNMENT_16
12387 def_bool y
12388 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12389 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12390
12391 config X86_INTEL_USERCOPY
12392 def_bool y
12393 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12394 # generates cmov.
12395 config X86_CMOV
12396 def_bool y
12397 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12398 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12399
12400 config X86_MINIMUM_CPU_FAMILY
12401 int
12402 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12403 index 61bd2ad..50b625d 100644
12404 --- a/arch/x86/Kconfig.debug
12405 +++ b/arch/x86/Kconfig.debug
12406 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12407 config DEBUG_RODATA
12408 bool "Write protect kernel read-only data structures"
12409 default y
12410 - depends on DEBUG_KERNEL
12411 + depends on DEBUG_KERNEL && BROKEN
12412 ---help---
12413 Mark the kernel read-only data as write-protected in the pagetables,
12414 in order to catch accidental (and incorrect) writes to such const
12415 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12416
12417 config DEBUG_SET_MODULE_RONX
12418 bool "Set loadable kernel module data as NX and text as RO"
12419 - depends on MODULES
12420 + depends on MODULES && BROKEN
12421 ---help---
12422 This option helps catch unintended modifications to loadable
12423 kernel module's text and read-only data. It also prevents execution
12424 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12425 index 33f71b0..c2cefa2 100644
12426 --- a/arch/x86/Makefile
12427 +++ b/arch/x86/Makefile
12428 @@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
12429 # CPU-specific tuning. Anything which can be shared with UML should go here.
12430 include $(srctree)/arch/x86/Makefile_32.cpu
12431 KBUILD_CFLAGS += $(cflags-y)
12432 -
12433 - # temporary until string.h is fixed
12434 - KBUILD_CFLAGS += -ffreestanding
12435 else
12436 BITS := 64
12437 UTS_MACHINE := x86_64
12438 @@ -114,6 +111,9 @@ else
12439 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12440 endif
12441
12442 +# temporary until string.h is fixed
12443 +KBUILD_CFLAGS += -ffreestanding
12444 +
12445 # Make sure compiler does not have buggy stack-protector support.
12446 ifdef CONFIG_CC_STACKPROTECTOR
12447 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12448 @@ -271,3 +271,12 @@ define archhelp
12449 echo ' FDINITRD=file initrd for the booted kernel'
12450 echo ' kvmconfig - Enable additional options for guest kernel support'
12451 endef
12452 +
12453 +define OLD_LD
12454 +
12455 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12456 +*** Please upgrade your binutils to 2.18 or newer
12457 +endef
12458 +
12459 +archprepare:
12460 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12461 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12462 index dbe8dd2..2f0a98f 100644
12463 --- a/arch/x86/boot/Makefile
12464 +++ b/arch/x86/boot/Makefile
12465 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12466 # ---------------------------------------------------------------------------
12467
12468 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12469 +ifdef CONSTIFY_PLUGIN
12470 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12471 +endif
12472 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12473 GCOV_PROFILE := n
12474
12475 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12476 index 878e4b9..20537ab 100644
12477 --- a/arch/x86/boot/bitops.h
12478 +++ b/arch/x86/boot/bitops.h
12479 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12480 u8 v;
12481 const u32 *p = (const u32 *)addr;
12482
12483 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12484 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12485 return v;
12486 }
12487
12488 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12489
12490 static inline void set_bit(int nr, void *addr)
12491 {
12492 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12493 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12494 }
12495
12496 #endif /* BOOT_BITOPS_H */
12497 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12498 index bd49ec6..94c7f58 100644
12499 --- a/arch/x86/boot/boot.h
12500 +++ b/arch/x86/boot/boot.h
12501 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12502 static inline u16 ds(void)
12503 {
12504 u16 seg;
12505 - asm("movw %%ds,%0" : "=rm" (seg));
12506 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12507 return seg;
12508 }
12509
12510 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12511 index 0fcd913..3bb5c42 100644
12512 --- a/arch/x86/boot/compressed/Makefile
12513 +++ b/arch/x86/boot/compressed/Makefile
12514 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12515 KBUILD_CFLAGS += -mno-mmx -mno-sse
12516 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12517 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12518 +ifdef CONSTIFY_PLUGIN
12519 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12520 +endif
12521
12522 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12523 GCOV_PROFILE := n
12524 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12525 index a53440e..c3dbf1e 100644
12526 --- a/arch/x86/boot/compressed/efi_stub_32.S
12527 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12528 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12529 * parameter 2, ..., param n. To make things easy, we save the return
12530 * address of efi_call_phys in a global variable.
12531 */
12532 - popl %ecx
12533 - movl %ecx, saved_return_addr(%edx)
12534 - /* get the function pointer into ECX*/
12535 - popl %ecx
12536 - movl %ecx, efi_rt_function_ptr(%edx)
12537 + popl saved_return_addr(%edx)
12538 + popl efi_rt_function_ptr(%edx)
12539
12540 /*
12541 * 3. Call the physical function.
12542 */
12543 - call *%ecx
12544 + call *efi_rt_function_ptr(%edx)
12545
12546 /*
12547 * 4. Balance the stack. And because EAX contain the return value,
12548 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12549 1: popl %edx
12550 subl $1b, %edx
12551
12552 - movl efi_rt_function_ptr(%edx), %ecx
12553 - pushl %ecx
12554 + pushl efi_rt_function_ptr(%edx)
12555
12556 /*
12557 * 10. Push the saved return address onto the stack and return.
12558 */
12559 - movl saved_return_addr(%edx), %ecx
12560 - pushl %ecx
12561 - ret
12562 + jmpl *saved_return_addr(%edx)
12563 ENDPROC(efi_call_phys)
12564 .previous
12565
12566 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12567 index cbed140..5f2ca57 100644
12568 --- a/arch/x86/boot/compressed/head_32.S
12569 +++ b/arch/x86/boot/compressed/head_32.S
12570 @@ -140,10 +140,10 @@ preferred_addr:
12571 addl %eax, %ebx
12572 notl %eax
12573 andl %eax, %ebx
12574 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12575 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12576 jge 1f
12577 #endif
12578 - movl $LOAD_PHYSICAL_ADDR, %ebx
12579 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12580 1:
12581
12582 /* Target address to relocate to for decompression */
12583 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12584 index 0d558ee..58f257e 100644
12585 --- a/arch/x86/boot/compressed/head_64.S
12586 +++ b/arch/x86/boot/compressed/head_64.S
12587 @@ -94,10 +94,10 @@ ENTRY(startup_32)
12588 addl %eax, %ebx
12589 notl %eax
12590 andl %eax, %ebx
12591 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12592 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12593 jge 1f
12594 #endif
12595 - movl $LOAD_PHYSICAL_ADDR, %ebx
12596 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12597 1:
12598
12599 /* Target address to relocate to for decompression */
12600 @@ -322,10 +322,10 @@ preferred_addr:
12601 addq %rax, %rbp
12602 notq %rax
12603 andq %rax, %rbp
12604 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
12605 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12606 jge 1f
12607 #endif
12608 - movq $LOAD_PHYSICAL_ADDR, %rbp
12609 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12610 1:
12611
12612 /* Target address to relocate to for decompression */
12613 @@ -431,8 +431,8 @@ gdt:
12614 .long gdt
12615 .word 0
12616 .quad 0x0000000000000000 /* NULL descriptor */
12617 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12618 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12619 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12620 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12621 .quad 0x0080890000000000 /* TS descriptor */
12622 .quad 0x0000000000000000 /* TS continued */
12623 gdt_end:
12624 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12625 index 57ab74d..7c52182 100644
12626 --- a/arch/x86/boot/compressed/misc.c
12627 +++ b/arch/x86/boot/compressed/misc.c
12628 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12629 * Calculate the delta between where vmlinux was linked to load
12630 * and where it was actually loaded.
12631 */
12632 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12633 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12634 if (!delta) {
12635 debug_putstr("No relocation needed... ");
12636 return;
12637 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
12638 Elf32_Ehdr ehdr;
12639 Elf32_Phdr *phdrs, *phdr;
12640 #endif
12641 - void *dest;
12642 + void *dest, *prev;
12643 int i;
12644
12645 memcpy(&ehdr, output, sizeof(ehdr));
12646 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
12647 case PT_LOAD:
12648 #ifdef CONFIG_RELOCATABLE
12649 dest = output;
12650 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12651 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12652 #else
12653 dest = (void *)(phdr->p_paddr);
12654 #endif
12655 memcpy(dest,
12656 output + phdr->p_offset,
12657 phdr->p_filesz);
12658 + if (i)
12659 + memset(prev, 0xff, dest - prev);
12660 + prev = dest + phdr->p_filesz;
12661 break;
12662 default: /* Ignore other PT_* */ break;
12663 }
12664 @@ -395,7 +398,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12665 error("Destination address too large");
12666 #endif
12667 #ifndef CONFIG_RELOCATABLE
12668 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12669 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12670 error("Wrong destination address");
12671 #endif
12672
12673 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12674 index 1fd7d57..0f7d096 100644
12675 --- a/arch/x86/boot/cpucheck.c
12676 +++ b/arch/x86/boot/cpucheck.c
12677 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12678 u32 ecx = MSR_K7_HWCR;
12679 u32 eax, edx;
12680
12681 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12682 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12683 eax &= ~(1 << 15);
12684 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12685 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12686
12687 get_cpuflags(); /* Make sure it really did something */
12688 err = check_cpuflags();
12689 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12690 u32 ecx = MSR_VIA_FCR;
12691 u32 eax, edx;
12692
12693 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12694 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12695 eax |= (1<<1)|(1<<7);
12696 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12697 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12698
12699 set_bit(X86_FEATURE_CX8, cpu.flags);
12700 err = check_cpuflags();
12701 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12702 u32 eax, edx;
12703 u32 level = 1;
12704
12705 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12706 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12707 - asm("cpuid"
12708 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12709 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12710 + asm volatile("cpuid"
12711 : "+a" (level), "=d" (cpu.flags[0])
12712 : : "ecx", "ebx");
12713 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12714 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12715
12716 err = check_cpuflags();
12717 } else if (err == 0x01 &&
12718 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12719 index 84c2234..3ef6360 100644
12720 --- a/arch/x86/boot/header.S
12721 +++ b/arch/x86/boot/header.S
12722 @@ -420,10 +420,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12723 # single linked list of
12724 # struct setup_data
12725
12726 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12727 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12728
12729 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12730 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12731 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12732 +#else
12733 #define VO_INIT_SIZE (VO__end - VO__text)
12734 +#endif
12735 #if ZO_INIT_SIZE > VO_INIT_SIZE
12736 #define INIT_SIZE ZO_INIT_SIZE
12737 #else
12738 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12739 index db75d07..8e6d0af 100644
12740 --- a/arch/x86/boot/memory.c
12741 +++ b/arch/x86/boot/memory.c
12742 @@ -19,7 +19,7 @@
12743
12744 static int detect_memory_e820(void)
12745 {
12746 - int count = 0;
12747 + unsigned int count = 0;
12748 struct biosregs ireg, oreg;
12749 struct e820entry *desc = boot_params.e820_map;
12750 static struct e820entry buf; /* static so it is zeroed */
12751 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12752 index ba3e100..6501b8f 100644
12753 --- a/arch/x86/boot/video-vesa.c
12754 +++ b/arch/x86/boot/video-vesa.c
12755 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
12756
12757 boot_params.screen_info.vesapm_seg = oreg.es;
12758 boot_params.screen_info.vesapm_off = oreg.di;
12759 + boot_params.screen_info.vesapm_size = oreg.cx;
12760 }
12761
12762 /*
12763 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12764 index 43eda28..5ab5fdb 100644
12765 --- a/arch/x86/boot/video.c
12766 +++ b/arch/x86/boot/video.c
12767 @@ -96,7 +96,7 @@ static void store_mode_params(void)
12768 static unsigned int get_entry(void)
12769 {
12770 char entry_buf[4];
12771 - int i, len = 0;
12772 + unsigned int i, len = 0;
12773 int key;
12774 unsigned int v;
12775
12776 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12777 index 9105655..41779c1 100644
12778 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
12779 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12780 @@ -8,6 +8,8 @@
12781 * including this sentence is retained in full.
12782 */
12783
12784 +#include <asm/alternative-asm.h>
12785 +
12786 .extern crypto_ft_tab
12787 .extern crypto_it_tab
12788 .extern crypto_fl_tab
12789 @@ -70,6 +72,8 @@
12790 je B192; \
12791 leaq 32(r9),r9;
12792
12793 +#define ret pax_force_retaddr; ret
12794 +
12795 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12796 movq r1,r2; \
12797 movq r3,r4; \
12798 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12799 index 477e9d7..c92c7d8 100644
12800 --- a/arch/x86/crypto/aesni-intel_asm.S
12801 +++ b/arch/x86/crypto/aesni-intel_asm.S
12802 @@ -31,6 +31,7 @@
12803
12804 #include <linux/linkage.h>
12805 #include <asm/inst.h>
12806 +#include <asm/alternative-asm.h>
12807
12808 #ifdef __x86_64__
12809 .data
12810 @@ -205,7 +206,7 @@ enc: .octa 0x2
12811 * num_initial_blocks = b mod 4
12812 * encrypt the initial num_initial_blocks blocks and apply ghash on
12813 * the ciphertext
12814 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12815 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12816 * are clobbered
12817 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12818 */
12819 @@ -214,8 +215,8 @@ enc: .octa 0x2
12820 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12821 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12822 mov arg7, %r10 # %r10 = AAD
12823 - mov arg8, %r12 # %r12 = aadLen
12824 - mov %r12, %r11
12825 + mov arg8, %r15 # %r15 = aadLen
12826 + mov %r15, %r11
12827 pxor %xmm\i, %xmm\i
12828 _get_AAD_loop\num_initial_blocks\operation:
12829 movd (%r10), \TMP1
12830 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12831 psrldq $4, %xmm\i
12832 pxor \TMP1, %xmm\i
12833 add $4, %r10
12834 - sub $4, %r12
12835 + sub $4, %r15
12836 jne _get_AAD_loop\num_initial_blocks\operation
12837 cmp $16, %r11
12838 je _get_AAD_loop2_done\num_initial_blocks\operation
12839 - mov $16, %r12
12840 + mov $16, %r15
12841 _get_AAD_loop2\num_initial_blocks\operation:
12842 psrldq $4, %xmm\i
12843 - sub $4, %r12
12844 - cmp %r11, %r12
12845 + sub $4, %r15
12846 + cmp %r11, %r15
12847 jne _get_AAD_loop2\num_initial_blocks\operation
12848 _get_AAD_loop2_done\num_initial_blocks\operation:
12849 movdqa SHUF_MASK(%rip), %xmm14
12850 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12851 * num_initial_blocks = b mod 4
12852 * encrypt the initial num_initial_blocks blocks and apply ghash on
12853 * the ciphertext
12854 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12855 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12856 * are clobbered
12857 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12858 */
12859 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12860 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12861 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12862 mov arg7, %r10 # %r10 = AAD
12863 - mov arg8, %r12 # %r12 = aadLen
12864 - mov %r12, %r11
12865 + mov arg8, %r15 # %r15 = aadLen
12866 + mov %r15, %r11
12867 pxor %xmm\i, %xmm\i
12868 _get_AAD_loop\num_initial_blocks\operation:
12869 movd (%r10), \TMP1
12870 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12871 psrldq $4, %xmm\i
12872 pxor \TMP1, %xmm\i
12873 add $4, %r10
12874 - sub $4, %r12
12875 + sub $4, %r15
12876 jne _get_AAD_loop\num_initial_blocks\operation
12877 cmp $16, %r11
12878 je _get_AAD_loop2_done\num_initial_blocks\operation
12879 - mov $16, %r12
12880 + mov $16, %r15
12881 _get_AAD_loop2\num_initial_blocks\operation:
12882 psrldq $4, %xmm\i
12883 - sub $4, %r12
12884 - cmp %r11, %r12
12885 + sub $4, %r15
12886 + cmp %r11, %r15
12887 jne _get_AAD_loop2\num_initial_blocks\operation
12888 _get_AAD_loop2_done\num_initial_blocks\operation:
12889 movdqa SHUF_MASK(%rip), %xmm14
12890 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12891 *
12892 *****************************************************************************/
12893 ENTRY(aesni_gcm_dec)
12894 - push %r12
12895 + push %r15
12896 push %r13
12897 push %r14
12898 mov %rsp, %r14
12899 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12900 */
12901 sub $VARIABLE_OFFSET, %rsp
12902 and $~63, %rsp # align rsp to 64 bytes
12903 - mov %arg6, %r12
12904 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
12905 + mov %arg6, %r15
12906 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
12907 movdqa SHUF_MASK(%rip), %xmm2
12908 PSHUFB_XMM %xmm2, %xmm13
12909
12910 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12911 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12912 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12913 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12914 - mov %r13, %r12
12915 - and $(3<<4), %r12
12916 + mov %r13, %r15
12917 + and $(3<<4), %r15
12918 jz _initial_num_blocks_is_0_decrypt
12919 - cmp $(2<<4), %r12
12920 + cmp $(2<<4), %r15
12921 jb _initial_num_blocks_is_1_decrypt
12922 je _initial_num_blocks_is_2_decrypt
12923 _initial_num_blocks_is_3_decrypt:
12924 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12925 sub $16, %r11
12926 add %r13, %r11
12927 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12928 - lea SHIFT_MASK+16(%rip), %r12
12929 - sub %r13, %r12
12930 + lea SHIFT_MASK+16(%rip), %r15
12931 + sub %r13, %r15
12932 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12933 # (%r13 is the number of bytes in plaintext mod 16)
12934 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12935 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12936 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12937
12938 movdqa %xmm1, %xmm2
12939 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12940 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12941 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12942 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12943 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12944 pand %xmm1, %xmm2
12945 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12946 sub $1, %r13
12947 jne _less_than_8_bytes_left_decrypt
12948 _multiple_of_16_bytes_decrypt:
12949 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
12950 - shl $3, %r12 # convert into number of bits
12951 - movd %r12d, %xmm15 # len(A) in %xmm15
12952 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
12953 + shl $3, %r15 # convert into number of bits
12954 + movd %r15d, %xmm15 # len(A) in %xmm15
12955 shl $3, %arg4 # len(C) in bits (*128)
12956 MOVQ_R64_XMM %arg4, %xmm1
12957 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12958 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12959 mov %r14, %rsp
12960 pop %r14
12961 pop %r13
12962 - pop %r12
12963 + pop %r15
12964 + pax_force_retaddr
12965 ret
12966 ENDPROC(aesni_gcm_dec)
12967
12968 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12969 * poly = x^128 + x^127 + x^126 + x^121 + 1
12970 ***************************************************************************/
12971 ENTRY(aesni_gcm_enc)
12972 - push %r12
12973 + push %r15
12974 push %r13
12975 push %r14
12976 mov %rsp, %r14
12977 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12978 #
12979 sub $VARIABLE_OFFSET, %rsp
12980 and $~63, %rsp
12981 - mov %arg6, %r12
12982 - movdqu (%r12), %xmm13
12983 + mov %arg6, %r15
12984 + movdqu (%r15), %xmm13
12985 movdqa SHUF_MASK(%rip), %xmm2
12986 PSHUFB_XMM %xmm2, %xmm13
12987
12988 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12989 movdqa %xmm13, HashKey(%rsp)
12990 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12991 and $-16, %r13
12992 - mov %r13, %r12
12993 + mov %r13, %r15
12994
12995 # Encrypt first few blocks
12996
12997 - and $(3<<4), %r12
12998 + and $(3<<4), %r15
12999 jz _initial_num_blocks_is_0_encrypt
13000 - cmp $(2<<4), %r12
13001 + cmp $(2<<4), %r15
13002 jb _initial_num_blocks_is_1_encrypt
13003 je _initial_num_blocks_is_2_encrypt
13004 _initial_num_blocks_is_3_encrypt:
13005 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13006 sub $16, %r11
13007 add %r13, %r11
13008 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13009 - lea SHIFT_MASK+16(%rip), %r12
13010 - sub %r13, %r12
13011 + lea SHIFT_MASK+16(%rip), %r15
13012 + sub %r13, %r15
13013 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13014 # (%r13 is the number of bytes in plaintext mod 16)
13015 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13016 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13017 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13018 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13019 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13020 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13021 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13022 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13023 movdqa SHUF_MASK(%rip), %xmm10
13024 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13025 sub $1, %r13
13026 jne _less_than_8_bytes_left_encrypt
13027 _multiple_of_16_bytes_encrypt:
13028 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13029 - shl $3, %r12
13030 - movd %r12d, %xmm15 # len(A) in %xmm15
13031 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13032 + shl $3, %r15
13033 + movd %r15d, %xmm15 # len(A) in %xmm15
13034 shl $3, %arg4 # len(C) in bits (*128)
13035 MOVQ_R64_XMM %arg4, %xmm1
13036 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13037 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13038 mov %r14, %rsp
13039 pop %r14
13040 pop %r13
13041 - pop %r12
13042 + pop %r15
13043 + pax_force_retaddr
13044 ret
13045 ENDPROC(aesni_gcm_enc)
13046
13047 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
13048 pxor %xmm1, %xmm0
13049 movaps %xmm0, (TKEYP)
13050 add $0x10, TKEYP
13051 + pax_force_retaddr
13052 ret
13053 ENDPROC(_key_expansion_128)
13054 ENDPROC(_key_expansion_256a)
13055 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
13056 shufps $0b01001110, %xmm2, %xmm1
13057 movaps %xmm1, 0x10(TKEYP)
13058 add $0x20, TKEYP
13059 + pax_force_retaddr
13060 ret
13061 ENDPROC(_key_expansion_192a)
13062
13063 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13064
13065 movaps %xmm0, (TKEYP)
13066 add $0x10, TKEYP
13067 + pax_force_retaddr
13068 ret
13069 ENDPROC(_key_expansion_192b)
13070
13071 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13072 pxor %xmm1, %xmm2
13073 movaps %xmm2, (TKEYP)
13074 add $0x10, TKEYP
13075 + pax_force_retaddr
13076 ret
13077 ENDPROC(_key_expansion_256b)
13078
13079 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13080 #ifndef __x86_64__
13081 popl KEYP
13082 #endif
13083 + pax_force_retaddr
13084 ret
13085 ENDPROC(aesni_set_key)
13086
13087 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13088 popl KLEN
13089 popl KEYP
13090 #endif
13091 + pax_force_retaddr
13092 ret
13093 ENDPROC(aesni_enc)
13094
13095 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13096 AESENC KEY STATE
13097 movaps 0x70(TKEYP), KEY
13098 AESENCLAST KEY STATE
13099 + pax_force_retaddr
13100 ret
13101 ENDPROC(_aesni_enc1)
13102
13103 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13104 AESENCLAST KEY STATE2
13105 AESENCLAST KEY STATE3
13106 AESENCLAST KEY STATE4
13107 + pax_force_retaddr
13108 ret
13109 ENDPROC(_aesni_enc4)
13110
13111 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13112 popl KLEN
13113 popl KEYP
13114 #endif
13115 + pax_force_retaddr
13116 ret
13117 ENDPROC(aesni_dec)
13118
13119 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13120 AESDEC KEY STATE
13121 movaps 0x70(TKEYP), KEY
13122 AESDECLAST KEY STATE
13123 + pax_force_retaddr
13124 ret
13125 ENDPROC(_aesni_dec1)
13126
13127 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13128 AESDECLAST KEY STATE2
13129 AESDECLAST KEY STATE3
13130 AESDECLAST KEY STATE4
13131 + pax_force_retaddr
13132 ret
13133 ENDPROC(_aesni_dec4)
13134
13135 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13136 popl KEYP
13137 popl LEN
13138 #endif
13139 + pax_force_retaddr
13140 ret
13141 ENDPROC(aesni_ecb_enc)
13142
13143 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13144 popl KEYP
13145 popl LEN
13146 #endif
13147 + pax_force_retaddr
13148 ret
13149 ENDPROC(aesni_ecb_dec)
13150
13151 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13152 popl LEN
13153 popl IVP
13154 #endif
13155 + pax_force_retaddr
13156 ret
13157 ENDPROC(aesni_cbc_enc)
13158
13159 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13160 popl LEN
13161 popl IVP
13162 #endif
13163 + pax_force_retaddr
13164 ret
13165 ENDPROC(aesni_cbc_dec)
13166
13167 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13168 mov $1, TCTR_LOW
13169 MOVQ_R64_XMM TCTR_LOW INC
13170 MOVQ_R64_XMM CTR TCTR_LOW
13171 + pax_force_retaddr
13172 ret
13173 ENDPROC(_aesni_inc_init)
13174
13175 @@ -2579,6 +2598,7 @@ _aesni_inc:
13176 .Linc_low:
13177 movaps CTR, IV
13178 PSHUFB_XMM BSWAP_MASK IV
13179 + pax_force_retaddr
13180 ret
13181 ENDPROC(_aesni_inc)
13182
13183 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13184 .Lctr_enc_ret:
13185 movups IV, (IVP)
13186 .Lctr_enc_just_ret:
13187 + pax_force_retaddr
13188 ret
13189 ENDPROC(aesni_ctr_enc)
13190
13191 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13192 pxor INC, STATE4
13193 movdqu STATE4, 0x70(OUTP)
13194
13195 + pax_force_retaddr
13196 ret
13197 ENDPROC(aesni_xts_crypt8)
13198
13199 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13200 index 246c670..466e2d6 100644
13201 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13202 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13203 @@ -21,6 +21,7 @@
13204 */
13205
13206 #include <linux/linkage.h>
13207 +#include <asm/alternative-asm.h>
13208
13209 .file "blowfish-x86_64-asm.S"
13210 .text
13211 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13212 jnz .L__enc_xor;
13213
13214 write_block();
13215 + pax_force_retaddr
13216 ret;
13217 .L__enc_xor:
13218 xor_block();
13219 + pax_force_retaddr
13220 ret;
13221 ENDPROC(__blowfish_enc_blk)
13222
13223 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13224
13225 movq %r11, %rbp;
13226
13227 + pax_force_retaddr
13228 ret;
13229 ENDPROC(blowfish_dec_blk)
13230
13231 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13232
13233 popq %rbx;
13234 popq %rbp;
13235 + pax_force_retaddr
13236 ret;
13237
13238 .L__enc_xor4:
13239 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13240
13241 popq %rbx;
13242 popq %rbp;
13243 + pax_force_retaddr
13244 ret;
13245 ENDPROC(__blowfish_enc_blk_4way)
13246
13247 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13248 popq %rbx;
13249 popq %rbp;
13250
13251 + pax_force_retaddr
13252 ret;
13253 ENDPROC(blowfish_dec_blk_4way)
13254 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13255 index ce71f92..1dce7ec 100644
13256 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13257 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13258 @@ -16,6 +16,7 @@
13259 */
13260
13261 #include <linux/linkage.h>
13262 +#include <asm/alternative-asm.h>
13263
13264 #define CAMELLIA_TABLE_BYTE_LEN 272
13265
13266 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13267 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13268 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13269 %rcx, (%r9));
13270 + pax_force_retaddr
13271 ret;
13272 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13273
13274 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13275 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13276 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13277 %rax, (%r9));
13278 + pax_force_retaddr
13279 ret;
13280 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13281
13282 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13283 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13284 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13285
13286 + pax_force_retaddr
13287 ret;
13288
13289 .align 8
13290 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13291 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13292 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13293
13294 + pax_force_retaddr
13295 ret;
13296
13297 .align 8
13298 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13299 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13300 %xmm8, %rsi);
13301
13302 + pax_force_retaddr
13303 ret;
13304 ENDPROC(camellia_ecb_enc_16way)
13305
13306 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13307 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13308 %xmm8, %rsi);
13309
13310 + pax_force_retaddr
13311 ret;
13312 ENDPROC(camellia_ecb_dec_16way)
13313
13314 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13315 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13316 %xmm8, %rsi);
13317
13318 + pax_force_retaddr
13319 ret;
13320 ENDPROC(camellia_cbc_dec_16way)
13321
13322 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13323 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13324 %xmm8, %rsi);
13325
13326 + pax_force_retaddr
13327 ret;
13328 ENDPROC(camellia_ctr_16way)
13329
13330 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13331 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13332 %xmm8, %rsi);
13333
13334 + pax_force_retaddr
13335 ret;
13336 ENDPROC(camellia_xts_crypt_16way)
13337
13338 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13339 index 0e0b886..5a3123c 100644
13340 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13341 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13342 @@ -11,6 +11,7 @@
13343 */
13344
13345 #include <linux/linkage.h>
13346 +#include <asm/alternative-asm.h>
13347
13348 #define CAMELLIA_TABLE_BYTE_LEN 272
13349
13350 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13351 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13352 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13353 %rcx, (%r9));
13354 + pax_force_retaddr
13355 ret;
13356 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13357
13358 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13359 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13360 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13361 %rax, (%r9));
13362 + pax_force_retaddr
13363 ret;
13364 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13365
13366 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13367 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13368 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13369
13370 + pax_force_retaddr
13371 ret;
13372
13373 .align 8
13374 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13375 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13376 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13377
13378 + pax_force_retaddr
13379 ret;
13380
13381 .align 8
13382 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13383
13384 vzeroupper;
13385
13386 + pax_force_retaddr
13387 ret;
13388 ENDPROC(camellia_ecb_enc_32way)
13389
13390 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13391
13392 vzeroupper;
13393
13394 + pax_force_retaddr
13395 ret;
13396 ENDPROC(camellia_ecb_dec_32way)
13397
13398 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13399
13400 vzeroupper;
13401
13402 + pax_force_retaddr
13403 ret;
13404 ENDPROC(camellia_cbc_dec_32way)
13405
13406 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13407
13408 vzeroupper;
13409
13410 + pax_force_retaddr
13411 ret;
13412 ENDPROC(camellia_ctr_32way)
13413
13414 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13415
13416 vzeroupper;
13417
13418 + pax_force_retaddr
13419 ret;
13420 ENDPROC(camellia_xts_crypt_32way)
13421
13422 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13423 index 310319c..db3d7b5 100644
13424 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13425 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13426 @@ -21,6 +21,7 @@
13427 */
13428
13429 #include <linux/linkage.h>
13430 +#include <asm/alternative-asm.h>
13431
13432 .file "camellia-x86_64-asm_64.S"
13433 .text
13434 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13435 enc_outunpack(mov, RT1);
13436
13437 movq RRBP, %rbp;
13438 + pax_force_retaddr
13439 ret;
13440
13441 .L__enc_xor:
13442 enc_outunpack(xor, RT1);
13443
13444 movq RRBP, %rbp;
13445 + pax_force_retaddr
13446 ret;
13447 ENDPROC(__camellia_enc_blk)
13448
13449 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13450 dec_outunpack();
13451
13452 movq RRBP, %rbp;
13453 + pax_force_retaddr
13454 ret;
13455 ENDPROC(camellia_dec_blk)
13456
13457 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13458
13459 movq RRBP, %rbp;
13460 popq %rbx;
13461 + pax_force_retaddr
13462 ret;
13463
13464 .L__enc2_xor:
13465 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13466
13467 movq RRBP, %rbp;
13468 popq %rbx;
13469 + pax_force_retaddr
13470 ret;
13471 ENDPROC(__camellia_enc_blk_2way)
13472
13473 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13474
13475 movq RRBP, %rbp;
13476 movq RXOR, %rbx;
13477 + pax_force_retaddr
13478 ret;
13479 ENDPROC(camellia_dec_blk_2way)
13480 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13481 index c35fd5d..2d8c7db 100644
13482 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13483 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13484 @@ -24,6 +24,7 @@
13485 */
13486
13487 #include <linux/linkage.h>
13488 +#include <asm/alternative-asm.h>
13489
13490 .file "cast5-avx-x86_64-asm_64.S"
13491
13492 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13493 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13494 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13495
13496 + pax_force_retaddr
13497 ret;
13498 ENDPROC(__cast5_enc_blk16)
13499
13500 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13501 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13502 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13503
13504 + pax_force_retaddr
13505 ret;
13506
13507 .L__skip_dec:
13508 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13509 vmovdqu RR4, (6*4*4)(%r11);
13510 vmovdqu RL4, (7*4*4)(%r11);
13511
13512 + pax_force_retaddr
13513 ret;
13514 ENDPROC(cast5_ecb_enc_16way)
13515
13516 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13517 vmovdqu RR4, (6*4*4)(%r11);
13518 vmovdqu RL4, (7*4*4)(%r11);
13519
13520 + pax_force_retaddr
13521 ret;
13522 ENDPROC(cast5_ecb_dec_16way)
13523
13524 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13525 * %rdx: src
13526 */
13527
13528 - pushq %r12;
13529 + pushq %r14;
13530
13531 movq %rsi, %r11;
13532 - movq %rdx, %r12;
13533 + movq %rdx, %r14;
13534
13535 vmovdqu (0*16)(%rdx), RL1;
13536 vmovdqu (1*16)(%rdx), RR1;
13537 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13538 call __cast5_dec_blk16;
13539
13540 /* xor with src */
13541 - vmovq (%r12), RX;
13542 + vmovq (%r14), RX;
13543 vpshufd $0x4f, RX, RX;
13544 vpxor RX, RR1, RR1;
13545 - vpxor 0*16+8(%r12), RL1, RL1;
13546 - vpxor 1*16+8(%r12), RR2, RR2;
13547 - vpxor 2*16+8(%r12), RL2, RL2;
13548 - vpxor 3*16+8(%r12), RR3, RR3;
13549 - vpxor 4*16+8(%r12), RL3, RL3;
13550 - vpxor 5*16+8(%r12), RR4, RR4;
13551 - vpxor 6*16+8(%r12), RL4, RL4;
13552 + vpxor 0*16+8(%r14), RL1, RL1;
13553 + vpxor 1*16+8(%r14), RR2, RR2;
13554 + vpxor 2*16+8(%r14), RL2, RL2;
13555 + vpxor 3*16+8(%r14), RR3, RR3;
13556 + vpxor 4*16+8(%r14), RL3, RL3;
13557 + vpxor 5*16+8(%r14), RR4, RR4;
13558 + vpxor 6*16+8(%r14), RL4, RL4;
13559
13560 vmovdqu RR1, (0*16)(%r11);
13561 vmovdqu RL1, (1*16)(%r11);
13562 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13563 vmovdqu RR4, (6*16)(%r11);
13564 vmovdqu RL4, (7*16)(%r11);
13565
13566 - popq %r12;
13567 + popq %r14;
13568
13569 + pax_force_retaddr
13570 ret;
13571 ENDPROC(cast5_cbc_dec_16way)
13572
13573 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13574 * %rcx: iv (big endian, 64bit)
13575 */
13576
13577 - pushq %r12;
13578 + pushq %r14;
13579
13580 movq %rsi, %r11;
13581 - movq %rdx, %r12;
13582 + movq %rdx, %r14;
13583
13584 vpcmpeqd RTMP, RTMP, RTMP;
13585 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13586 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13587 call __cast5_enc_blk16;
13588
13589 /* dst = src ^ iv */
13590 - vpxor (0*16)(%r12), RR1, RR1;
13591 - vpxor (1*16)(%r12), RL1, RL1;
13592 - vpxor (2*16)(%r12), RR2, RR2;
13593 - vpxor (3*16)(%r12), RL2, RL2;
13594 - vpxor (4*16)(%r12), RR3, RR3;
13595 - vpxor (5*16)(%r12), RL3, RL3;
13596 - vpxor (6*16)(%r12), RR4, RR4;
13597 - vpxor (7*16)(%r12), RL4, RL4;
13598 + vpxor (0*16)(%r14), RR1, RR1;
13599 + vpxor (1*16)(%r14), RL1, RL1;
13600 + vpxor (2*16)(%r14), RR2, RR2;
13601 + vpxor (3*16)(%r14), RL2, RL2;
13602 + vpxor (4*16)(%r14), RR3, RR3;
13603 + vpxor (5*16)(%r14), RL3, RL3;
13604 + vpxor (6*16)(%r14), RR4, RR4;
13605 + vpxor (7*16)(%r14), RL4, RL4;
13606 vmovdqu RR1, (0*16)(%r11);
13607 vmovdqu RL1, (1*16)(%r11);
13608 vmovdqu RR2, (2*16)(%r11);
13609 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13610 vmovdqu RR4, (6*16)(%r11);
13611 vmovdqu RL4, (7*16)(%r11);
13612
13613 - popq %r12;
13614 + popq %r14;
13615
13616 + pax_force_retaddr
13617 ret;
13618 ENDPROC(cast5_ctr_16way)
13619 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13620 index e3531f8..e123f35 100644
13621 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13622 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13623 @@ -24,6 +24,7 @@
13624 */
13625
13626 #include <linux/linkage.h>
13627 +#include <asm/alternative-asm.h>
13628 #include "glue_helper-asm-avx.S"
13629
13630 .file "cast6-avx-x86_64-asm_64.S"
13631 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13632 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13633 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13634
13635 + pax_force_retaddr
13636 ret;
13637 ENDPROC(__cast6_enc_blk8)
13638
13639 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13640 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13641 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13642
13643 + pax_force_retaddr
13644 ret;
13645 ENDPROC(__cast6_dec_blk8)
13646
13647 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13648
13649 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13650
13651 + pax_force_retaddr
13652 ret;
13653 ENDPROC(cast6_ecb_enc_8way)
13654
13655 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13656
13657 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13658
13659 + pax_force_retaddr
13660 ret;
13661 ENDPROC(cast6_ecb_dec_8way)
13662
13663 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13664 * %rdx: src
13665 */
13666
13667 - pushq %r12;
13668 + pushq %r14;
13669
13670 movq %rsi, %r11;
13671 - movq %rdx, %r12;
13672 + movq %rdx, %r14;
13673
13674 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13675
13676 call __cast6_dec_blk8;
13677
13678 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13679 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13680
13681 - popq %r12;
13682 + popq %r14;
13683
13684 + pax_force_retaddr
13685 ret;
13686 ENDPROC(cast6_cbc_dec_8way)
13687
13688 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13689 * %rcx: iv (little endian, 128bit)
13690 */
13691
13692 - pushq %r12;
13693 + pushq %r14;
13694
13695 movq %rsi, %r11;
13696 - movq %rdx, %r12;
13697 + movq %rdx, %r14;
13698
13699 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13700 RD2, RX, RKR, RKM);
13701
13702 call __cast6_enc_blk8;
13703
13704 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13705 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13706
13707 - popq %r12;
13708 + popq %r14;
13709
13710 + pax_force_retaddr
13711 ret;
13712 ENDPROC(cast6_ctr_8way)
13713
13714 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13715 /* dst <= regs xor IVs(in dst) */
13716 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13717
13718 + pax_force_retaddr
13719 ret;
13720 ENDPROC(cast6_xts_enc_8way)
13721
13722 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13723 /* dst <= regs xor IVs(in dst) */
13724 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13725
13726 + pax_force_retaddr
13727 ret;
13728 ENDPROC(cast6_xts_dec_8way)
13729 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13730 index dbc4339..de6e120 100644
13731 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13732 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13733 @@ -45,6 +45,7 @@
13734
13735 #include <asm/inst.h>
13736 #include <linux/linkage.h>
13737 +#include <asm/alternative-asm.h>
13738
13739 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13740
13741 @@ -312,6 +313,7 @@ do_return:
13742 popq %rsi
13743 popq %rdi
13744 popq %rbx
13745 + pax_force_retaddr
13746 ret
13747
13748 ################################################################
13749 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13750 index 185fad4..ff4cd36 100644
13751 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13752 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13753 @@ -18,6 +18,7 @@
13754
13755 #include <linux/linkage.h>
13756 #include <asm/inst.h>
13757 +#include <asm/alternative-asm.h>
13758
13759 .data
13760
13761 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13762 psrlq $1, T2
13763 pxor T2, T1
13764 pxor T1, DATA
13765 + pax_force_retaddr
13766 ret
13767 ENDPROC(__clmul_gf128mul_ble)
13768
13769 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13770 call __clmul_gf128mul_ble
13771 PSHUFB_XMM BSWAP DATA
13772 movups DATA, (%rdi)
13773 + pax_force_retaddr
13774 ret
13775 ENDPROC(clmul_ghash_mul)
13776
13777 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13778 PSHUFB_XMM BSWAP DATA
13779 movups DATA, (%rdi)
13780 .Lupdate_just_ret:
13781 + pax_force_retaddr
13782 ret
13783 ENDPROC(clmul_ghash_update)
13784 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13785 index 9279e0b..c4b3d2c 100644
13786 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13787 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13788 @@ -1,4 +1,5 @@
13789 #include <linux/linkage.h>
13790 +#include <asm/alternative-asm.h>
13791
13792 # enter salsa20_encrypt_bytes
13793 ENTRY(salsa20_encrypt_bytes)
13794 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13795 add %r11,%rsp
13796 mov %rdi,%rax
13797 mov %rsi,%rdx
13798 + pax_force_retaddr
13799 ret
13800 # bytesatleast65:
13801 ._bytesatleast65:
13802 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13803 add %r11,%rsp
13804 mov %rdi,%rax
13805 mov %rsi,%rdx
13806 + pax_force_retaddr
13807 ret
13808 ENDPROC(salsa20_keysetup)
13809
13810 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13811 add %r11,%rsp
13812 mov %rdi,%rax
13813 mov %rsi,%rdx
13814 + pax_force_retaddr
13815 ret
13816 ENDPROC(salsa20_ivsetup)
13817 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13818 index 2f202f4..d9164d6 100644
13819 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13820 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13821 @@ -24,6 +24,7 @@
13822 */
13823
13824 #include <linux/linkage.h>
13825 +#include <asm/alternative-asm.h>
13826 #include "glue_helper-asm-avx.S"
13827
13828 .file "serpent-avx-x86_64-asm_64.S"
13829 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13830 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13831 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13832
13833 + pax_force_retaddr
13834 ret;
13835 ENDPROC(__serpent_enc_blk8_avx)
13836
13837 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13838 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13839 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13840
13841 + pax_force_retaddr
13842 ret;
13843 ENDPROC(__serpent_dec_blk8_avx)
13844
13845 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13846
13847 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13848
13849 + pax_force_retaddr
13850 ret;
13851 ENDPROC(serpent_ecb_enc_8way_avx)
13852
13853 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13854
13855 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13856
13857 + pax_force_retaddr
13858 ret;
13859 ENDPROC(serpent_ecb_dec_8way_avx)
13860
13861 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13862
13863 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13864
13865 + pax_force_retaddr
13866 ret;
13867 ENDPROC(serpent_cbc_dec_8way_avx)
13868
13869 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13870
13871 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13872
13873 + pax_force_retaddr
13874 ret;
13875 ENDPROC(serpent_ctr_8way_avx)
13876
13877 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13878 /* dst <= regs xor IVs(in dst) */
13879 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13880
13881 + pax_force_retaddr
13882 ret;
13883 ENDPROC(serpent_xts_enc_8way_avx)
13884
13885 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13886 /* dst <= regs xor IVs(in dst) */
13887 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13888
13889 + pax_force_retaddr
13890 ret;
13891 ENDPROC(serpent_xts_dec_8way_avx)
13892 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13893 index b222085..abd483c 100644
13894 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
13895 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13896 @@ -15,6 +15,7 @@
13897 */
13898
13899 #include <linux/linkage.h>
13900 +#include <asm/alternative-asm.h>
13901 #include "glue_helper-asm-avx2.S"
13902
13903 .file "serpent-avx2-asm_64.S"
13904 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
13905 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13906 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13907
13908 + pax_force_retaddr
13909 ret;
13910 ENDPROC(__serpent_enc_blk16)
13911
13912 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
13913 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13914 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13915
13916 + pax_force_retaddr
13917 ret;
13918 ENDPROC(__serpent_dec_blk16)
13919
13920 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13921
13922 vzeroupper;
13923
13924 + pax_force_retaddr
13925 ret;
13926 ENDPROC(serpent_ecb_enc_16way)
13927
13928 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13929
13930 vzeroupper;
13931
13932 + pax_force_retaddr
13933 ret;
13934 ENDPROC(serpent_ecb_dec_16way)
13935
13936 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13937
13938 vzeroupper;
13939
13940 + pax_force_retaddr
13941 ret;
13942 ENDPROC(serpent_cbc_dec_16way)
13943
13944 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13945
13946 vzeroupper;
13947
13948 + pax_force_retaddr
13949 ret;
13950 ENDPROC(serpent_ctr_16way)
13951
13952 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13953
13954 vzeroupper;
13955
13956 + pax_force_retaddr
13957 ret;
13958 ENDPROC(serpent_xts_enc_16way)
13959
13960 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13961
13962 vzeroupper;
13963
13964 + pax_force_retaddr
13965 ret;
13966 ENDPROC(serpent_xts_dec_16way)
13967 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13968 index acc066c..1559cc4 100644
13969 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13970 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13971 @@ -25,6 +25,7 @@
13972 */
13973
13974 #include <linux/linkage.h>
13975 +#include <asm/alternative-asm.h>
13976
13977 .file "serpent-sse2-x86_64-asm_64.S"
13978 .text
13979 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13980 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13981 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13982
13983 + pax_force_retaddr
13984 ret;
13985
13986 .L__enc_xor8:
13987 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13988 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13989
13990 + pax_force_retaddr
13991 ret;
13992 ENDPROC(__serpent_enc_blk_8way)
13993
13994 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13995 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13996 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13997
13998 + pax_force_retaddr
13999 ret;
14000 ENDPROC(serpent_dec_blk_8way)
14001 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14002 index a410950..9dfe7ad 100644
14003 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14004 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14005 @@ -29,6 +29,7 @@
14006 */
14007
14008 #include <linux/linkage.h>
14009 +#include <asm/alternative-asm.h>
14010
14011 #define CTX %rdi // arg1
14012 #define BUF %rsi // arg2
14013 @@ -75,9 +76,9 @@
14014
14015 push %rbx
14016 push %rbp
14017 - push %r12
14018 + push %r14
14019
14020 - mov %rsp, %r12
14021 + mov %rsp, %r14
14022 sub $64, %rsp # allocate workspace
14023 and $~15, %rsp # align stack
14024
14025 @@ -99,11 +100,12 @@
14026 xor %rax, %rax
14027 rep stosq
14028
14029 - mov %r12, %rsp # deallocate workspace
14030 + mov %r14, %rsp # deallocate workspace
14031
14032 - pop %r12
14033 + pop %r14
14034 pop %rbp
14035 pop %rbx
14036 + pax_force_retaddr
14037 ret
14038
14039 ENDPROC(\name)
14040 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14041 index 642f156..51a513c 100644
14042 --- a/arch/x86/crypto/sha256-avx-asm.S
14043 +++ b/arch/x86/crypto/sha256-avx-asm.S
14044 @@ -49,6 +49,7 @@
14045
14046 #ifdef CONFIG_AS_AVX
14047 #include <linux/linkage.h>
14048 +#include <asm/alternative-asm.h>
14049
14050 ## assume buffers not aligned
14051 #define VMOVDQ vmovdqu
14052 @@ -460,6 +461,7 @@ done_hash:
14053 popq %r13
14054 popq %rbp
14055 popq %rbx
14056 + pax_force_retaddr
14057 ret
14058 ENDPROC(sha256_transform_avx)
14059
14060 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14061 index 9e86944..3795e6a 100644
14062 --- a/arch/x86/crypto/sha256-avx2-asm.S
14063 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14064 @@ -50,6 +50,7 @@
14065
14066 #ifdef CONFIG_AS_AVX2
14067 #include <linux/linkage.h>
14068 +#include <asm/alternative-asm.h>
14069
14070 ## assume buffers not aligned
14071 #define VMOVDQ vmovdqu
14072 @@ -720,6 +721,7 @@ done_hash:
14073 popq %r12
14074 popq %rbp
14075 popq %rbx
14076 + pax_force_retaddr
14077 ret
14078 ENDPROC(sha256_transform_rorx)
14079
14080 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14081 index f833b74..8c62a9e 100644
14082 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14083 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14084 @@ -47,6 +47,7 @@
14085 ########################################################################
14086
14087 #include <linux/linkage.h>
14088 +#include <asm/alternative-asm.h>
14089
14090 ## assume buffers not aligned
14091 #define MOVDQ movdqu
14092 @@ -471,6 +472,7 @@ done_hash:
14093 popq %rbp
14094 popq %rbx
14095
14096 + pax_force_retaddr
14097 ret
14098 ENDPROC(sha256_transform_ssse3)
14099
14100 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14101 index 974dde9..a823ff9 100644
14102 --- a/arch/x86/crypto/sha512-avx-asm.S
14103 +++ b/arch/x86/crypto/sha512-avx-asm.S
14104 @@ -49,6 +49,7 @@
14105
14106 #ifdef CONFIG_AS_AVX
14107 #include <linux/linkage.h>
14108 +#include <asm/alternative-asm.h>
14109
14110 .text
14111
14112 @@ -364,6 +365,7 @@ updateblock:
14113 mov frame_RSPSAVE(%rsp), %rsp
14114
14115 nowork:
14116 + pax_force_retaddr
14117 ret
14118 ENDPROC(sha512_transform_avx)
14119
14120 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14121 index 568b961..ed20c37 100644
14122 --- a/arch/x86/crypto/sha512-avx2-asm.S
14123 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14124 @@ -51,6 +51,7 @@
14125
14126 #ifdef CONFIG_AS_AVX2
14127 #include <linux/linkage.h>
14128 +#include <asm/alternative-asm.h>
14129
14130 .text
14131
14132 @@ -678,6 +679,7 @@ done_hash:
14133
14134 # Restore Stack Pointer
14135 mov frame_RSPSAVE(%rsp), %rsp
14136 + pax_force_retaddr
14137 ret
14138 ENDPROC(sha512_transform_rorx)
14139
14140 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14141 index fb56855..6edd768 100644
14142 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14143 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14144 @@ -48,6 +48,7 @@
14145 ########################################################################
14146
14147 #include <linux/linkage.h>
14148 +#include <asm/alternative-asm.h>
14149
14150 .text
14151
14152 @@ -363,6 +364,7 @@ updateblock:
14153 mov frame_RSPSAVE(%rsp), %rsp
14154
14155 nowork:
14156 + pax_force_retaddr
14157 ret
14158 ENDPROC(sha512_transform_ssse3)
14159
14160 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14161 index 0505813..b067311 100644
14162 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14163 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14164 @@ -24,6 +24,7 @@
14165 */
14166
14167 #include <linux/linkage.h>
14168 +#include <asm/alternative-asm.h>
14169 #include "glue_helper-asm-avx.S"
14170
14171 .file "twofish-avx-x86_64-asm_64.S"
14172 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14173 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14174 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14175
14176 + pax_force_retaddr
14177 ret;
14178 ENDPROC(__twofish_enc_blk8)
14179
14180 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14181 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14182 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14183
14184 + pax_force_retaddr
14185 ret;
14186 ENDPROC(__twofish_dec_blk8)
14187
14188 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14189
14190 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14191
14192 + pax_force_retaddr
14193 ret;
14194 ENDPROC(twofish_ecb_enc_8way)
14195
14196 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14197
14198 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14199
14200 + pax_force_retaddr
14201 ret;
14202 ENDPROC(twofish_ecb_dec_8way)
14203
14204 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14205 * %rdx: src
14206 */
14207
14208 - pushq %r12;
14209 + pushq %r14;
14210
14211 movq %rsi, %r11;
14212 - movq %rdx, %r12;
14213 + movq %rdx, %r14;
14214
14215 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14216
14217 call __twofish_dec_blk8;
14218
14219 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14220 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14221
14222 - popq %r12;
14223 + popq %r14;
14224
14225 + pax_force_retaddr
14226 ret;
14227 ENDPROC(twofish_cbc_dec_8way)
14228
14229 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14230 * %rcx: iv (little endian, 128bit)
14231 */
14232
14233 - pushq %r12;
14234 + pushq %r14;
14235
14236 movq %rsi, %r11;
14237 - movq %rdx, %r12;
14238 + movq %rdx, %r14;
14239
14240 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14241 RD2, RX0, RX1, RY0);
14242
14243 call __twofish_enc_blk8;
14244
14245 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14246 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14247
14248 - popq %r12;
14249 + popq %r14;
14250
14251 + pax_force_retaddr
14252 ret;
14253 ENDPROC(twofish_ctr_8way)
14254
14255 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14256 /* dst <= regs xor IVs(in dst) */
14257 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14258
14259 + pax_force_retaddr
14260 ret;
14261 ENDPROC(twofish_xts_enc_8way)
14262
14263 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14264 /* dst <= regs xor IVs(in dst) */
14265 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14266
14267 + pax_force_retaddr
14268 ret;
14269 ENDPROC(twofish_xts_dec_8way)
14270 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14271 index 1c3b7ce..02f578d 100644
14272 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14273 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14274 @@ -21,6 +21,7 @@
14275 */
14276
14277 #include <linux/linkage.h>
14278 +#include <asm/alternative-asm.h>
14279
14280 .file "twofish-x86_64-asm-3way.S"
14281 .text
14282 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14283 popq %r13;
14284 popq %r14;
14285 popq %r15;
14286 + pax_force_retaddr
14287 ret;
14288
14289 .L__enc_xor3:
14290 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14291 popq %r13;
14292 popq %r14;
14293 popq %r15;
14294 + pax_force_retaddr
14295 ret;
14296 ENDPROC(__twofish_enc_blk_3way)
14297
14298 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14299 popq %r13;
14300 popq %r14;
14301 popq %r15;
14302 + pax_force_retaddr
14303 ret;
14304 ENDPROC(twofish_dec_blk_3way)
14305 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14306 index a039d21..524b8b2 100644
14307 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14308 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14309 @@ -22,6 +22,7 @@
14310
14311 #include <linux/linkage.h>
14312 #include <asm/asm-offsets.h>
14313 +#include <asm/alternative-asm.h>
14314
14315 #define a_offset 0
14316 #define b_offset 4
14317 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14318
14319 popq R1
14320 movq $1,%rax
14321 + pax_force_retaddr
14322 ret
14323 ENDPROC(twofish_enc_blk)
14324
14325 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14326
14327 popq R1
14328 movq $1,%rax
14329 + pax_force_retaddr
14330 ret
14331 ENDPROC(twofish_dec_blk)
14332 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14333 index d21ff89..6da8e6e 100644
14334 --- a/arch/x86/ia32/ia32_aout.c
14335 +++ b/arch/x86/ia32/ia32_aout.c
14336 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14337 unsigned long dump_start, dump_size;
14338 struct user32 dump;
14339
14340 + memset(&dump, 0, sizeof(dump));
14341 +
14342 fs = get_fs();
14343 set_fs(KERNEL_DS);
14344 has_dumped = 1;
14345 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14346 index 2206757..85cbcfa 100644
14347 --- a/arch/x86/ia32/ia32_signal.c
14348 +++ b/arch/x86/ia32/ia32_signal.c
14349 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14350 if (__get_user(set.sig[0], &frame->sc.oldmask)
14351 || (_COMPAT_NSIG_WORDS > 1
14352 && __copy_from_user((((char *) &set.sig) + 4),
14353 - &frame->extramask,
14354 + frame->extramask,
14355 sizeof(frame->extramask))))
14356 goto badframe;
14357
14358 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14359 sp -= frame_size;
14360 /* Align the stack pointer according to the i386 ABI,
14361 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14362 - sp = ((sp + 4) & -16ul) - 4;
14363 + sp = ((sp - 12) & -16ul) - 4;
14364 return (void __user *) sp;
14365 }
14366
14367 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14368 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14369 sigreturn);
14370 else
14371 - restorer = &frame->retcode;
14372 + restorer = frame->retcode;
14373 }
14374
14375 put_user_try {
14376 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14377 * These are actually not used anymore, but left because some
14378 * gdb versions depend on them as a marker.
14379 */
14380 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14381 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14382 } put_user_catch(err);
14383
14384 if (err)
14385 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14386 0xb8,
14387 __NR_ia32_rt_sigreturn,
14388 0x80cd,
14389 - 0,
14390 + 0
14391 };
14392
14393 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14394 @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14395
14396 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14397 restorer = ksig->ka.sa.sa_restorer;
14398 + else if (current->mm->context.vdso)
14399 + /* Return stub is in 32bit vsyscall page */
14400 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14401 else
14402 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14403 - rt_sigreturn);
14404 + restorer = frame->retcode;
14405 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14406
14407 /*
14408 * Not actually used anymore, but left because some gdb
14409 * versions need it.
14410 */
14411 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14412 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14413 } put_user_catch(err);
14414
14415 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14416 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14417 index 4299eb0..fefe70e 100644
14418 --- a/arch/x86/ia32/ia32entry.S
14419 +++ b/arch/x86/ia32/ia32entry.S
14420 @@ -15,8 +15,10 @@
14421 #include <asm/irqflags.h>
14422 #include <asm/asm.h>
14423 #include <asm/smap.h>
14424 +#include <asm/pgtable.h>
14425 #include <linux/linkage.h>
14426 #include <linux/err.h>
14427 +#include <asm/alternative-asm.h>
14428
14429 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14430 #include <linux/elf-em.h>
14431 @@ -62,12 +64,12 @@
14432 */
14433 .macro LOAD_ARGS32 offset, _r9=0
14434 .if \_r9
14435 - movl \offset+16(%rsp),%r9d
14436 + movl \offset+R9(%rsp),%r9d
14437 .endif
14438 - movl \offset+40(%rsp),%ecx
14439 - movl \offset+48(%rsp),%edx
14440 - movl \offset+56(%rsp),%esi
14441 - movl \offset+64(%rsp),%edi
14442 + movl \offset+RCX(%rsp),%ecx
14443 + movl \offset+RDX(%rsp),%edx
14444 + movl \offset+RSI(%rsp),%esi
14445 + movl \offset+RDI(%rsp),%edi
14446 movl %eax,%eax /* zero extension */
14447 .endm
14448
14449 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14450 ENDPROC(native_irq_enable_sysexit)
14451 #endif
14452
14453 + .macro pax_enter_kernel_user
14454 + pax_set_fptr_mask
14455 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14456 + call pax_enter_kernel_user
14457 +#endif
14458 + .endm
14459 +
14460 + .macro pax_exit_kernel_user
14461 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14462 + call pax_exit_kernel_user
14463 +#endif
14464 +#ifdef CONFIG_PAX_RANDKSTACK
14465 + pushq %rax
14466 + pushq %r11
14467 + call pax_randomize_kstack
14468 + popq %r11
14469 + popq %rax
14470 +#endif
14471 + .endm
14472 +
14473 + .macro pax_erase_kstack
14474 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14475 + call pax_erase_kstack
14476 +#endif
14477 + .endm
14478 +
14479 /*
14480 * 32bit SYSENTER instruction entry.
14481 *
14482 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14483 CFI_REGISTER rsp,rbp
14484 SWAPGS_UNSAFE_STACK
14485 movq PER_CPU_VAR(kernel_stack), %rsp
14486 - addq $(KERNEL_STACK_OFFSET),%rsp
14487 - /*
14488 - * No need to follow this irqs on/off section: the syscall
14489 - * disabled irqs, here we enable it straight after entry:
14490 - */
14491 - ENABLE_INTERRUPTS(CLBR_NONE)
14492 movl %ebp,%ebp /* zero extension */
14493 pushq_cfi $__USER32_DS
14494 /*CFI_REL_OFFSET ss,0*/
14495 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14496 CFI_REL_OFFSET rsp,0
14497 pushfq_cfi
14498 /*CFI_REL_OFFSET rflags,0*/
14499 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14500 - CFI_REGISTER rip,r10
14501 + orl $X86_EFLAGS_IF,(%rsp)
14502 + GET_THREAD_INFO(%r11)
14503 + movl TI_sysenter_return(%r11), %r11d
14504 + CFI_REGISTER rip,r11
14505 pushq_cfi $__USER32_CS
14506 /*CFI_REL_OFFSET cs,0*/
14507 movl %eax, %eax
14508 - pushq_cfi %r10
14509 + pushq_cfi %r11
14510 CFI_REL_OFFSET rip,0
14511 pushq_cfi %rax
14512 cld
14513 SAVE_ARGS 0,1,0
14514 + pax_enter_kernel_user
14515 +
14516 +#ifdef CONFIG_PAX_RANDKSTACK
14517 + pax_erase_kstack
14518 +#endif
14519 +
14520 + /*
14521 + * No need to follow this irqs on/off section: the syscall
14522 + * disabled irqs, here we enable it straight after entry:
14523 + */
14524 + ENABLE_INTERRUPTS(CLBR_NONE)
14525 /* no need to do an access_ok check here because rbp has been
14526 32bit zero extended */
14527 +
14528 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14529 + addq pax_user_shadow_base,%rbp
14530 + ASM_PAX_OPEN_USERLAND
14531 +#endif
14532 +
14533 ASM_STAC
14534 1: movl (%rbp),%ebp
14535 _ASM_EXTABLE(1b,ia32_badarg)
14536 ASM_CLAC
14537 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14538 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14539 +
14540 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14541 + ASM_PAX_CLOSE_USERLAND
14542 +#endif
14543 +
14544 + GET_THREAD_INFO(%r11)
14545 + orl $TS_COMPAT,TI_status(%r11)
14546 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14547 CFI_REMEMBER_STATE
14548 jnz sysenter_tracesys
14549 cmpq $(IA32_NR_syscalls-1),%rax
14550 @@ -162,15 +209,18 @@ sysenter_do_call:
14551 sysenter_dispatch:
14552 call *ia32_sys_call_table(,%rax,8)
14553 movq %rax,RAX-ARGOFFSET(%rsp)
14554 + GET_THREAD_INFO(%r11)
14555 DISABLE_INTERRUPTS(CLBR_NONE)
14556 TRACE_IRQS_OFF
14557 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14558 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14559 jnz sysexit_audit
14560 sysexit_from_sys_call:
14561 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14562 + pax_exit_kernel_user
14563 + pax_erase_kstack
14564 + andl $~TS_COMPAT,TI_status(%r11)
14565 /* clear IF, that popfq doesn't enable interrupts early */
14566 - andl $~0x200,EFLAGS-R11(%rsp)
14567 - movl RIP-R11(%rsp),%edx /* User %eip */
14568 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14569 + movl RIP(%rsp),%edx /* User %eip */
14570 CFI_REGISTER rip,rdx
14571 RESTORE_ARGS 0,24,0,0,0,0
14572 xorq %r8,%r8
14573 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
14574 movl %eax,%esi /* 2nd arg: syscall number */
14575 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14576 call __audit_syscall_entry
14577 +
14578 + pax_erase_kstack
14579 +
14580 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14581 cmpq $(IA32_NR_syscalls-1),%rax
14582 ja ia32_badsys
14583 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
14584 .endm
14585
14586 .macro auditsys_exit exit
14587 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14588 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14589 jnz ia32_ret_from_sys_call
14590 TRACE_IRQS_ON
14591 ENABLE_INTERRUPTS(CLBR_NONE)
14592 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
14593 1: setbe %al /* 1 if error, 0 if not */
14594 movzbl %al,%edi /* zero-extend that into %edi */
14595 call __audit_syscall_exit
14596 + GET_THREAD_INFO(%r11)
14597 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14598 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14599 DISABLE_INTERRUPTS(CLBR_NONE)
14600 TRACE_IRQS_OFF
14601 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14602 + testl %edi,TI_flags(%r11)
14603 jz \exit
14604 CLEAR_RREGS -ARGOFFSET
14605 jmp int_with_check
14606 @@ -237,7 +291,7 @@ sysexit_audit:
14607
14608 sysenter_tracesys:
14609 #ifdef CONFIG_AUDITSYSCALL
14610 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14611 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14612 jz sysenter_auditsys
14613 #endif
14614 SAVE_REST
14615 @@ -249,6 +303,9 @@ sysenter_tracesys:
14616 RESTORE_REST
14617 cmpq $(IA32_NR_syscalls-1),%rax
14618 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14619 +
14620 + pax_erase_kstack
14621 +
14622 jmp sysenter_do_call
14623 CFI_ENDPROC
14624 ENDPROC(ia32_sysenter_target)
14625 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14626 ENTRY(ia32_cstar_target)
14627 CFI_STARTPROC32 simple
14628 CFI_SIGNAL_FRAME
14629 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14630 + CFI_DEF_CFA rsp,0
14631 CFI_REGISTER rip,rcx
14632 /*CFI_REGISTER rflags,r11*/
14633 SWAPGS_UNSAFE_STACK
14634 movl %esp,%r8d
14635 CFI_REGISTER rsp,r8
14636 movq PER_CPU_VAR(kernel_stack),%rsp
14637 + SAVE_ARGS 8*6,0,0
14638 + pax_enter_kernel_user
14639 +
14640 +#ifdef CONFIG_PAX_RANDKSTACK
14641 + pax_erase_kstack
14642 +#endif
14643 +
14644 /*
14645 * No need to follow this irqs on/off section: the syscall
14646 * disabled irqs and here we enable it straight after entry:
14647 */
14648 ENABLE_INTERRUPTS(CLBR_NONE)
14649 - SAVE_ARGS 8,0,0
14650 movl %eax,%eax /* zero extension */
14651 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14652 movq %rcx,RIP-ARGOFFSET(%rsp)
14653 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14654 /* no need to do an access_ok check here because r8 has been
14655 32bit zero extended */
14656 /* hardware stack frame is complete now */
14657 +
14658 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14659 + ASM_PAX_OPEN_USERLAND
14660 + movq pax_user_shadow_base,%r8
14661 + addq RSP-ARGOFFSET(%rsp),%r8
14662 +#endif
14663 +
14664 ASM_STAC
14665 1: movl (%r8),%r9d
14666 _ASM_EXTABLE(1b,ia32_badarg)
14667 ASM_CLAC
14668 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14669 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14670 +
14671 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14672 + ASM_PAX_CLOSE_USERLAND
14673 +#endif
14674 +
14675 + GET_THREAD_INFO(%r11)
14676 + orl $TS_COMPAT,TI_status(%r11)
14677 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14678 CFI_REMEMBER_STATE
14679 jnz cstar_tracesys
14680 cmpq $IA32_NR_syscalls-1,%rax
14681 @@ -319,13 +395,16 @@ cstar_do_call:
14682 cstar_dispatch:
14683 call *ia32_sys_call_table(,%rax,8)
14684 movq %rax,RAX-ARGOFFSET(%rsp)
14685 + GET_THREAD_INFO(%r11)
14686 DISABLE_INTERRUPTS(CLBR_NONE)
14687 TRACE_IRQS_OFF
14688 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14689 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14690 jnz sysretl_audit
14691 sysretl_from_sys_call:
14692 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14693 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14694 + pax_exit_kernel_user
14695 + pax_erase_kstack
14696 + andl $~TS_COMPAT,TI_status(%r11)
14697 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14698 movl RIP-ARGOFFSET(%rsp),%ecx
14699 CFI_REGISTER rip,rcx
14700 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14701 @@ -352,7 +431,7 @@ sysretl_audit:
14702
14703 cstar_tracesys:
14704 #ifdef CONFIG_AUDITSYSCALL
14705 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14706 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14707 jz cstar_auditsys
14708 #endif
14709 xchgl %r9d,%ebp
14710 @@ -366,11 +445,19 @@ cstar_tracesys:
14711 xchgl %ebp,%r9d
14712 cmpq $(IA32_NR_syscalls-1),%rax
14713 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14714 +
14715 + pax_erase_kstack
14716 +
14717 jmp cstar_do_call
14718 END(ia32_cstar_target)
14719
14720 ia32_badarg:
14721 ASM_CLAC
14722 +
14723 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14724 + ASM_PAX_CLOSE_USERLAND
14725 +#endif
14726 +
14727 movq $-EFAULT,%rax
14728 jmp ia32_sysret
14729 CFI_ENDPROC
14730 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14731 CFI_REL_OFFSET rip,RIP-RIP
14732 PARAVIRT_ADJUST_EXCEPTION_FRAME
14733 SWAPGS
14734 - /*
14735 - * No need to follow this irqs on/off section: the syscall
14736 - * disabled irqs and here we enable it straight after entry:
14737 - */
14738 - ENABLE_INTERRUPTS(CLBR_NONE)
14739 movl %eax,%eax
14740 pushq_cfi %rax
14741 cld
14742 /* note the registers are not zero extended to the sf.
14743 this could be a problem. */
14744 SAVE_ARGS 0,1,0
14745 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14746 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14747 + pax_enter_kernel_user
14748 +
14749 +#ifdef CONFIG_PAX_RANDKSTACK
14750 + pax_erase_kstack
14751 +#endif
14752 +
14753 + /*
14754 + * No need to follow this irqs on/off section: the syscall
14755 + * disabled irqs and here we enable it straight after entry:
14756 + */
14757 + ENABLE_INTERRUPTS(CLBR_NONE)
14758 + GET_THREAD_INFO(%r11)
14759 + orl $TS_COMPAT,TI_status(%r11)
14760 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14761 jnz ia32_tracesys
14762 cmpq $(IA32_NR_syscalls-1),%rax
14763 ja ia32_badsys
14764 @@ -442,6 +536,9 @@ ia32_tracesys:
14765 RESTORE_REST
14766 cmpq $(IA32_NR_syscalls-1),%rax
14767 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14768 +
14769 + pax_erase_kstack
14770 +
14771 jmp ia32_do_call
14772 END(ia32_syscall)
14773
14774 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14775 index 8e0ceec..af13504 100644
14776 --- a/arch/x86/ia32/sys_ia32.c
14777 +++ b/arch/x86/ia32/sys_ia32.c
14778 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14779 */
14780 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14781 {
14782 - typeof(ubuf->st_uid) uid = 0;
14783 - typeof(ubuf->st_gid) gid = 0;
14784 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
14785 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
14786 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14787 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14788 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14789 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14790 index 372231c..51b537d 100644
14791 --- a/arch/x86/include/asm/alternative-asm.h
14792 +++ b/arch/x86/include/asm/alternative-asm.h
14793 @@ -18,6 +18,45 @@
14794 .endm
14795 #endif
14796
14797 +#ifdef KERNEXEC_PLUGIN
14798 + .macro pax_force_retaddr_bts rip=0
14799 + btsq $63,\rip(%rsp)
14800 + .endm
14801 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14802 + .macro pax_force_retaddr rip=0, reload=0
14803 + btsq $63,\rip(%rsp)
14804 + .endm
14805 + .macro pax_force_fptr ptr
14806 + btsq $63,\ptr
14807 + .endm
14808 + .macro pax_set_fptr_mask
14809 + .endm
14810 +#endif
14811 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14812 + .macro pax_force_retaddr rip=0, reload=0
14813 + .if \reload
14814 + pax_set_fptr_mask
14815 + .endif
14816 + orq %r12,\rip(%rsp)
14817 + .endm
14818 + .macro pax_force_fptr ptr
14819 + orq %r12,\ptr
14820 + .endm
14821 + .macro pax_set_fptr_mask
14822 + movabs $0x8000000000000000,%r12
14823 + .endm
14824 +#endif
14825 +#else
14826 + .macro pax_force_retaddr rip=0, reload=0
14827 + .endm
14828 + .macro pax_force_fptr ptr
14829 + .endm
14830 + .macro pax_force_retaddr_bts rip=0
14831 + .endm
14832 + .macro pax_set_fptr_mask
14833 + .endm
14834 +#endif
14835 +
14836 .macro altinstruction_entry orig alt feature orig_len alt_len
14837 .long \orig - .
14838 .long \alt - .
14839 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14840 index 0a3f9c9..c9d081d 100644
14841 --- a/arch/x86/include/asm/alternative.h
14842 +++ b/arch/x86/include/asm/alternative.h
14843 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14844 ".pushsection .discard,\"aw\",@progbits\n" \
14845 DISCARD_ENTRY(1) \
14846 ".popsection\n" \
14847 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14848 + ".pushsection .altinstr_replacement, \"a\"\n" \
14849 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14850 ".popsection"
14851
14852 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14853 DISCARD_ENTRY(1) \
14854 DISCARD_ENTRY(2) \
14855 ".popsection\n" \
14856 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14857 + ".pushsection .altinstr_replacement, \"a\"\n" \
14858 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14859 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14860 ".popsection"
14861 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14862 index 19b0eba..12254cd 100644
14863 --- a/arch/x86/include/asm/apic.h
14864 +++ b/arch/x86/include/asm/apic.h
14865 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14866
14867 #ifdef CONFIG_X86_LOCAL_APIC
14868
14869 -extern unsigned int apic_verbosity;
14870 +extern int apic_verbosity;
14871 extern int local_apic_timer_c2_ok;
14872
14873 extern int disable_apic;
14874 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14875 index 20370c6..a2eb9b0 100644
14876 --- a/arch/x86/include/asm/apm.h
14877 +++ b/arch/x86/include/asm/apm.h
14878 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14879 __asm__ __volatile__(APM_DO_ZERO_SEGS
14880 "pushl %%edi\n\t"
14881 "pushl %%ebp\n\t"
14882 - "lcall *%%cs:apm_bios_entry\n\t"
14883 + "lcall *%%ss:apm_bios_entry\n\t"
14884 "setc %%al\n\t"
14885 "popl %%ebp\n\t"
14886 "popl %%edi\n\t"
14887 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14888 __asm__ __volatile__(APM_DO_ZERO_SEGS
14889 "pushl %%edi\n\t"
14890 "pushl %%ebp\n\t"
14891 - "lcall *%%cs:apm_bios_entry\n\t"
14892 + "lcall *%%ss:apm_bios_entry\n\t"
14893 "setc %%bl\n\t"
14894 "popl %%ebp\n\t"
14895 "popl %%edi\n\t"
14896 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14897 index b17f4f4..9620151 100644
14898 --- a/arch/x86/include/asm/atomic.h
14899 +++ b/arch/x86/include/asm/atomic.h
14900 @@ -23,7 +23,18 @@
14901 */
14902 static inline int atomic_read(const atomic_t *v)
14903 {
14904 - return (*(volatile int *)&(v)->counter);
14905 + return (*(volatile const int *)&(v)->counter);
14906 +}
14907 +
14908 +/**
14909 + * atomic_read_unchecked - read atomic variable
14910 + * @v: pointer of type atomic_unchecked_t
14911 + *
14912 + * Atomically reads the value of @v.
14913 + */
14914 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14915 +{
14916 + return (*(volatile const int *)&(v)->counter);
14917 }
14918
14919 /**
14920 @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14921 }
14922
14923 /**
14924 + * atomic_set_unchecked - set atomic variable
14925 + * @v: pointer of type atomic_unchecked_t
14926 + * @i: required value
14927 + *
14928 + * Atomically sets the value of @v to @i.
14929 + */
14930 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14931 +{
14932 + v->counter = i;
14933 +}
14934 +
14935 +/**
14936 * atomic_add - add integer to atomic variable
14937 * @i: integer value to add
14938 * @v: pointer of type atomic_t
14939 @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14940 */
14941 static inline void atomic_add(int i, atomic_t *v)
14942 {
14943 - asm volatile(LOCK_PREFIX "addl %1,%0"
14944 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14945 +
14946 +#ifdef CONFIG_PAX_REFCOUNT
14947 + "jno 0f\n"
14948 + LOCK_PREFIX "subl %1,%0\n"
14949 + "int $4\n0:\n"
14950 + _ASM_EXTABLE(0b, 0b)
14951 +#endif
14952 +
14953 + : "+m" (v->counter)
14954 + : "ir" (i));
14955 +}
14956 +
14957 +/**
14958 + * atomic_add_unchecked - add integer to atomic variable
14959 + * @i: integer value to add
14960 + * @v: pointer of type atomic_unchecked_t
14961 + *
14962 + * Atomically adds @i to @v.
14963 + */
14964 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14965 +{
14966 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14967 : "+m" (v->counter)
14968 : "ir" (i));
14969 }
14970 @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14971 */
14972 static inline void atomic_sub(int i, atomic_t *v)
14973 {
14974 - asm volatile(LOCK_PREFIX "subl %1,%0"
14975 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14976 +
14977 +#ifdef CONFIG_PAX_REFCOUNT
14978 + "jno 0f\n"
14979 + LOCK_PREFIX "addl %1,%0\n"
14980 + "int $4\n0:\n"
14981 + _ASM_EXTABLE(0b, 0b)
14982 +#endif
14983 +
14984 + : "+m" (v->counter)
14985 + : "ir" (i));
14986 +}
14987 +
14988 +/**
14989 + * atomic_sub_unchecked - subtract integer from atomic variable
14990 + * @i: integer value to subtract
14991 + * @v: pointer of type atomic_unchecked_t
14992 + *
14993 + * Atomically subtracts @i from @v.
14994 + */
14995 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14996 +{
14997 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14998 : "+m" (v->counter)
14999 : "ir" (i));
15000 }
15001 @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15002 */
15003 static inline int atomic_sub_and_test(int i, atomic_t *v)
15004 {
15005 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15006 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15007 }
15008
15009 /**
15010 @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15011 */
15012 static inline void atomic_inc(atomic_t *v)
15013 {
15014 - asm volatile(LOCK_PREFIX "incl %0"
15015 + asm volatile(LOCK_PREFIX "incl %0\n"
15016 +
15017 +#ifdef CONFIG_PAX_REFCOUNT
15018 + "jno 0f\n"
15019 + LOCK_PREFIX "decl %0\n"
15020 + "int $4\n0:\n"
15021 + _ASM_EXTABLE(0b, 0b)
15022 +#endif
15023 +
15024 + : "+m" (v->counter));
15025 +}
15026 +
15027 +/**
15028 + * atomic_inc_unchecked - increment atomic variable
15029 + * @v: pointer of type atomic_unchecked_t
15030 + *
15031 + * Atomically increments @v by 1.
15032 + */
15033 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15034 +{
15035 + asm volatile(LOCK_PREFIX "incl %0\n"
15036 : "+m" (v->counter));
15037 }
15038
15039 @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
15040 */
15041 static inline void atomic_dec(atomic_t *v)
15042 {
15043 - asm volatile(LOCK_PREFIX "decl %0"
15044 + asm volatile(LOCK_PREFIX "decl %0\n"
15045 +
15046 +#ifdef CONFIG_PAX_REFCOUNT
15047 + "jno 0f\n"
15048 + LOCK_PREFIX "incl %0\n"
15049 + "int $4\n0:\n"
15050 + _ASM_EXTABLE(0b, 0b)
15051 +#endif
15052 +
15053 + : "+m" (v->counter));
15054 +}
15055 +
15056 +/**
15057 + * atomic_dec_unchecked - decrement atomic variable
15058 + * @v: pointer of type atomic_unchecked_t
15059 + *
15060 + * Atomically decrements @v by 1.
15061 + */
15062 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15063 +{
15064 + asm volatile(LOCK_PREFIX "decl %0\n"
15065 : "+m" (v->counter));
15066 }
15067
15068 @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15069 */
15070 static inline int atomic_dec_and_test(atomic_t *v)
15071 {
15072 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15073 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15074 }
15075
15076 /**
15077 @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15078 */
15079 static inline int atomic_inc_and_test(atomic_t *v)
15080 {
15081 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15082 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15083 +}
15084 +
15085 +/**
15086 + * atomic_inc_and_test_unchecked - increment and test
15087 + * @v: pointer of type atomic_unchecked_t
15088 + *
15089 + * Atomically increments @v by 1
15090 + * and returns true if the result is zero, or false for all
15091 + * other cases.
15092 + */
15093 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15094 +{
15095 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15096 }
15097
15098 /**
15099 @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15100 */
15101 static inline int atomic_add_negative(int i, atomic_t *v)
15102 {
15103 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15104 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15105 }
15106
15107 /**
15108 @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15109 */
15110 static inline int atomic_add_return(int i, atomic_t *v)
15111 {
15112 + return i + xadd_check_overflow(&v->counter, i);
15113 +}
15114 +
15115 +/**
15116 + * atomic_add_return_unchecked - add integer and return
15117 + * @i: integer value to add
15118 + * @v: pointer of type atomic_unchecked_t
15119 + *
15120 + * Atomically adds @i to @v and returns @i + @v
15121 + */
15122 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15123 +{
15124 return i + xadd(&v->counter, i);
15125 }
15126
15127 @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15128 }
15129
15130 #define atomic_inc_return(v) (atomic_add_return(1, v))
15131 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15132 +{
15133 + return atomic_add_return_unchecked(1, v);
15134 +}
15135 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15136
15137 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15138 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15139 +{
15140 + return cmpxchg(&v->counter, old, new);
15141 +}
15142 +
15143 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15144 {
15145 return cmpxchg(&v->counter, old, new);
15146 }
15147 @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15148 return xchg(&v->counter, new);
15149 }
15150
15151 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15152 +{
15153 + return xchg(&v->counter, new);
15154 +}
15155 +
15156 /**
15157 * __atomic_add_unless - add unless the number is already a given value
15158 * @v: pointer of type atomic_t
15159 @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15160 * Atomically adds @a to @v, so long as @v was not already @u.
15161 * Returns the old value of @v.
15162 */
15163 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15164 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15165 {
15166 - int c, old;
15167 + int c, old, new;
15168 c = atomic_read(v);
15169 for (;;) {
15170 - if (unlikely(c == (u)))
15171 + if (unlikely(c == u))
15172 break;
15173 - old = atomic_cmpxchg((v), c, c + (a));
15174 +
15175 + asm volatile("addl %2,%0\n"
15176 +
15177 +#ifdef CONFIG_PAX_REFCOUNT
15178 + "jno 0f\n"
15179 + "subl %2,%0\n"
15180 + "int $4\n0:\n"
15181 + _ASM_EXTABLE(0b, 0b)
15182 +#endif
15183 +
15184 + : "=r" (new)
15185 + : "0" (c), "ir" (a));
15186 +
15187 + old = atomic_cmpxchg(v, c, new);
15188 if (likely(old == c))
15189 break;
15190 c = old;
15191 @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15192 }
15193
15194 /**
15195 + * atomic_inc_not_zero_hint - increment if not null
15196 + * @v: pointer of type atomic_t
15197 + * @hint: probable value of the atomic before the increment
15198 + *
15199 + * This version of atomic_inc_not_zero() gives a hint of probable
15200 + * value of the atomic. This helps processor to not read the memory
15201 + * before doing the atomic read/modify/write cycle, lowering
15202 + * number of bus transactions on some arches.
15203 + *
15204 + * Returns: 0 if increment was not done, 1 otherwise.
15205 + */
15206 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15207 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15208 +{
15209 + int val, c = hint, new;
15210 +
15211 + /* sanity test, should be removed by compiler if hint is a constant */
15212 + if (!hint)
15213 + return __atomic_add_unless(v, 1, 0);
15214 +
15215 + do {
15216 + asm volatile("incl %0\n"
15217 +
15218 +#ifdef CONFIG_PAX_REFCOUNT
15219 + "jno 0f\n"
15220 + "decl %0\n"
15221 + "int $4\n0:\n"
15222 + _ASM_EXTABLE(0b, 0b)
15223 +#endif
15224 +
15225 + : "=r" (new)
15226 + : "0" (c));
15227 +
15228 + val = atomic_cmpxchg(v, c, new);
15229 + if (val == c)
15230 + return 1;
15231 + c = val;
15232 + } while (c);
15233 +
15234 + return 0;
15235 +}
15236 +
15237 +/**
15238 * atomic_inc_short - increment of a short integer
15239 * @v: pointer to type int
15240 *
15241 @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15242 #endif
15243
15244 /* These are x86-specific, used by some header files */
15245 -#define atomic_clear_mask(mask, addr) \
15246 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15247 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15248 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15249 +{
15250 + asm volatile(LOCK_PREFIX "andl %1,%0"
15251 + : "+m" (v->counter)
15252 + : "r" (~(mask))
15253 + : "memory");
15254 +}
15255
15256 -#define atomic_set_mask(mask, addr) \
15257 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15258 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15259 - : "memory")
15260 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15261 +{
15262 + asm volatile(LOCK_PREFIX "andl %1,%0"
15263 + : "+m" (v->counter)
15264 + : "r" (~(mask))
15265 + : "memory");
15266 +}
15267 +
15268 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15269 +{
15270 + asm volatile(LOCK_PREFIX "orl %1,%0"
15271 + : "+m" (v->counter)
15272 + : "r" (mask)
15273 + : "memory");
15274 +}
15275 +
15276 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15277 +{
15278 + asm volatile(LOCK_PREFIX "orl %1,%0"
15279 + : "+m" (v->counter)
15280 + : "r" (mask)
15281 + : "memory");
15282 +}
15283
15284 /* Atomic operations are already serializing on x86 */
15285 #define smp_mb__before_atomic_dec() barrier()
15286 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15287 index b154de7..bf18a5a 100644
15288 --- a/arch/x86/include/asm/atomic64_32.h
15289 +++ b/arch/x86/include/asm/atomic64_32.h
15290 @@ -12,6 +12,14 @@ typedef struct {
15291 u64 __aligned(8) counter;
15292 } atomic64_t;
15293
15294 +#ifdef CONFIG_PAX_REFCOUNT
15295 +typedef struct {
15296 + u64 __aligned(8) counter;
15297 +} atomic64_unchecked_t;
15298 +#else
15299 +typedef atomic64_t atomic64_unchecked_t;
15300 +#endif
15301 +
15302 #define ATOMIC64_INIT(val) { (val) }
15303
15304 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15305 @@ -37,21 +45,31 @@ typedef struct {
15306 ATOMIC64_DECL_ONE(sym##_386)
15307
15308 ATOMIC64_DECL_ONE(add_386);
15309 +ATOMIC64_DECL_ONE(add_unchecked_386);
15310 ATOMIC64_DECL_ONE(sub_386);
15311 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15312 ATOMIC64_DECL_ONE(inc_386);
15313 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15314 ATOMIC64_DECL_ONE(dec_386);
15315 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15316 #endif
15317
15318 #define alternative_atomic64(f, out, in...) \
15319 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15320
15321 ATOMIC64_DECL(read);
15322 +ATOMIC64_DECL(read_unchecked);
15323 ATOMIC64_DECL(set);
15324 +ATOMIC64_DECL(set_unchecked);
15325 ATOMIC64_DECL(xchg);
15326 ATOMIC64_DECL(add_return);
15327 +ATOMIC64_DECL(add_return_unchecked);
15328 ATOMIC64_DECL(sub_return);
15329 +ATOMIC64_DECL(sub_return_unchecked);
15330 ATOMIC64_DECL(inc_return);
15331 +ATOMIC64_DECL(inc_return_unchecked);
15332 ATOMIC64_DECL(dec_return);
15333 +ATOMIC64_DECL(dec_return_unchecked);
15334 ATOMIC64_DECL(dec_if_positive);
15335 ATOMIC64_DECL(inc_not_zero);
15336 ATOMIC64_DECL(add_unless);
15337 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15338 }
15339
15340 /**
15341 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15342 + * @p: pointer to type atomic64_unchecked_t
15343 + * @o: expected value
15344 + * @n: new value
15345 + *
15346 + * Atomically sets @v to @n if it was equal to @o and returns
15347 + * the old value.
15348 + */
15349 +
15350 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15351 +{
15352 + return cmpxchg64(&v->counter, o, n);
15353 +}
15354 +
15355 +/**
15356 * atomic64_xchg - xchg atomic64 variable
15357 * @v: pointer to type atomic64_t
15358 * @n: value to assign
15359 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15360 }
15361
15362 /**
15363 + * atomic64_set_unchecked - set atomic64 variable
15364 + * @v: pointer to type atomic64_unchecked_t
15365 + * @n: value to assign
15366 + *
15367 + * Atomically sets the value of @v to @n.
15368 + */
15369 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15370 +{
15371 + unsigned high = (unsigned)(i >> 32);
15372 + unsigned low = (unsigned)i;
15373 + alternative_atomic64(set, /* no output */,
15374 + "S" (v), "b" (low), "c" (high)
15375 + : "eax", "edx", "memory");
15376 +}
15377 +
15378 +/**
15379 * atomic64_read - read atomic64 variable
15380 * @v: pointer to type atomic64_t
15381 *
15382 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15383 }
15384
15385 /**
15386 + * atomic64_read_unchecked - read atomic64 variable
15387 + * @v: pointer to type atomic64_unchecked_t
15388 + *
15389 + * Atomically reads the value of @v and returns it.
15390 + */
15391 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15392 +{
15393 + long long r;
15394 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15395 + return r;
15396 + }
15397 +
15398 +/**
15399 * atomic64_add_return - add and return
15400 * @i: integer value to add
15401 * @v: pointer to type atomic64_t
15402 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15403 return i;
15404 }
15405
15406 +/**
15407 + * atomic64_add_return_unchecked - add and return
15408 + * @i: integer value to add
15409 + * @v: pointer to type atomic64_unchecked_t
15410 + *
15411 + * Atomically adds @i to @v and returns @i + *@v
15412 + */
15413 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15414 +{
15415 + alternative_atomic64(add_return_unchecked,
15416 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15417 + ASM_NO_INPUT_CLOBBER("memory"));
15418 + return i;
15419 +}
15420 +
15421 /*
15422 * Other variants with different arithmetic operators:
15423 */
15424 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15425 return a;
15426 }
15427
15428 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15429 +{
15430 + long long a;
15431 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15432 + "S" (v) : "memory", "ecx");
15433 + return a;
15434 +}
15435 +
15436 static inline long long atomic64_dec_return(atomic64_t *v)
15437 {
15438 long long a;
15439 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15440 }
15441
15442 /**
15443 + * atomic64_add_unchecked - add integer to atomic64 variable
15444 + * @i: integer value to add
15445 + * @v: pointer to type atomic64_unchecked_t
15446 + *
15447 + * Atomically adds @i to @v.
15448 + */
15449 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15450 +{
15451 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15452 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15453 + ASM_NO_INPUT_CLOBBER("memory"));
15454 + return i;
15455 +}
15456 +
15457 +/**
15458 * atomic64_sub - subtract the atomic64 variable
15459 * @i: integer value to subtract
15460 * @v: pointer to type atomic64_t
15461 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15462 index 46e9052..ae45136 100644
15463 --- a/arch/x86/include/asm/atomic64_64.h
15464 +++ b/arch/x86/include/asm/atomic64_64.h
15465 @@ -18,7 +18,19 @@
15466 */
15467 static inline long atomic64_read(const atomic64_t *v)
15468 {
15469 - return (*(volatile long *)&(v)->counter);
15470 + return (*(volatile const long *)&(v)->counter);
15471 +}
15472 +
15473 +/**
15474 + * atomic64_read_unchecked - read atomic64 variable
15475 + * @v: pointer of type atomic64_unchecked_t
15476 + *
15477 + * Atomically reads the value of @v.
15478 + * Doesn't imply a read memory barrier.
15479 + */
15480 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15481 +{
15482 + return (*(volatile const long *)&(v)->counter);
15483 }
15484
15485 /**
15486 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15487 }
15488
15489 /**
15490 + * atomic64_set_unchecked - set atomic64 variable
15491 + * @v: pointer to type atomic64_unchecked_t
15492 + * @i: required value
15493 + *
15494 + * Atomically sets the value of @v to @i.
15495 + */
15496 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15497 +{
15498 + v->counter = i;
15499 +}
15500 +
15501 +/**
15502 * atomic64_add - add integer to atomic64 variable
15503 * @i: integer value to add
15504 * @v: pointer to type atomic64_t
15505 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15506 */
15507 static inline void atomic64_add(long i, atomic64_t *v)
15508 {
15509 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15510 +
15511 +#ifdef CONFIG_PAX_REFCOUNT
15512 + "jno 0f\n"
15513 + LOCK_PREFIX "subq %1,%0\n"
15514 + "int $4\n0:\n"
15515 + _ASM_EXTABLE(0b, 0b)
15516 +#endif
15517 +
15518 + : "=m" (v->counter)
15519 + : "er" (i), "m" (v->counter));
15520 +}
15521 +
15522 +/**
15523 + * atomic64_add_unchecked - add integer to atomic64 variable
15524 + * @i: integer value to add
15525 + * @v: pointer to type atomic64_unchecked_t
15526 + *
15527 + * Atomically adds @i to @v.
15528 + */
15529 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15530 +{
15531 asm volatile(LOCK_PREFIX "addq %1,%0"
15532 : "=m" (v->counter)
15533 : "er" (i), "m" (v->counter));
15534 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15535 */
15536 static inline void atomic64_sub(long i, atomic64_t *v)
15537 {
15538 - asm volatile(LOCK_PREFIX "subq %1,%0"
15539 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15540 +
15541 +#ifdef CONFIG_PAX_REFCOUNT
15542 + "jno 0f\n"
15543 + LOCK_PREFIX "addq %1,%0\n"
15544 + "int $4\n0:\n"
15545 + _ASM_EXTABLE(0b, 0b)
15546 +#endif
15547 +
15548 + : "=m" (v->counter)
15549 + : "er" (i), "m" (v->counter));
15550 +}
15551 +
15552 +/**
15553 + * atomic64_sub_unchecked - subtract the atomic64 variable
15554 + * @i: integer value to subtract
15555 + * @v: pointer to type atomic64_unchecked_t
15556 + *
15557 + * Atomically subtracts @i from @v.
15558 + */
15559 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15560 +{
15561 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15562 : "=m" (v->counter)
15563 : "er" (i), "m" (v->counter));
15564 }
15565 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15566 */
15567 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15568 {
15569 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15570 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15571 }
15572
15573 /**
15574 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15575 */
15576 static inline void atomic64_inc(atomic64_t *v)
15577 {
15578 + asm volatile(LOCK_PREFIX "incq %0\n"
15579 +
15580 +#ifdef CONFIG_PAX_REFCOUNT
15581 + "jno 0f\n"
15582 + LOCK_PREFIX "decq %0\n"
15583 + "int $4\n0:\n"
15584 + _ASM_EXTABLE(0b, 0b)
15585 +#endif
15586 +
15587 + : "=m" (v->counter)
15588 + : "m" (v->counter));
15589 +}
15590 +
15591 +/**
15592 + * atomic64_inc_unchecked - increment atomic64 variable
15593 + * @v: pointer to type atomic64_unchecked_t
15594 + *
15595 + * Atomically increments @v by 1.
15596 + */
15597 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15598 +{
15599 asm volatile(LOCK_PREFIX "incq %0"
15600 : "=m" (v->counter)
15601 : "m" (v->counter));
15602 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15603 */
15604 static inline void atomic64_dec(atomic64_t *v)
15605 {
15606 - asm volatile(LOCK_PREFIX "decq %0"
15607 + asm volatile(LOCK_PREFIX "decq %0\n"
15608 +
15609 +#ifdef CONFIG_PAX_REFCOUNT
15610 + "jno 0f\n"
15611 + LOCK_PREFIX "incq %0\n"
15612 + "int $4\n0:\n"
15613 + _ASM_EXTABLE(0b, 0b)
15614 +#endif
15615 +
15616 + : "=m" (v->counter)
15617 + : "m" (v->counter));
15618 +}
15619 +
15620 +/**
15621 + * atomic64_dec_unchecked - decrement atomic64 variable
15622 + * @v: pointer to type atomic64_t
15623 + *
15624 + * Atomically decrements @v by 1.
15625 + */
15626 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15627 +{
15628 + asm volatile(LOCK_PREFIX "decq %0\n"
15629 : "=m" (v->counter)
15630 : "m" (v->counter));
15631 }
15632 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15633 */
15634 static inline int atomic64_dec_and_test(atomic64_t *v)
15635 {
15636 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15637 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15638 }
15639
15640 /**
15641 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15642 */
15643 static inline int atomic64_inc_and_test(atomic64_t *v)
15644 {
15645 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15646 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15647 }
15648
15649 /**
15650 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15651 */
15652 static inline int atomic64_add_negative(long i, atomic64_t *v)
15653 {
15654 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15655 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15656 }
15657
15658 /**
15659 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15660 */
15661 static inline long atomic64_add_return(long i, atomic64_t *v)
15662 {
15663 + return i + xadd_check_overflow(&v->counter, i);
15664 +}
15665 +
15666 +/**
15667 + * atomic64_add_return_unchecked - add and return
15668 + * @i: integer value to add
15669 + * @v: pointer to type atomic64_unchecked_t
15670 + *
15671 + * Atomically adds @i to @v and returns @i + @v
15672 + */
15673 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15674 +{
15675 return i + xadd(&v->counter, i);
15676 }
15677
15678 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15679 }
15680
15681 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15682 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15683 +{
15684 + return atomic64_add_return_unchecked(1, v);
15685 +}
15686 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15687
15688 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15689 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15690 return cmpxchg(&v->counter, old, new);
15691 }
15692
15693 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15694 +{
15695 + return cmpxchg(&v->counter, old, new);
15696 +}
15697 +
15698 static inline long atomic64_xchg(atomic64_t *v, long new)
15699 {
15700 return xchg(&v->counter, new);
15701 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15702 */
15703 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15704 {
15705 - long c, old;
15706 + long c, old, new;
15707 c = atomic64_read(v);
15708 for (;;) {
15709 - if (unlikely(c == (u)))
15710 + if (unlikely(c == u))
15711 break;
15712 - old = atomic64_cmpxchg((v), c, c + (a));
15713 +
15714 + asm volatile("add %2,%0\n"
15715 +
15716 +#ifdef CONFIG_PAX_REFCOUNT
15717 + "jno 0f\n"
15718 + "sub %2,%0\n"
15719 + "int $4\n0:\n"
15720 + _ASM_EXTABLE(0b, 0b)
15721 +#endif
15722 +
15723 + : "=r" (new)
15724 + : "0" (c), "ir" (a));
15725 +
15726 + old = atomic64_cmpxchg(v, c, new);
15727 if (likely(old == c))
15728 break;
15729 c = old;
15730 }
15731 - return c != (u);
15732 + return c != u;
15733 }
15734
15735 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15736 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
15737 index 69bbb48..32517fe 100644
15738 --- a/arch/x86/include/asm/barrier.h
15739 +++ b/arch/x86/include/asm/barrier.h
15740 @@ -107,7 +107,7 @@
15741 do { \
15742 compiletime_assert_atomic_type(*p); \
15743 smp_mb(); \
15744 - ACCESS_ONCE(*p) = (v); \
15745 + ACCESS_ONCE_RW(*p) = (v); \
15746 } while (0)
15747
15748 #define smp_load_acquire(p) \
15749 @@ -124,7 +124,7 @@ do { \
15750 do { \
15751 compiletime_assert_atomic_type(*p); \
15752 barrier(); \
15753 - ACCESS_ONCE(*p) = (v); \
15754 + ACCESS_ONCE_RW(*p) = (v); \
15755 } while (0)
15756
15757 #define smp_load_acquire(p) \
15758 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15759 index 9fc1af7..776d75a 100644
15760 --- a/arch/x86/include/asm/bitops.h
15761 +++ b/arch/x86/include/asm/bitops.h
15762 @@ -49,7 +49,7 @@
15763 * a mask operation on a byte.
15764 */
15765 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15766 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15767 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15768 #define CONST_MASK(nr) (1 << ((nr) & 7))
15769
15770 /**
15771 @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15772 */
15773 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15774 {
15775 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15776 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15777 }
15778
15779 /**
15780 @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15781 */
15782 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15783 {
15784 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15785 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15786 }
15787
15788 /**
15789 @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15790 */
15791 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15792 {
15793 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15794 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15795 }
15796
15797 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15798 @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15799 *
15800 * Undefined if no bit exists, so code should check against 0 first.
15801 */
15802 -static inline unsigned long __ffs(unsigned long word)
15803 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15804 {
15805 asm("rep; bsf %1,%0"
15806 : "=r" (word)
15807 @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15808 *
15809 * Undefined if no zero exists, so code should check against ~0UL first.
15810 */
15811 -static inline unsigned long ffz(unsigned long word)
15812 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15813 {
15814 asm("rep; bsf %1,%0"
15815 : "=r" (word)
15816 @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15817 *
15818 * Undefined if no set bit exists, so code should check against 0 first.
15819 */
15820 -static inline unsigned long __fls(unsigned long word)
15821 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15822 {
15823 asm("bsr %1,%0"
15824 : "=r" (word)
15825 @@ -436,7 +436,7 @@ static inline int ffs(int x)
15826 * set bit if value is nonzero. The last (most significant) bit is
15827 * at position 32.
15828 */
15829 -static inline int fls(int x)
15830 +static inline int __intentional_overflow(-1) fls(int x)
15831 {
15832 int r;
15833
15834 @@ -478,7 +478,7 @@ static inline int fls(int x)
15835 * at position 64.
15836 */
15837 #ifdef CONFIG_X86_64
15838 -static __always_inline int fls64(__u64 x)
15839 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
15840 {
15841 int bitpos = -1;
15842 /*
15843 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15844 index 4fa687a..60f2d39 100644
15845 --- a/arch/x86/include/asm/boot.h
15846 +++ b/arch/x86/include/asm/boot.h
15847 @@ -6,10 +6,15 @@
15848 #include <uapi/asm/boot.h>
15849
15850 /* Physical address where kernel should be loaded. */
15851 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15852 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15853 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15854 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15855
15856 +#ifndef __ASSEMBLY__
15857 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
15858 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15859 +#endif
15860 +
15861 /* Minimum kernel alignment, as a power of two */
15862 #ifdef CONFIG_X86_64
15863 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15864 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15865 index 48f99f1..d78ebf9 100644
15866 --- a/arch/x86/include/asm/cache.h
15867 +++ b/arch/x86/include/asm/cache.h
15868 @@ -5,12 +5,13 @@
15869
15870 /* L1 cache line size */
15871 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15872 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15873 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15874
15875 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15876 +#define __read_only __attribute__((__section__(".data..read_only")))
15877
15878 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15879 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15880 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15881
15882 #ifdef CONFIG_X86_VSMP
15883 #ifdef CONFIG_SMP
15884 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15885 index 9863ee3..4a1f8e1 100644
15886 --- a/arch/x86/include/asm/cacheflush.h
15887 +++ b/arch/x86/include/asm/cacheflush.h
15888 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15889 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15890
15891 if (pg_flags == _PGMT_DEFAULT)
15892 - return -1;
15893 + return ~0UL;
15894 else if (pg_flags == _PGMT_WC)
15895 return _PAGE_CACHE_WC;
15896 else if (pg_flags == _PGMT_UC_MINUS)
15897 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15898 index cb4c73b..c473c29 100644
15899 --- a/arch/x86/include/asm/calling.h
15900 +++ b/arch/x86/include/asm/calling.h
15901 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15902 #define RSP 152
15903 #define SS 160
15904
15905 -#define ARGOFFSET R11
15906 -#define SWFRAME ORIG_RAX
15907 +#define ARGOFFSET R15
15908
15909 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15910 - subq $9*8+\addskip, %rsp
15911 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15912 - movq_cfi rdi, 8*8
15913 - movq_cfi rsi, 7*8
15914 - movq_cfi rdx, 6*8
15915 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15916 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15917 + movq_cfi rdi, RDI
15918 + movq_cfi rsi, RSI
15919 + movq_cfi rdx, RDX
15920
15921 .if \save_rcx
15922 - movq_cfi rcx, 5*8
15923 + movq_cfi rcx, RCX
15924 .endif
15925
15926 - movq_cfi rax, 4*8
15927 + movq_cfi rax, RAX
15928
15929 .if \save_r891011
15930 - movq_cfi r8, 3*8
15931 - movq_cfi r9, 2*8
15932 - movq_cfi r10, 1*8
15933 - movq_cfi r11, 0*8
15934 + movq_cfi r8, R8
15935 + movq_cfi r9, R9
15936 + movq_cfi r10, R10
15937 + movq_cfi r11, R11
15938 .endif
15939
15940 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15941 + movq_cfi r12, R12
15942 +#endif
15943 +
15944 .endm
15945
15946 -#define ARG_SKIP (9*8)
15947 +#define ARG_SKIP ORIG_RAX
15948
15949 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15950 rstor_r8910=1, rstor_rdx=1
15951 +
15952 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15953 + movq_cfi_restore R12, r12
15954 +#endif
15955 +
15956 .if \rstor_r11
15957 - movq_cfi_restore 0*8, r11
15958 + movq_cfi_restore R11, r11
15959 .endif
15960
15961 .if \rstor_r8910
15962 - movq_cfi_restore 1*8, r10
15963 - movq_cfi_restore 2*8, r9
15964 - movq_cfi_restore 3*8, r8
15965 + movq_cfi_restore R10, r10
15966 + movq_cfi_restore R9, r9
15967 + movq_cfi_restore R8, r8
15968 .endif
15969
15970 .if \rstor_rax
15971 - movq_cfi_restore 4*8, rax
15972 + movq_cfi_restore RAX, rax
15973 .endif
15974
15975 .if \rstor_rcx
15976 - movq_cfi_restore 5*8, rcx
15977 + movq_cfi_restore RCX, rcx
15978 .endif
15979
15980 .if \rstor_rdx
15981 - movq_cfi_restore 6*8, rdx
15982 + movq_cfi_restore RDX, rdx
15983 .endif
15984
15985 - movq_cfi_restore 7*8, rsi
15986 - movq_cfi_restore 8*8, rdi
15987 + movq_cfi_restore RSI, rsi
15988 + movq_cfi_restore RDI, rdi
15989
15990 - .if ARG_SKIP+\addskip > 0
15991 - addq $ARG_SKIP+\addskip, %rsp
15992 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15993 + .if ORIG_RAX+\addskip > 0
15994 + addq $ORIG_RAX+\addskip, %rsp
15995 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15996 .endif
15997 .endm
15998
15999 - .macro LOAD_ARGS offset, skiprax=0
16000 - movq \offset(%rsp), %r11
16001 - movq \offset+8(%rsp), %r10
16002 - movq \offset+16(%rsp), %r9
16003 - movq \offset+24(%rsp), %r8
16004 - movq \offset+40(%rsp), %rcx
16005 - movq \offset+48(%rsp), %rdx
16006 - movq \offset+56(%rsp), %rsi
16007 - movq \offset+64(%rsp), %rdi
16008 + .macro LOAD_ARGS skiprax=0
16009 + movq R11(%rsp), %r11
16010 + movq R10(%rsp), %r10
16011 + movq R9(%rsp), %r9
16012 + movq R8(%rsp), %r8
16013 + movq RCX(%rsp), %rcx
16014 + movq RDX(%rsp), %rdx
16015 + movq RSI(%rsp), %rsi
16016 + movq RDI(%rsp), %rdi
16017 .if \skiprax
16018 .else
16019 - movq \offset+72(%rsp), %rax
16020 + movq RAX(%rsp), %rax
16021 .endif
16022 .endm
16023
16024 -#define REST_SKIP (6*8)
16025 -
16026 .macro SAVE_REST
16027 - subq $REST_SKIP, %rsp
16028 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16029 - movq_cfi rbx, 5*8
16030 - movq_cfi rbp, 4*8
16031 - movq_cfi r12, 3*8
16032 - movq_cfi r13, 2*8
16033 - movq_cfi r14, 1*8
16034 - movq_cfi r15, 0*8
16035 + movq_cfi rbx, RBX
16036 + movq_cfi rbp, RBP
16037 +
16038 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16039 + movq_cfi r12, R12
16040 +#endif
16041 +
16042 + movq_cfi r13, R13
16043 + movq_cfi r14, R14
16044 + movq_cfi r15, R15
16045 .endm
16046
16047 .macro RESTORE_REST
16048 - movq_cfi_restore 0*8, r15
16049 - movq_cfi_restore 1*8, r14
16050 - movq_cfi_restore 2*8, r13
16051 - movq_cfi_restore 3*8, r12
16052 - movq_cfi_restore 4*8, rbp
16053 - movq_cfi_restore 5*8, rbx
16054 - addq $REST_SKIP, %rsp
16055 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16056 + movq_cfi_restore R15, r15
16057 + movq_cfi_restore R14, r14
16058 + movq_cfi_restore R13, r13
16059 +
16060 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16061 + movq_cfi_restore R12, r12
16062 +#endif
16063 +
16064 + movq_cfi_restore RBP, rbp
16065 + movq_cfi_restore RBX, rbx
16066 .endm
16067
16068 .macro SAVE_ALL
16069 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16070 index f50de69..2b0a458 100644
16071 --- a/arch/x86/include/asm/checksum_32.h
16072 +++ b/arch/x86/include/asm/checksum_32.h
16073 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16074 int len, __wsum sum,
16075 int *src_err_ptr, int *dst_err_ptr);
16076
16077 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16078 + int len, __wsum sum,
16079 + int *src_err_ptr, int *dst_err_ptr);
16080 +
16081 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16082 + int len, __wsum sum,
16083 + int *src_err_ptr, int *dst_err_ptr);
16084 +
16085 /*
16086 * Note: when you get a NULL pointer exception here this means someone
16087 * passed in an incorrect kernel address to one of these functions.
16088 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16089
16090 might_sleep();
16091 stac();
16092 - ret = csum_partial_copy_generic((__force void *)src, dst,
16093 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16094 len, sum, err_ptr, NULL);
16095 clac();
16096
16097 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16098 might_sleep();
16099 if (access_ok(VERIFY_WRITE, dst, len)) {
16100 stac();
16101 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16102 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16103 len, sum, NULL, err_ptr);
16104 clac();
16105 return ret;
16106 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16107 index d47786a..2d8883e 100644
16108 --- a/arch/x86/include/asm/cmpxchg.h
16109 +++ b/arch/x86/include/asm/cmpxchg.h
16110 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16111 __compiletime_error("Bad argument size for cmpxchg");
16112 extern void __xadd_wrong_size(void)
16113 __compiletime_error("Bad argument size for xadd");
16114 +extern void __xadd_check_overflow_wrong_size(void)
16115 + __compiletime_error("Bad argument size for xadd_check_overflow");
16116 extern void __add_wrong_size(void)
16117 __compiletime_error("Bad argument size for add");
16118 +extern void __add_check_overflow_wrong_size(void)
16119 + __compiletime_error("Bad argument size for add_check_overflow");
16120
16121 /*
16122 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16123 @@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16124 __ret; \
16125 })
16126
16127 +#ifdef CONFIG_PAX_REFCOUNT
16128 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16129 + ({ \
16130 + __typeof__ (*(ptr)) __ret = (arg); \
16131 + switch (sizeof(*(ptr))) { \
16132 + case __X86_CASE_L: \
16133 + asm volatile (lock #op "l %0, %1\n" \
16134 + "jno 0f\n" \
16135 + "mov %0,%1\n" \
16136 + "int $4\n0:\n" \
16137 + _ASM_EXTABLE(0b, 0b) \
16138 + : "+r" (__ret), "+m" (*(ptr)) \
16139 + : : "memory", "cc"); \
16140 + break; \
16141 + case __X86_CASE_Q: \
16142 + asm volatile (lock #op "q %q0, %1\n" \
16143 + "jno 0f\n" \
16144 + "mov %0,%1\n" \
16145 + "int $4\n0:\n" \
16146 + _ASM_EXTABLE(0b, 0b) \
16147 + : "+r" (__ret), "+m" (*(ptr)) \
16148 + : : "memory", "cc"); \
16149 + break; \
16150 + default: \
16151 + __ ## op ## _check_overflow_wrong_size(); \
16152 + } \
16153 + __ret; \
16154 + })
16155 +#else
16156 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16157 +#endif
16158 +
16159 /*
16160 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16161 * Since this is generally used to protect other memory information, we
16162 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16163 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16164 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16165
16166 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16167 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16168 +
16169 #define __add(ptr, inc, lock) \
16170 ({ \
16171 __typeof__ (*(ptr)) __ret = (inc); \
16172 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16173 index 59c6c40..5e0b22c 100644
16174 --- a/arch/x86/include/asm/compat.h
16175 +++ b/arch/x86/include/asm/compat.h
16176 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16177 typedef u32 compat_uint_t;
16178 typedef u32 compat_ulong_t;
16179 typedef u64 __attribute__((aligned(4))) compat_u64;
16180 -typedef u32 compat_uptr_t;
16181 +typedef u32 __user compat_uptr_t;
16182
16183 struct compat_timespec {
16184 compat_time_t tv_sec;
16185 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16186 index e265ff9..72c253b 100644
16187 --- a/arch/x86/include/asm/cpufeature.h
16188 +++ b/arch/x86/include/asm/cpufeature.h
16189 @@ -203,7 +203,7 @@
16190 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16191 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16192 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16193 -
16194 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16195
16196 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16197 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16198 @@ -211,7 +211,7 @@
16199 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16200 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16201 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16202 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16203 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16204 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16205 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16206 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16207 @@ -359,6 +359,7 @@ extern const char * const x86_power_flags[32];
16208 #undef cpu_has_centaur_mcr
16209 #define cpu_has_centaur_mcr 0
16210
16211 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16212 #endif /* CONFIG_X86_64 */
16213
16214 #if __GNUC__ >= 4
16215 @@ -411,7 +412,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16216
16217 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16218 t_warn:
16219 - warn_pre_alternatives();
16220 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16221 + warn_pre_alternatives();
16222 return false;
16223 #endif
16224
16225 @@ -431,7 +433,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16226 ".section .discard,\"aw\",@progbits\n"
16227 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16228 ".previous\n"
16229 - ".section .altinstr_replacement,\"ax\"\n"
16230 + ".section .altinstr_replacement,\"a\"\n"
16231 "3: movb $1,%0\n"
16232 "4:\n"
16233 ".previous\n"
16234 @@ -468,7 +470,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16235 " .byte 2b - 1b\n" /* src len */
16236 " .byte 4f - 3f\n" /* repl len */
16237 ".previous\n"
16238 - ".section .altinstr_replacement,\"ax\"\n"
16239 + ".section .altinstr_replacement,\"a\"\n"
16240 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16241 "4:\n"
16242 ".previous\n"
16243 @@ -501,7 +503,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16244 ".section .discard,\"aw\",@progbits\n"
16245 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16246 ".previous\n"
16247 - ".section .altinstr_replacement,\"ax\"\n"
16248 + ".section .altinstr_replacement,\"a\"\n"
16249 "3: movb $0,%0\n"
16250 "4:\n"
16251 ".previous\n"
16252 @@ -515,7 +517,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16253 ".section .discard,\"aw\",@progbits\n"
16254 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16255 ".previous\n"
16256 - ".section .altinstr_replacement,\"ax\"\n"
16257 + ".section .altinstr_replacement,\"a\"\n"
16258 "5: movb $1,%0\n"
16259 "6:\n"
16260 ".previous\n"
16261 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16262 index 50d033a..37deb26 100644
16263 --- a/arch/x86/include/asm/desc.h
16264 +++ b/arch/x86/include/asm/desc.h
16265 @@ -4,6 +4,7 @@
16266 #include <asm/desc_defs.h>
16267 #include <asm/ldt.h>
16268 #include <asm/mmu.h>
16269 +#include <asm/pgtable.h>
16270
16271 #include <linux/smp.h>
16272 #include <linux/percpu.h>
16273 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16274
16275 desc->type = (info->read_exec_only ^ 1) << 1;
16276 desc->type |= info->contents << 2;
16277 + desc->type |= info->seg_not_present ^ 1;
16278
16279 desc->s = 1;
16280 desc->dpl = 0x3;
16281 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16282 }
16283
16284 extern struct desc_ptr idt_descr;
16285 -extern gate_desc idt_table[];
16286 -extern struct desc_ptr debug_idt_descr;
16287 -extern gate_desc debug_idt_table[];
16288 -
16289 -struct gdt_page {
16290 - struct desc_struct gdt[GDT_ENTRIES];
16291 -} __attribute__((aligned(PAGE_SIZE)));
16292 -
16293 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16294 +extern gate_desc idt_table[IDT_ENTRIES];
16295 +extern const struct desc_ptr debug_idt_descr;
16296 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16297
16298 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16299 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16300 {
16301 - return per_cpu(gdt_page, cpu).gdt;
16302 + return cpu_gdt_table[cpu];
16303 }
16304
16305 #ifdef CONFIG_X86_64
16306 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16307 unsigned long base, unsigned dpl, unsigned flags,
16308 unsigned short seg)
16309 {
16310 - gate->a = (seg << 16) | (base & 0xffff);
16311 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16312 + gate->gate.offset_low = base;
16313 + gate->gate.seg = seg;
16314 + gate->gate.reserved = 0;
16315 + gate->gate.type = type;
16316 + gate->gate.s = 0;
16317 + gate->gate.dpl = dpl;
16318 + gate->gate.p = 1;
16319 + gate->gate.offset_high = base >> 16;
16320 }
16321
16322 #endif
16323 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16324
16325 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16326 {
16327 + pax_open_kernel();
16328 memcpy(&idt[entry], gate, sizeof(*gate));
16329 + pax_close_kernel();
16330 }
16331
16332 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16333 {
16334 + pax_open_kernel();
16335 memcpy(&ldt[entry], desc, 8);
16336 + pax_close_kernel();
16337 }
16338
16339 static inline void
16340 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16341 default: size = sizeof(*gdt); break;
16342 }
16343
16344 + pax_open_kernel();
16345 memcpy(&gdt[entry], desc, size);
16346 + pax_close_kernel();
16347 }
16348
16349 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16350 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16351
16352 static inline void native_load_tr_desc(void)
16353 {
16354 + pax_open_kernel();
16355 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16356 + pax_close_kernel();
16357 }
16358
16359 static inline void native_load_gdt(const struct desc_ptr *dtr)
16360 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16361 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16362 unsigned int i;
16363
16364 + pax_open_kernel();
16365 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16366 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16367 + pax_close_kernel();
16368 }
16369
16370 #define _LDT_empty(info) \
16371 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16372 preempt_enable();
16373 }
16374
16375 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16376 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16377 {
16378 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16379 }
16380 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16381 }
16382
16383 #ifdef CONFIG_X86_64
16384 -static inline void set_nmi_gate(int gate, void *addr)
16385 +static inline void set_nmi_gate(int gate, const void *addr)
16386 {
16387 gate_desc s;
16388
16389 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16390 #endif
16391
16392 #ifdef CONFIG_TRACING
16393 -extern struct desc_ptr trace_idt_descr;
16394 -extern gate_desc trace_idt_table[];
16395 +extern const struct desc_ptr trace_idt_descr;
16396 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16397 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16398 {
16399 write_idt_entry(trace_idt_table, entry, gate);
16400 }
16401
16402 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16403 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16404 unsigned dpl, unsigned ist, unsigned seg)
16405 {
16406 gate_desc s;
16407 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16408 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16409 #endif
16410
16411 -static inline void _set_gate(int gate, unsigned type, void *addr,
16412 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16413 unsigned dpl, unsigned ist, unsigned seg)
16414 {
16415 gate_desc s;
16416 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16417 #define set_intr_gate(n, addr) \
16418 do { \
16419 BUG_ON((unsigned)n > 0xFF); \
16420 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16421 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16422 __KERNEL_CS); \
16423 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16424 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16425 0, 0, __KERNEL_CS); \
16426 } while (0)
16427
16428 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16429 /*
16430 * This routine sets up an interrupt gate at directory privilege level 3.
16431 */
16432 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16433 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16434 {
16435 BUG_ON((unsigned)n > 0xFF);
16436 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16437 }
16438
16439 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16440 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16441 {
16442 BUG_ON((unsigned)n > 0xFF);
16443 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16444 }
16445
16446 -static inline void set_trap_gate(unsigned int n, void *addr)
16447 +static inline void set_trap_gate(unsigned int n, const void *addr)
16448 {
16449 BUG_ON((unsigned)n > 0xFF);
16450 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16451 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16452 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16453 {
16454 BUG_ON((unsigned)n > 0xFF);
16455 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16456 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16457 }
16458
16459 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16460 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16461 {
16462 BUG_ON((unsigned)n > 0xFF);
16463 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16464 }
16465
16466 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16467 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16468 {
16469 BUG_ON((unsigned)n > 0xFF);
16470 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16471 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16472 else
16473 load_idt((const struct desc_ptr *)&idt_descr);
16474 }
16475 +
16476 +#ifdef CONFIG_X86_32
16477 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16478 +{
16479 + struct desc_struct d;
16480 +
16481 + if (likely(limit))
16482 + limit = (limit - 1UL) >> PAGE_SHIFT;
16483 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16484 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16485 +}
16486 +#endif
16487 +
16488 #endif /* _ASM_X86_DESC_H */
16489 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16490 index 278441f..b95a174 100644
16491 --- a/arch/x86/include/asm/desc_defs.h
16492 +++ b/arch/x86/include/asm/desc_defs.h
16493 @@ -31,6 +31,12 @@ struct desc_struct {
16494 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16495 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16496 };
16497 + struct {
16498 + u16 offset_low;
16499 + u16 seg;
16500 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16501 + unsigned offset_high: 16;
16502 + } gate;
16503 };
16504 } __attribute__((packed));
16505
16506 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16507 index ced283a..ffe04cc 100644
16508 --- a/arch/x86/include/asm/div64.h
16509 +++ b/arch/x86/include/asm/div64.h
16510 @@ -39,7 +39,7 @@
16511 __mod; \
16512 })
16513
16514 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16515 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16516 {
16517 union {
16518 u64 v64;
16519 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16520 index 2c71182..731124d 100644
16521 --- a/arch/x86/include/asm/elf.h
16522 +++ b/arch/x86/include/asm/elf.h
16523 @@ -243,7 +243,25 @@ extern int force_personality32;
16524 the loader. We need to make sure that it is out of the way of the program
16525 that it will "exec", and that there is sufficient room for the brk. */
16526
16527 +#ifdef CONFIG_PAX_SEGMEXEC
16528 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16529 +#else
16530 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16531 +#endif
16532 +
16533 +#ifdef CONFIG_PAX_ASLR
16534 +#ifdef CONFIG_X86_32
16535 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16536 +
16537 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16538 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16539 +#else
16540 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16541 +
16542 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16543 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16544 +#endif
16545 +#endif
16546
16547 /* This yields a mask that user programs can use to figure out what
16548 instruction set this CPU supports. This could be done in user space,
16549 @@ -292,16 +310,12 @@ do { \
16550
16551 #define ARCH_DLINFO \
16552 do { \
16553 - if (vdso_enabled) \
16554 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16555 - (unsigned long)current->mm->context.vdso); \
16556 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16557 } while (0)
16558
16559 #define ARCH_DLINFO_X32 \
16560 do { \
16561 - if (vdso_enabled) \
16562 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16563 - (unsigned long)current->mm->context.vdso); \
16564 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16565 } while (0)
16566
16567 #define AT_SYSINFO 32
16568 @@ -316,7 +330,7 @@ else \
16569
16570 #endif /* !CONFIG_X86_32 */
16571
16572 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16573 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16574
16575 #define VDSO_ENTRY \
16576 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16577 @@ -332,9 +346,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16578 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16579 #define compat_arch_setup_additional_pages syscall32_setup_pages
16580
16581 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16582 -#define arch_randomize_brk arch_randomize_brk
16583 -
16584 /*
16585 * True on X86_32 or when emulating IA32 on X86_64
16586 */
16587 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16588 index 77a99ac..39ff7f5 100644
16589 --- a/arch/x86/include/asm/emergency-restart.h
16590 +++ b/arch/x86/include/asm/emergency-restart.h
16591 @@ -1,6 +1,6 @@
16592 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16593 #define _ASM_X86_EMERGENCY_RESTART_H
16594
16595 -extern void machine_emergency_restart(void);
16596 +extern void machine_emergency_restart(void) __noreturn;
16597
16598 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16599 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16600 index 1c7eefe..d0e4702 100644
16601 --- a/arch/x86/include/asm/floppy.h
16602 +++ b/arch/x86/include/asm/floppy.h
16603 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16604 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16605 } fd_routine[] = {
16606 {
16607 - request_dma,
16608 - free_dma,
16609 - get_dma_residue,
16610 - dma_mem_alloc,
16611 - hard_dma_setup
16612 + ._request_dma = request_dma,
16613 + ._free_dma = free_dma,
16614 + ._get_dma_residue = get_dma_residue,
16615 + ._dma_mem_alloc = dma_mem_alloc,
16616 + ._dma_setup = hard_dma_setup
16617 },
16618 {
16619 - vdma_request_dma,
16620 - vdma_nop,
16621 - vdma_get_dma_residue,
16622 - vdma_mem_alloc,
16623 - vdma_dma_setup
16624 + ._request_dma = vdma_request_dma,
16625 + ._free_dma = vdma_nop,
16626 + ._get_dma_residue = vdma_get_dma_residue,
16627 + ._dma_mem_alloc = vdma_mem_alloc,
16628 + ._dma_setup = vdma_dma_setup
16629 }
16630 };
16631
16632 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16633 index cea1c76..6c0d79b 100644
16634 --- a/arch/x86/include/asm/fpu-internal.h
16635 +++ b/arch/x86/include/asm/fpu-internal.h
16636 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16637 #define user_insn(insn, output, input...) \
16638 ({ \
16639 int err; \
16640 + pax_open_userland(); \
16641 asm volatile(ASM_STAC "\n" \
16642 - "1:" #insn "\n\t" \
16643 + "1:" \
16644 + __copyuser_seg \
16645 + #insn "\n\t" \
16646 "2: " ASM_CLAC "\n" \
16647 ".section .fixup,\"ax\"\n" \
16648 "3: movl $-1,%[err]\n" \
16649 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16650 _ASM_EXTABLE(1b, 3b) \
16651 : [err] "=r" (err), output \
16652 : "0"(0), input); \
16653 + pax_close_userland(); \
16654 err; \
16655 })
16656
16657 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16658 "fnclex\n\t"
16659 "emms\n\t"
16660 "fildl %P[addr]" /* set F?P to defined value */
16661 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16662 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16663 }
16664
16665 return fpu_restore_checking(&tsk->thread.fpu);
16666 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16667 index b4c1f54..e290c08 100644
16668 --- a/arch/x86/include/asm/futex.h
16669 +++ b/arch/x86/include/asm/futex.h
16670 @@ -12,6 +12,7 @@
16671 #include <asm/smap.h>
16672
16673 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16674 + typecheck(u32 __user *, uaddr); \
16675 asm volatile("\t" ASM_STAC "\n" \
16676 "1:\t" insn "\n" \
16677 "2:\t" ASM_CLAC "\n" \
16678 @@ -20,15 +21,16 @@
16679 "\tjmp\t2b\n" \
16680 "\t.previous\n" \
16681 _ASM_EXTABLE(1b, 3b) \
16682 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16683 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16684 : "i" (-EFAULT), "0" (oparg), "1" (0))
16685
16686 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16687 + typecheck(u32 __user *, uaddr); \
16688 asm volatile("\t" ASM_STAC "\n" \
16689 "1:\tmovl %2, %0\n" \
16690 "\tmovl\t%0, %3\n" \
16691 "\t" insn "\n" \
16692 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16693 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16694 "\tjnz\t1b\n" \
16695 "3:\t" ASM_CLAC "\n" \
16696 "\t.section .fixup,\"ax\"\n" \
16697 @@ -38,7 +40,7 @@
16698 _ASM_EXTABLE(1b, 4b) \
16699 _ASM_EXTABLE(2b, 4b) \
16700 : "=&a" (oldval), "=&r" (ret), \
16701 - "+m" (*uaddr), "=&r" (tem) \
16702 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16703 : "r" (oparg), "i" (-EFAULT), "1" (0))
16704
16705 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16706 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16707
16708 pagefault_disable();
16709
16710 + pax_open_userland();
16711 switch (op) {
16712 case FUTEX_OP_SET:
16713 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16714 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16715 break;
16716 case FUTEX_OP_ADD:
16717 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16718 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16719 uaddr, oparg);
16720 break;
16721 case FUTEX_OP_OR:
16722 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16723 default:
16724 ret = -ENOSYS;
16725 }
16726 + pax_close_userland();
16727
16728 pagefault_enable();
16729
16730 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16731 index a307b75..ec74ca2 100644
16732 --- a/arch/x86/include/asm/hw_irq.h
16733 +++ b/arch/x86/include/asm/hw_irq.h
16734 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
16735 extern void enable_IO_APIC(void);
16736
16737 /* Statistics */
16738 -extern atomic_t irq_err_count;
16739 -extern atomic_t irq_mis_count;
16740 +extern atomic_unchecked_t irq_err_count;
16741 +extern atomic_unchecked_t irq_mis_count;
16742
16743 /* EISA */
16744 extern void eisa_set_level_irq(unsigned int irq);
16745 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16746 index a203659..9889f1c 100644
16747 --- a/arch/x86/include/asm/i8259.h
16748 +++ b/arch/x86/include/asm/i8259.h
16749 @@ -62,7 +62,7 @@ struct legacy_pic {
16750 void (*init)(int auto_eoi);
16751 int (*irq_pending)(unsigned int irq);
16752 void (*make_irq)(unsigned int irq);
16753 -};
16754 +} __do_const;
16755
16756 extern struct legacy_pic *legacy_pic;
16757 extern struct legacy_pic null_legacy_pic;
16758 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16759 index b8237d8..3e8864e 100644
16760 --- a/arch/x86/include/asm/io.h
16761 +++ b/arch/x86/include/asm/io.h
16762 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16763 "m" (*(volatile type __force *)addr) barrier); }
16764
16765 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16766 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16767 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16768 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16769 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16770
16771 build_mmio_read(__readb, "b", unsigned char, "=q", )
16772 -build_mmio_read(__readw, "w", unsigned short, "=r", )
16773 -build_mmio_read(__readl, "l", unsigned int, "=r", )
16774 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16775 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16776
16777 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16778 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16779 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
16780 * this function
16781 */
16782
16783 -static inline phys_addr_t virt_to_phys(volatile void *address)
16784 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
16785 {
16786 return __pa(address);
16787 }
16788 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16789 return ioremap_nocache(offset, size);
16790 }
16791
16792 -extern void iounmap(volatile void __iomem *addr);
16793 +extern void iounmap(const volatile void __iomem *addr);
16794
16795 extern void set_iounmap_nonlazy(void);
16796
16797 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
16798
16799 #include <linux/vmalloc.h>
16800
16801 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16802 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16803 +{
16804 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16805 +}
16806 +
16807 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16808 +{
16809 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16810 +}
16811 +
16812 /*
16813 * Convert a virtual cached pointer to an uncached pointer
16814 */
16815 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16816 index bba3cf8..06bc8da 100644
16817 --- a/arch/x86/include/asm/irqflags.h
16818 +++ b/arch/x86/include/asm/irqflags.h
16819 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16820 sti; \
16821 sysexit
16822
16823 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
16824 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16825 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
16826 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16827 +
16828 #else
16829 #define INTERRUPT_RETURN iret
16830 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16831 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16832 index 9454c16..e4100e3 100644
16833 --- a/arch/x86/include/asm/kprobes.h
16834 +++ b/arch/x86/include/asm/kprobes.h
16835 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16836 #define RELATIVEJUMP_SIZE 5
16837 #define RELATIVECALL_OPCODE 0xe8
16838 #define RELATIVE_ADDR_SIZE 4
16839 -#define MAX_STACK_SIZE 64
16840 -#define MIN_STACK_SIZE(ADDR) \
16841 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16842 - THREAD_SIZE - (unsigned long)(ADDR))) \
16843 - ? (MAX_STACK_SIZE) \
16844 - : (((unsigned long)current_thread_info()) + \
16845 - THREAD_SIZE - (unsigned long)(ADDR)))
16846 +#define MAX_STACK_SIZE 64UL
16847 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16848
16849 #define flush_insn_slot(p) do { } while (0)
16850
16851 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16852 index 4ad6560..75c7bdd 100644
16853 --- a/arch/x86/include/asm/local.h
16854 +++ b/arch/x86/include/asm/local.h
16855 @@ -10,33 +10,97 @@ typedef struct {
16856 atomic_long_t a;
16857 } local_t;
16858
16859 +typedef struct {
16860 + atomic_long_unchecked_t a;
16861 +} local_unchecked_t;
16862 +
16863 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16864
16865 #define local_read(l) atomic_long_read(&(l)->a)
16866 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16867 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16868 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16869
16870 static inline void local_inc(local_t *l)
16871 {
16872 - asm volatile(_ASM_INC "%0"
16873 + asm volatile(_ASM_INC "%0\n"
16874 +
16875 +#ifdef CONFIG_PAX_REFCOUNT
16876 + "jno 0f\n"
16877 + _ASM_DEC "%0\n"
16878 + "int $4\n0:\n"
16879 + _ASM_EXTABLE(0b, 0b)
16880 +#endif
16881 +
16882 + : "+m" (l->a.counter));
16883 +}
16884 +
16885 +static inline void local_inc_unchecked(local_unchecked_t *l)
16886 +{
16887 + asm volatile(_ASM_INC "%0\n"
16888 : "+m" (l->a.counter));
16889 }
16890
16891 static inline void local_dec(local_t *l)
16892 {
16893 - asm volatile(_ASM_DEC "%0"
16894 + asm volatile(_ASM_DEC "%0\n"
16895 +
16896 +#ifdef CONFIG_PAX_REFCOUNT
16897 + "jno 0f\n"
16898 + _ASM_INC "%0\n"
16899 + "int $4\n0:\n"
16900 + _ASM_EXTABLE(0b, 0b)
16901 +#endif
16902 +
16903 + : "+m" (l->a.counter));
16904 +}
16905 +
16906 +static inline void local_dec_unchecked(local_unchecked_t *l)
16907 +{
16908 + asm volatile(_ASM_DEC "%0\n"
16909 : "+m" (l->a.counter));
16910 }
16911
16912 static inline void local_add(long i, local_t *l)
16913 {
16914 - asm volatile(_ASM_ADD "%1,%0"
16915 + asm volatile(_ASM_ADD "%1,%0\n"
16916 +
16917 +#ifdef CONFIG_PAX_REFCOUNT
16918 + "jno 0f\n"
16919 + _ASM_SUB "%1,%0\n"
16920 + "int $4\n0:\n"
16921 + _ASM_EXTABLE(0b, 0b)
16922 +#endif
16923 +
16924 + : "+m" (l->a.counter)
16925 + : "ir" (i));
16926 +}
16927 +
16928 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
16929 +{
16930 + asm volatile(_ASM_ADD "%1,%0\n"
16931 : "+m" (l->a.counter)
16932 : "ir" (i));
16933 }
16934
16935 static inline void local_sub(long i, local_t *l)
16936 {
16937 - asm volatile(_ASM_SUB "%1,%0"
16938 + asm volatile(_ASM_SUB "%1,%0\n"
16939 +
16940 +#ifdef CONFIG_PAX_REFCOUNT
16941 + "jno 0f\n"
16942 + _ASM_ADD "%1,%0\n"
16943 + "int $4\n0:\n"
16944 + _ASM_EXTABLE(0b, 0b)
16945 +#endif
16946 +
16947 + : "+m" (l->a.counter)
16948 + : "ir" (i));
16949 +}
16950 +
16951 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16952 +{
16953 + asm volatile(_ASM_SUB "%1,%0\n"
16954 : "+m" (l->a.counter)
16955 : "ir" (i));
16956 }
16957 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16958 */
16959 static inline int local_sub_and_test(long i, local_t *l)
16960 {
16961 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16962 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16963 }
16964
16965 /**
16966 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16967 */
16968 static inline int local_dec_and_test(local_t *l)
16969 {
16970 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16971 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16972 }
16973
16974 /**
16975 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16976 */
16977 static inline int local_inc_and_test(local_t *l)
16978 {
16979 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16980 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16981 }
16982
16983 /**
16984 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16985 */
16986 static inline int local_add_negative(long i, local_t *l)
16987 {
16988 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16989 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16990 }
16991
16992 /**
16993 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16994 static inline long local_add_return(long i, local_t *l)
16995 {
16996 long __i = i;
16997 + asm volatile(_ASM_XADD "%0, %1\n"
16998 +
16999 +#ifdef CONFIG_PAX_REFCOUNT
17000 + "jno 0f\n"
17001 + _ASM_MOV "%0,%1\n"
17002 + "int $4\n0:\n"
17003 + _ASM_EXTABLE(0b, 0b)
17004 +#endif
17005 +
17006 + : "+r" (i), "+m" (l->a.counter)
17007 + : : "memory");
17008 + return i + __i;
17009 +}
17010 +
17011 +/**
17012 + * local_add_return_unchecked - add and return
17013 + * @i: integer value to add
17014 + * @l: pointer to type local_unchecked_t
17015 + *
17016 + * Atomically adds @i to @l and returns @i + @l
17017 + */
17018 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17019 +{
17020 + long __i = i;
17021 asm volatile(_ASM_XADD "%0, %1;"
17022 : "+r" (i), "+m" (l->a.counter)
17023 : : "memory");
17024 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17025
17026 #define local_cmpxchg(l, o, n) \
17027 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17028 +#define local_cmpxchg_unchecked(l, o, n) \
17029 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17030 /* Always has a lock prefix */
17031 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17032
17033 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17034 new file mode 100644
17035 index 0000000..2bfd3ba
17036 --- /dev/null
17037 +++ b/arch/x86/include/asm/mman.h
17038 @@ -0,0 +1,15 @@
17039 +#ifndef _X86_MMAN_H
17040 +#define _X86_MMAN_H
17041 +
17042 +#include <uapi/asm/mman.h>
17043 +
17044 +#ifdef __KERNEL__
17045 +#ifndef __ASSEMBLY__
17046 +#ifdef CONFIG_X86_32
17047 +#define arch_mmap_check i386_mmap_check
17048 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17049 +#endif
17050 +#endif
17051 +#endif
17052 +
17053 +#endif /* X86_MMAN_H */
17054 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17055 index 5f55e69..e20bfb1 100644
17056 --- a/arch/x86/include/asm/mmu.h
17057 +++ b/arch/x86/include/asm/mmu.h
17058 @@ -9,7 +9,7 @@
17059 * we put the segment information here.
17060 */
17061 typedef struct {
17062 - void *ldt;
17063 + struct desc_struct *ldt;
17064 int size;
17065
17066 #ifdef CONFIG_X86_64
17067 @@ -18,7 +18,19 @@ typedef struct {
17068 #endif
17069
17070 struct mutex lock;
17071 - void *vdso;
17072 + unsigned long vdso;
17073 +
17074 +#ifdef CONFIG_X86_32
17075 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17076 + unsigned long user_cs_base;
17077 + unsigned long user_cs_limit;
17078 +
17079 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17080 + cpumask_t cpu_user_cs_mask;
17081 +#endif
17082 +
17083 +#endif
17084 +#endif
17085 } mm_context_t;
17086
17087 #ifdef CONFIG_SMP
17088 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17089 index be12c53..4d24039 100644
17090 --- a/arch/x86/include/asm/mmu_context.h
17091 +++ b/arch/x86/include/asm/mmu_context.h
17092 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17093
17094 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17095 {
17096 +
17097 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17098 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17099 + unsigned int i;
17100 + pgd_t *pgd;
17101 +
17102 + pax_open_kernel();
17103 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17104 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17105 + set_pgd_batched(pgd+i, native_make_pgd(0));
17106 + pax_close_kernel();
17107 + }
17108 +#endif
17109 +
17110 #ifdef CONFIG_SMP
17111 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17112 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17113 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17114 struct task_struct *tsk)
17115 {
17116 unsigned cpu = smp_processor_id();
17117 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17118 + int tlbstate = TLBSTATE_OK;
17119 +#endif
17120
17121 if (likely(prev != next)) {
17122 #ifdef CONFIG_SMP
17123 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17124 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17125 +#endif
17126 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17127 this_cpu_write(cpu_tlbstate.active_mm, next);
17128 #endif
17129 cpumask_set_cpu(cpu, mm_cpumask(next));
17130
17131 /* Re-load page tables */
17132 +#ifdef CONFIG_PAX_PER_CPU_PGD
17133 + pax_open_kernel();
17134 +
17135 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17136 + if (static_cpu_has(X86_FEATURE_PCID))
17137 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17138 + else
17139 +#endif
17140 +
17141 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17142 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17143 + pax_close_kernel();
17144 + 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));
17145 +
17146 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17147 + if (static_cpu_has(X86_FEATURE_PCID)) {
17148 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17149 + u64 descriptor[2];
17150 + descriptor[0] = PCID_USER;
17151 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17152 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17153 + descriptor[0] = PCID_KERNEL;
17154 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17155 + }
17156 + } else {
17157 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17158 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17159 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17160 + else
17161 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17162 + }
17163 + } else
17164 +#endif
17165 +
17166 + load_cr3(get_cpu_pgd(cpu, kernel));
17167 +#else
17168 load_cr3(next->pgd);
17169 +#endif
17170
17171 /* Stop flush ipis for the previous mm */
17172 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17173 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17174 /* Load the LDT, if the LDT is different: */
17175 if (unlikely(prev->context.ldt != next->context.ldt))
17176 load_LDT_nolock(&next->context);
17177 +
17178 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17179 + if (!(__supported_pte_mask & _PAGE_NX)) {
17180 + smp_mb__before_clear_bit();
17181 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17182 + smp_mb__after_clear_bit();
17183 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17184 + }
17185 +#endif
17186 +
17187 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17188 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17189 + prev->context.user_cs_limit != next->context.user_cs_limit))
17190 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17191 +#ifdef CONFIG_SMP
17192 + else if (unlikely(tlbstate != TLBSTATE_OK))
17193 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17194 +#endif
17195 +#endif
17196 +
17197 }
17198 + else {
17199 +
17200 +#ifdef CONFIG_PAX_PER_CPU_PGD
17201 + pax_open_kernel();
17202 +
17203 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17204 + if (static_cpu_has(X86_FEATURE_PCID))
17205 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17206 + else
17207 +#endif
17208 +
17209 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17210 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17211 + pax_close_kernel();
17212 + 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));
17213 +
17214 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17215 + if (static_cpu_has(X86_FEATURE_PCID)) {
17216 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17217 + u64 descriptor[2];
17218 + descriptor[0] = PCID_USER;
17219 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17220 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17221 + descriptor[0] = PCID_KERNEL;
17222 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17223 + }
17224 + } else {
17225 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17226 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17227 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17228 + else
17229 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17230 + }
17231 + } else
17232 +#endif
17233 +
17234 + load_cr3(get_cpu_pgd(cpu, kernel));
17235 +#endif
17236 +
17237 #ifdef CONFIG_SMP
17238 - else {
17239 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17240 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17241
17242 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17243 * tlb flush IPI delivery. We must reload CR3
17244 * to make sure to use no freed page tables.
17245 */
17246 +
17247 +#ifndef CONFIG_PAX_PER_CPU_PGD
17248 load_cr3(next->pgd);
17249 +#endif
17250 +
17251 load_LDT_nolock(&next->context);
17252 +
17253 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17254 + if (!(__supported_pte_mask & _PAGE_NX))
17255 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17256 +#endif
17257 +
17258 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17259 +#ifdef CONFIG_PAX_PAGEEXEC
17260 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17261 +#endif
17262 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17263 +#endif
17264 +
17265 }
17266 +#endif
17267 }
17268 -#endif
17269 }
17270
17271 #define activate_mm(prev, next) \
17272 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17273 index e3b7819..b257c64 100644
17274 --- a/arch/x86/include/asm/module.h
17275 +++ b/arch/x86/include/asm/module.h
17276 @@ -5,6 +5,7 @@
17277
17278 #ifdef CONFIG_X86_64
17279 /* X86_64 does not define MODULE_PROC_FAMILY */
17280 +#define MODULE_PROC_FAMILY ""
17281 #elif defined CONFIG_M486
17282 #define MODULE_PROC_FAMILY "486 "
17283 #elif defined CONFIG_M586
17284 @@ -57,8 +58,20 @@
17285 #error unknown processor family
17286 #endif
17287
17288 -#ifdef CONFIG_X86_32
17289 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17290 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17291 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17292 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17293 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17294 +#else
17295 +#define MODULE_PAX_KERNEXEC ""
17296 #endif
17297
17298 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17299 +#define MODULE_PAX_UDEREF "UDEREF "
17300 +#else
17301 +#define MODULE_PAX_UDEREF ""
17302 +#endif
17303 +
17304 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17305 +
17306 #endif /* _ASM_X86_MODULE_H */
17307 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17308 index 5f2fc44..106caa6 100644
17309 --- a/arch/x86/include/asm/nmi.h
17310 +++ b/arch/x86/include/asm/nmi.h
17311 @@ -36,26 +36,35 @@ enum {
17312
17313 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17314
17315 +struct nmiaction;
17316 +
17317 +struct nmiwork {
17318 + const struct nmiaction *action;
17319 + u64 max_duration;
17320 + struct irq_work irq_work;
17321 +};
17322 +
17323 struct nmiaction {
17324 struct list_head list;
17325 nmi_handler_t handler;
17326 - u64 max_duration;
17327 - struct irq_work irq_work;
17328 unsigned long flags;
17329 const char *name;
17330 -};
17331 + struct nmiwork *work;
17332 +} __do_const;
17333
17334 #define register_nmi_handler(t, fn, fg, n, init...) \
17335 ({ \
17336 - static struct nmiaction init fn##_na = { \
17337 + static struct nmiwork fn##_nw; \
17338 + static const struct nmiaction init fn##_na = { \
17339 .handler = (fn), \
17340 .name = (n), \
17341 .flags = (fg), \
17342 + .work = &fn##_nw, \
17343 }; \
17344 __register_nmi_handler((t), &fn##_na); \
17345 })
17346
17347 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17348 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17349
17350 void unregister_nmi_handler(unsigned int, const char *);
17351
17352 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17353 index 775873d..04cd306 100644
17354 --- a/arch/x86/include/asm/page.h
17355 +++ b/arch/x86/include/asm/page.h
17356 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17357 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17358
17359 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17360 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17361
17362 #define __boot_va(x) __va(x)
17363 #define __boot_pa(x) __pa(x)
17364 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17365 * virt_to_page(kaddr) returns a valid pointer if and only if
17366 * virt_addr_valid(kaddr) returns true.
17367 */
17368 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17369 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17370 extern bool __virt_addr_valid(unsigned long kaddr);
17371 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17372
17373 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17374 +#define virt_to_page(kaddr) \
17375 + ({ \
17376 + const void *__kaddr = (const void *)(kaddr); \
17377 + BUG_ON(!virt_addr_valid(__kaddr)); \
17378 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17379 + })
17380 +#else
17381 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17382 +#endif
17383 +
17384 #endif /* __ASSEMBLY__ */
17385
17386 #include <asm-generic/memory_model.h>
17387 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17388 index 0f1ddee..e2fc3d1 100644
17389 --- a/arch/x86/include/asm/page_64.h
17390 +++ b/arch/x86/include/asm/page_64.h
17391 @@ -7,9 +7,9 @@
17392
17393 /* duplicated to the one in bootmem.h */
17394 extern unsigned long max_pfn;
17395 -extern unsigned long phys_base;
17396 +extern const unsigned long phys_base;
17397
17398 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17399 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17400 {
17401 unsigned long y = x - __START_KERNEL_map;
17402
17403 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17404 index cd6e1610..70f4418 100644
17405 --- a/arch/x86/include/asm/paravirt.h
17406 +++ b/arch/x86/include/asm/paravirt.h
17407 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17408 return (pmd_t) { ret };
17409 }
17410
17411 -static inline pmdval_t pmd_val(pmd_t pmd)
17412 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17413 {
17414 pmdval_t ret;
17415
17416 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17417 val);
17418 }
17419
17420 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17421 +{
17422 + pgdval_t val = native_pgd_val(pgd);
17423 +
17424 + if (sizeof(pgdval_t) > sizeof(long))
17425 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17426 + val, (u64)val >> 32);
17427 + else
17428 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17429 + val);
17430 +}
17431 +
17432 static inline void pgd_clear(pgd_t *pgdp)
17433 {
17434 set_pgd(pgdp, __pgd(0));
17435 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17436 pv_mmu_ops.set_fixmap(idx, phys, flags);
17437 }
17438
17439 +#ifdef CONFIG_PAX_KERNEXEC
17440 +static inline unsigned long pax_open_kernel(void)
17441 +{
17442 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17443 +}
17444 +
17445 +static inline unsigned long pax_close_kernel(void)
17446 +{
17447 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17448 +}
17449 +#else
17450 +static inline unsigned long pax_open_kernel(void) { return 0; }
17451 +static inline unsigned long pax_close_kernel(void) { return 0; }
17452 +#endif
17453 +
17454 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17455
17456 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17457 @@ -906,7 +933,7 @@ extern void default_banner(void);
17458
17459 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17460 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17461 -#define PARA_INDIRECT(addr) *%cs:addr
17462 +#define PARA_INDIRECT(addr) *%ss:addr
17463 #endif
17464
17465 #define INTERRUPT_RETURN \
17466 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17467 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17468 CLBR_NONE, \
17469 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17470 +
17471 +#define GET_CR0_INTO_RDI \
17472 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17473 + mov %rax,%rdi
17474 +
17475 +#define SET_RDI_INTO_CR0 \
17476 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17477 +
17478 +#define GET_CR3_INTO_RDI \
17479 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17480 + mov %rax,%rdi
17481 +
17482 +#define SET_RDI_INTO_CR3 \
17483 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17484 +
17485 #endif /* CONFIG_X86_32 */
17486
17487 #endif /* __ASSEMBLY__ */
17488 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17489 index 7549b8b..f0edfda 100644
17490 --- a/arch/x86/include/asm/paravirt_types.h
17491 +++ b/arch/x86/include/asm/paravirt_types.h
17492 @@ -84,7 +84,7 @@ struct pv_init_ops {
17493 */
17494 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17495 unsigned long addr, unsigned len);
17496 -};
17497 +} __no_const __no_randomize_layout;
17498
17499
17500 struct pv_lazy_ops {
17501 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17502 void (*enter)(void);
17503 void (*leave)(void);
17504 void (*flush)(void);
17505 -};
17506 +} __no_randomize_layout;
17507
17508 struct pv_time_ops {
17509 unsigned long long (*sched_clock)(void);
17510 unsigned long long (*steal_clock)(int cpu);
17511 unsigned long (*get_tsc_khz)(void);
17512 -};
17513 +} __no_const __no_randomize_layout;
17514
17515 struct pv_cpu_ops {
17516 /* hooks for various privileged instructions */
17517 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17518
17519 void (*start_context_switch)(struct task_struct *prev);
17520 void (*end_context_switch)(struct task_struct *next);
17521 -};
17522 +} __no_const __no_randomize_layout;
17523
17524 struct pv_irq_ops {
17525 /*
17526 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17527 #ifdef CONFIG_X86_64
17528 void (*adjust_exception_frame)(void);
17529 #endif
17530 -};
17531 +} __no_randomize_layout;
17532
17533 struct pv_apic_ops {
17534 #ifdef CONFIG_X86_LOCAL_APIC
17535 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17536 unsigned long start_eip,
17537 unsigned long start_esp);
17538 #endif
17539 -};
17540 +} __no_const __no_randomize_layout;
17541
17542 struct pv_mmu_ops {
17543 unsigned long (*read_cr2)(void);
17544 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17545 struct paravirt_callee_save make_pud;
17546
17547 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17548 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17549 #endif /* PAGETABLE_LEVELS == 4 */
17550 #endif /* PAGETABLE_LEVELS >= 3 */
17551
17552 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17553 an mfn. We can tell which is which from the index. */
17554 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17555 phys_addr_t phys, pgprot_t flags);
17556 -};
17557 +
17558 +#ifdef CONFIG_PAX_KERNEXEC
17559 + unsigned long (*pax_open_kernel)(void);
17560 + unsigned long (*pax_close_kernel)(void);
17561 +#endif
17562 +
17563 +} __no_randomize_layout;
17564
17565 struct arch_spinlock;
17566 #ifdef CONFIG_SMP
17567 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17568 struct pv_lock_ops {
17569 struct paravirt_callee_save lock_spinning;
17570 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17571 -};
17572 +} __no_randomize_layout;
17573
17574 /* This contains all the paravirt structures: we get a convenient
17575 * number for each function using the offset which we use to indicate
17576 - * what to patch. */
17577 + * what to patch.
17578 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17579 + */
17580 +
17581 struct paravirt_patch_template {
17582 struct pv_init_ops pv_init_ops;
17583 struct pv_time_ops pv_time_ops;
17584 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17585 struct pv_apic_ops pv_apic_ops;
17586 struct pv_mmu_ops pv_mmu_ops;
17587 struct pv_lock_ops pv_lock_ops;
17588 -};
17589 +} __no_randomize_layout;
17590
17591 extern struct pv_info pv_info;
17592 extern struct pv_init_ops pv_init_ops;
17593 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17594 index c4412e9..90e88c5 100644
17595 --- a/arch/x86/include/asm/pgalloc.h
17596 +++ b/arch/x86/include/asm/pgalloc.h
17597 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17598 pmd_t *pmd, pte_t *pte)
17599 {
17600 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17601 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17602 +}
17603 +
17604 +static inline void pmd_populate_user(struct mm_struct *mm,
17605 + pmd_t *pmd, pte_t *pte)
17606 +{
17607 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17608 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17609 }
17610
17611 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17612
17613 #ifdef CONFIG_X86_PAE
17614 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17615 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17616 +{
17617 + pud_populate(mm, pudp, pmd);
17618 +}
17619 #else /* !CONFIG_X86_PAE */
17620 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17621 {
17622 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17623 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17624 }
17625 +
17626 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17627 +{
17628 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17629 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17630 +}
17631 #endif /* CONFIG_X86_PAE */
17632
17633 #if PAGETABLE_LEVELS > 3
17634 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17635 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17636 }
17637
17638 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17639 +{
17640 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17641 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17642 +}
17643 +
17644 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17645 {
17646 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17647 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17648 index 0d193e2..bf59aeb 100644
17649 --- a/arch/x86/include/asm/pgtable-2level.h
17650 +++ b/arch/x86/include/asm/pgtable-2level.h
17651 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17652
17653 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17654 {
17655 + pax_open_kernel();
17656 *pmdp = pmd;
17657 + pax_close_kernel();
17658 }
17659
17660 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17661 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17662 index 81bb91b..9392125 100644
17663 --- a/arch/x86/include/asm/pgtable-3level.h
17664 +++ b/arch/x86/include/asm/pgtable-3level.h
17665 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17666
17667 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17668 {
17669 + pax_open_kernel();
17670 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17671 + pax_close_kernel();
17672 }
17673
17674 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17675 {
17676 + pax_open_kernel();
17677 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17678 + pax_close_kernel();
17679 }
17680
17681 /*
17682 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17683 index b459ddf..b44081b 100644
17684 --- a/arch/x86/include/asm/pgtable.h
17685 +++ b/arch/x86/include/asm/pgtable.h
17686 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17687
17688 #ifndef __PAGETABLE_PUD_FOLDED
17689 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17690 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17691 #define pgd_clear(pgd) native_pgd_clear(pgd)
17692 #endif
17693
17694 @@ -83,12 +84,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17695
17696 #define arch_end_context_switch(prev) do {} while(0)
17697
17698 +#define pax_open_kernel() native_pax_open_kernel()
17699 +#define pax_close_kernel() native_pax_close_kernel()
17700 #endif /* CONFIG_PARAVIRT */
17701
17702 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17703 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17704 +
17705 +#ifdef CONFIG_PAX_KERNEXEC
17706 +static inline unsigned long native_pax_open_kernel(void)
17707 +{
17708 + unsigned long cr0;
17709 +
17710 + preempt_disable();
17711 + barrier();
17712 + cr0 = read_cr0() ^ X86_CR0_WP;
17713 + BUG_ON(cr0 & X86_CR0_WP);
17714 + write_cr0(cr0);
17715 + return cr0 ^ X86_CR0_WP;
17716 +}
17717 +
17718 +static inline unsigned long native_pax_close_kernel(void)
17719 +{
17720 + unsigned long cr0;
17721 +
17722 + cr0 = read_cr0() ^ X86_CR0_WP;
17723 + BUG_ON(!(cr0 & X86_CR0_WP));
17724 + write_cr0(cr0);
17725 + barrier();
17726 + preempt_enable_no_resched();
17727 + return cr0 ^ X86_CR0_WP;
17728 +}
17729 +#else
17730 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
17731 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
17732 +#endif
17733 +
17734 /*
17735 * The following only work if pte_present() is true.
17736 * Undefined behaviour if not..
17737 */
17738 +static inline int pte_user(pte_t pte)
17739 +{
17740 + return pte_val(pte) & _PAGE_USER;
17741 +}
17742 +
17743 static inline int pte_dirty(pte_t pte)
17744 {
17745 return pte_flags(pte) & _PAGE_DIRTY;
17746 @@ -149,6 +189,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17747 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17748 }
17749
17750 +static inline unsigned long pgd_pfn(pgd_t pgd)
17751 +{
17752 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17753 +}
17754 +
17755 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17756
17757 static inline int pmd_large(pmd_t pte)
17758 @@ -202,9 +247,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17759 return pte_clear_flags(pte, _PAGE_RW);
17760 }
17761
17762 +static inline pte_t pte_mkread(pte_t pte)
17763 +{
17764 + return __pte(pte_val(pte) | _PAGE_USER);
17765 +}
17766 +
17767 static inline pte_t pte_mkexec(pte_t pte)
17768 {
17769 - return pte_clear_flags(pte, _PAGE_NX);
17770 +#ifdef CONFIG_X86_PAE
17771 + if (__supported_pte_mask & _PAGE_NX)
17772 + return pte_clear_flags(pte, _PAGE_NX);
17773 + else
17774 +#endif
17775 + return pte_set_flags(pte, _PAGE_USER);
17776 +}
17777 +
17778 +static inline pte_t pte_exprotect(pte_t pte)
17779 +{
17780 +#ifdef CONFIG_X86_PAE
17781 + if (__supported_pte_mask & _PAGE_NX)
17782 + return pte_set_flags(pte, _PAGE_NX);
17783 + else
17784 +#endif
17785 + return pte_clear_flags(pte, _PAGE_USER);
17786 }
17787
17788 static inline pte_t pte_mkdirty(pte_t pte)
17789 @@ -431,6 +496,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17790 #endif
17791
17792 #ifndef __ASSEMBLY__
17793 +
17794 +#ifdef CONFIG_PAX_PER_CPU_PGD
17795 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17796 +enum cpu_pgd_type {kernel = 0, user = 1};
17797 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17798 +{
17799 + return cpu_pgd[cpu][type];
17800 +}
17801 +#endif
17802 +
17803 #include <linux/mm_types.h>
17804 #include <linux/mmdebug.h>
17805 #include <linux/log2.h>
17806 @@ -571,7 +646,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17807 * Currently stuck as a macro due to indirect forward reference to
17808 * linux/mmzone.h's __section_mem_map_addr() definition:
17809 */
17810 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17811 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17812
17813 /* Find an entry in the second-level page table.. */
17814 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17815 @@ -611,7 +686,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17816 * Currently stuck as a macro due to indirect forward reference to
17817 * linux/mmzone.h's __section_mem_map_addr() definition:
17818 */
17819 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17820 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17821
17822 /* to find an entry in a page-table-directory. */
17823 static inline unsigned long pud_index(unsigned long address)
17824 @@ -626,7 +701,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17825
17826 static inline int pgd_bad(pgd_t pgd)
17827 {
17828 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17829 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17830 }
17831
17832 static inline int pgd_none(pgd_t pgd)
17833 @@ -649,7 +724,12 @@ static inline int pgd_none(pgd_t pgd)
17834 * pgd_offset() returns a (pgd_t *)
17835 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17836 */
17837 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17838 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17839 +
17840 +#ifdef CONFIG_PAX_PER_CPU_PGD
17841 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17842 +#endif
17843 +
17844 /*
17845 * a shortcut which implies the use of the kernel's pgd, instead
17846 * of a process's
17847 @@ -660,6 +740,23 @@ static inline int pgd_none(pgd_t pgd)
17848 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17849 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17850
17851 +#ifdef CONFIG_X86_32
17852 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17853 +#else
17854 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17855 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17856 +
17857 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17858 +#ifdef __ASSEMBLY__
17859 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
17860 +#else
17861 +extern unsigned long pax_user_shadow_base;
17862 +extern pgdval_t clone_pgd_mask;
17863 +#endif
17864 +#endif
17865 +
17866 +#endif
17867 +
17868 #ifndef __ASSEMBLY__
17869
17870 extern int direct_gbpages;
17871 @@ -826,11 +923,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17872 * dst and src can be on the same page, but the range must not overlap,
17873 * and must not cross a page boundary.
17874 */
17875 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17876 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17877 {
17878 - memcpy(dst, src, count * sizeof(pgd_t));
17879 + pax_open_kernel();
17880 + while (count--)
17881 + *dst++ = *src++;
17882 + pax_close_kernel();
17883 }
17884
17885 +#ifdef CONFIG_PAX_PER_CPU_PGD
17886 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17887 +#endif
17888 +
17889 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17890 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17891 +#else
17892 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17893 +#endif
17894 +
17895 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17896 static inline int page_level_shift(enum pg_level level)
17897 {
17898 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17899 index 9ee3221..b979c6b 100644
17900 --- a/arch/x86/include/asm/pgtable_32.h
17901 +++ b/arch/x86/include/asm/pgtable_32.h
17902 @@ -25,9 +25,6 @@
17903 struct mm_struct;
17904 struct vm_area_struct;
17905
17906 -extern pgd_t swapper_pg_dir[1024];
17907 -extern pgd_t initial_page_table[1024];
17908 -
17909 static inline void pgtable_cache_init(void) { }
17910 static inline void check_pgt_cache(void) { }
17911 void paging_init(void);
17912 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17913 # include <asm/pgtable-2level.h>
17914 #endif
17915
17916 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17917 +extern pgd_t initial_page_table[PTRS_PER_PGD];
17918 +#ifdef CONFIG_X86_PAE
17919 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17920 +#endif
17921 +
17922 #if defined(CONFIG_HIGHPTE)
17923 #define pte_offset_map(dir, address) \
17924 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17925 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17926 /* Clear a kernel PTE and flush it from the TLB */
17927 #define kpte_clear_flush(ptep, vaddr) \
17928 do { \
17929 + pax_open_kernel(); \
17930 pte_clear(&init_mm, (vaddr), (ptep)); \
17931 + pax_close_kernel(); \
17932 __flush_tlb_one((vaddr)); \
17933 } while (0)
17934
17935 #endif /* !__ASSEMBLY__ */
17936
17937 +#define HAVE_ARCH_UNMAPPED_AREA
17938 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17939 +
17940 /*
17941 * kern_addr_valid() is (1) for FLATMEM and (0) for
17942 * SPARSEMEM and DISCONTIGMEM
17943 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17944 index ed5903b..c7fe163 100644
17945 --- a/arch/x86/include/asm/pgtable_32_types.h
17946 +++ b/arch/x86/include/asm/pgtable_32_types.h
17947 @@ -8,7 +8,7 @@
17948 */
17949 #ifdef CONFIG_X86_PAE
17950 # include <asm/pgtable-3level_types.h>
17951 -# define PMD_SIZE (1UL << PMD_SHIFT)
17952 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17953 # define PMD_MASK (~(PMD_SIZE - 1))
17954 #else
17955 # include <asm/pgtable-2level_types.h>
17956 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17957 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17958 #endif
17959
17960 +#ifdef CONFIG_PAX_KERNEXEC
17961 +#ifndef __ASSEMBLY__
17962 +extern unsigned char MODULES_EXEC_VADDR[];
17963 +extern unsigned char MODULES_EXEC_END[];
17964 +#endif
17965 +#include <asm/boot.h>
17966 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17967 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17968 +#else
17969 +#define ktla_ktva(addr) (addr)
17970 +#define ktva_ktla(addr) (addr)
17971 +#endif
17972 +
17973 #define MODULES_VADDR VMALLOC_START
17974 #define MODULES_END VMALLOC_END
17975 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17976 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17977 index e22c1db..23a625a 100644
17978 --- a/arch/x86/include/asm/pgtable_64.h
17979 +++ b/arch/x86/include/asm/pgtable_64.h
17980 @@ -16,10 +16,14 @@
17981
17982 extern pud_t level3_kernel_pgt[512];
17983 extern pud_t level3_ident_pgt[512];
17984 +extern pud_t level3_vmalloc_start_pgt[512];
17985 +extern pud_t level3_vmalloc_end_pgt[512];
17986 +extern pud_t level3_vmemmap_pgt[512];
17987 +extern pud_t level2_vmemmap_pgt[512];
17988 extern pmd_t level2_kernel_pgt[512];
17989 extern pmd_t level2_fixmap_pgt[512];
17990 -extern pmd_t level2_ident_pgt[512];
17991 -extern pgd_t init_level4_pgt[];
17992 +extern pmd_t level2_ident_pgt[512*2];
17993 +extern pgd_t init_level4_pgt[512];
17994
17995 #define swapper_pg_dir init_level4_pgt
17996
17997 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17998
17999 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18000 {
18001 + pax_open_kernel();
18002 *pmdp = pmd;
18003 + pax_close_kernel();
18004 }
18005
18006 static inline void native_pmd_clear(pmd_t *pmd)
18007 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18008
18009 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18010 {
18011 + pax_open_kernel();
18012 *pudp = pud;
18013 + pax_close_kernel();
18014 }
18015
18016 static inline void native_pud_clear(pud_t *pud)
18017 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18018
18019 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18020 {
18021 + pax_open_kernel();
18022 + *pgdp = pgd;
18023 + pax_close_kernel();
18024 +}
18025 +
18026 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18027 +{
18028 *pgdp = pgd;
18029 }
18030
18031 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18032 index c883bf7..19970b3 100644
18033 --- a/arch/x86/include/asm/pgtable_64_types.h
18034 +++ b/arch/x86/include/asm/pgtable_64_types.h
18035 @@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
18036 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18037 #define MODULES_END _AC(0xffffffffff000000, UL)
18038 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18039 +#define MODULES_EXEC_VADDR MODULES_VADDR
18040 +#define MODULES_EXEC_END MODULES_END
18041 +
18042 +#define ktla_ktva(addr) (addr)
18043 +#define ktva_ktla(addr) (addr)
18044
18045 #define EARLY_DYNAMIC_PAGE_TABLES 64
18046
18047 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18048 index eb3d449..8d95316 100644
18049 --- a/arch/x86/include/asm/pgtable_types.h
18050 +++ b/arch/x86/include/asm/pgtable_types.h
18051 @@ -16,13 +16,12 @@
18052 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
18053 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
18054 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
18055 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
18056 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
18057 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
18058 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
18059 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
18060 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
18061 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
18062 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
18063 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
18064 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
18065 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
18066
18067 /* If _PAGE_BIT_PRESENT is clear, we use these: */
18068 @@ -40,7 +39,6 @@
18069 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
18070 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
18071 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
18072 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
18073 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
18074 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
18075 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
18076 @@ -87,8 +85,10 @@
18077
18078 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18079 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18080 -#else
18081 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18082 #define _PAGE_NX (_AT(pteval_t, 0))
18083 +#else
18084 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18085 #endif
18086
18087 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18088 @@ -147,6 +147,9 @@
18089 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18090 _PAGE_ACCESSED)
18091
18092 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18093 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18094 +
18095 #define __PAGE_KERNEL_EXEC \
18096 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18097 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18098 @@ -157,7 +160,7 @@
18099 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18100 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18101 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18102 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18103 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18104 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18105 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18106 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18107 @@ -214,7 +217,7 @@
18108 #ifdef CONFIG_X86_64
18109 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18110 #else
18111 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18112 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18113 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18114 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18115 #endif
18116 @@ -253,7 +256,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18117 {
18118 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18119 }
18120 +#endif
18121
18122 +#if PAGETABLE_LEVELS == 3
18123 +#include <asm-generic/pgtable-nopud.h>
18124 +#endif
18125 +
18126 +#if PAGETABLE_LEVELS == 2
18127 +#include <asm-generic/pgtable-nopmd.h>
18128 +#endif
18129 +
18130 +#ifndef __ASSEMBLY__
18131 #if PAGETABLE_LEVELS > 3
18132 typedef struct { pudval_t pud; } pud_t;
18133
18134 @@ -267,8 +280,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18135 return pud.pud;
18136 }
18137 #else
18138 -#include <asm-generic/pgtable-nopud.h>
18139 -
18140 static inline pudval_t native_pud_val(pud_t pud)
18141 {
18142 return native_pgd_val(pud.pgd);
18143 @@ -288,8 +299,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18144 return pmd.pmd;
18145 }
18146 #else
18147 -#include <asm-generic/pgtable-nopmd.h>
18148 -
18149 static inline pmdval_t native_pmd_val(pmd_t pmd)
18150 {
18151 return native_pgd_val(pmd.pud.pgd);
18152 @@ -329,7 +338,6 @@ typedef struct page *pgtable_t;
18153
18154 extern pteval_t __supported_pte_mask;
18155 extern void set_nx(void);
18156 -extern int nx_enabled;
18157
18158 #define pgprot_writecombine pgprot_writecombine
18159 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18160 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18161 index 7024c12..71c46b9 100644
18162 --- a/arch/x86/include/asm/preempt.h
18163 +++ b/arch/x86/include/asm/preempt.h
18164 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18165 */
18166 static __always_inline bool __preempt_count_dec_and_test(void)
18167 {
18168 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18169 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18170 }
18171
18172 /*
18173 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18174 index a4ea023..33aa874 100644
18175 --- a/arch/x86/include/asm/processor.h
18176 +++ b/arch/x86/include/asm/processor.h
18177 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18178 /* Index into per_cpu list: */
18179 u16 cpu_index;
18180 u32 microcode;
18181 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18182 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18183
18184 #define X86_VENDOR_INTEL 0
18185 #define X86_VENDOR_CYRIX 1
18186 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18187 : "memory");
18188 }
18189
18190 +/* invpcid (%rdx),%rax */
18191 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18192 +
18193 +#define INVPCID_SINGLE_ADDRESS 0UL
18194 +#define INVPCID_SINGLE_CONTEXT 1UL
18195 +#define INVPCID_ALL_GLOBAL 2UL
18196 +#define INVPCID_ALL_MONGLOBAL 3UL
18197 +
18198 +#define PCID_KERNEL 0UL
18199 +#define PCID_USER 1UL
18200 +#define PCID_NOFLUSH (1UL << 63)
18201 +
18202 static inline void load_cr3(pgd_t *pgdir)
18203 {
18204 - write_cr3(__pa(pgdir));
18205 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18206 }
18207
18208 #ifdef CONFIG_X86_32
18209 @@ -283,7 +295,7 @@ struct tss_struct {
18210
18211 } ____cacheline_aligned;
18212
18213 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18214 +extern struct tss_struct init_tss[NR_CPUS];
18215
18216 /*
18217 * Save the original ist values for checking stack pointers during debugging
18218 @@ -479,6 +491,7 @@ struct thread_struct {
18219 unsigned short ds;
18220 unsigned short fsindex;
18221 unsigned short gsindex;
18222 + unsigned short ss;
18223 #endif
18224 #ifdef CONFIG_X86_32
18225 unsigned long ip;
18226 @@ -588,29 +601,8 @@ static inline void load_sp0(struct tss_struct *tss,
18227 extern unsigned long mmu_cr4_features;
18228 extern u32 *trampoline_cr4_features;
18229
18230 -static inline void set_in_cr4(unsigned long mask)
18231 -{
18232 - unsigned long cr4;
18233 -
18234 - mmu_cr4_features |= mask;
18235 - if (trampoline_cr4_features)
18236 - *trampoline_cr4_features = mmu_cr4_features;
18237 - cr4 = read_cr4();
18238 - cr4 |= mask;
18239 - write_cr4(cr4);
18240 -}
18241 -
18242 -static inline void clear_in_cr4(unsigned long mask)
18243 -{
18244 - unsigned long cr4;
18245 -
18246 - mmu_cr4_features &= ~mask;
18247 - if (trampoline_cr4_features)
18248 - *trampoline_cr4_features = mmu_cr4_features;
18249 - cr4 = read_cr4();
18250 - cr4 &= ~mask;
18251 - write_cr4(cr4);
18252 -}
18253 +extern void set_in_cr4(unsigned long mask);
18254 +extern void clear_in_cr4(unsigned long mask);
18255
18256 typedef struct {
18257 unsigned long seg;
18258 @@ -836,11 +828,18 @@ static inline void spin_lock_prefetch(const void *x)
18259 */
18260 #define TASK_SIZE PAGE_OFFSET
18261 #define TASK_SIZE_MAX TASK_SIZE
18262 +
18263 +#ifdef CONFIG_PAX_SEGMEXEC
18264 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18265 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18266 +#else
18267 #define STACK_TOP TASK_SIZE
18268 -#define STACK_TOP_MAX STACK_TOP
18269 +#endif
18270 +
18271 +#define STACK_TOP_MAX TASK_SIZE
18272
18273 #define INIT_THREAD { \
18274 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18275 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18276 .vm86_info = NULL, \
18277 .sysenter_cs = __KERNEL_CS, \
18278 .io_bitmap_ptr = NULL, \
18279 @@ -854,7 +853,7 @@ static inline void spin_lock_prefetch(const void *x)
18280 */
18281 #define INIT_TSS { \
18282 .x86_tss = { \
18283 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18284 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18285 .ss0 = __KERNEL_DS, \
18286 .ss1 = __KERNEL_CS, \
18287 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18288 @@ -865,11 +864,7 @@ static inline void spin_lock_prefetch(const void *x)
18289 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18290
18291 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18292 -#define KSTK_TOP(info) \
18293 -({ \
18294 - unsigned long *__ptr = (unsigned long *)(info); \
18295 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18296 -})
18297 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18298
18299 /*
18300 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18301 @@ -884,7 +879,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18302 #define task_pt_regs(task) \
18303 ({ \
18304 struct pt_regs *__regs__; \
18305 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18306 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18307 __regs__ - 1; \
18308 })
18309
18310 @@ -894,13 +889,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18311 /*
18312 * User space process size. 47bits minus one guard page.
18313 */
18314 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18315 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18316
18317 /* This decides where the kernel will search for a free chunk of vm
18318 * space during mmap's.
18319 */
18320 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18321 - 0xc0000000 : 0xFFFFe000)
18322 + 0xc0000000 : 0xFFFFf000)
18323
18324 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18325 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18326 @@ -911,11 +906,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18327 #define STACK_TOP_MAX TASK_SIZE_MAX
18328
18329 #define INIT_THREAD { \
18330 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18331 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18332 }
18333
18334 #define INIT_TSS { \
18335 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18336 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18337 }
18338
18339 /*
18340 @@ -943,6 +938,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18341 */
18342 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18343
18344 +#ifdef CONFIG_PAX_SEGMEXEC
18345 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18346 +#endif
18347 +
18348 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18349
18350 /* Get/set a process' ability to use the timestamp counter instruction */
18351 @@ -969,7 +968,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18352 return 0;
18353 }
18354
18355 -extern unsigned long arch_align_stack(unsigned long sp);
18356 +#define arch_align_stack(x) ((x) & ~0xfUL)
18357 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18358
18359 void default_idle(void);
18360 @@ -979,6 +978,6 @@ bool xen_set_default_idle(void);
18361 #define xen_set_default_idle 0
18362 #endif
18363
18364 -void stop_this_cpu(void *dummy);
18365 +void stop_this_cpu(void *dummy) __noreturn;
18366 void df_debug(struct pt_regs *regs, long error_code);
18367 #endif /* _ASM_X86_PROCESSOR_H */
18368 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18369 index 6205f0c..688a3a9 100644
18370 --- a/arch/x86/include/asm/ptrace.h
18371 +++ b/arch/x86/include/asm/ptrace.h
18372 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18373 }
18374
18375 /*
18376 - * user_mode_vm(regs) determines whether a register set came from user mode.
18377 + * user_mode(regs) determines whether a register set came from user mode.
18378 * This is true if V8086 mode was enabled OR if the register set was from
18379 * protected mode with RPL-3 CS value. This tricky test checks that with
18380 * one comparison. Many places in the kernel can bypass this full check
18381 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18382 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18383 + * be used.
18384 */
18385 -static inline int user_mode(struct pt_regs *regs)
18386 +static inline int user_mode_novm(struct pt_regs *regs)
18387 {
18388 #ifdef CONFIG_X86_32
18389 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18390 #else
18391 - return !!(regs->cs & 3);
18392 + return !!(regs->cs & SEGMENT_RPL_MASK);
18393 #endif
18394 }
18395
18396 -static inline int user_mode_vm(struct pt_regs *regs)
18397 +static inline int user_mode(struct pt_regs *regs)
18398 {
18399 #ifdef CONFIG_X86_32
18400 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18401 USER_RPL;
18402 #else
18403 - return user_mode(regs);
18404 + return user_mode_novm(regs);
18405 #endif
18406 }
18407
18408 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18409 #ifdef CONFIG_X86_64
18410 static inline bool user_64bit_mode(struct pt_regs *regs)
18411 {
18412 + unsigned long cs = regs->cs & 0xffff;
18413 #ifndef CONFIG_PARAVIRT
18414 /*
18415 * On non-paravirt systems, this is the only long mode CPL 3
18416 * selector. We do not allow long mode selectors in the LDT.
18417 */
18418 - return regs->cs == __USER_CS;
18419 + return cs == __USER_CS;
18420 #else
18421 /* Headers are too twisted for this to go in paravirt.h. */
18422 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18423 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18424 #endif
18425 }
18426
18427 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18428 * Traps from the kernel do not save sp and ss.
18429 * Use the helper function to retrieve sp.
18430 */
18431 - if (offset == offsetof(struct pt_regs, sp) &&
18432 - regs->cs == __KERNEL_CS)
18433 - return kernel_stack_pointer(regs);
18434 + if (offset == offsetof(struct pt_regs, sp)) {
18435 + unsigned long cs = regs->cs & 0xffff;
18436 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18437 + return kernel_stack_pointer(regs);
18438 + }
18439 #endif
18440 return *(unsigned long *)((unsigned long)regs + offset);
18441 }
18442 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18443 index 9c6b890..5305f53 100644
18444 --- a/arch/x86/include/asm/realmode.h
18445 +++ b/arch/x86/include/asm/realmode.h
18446 @@ -22,16 +22,14 @@ struct real_mode_header {
18447 #endif
18448 /* APM/BIOS reboot */
18449 u32 machine_real_restart_asm;
18450 -#ifdef CONFIG_X86_64
18451 u32 machine_real_restart_seg;
18452 -#endif
18453 };
18454
18455 /* This must match data at trampoline_32/64.S */
18456 struct trampoline_header {
18457 #ifdef CONFIG_X86_32
18458 u32 start;
18459 - u16 gdt_pad;
18460 + u16 boot_cs;
18461 u16 gdt_limit;
18462 u32 gdt_base;
18463 #else
18464 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18465 index a82c4f1..ac45053 100644
18466 --- a/arch/x86/include/asm/reboot.h
18467 +++ b/arch/x86/include/asm/reboot.h
18468 @@ -6,13 +6,13 @@
18469 struct pt_regs;
18470
18471 struct machine_ops {
18472 - void (*restart)(char *cmd);
18473 - void (*halt)(void);
18474 - void (*power_off)(void);
18475 + void (* __noreturn restart)(char *cmd);
18476 + void (* __noreturn halt)(void);
18477 + void (* __noreturn power_off)(void);
18478 void (*shutdown)(void);
18479 void (*crash_shutdown)(struct pt_regs *);
18480 - void (*emergency_restart)(void);
18481 -};
18482 + void (* __noreturn emergency_restart)(void);
18483 +} __no_const;
18484
18485 extern struct machine_ops machine_ops;
18486
18487 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18488 index 8f7866a..e442f20 100644
18489 --- a/arch/x86/include/asm/rmwcc.h
18490 +++ b/arch/x86/include/asm/rmwcc.h
18491 @@ -3,7 +3,34 @@
18492
18493 #ifdef CC_HAVE_ASM_GOTO
18494
18495 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18496 +#ifdef CONFIG_PAX_REFCOUNT
18497 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18498 +do { \
18499 + asm_volatile_goto (fullop \
18500 + ";jno 0f\n" \
18501 + fullantiop \
18502 + ";int $4\n0:\n" \
18503 + _ASM_EXTABLE(0b, 0b) \
18504 + ";j" cc " %l[cc_label]" \
18505 + : : "m" (var), ## __VA_ARGS__ \
18506 + : "memory" : cc_label); \
18507 + return 0; \
18508 +cc_label: \
18509 + return 1; \
18510 +} while (0)
18511 +#else
18512 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18513 +do { \
18514 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18515 + : : "m" (var), ## __VA_ARGS__ \
18516 + : "memory" : cc_label); \
18517 + return 0; \
18518 +cc_label: \
18519 + return 1; \
18520 +} while (0)
18521 +#endif
18522 +
18523 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18524 do { \
18525 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18526 : : "m" (var), ## __VA_ARGS__ \
18527 @@ -13,15 +40,46 @@ cc_label: \
18528 return 1; \
18529 } while (0)
18530
18531 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18532 - __GEN_RMWcc(op " " arg0, var, cc)
18533 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18534 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18535
18536 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18537 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18538 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18539 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18540 +
18541 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18542 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18543 +
18544 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18545 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18546
18547 #else /* !CC_HAVE_ASM_GOTO */
18548
18549 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18550 +#ifdef CONFIG_PAX_REFCOUNT
18551 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18552 +do { \
18553 + char c; \
18554 + asm volatile (fullop \
18555 + ";jno 0f\n" \
18556 + fullantiop \
18557 + ";int $4\n0:\n" \
18558 + _ASM_EXTABLE(0b, 0b) \
18559 + "; set" cc " %1" \
18560 + : "+m" (var), "=qm" (c) \
18561 + : __VA_ARGS__ : "memory"); \
18562 + return c != 0; \
18563 +} while (0)
18564 +#else
18565 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18566 +do { \
18567 + char c; \
18568 + asm volatile (fullop "; set" cc " %1" \
18569 + : "+m" (var), "=qm" (c) \
18570 + : __VA_ARGS__ : "memory"); \
18571 + return c != 0; \
18572 +} while (0)
18573 +#endif
18574 +
18575 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18576 do { \
18577 char c; \
18578 asm volatile (fullop "; set" cc " %1" \
18579 @@ -30,11 +88,17 @@ do { \
18580 return c != 0; \
18581 } while (0)
18582
18583 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18584 - __GEN_RMWcc(op " " arg0, var, cc)
18585 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18586 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18587 +
18588 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18589 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18590 +
18591 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18592 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18593
18594 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18595 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18596 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18597 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18598
18599 #endif /* CC_HAVE_ASM_GOTO */
18600
18601 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18602 index cad82c9..2e5c5c1 100644
18603 --- a/arch/x86/include/asm/rwsem.h
18604 +++ b/arch/x86/include/asm/rwsem.h
18605 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18606 {
18607 asm volatile("# beginning down_read\n\t"
18608 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18609 +
18610 +#ifdef CONFIG_PAX_REFCOUNT
18611 + "jno 0f\n"
18612 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18613 + "int $4\n0:\n"
18614 + _ASM_EXTABLE(0b, 0b)
18615 +#endif
18616 +
18617 /* adds 0x00000001 */
18618 " jns 1f\n"
18619 " call call_rwsem_down_read_failed\n"
18620 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18621 "1:\n\t"
18622 " mov %1,%2\n\t"
18623 " add %3,%2\n\t"
18624 +
18625 +#ifdef CONFIG_PAX_REFCOUNT
18626 + "jno 0f\n"
18627 + "sub %3,%2\n"
18628 + "int $4\n0:\n"
18629 + _ASM_EXTABLE(0b, 0b)
18630 +#endif
18631 +
18632 " jle 2f\n\t"
18633 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18634 " jnz 1b\n\t"
18635 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18636 long tmp;
18637 asm volatile("# beginning down_write\n\t"
18638 LOCK_PREFIX " xadd %1,(%2)\n\t"
18639 +
18640 +#ifdef CONFIG_PAX_REFCOUNT
18641 + "jno 0f\n"
18642 + "mov %1,(%2)\n"
18643 + "int $4\n0:\n"
18644 + _ASM_EXTABLE(0b, 0b)
18645 +#endif
18646 +
18647 /* adds 0xffff0001, returns the old value */
18648 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18649 /* was the active mask 0 before? */
18650 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18651 long tmp;
18652 asm volatile("# beginning __up_read\n\t"
18653 LOCK_PREFIX " xadd %1,(%2)\n\t"
18654 +
18655 +#ifdef CONFIG_PAX_REFCOUNT
18656 + "jno 0f\n"
18657 + "mov %1,(%2)\n"
18658 + "int $4\n0:\n"
18659 + _ASM_EXTABLE(0b, 0b)
18660 +#endif
18661 +
18662 /* subtracts 1, returns the old value */
18663 " jns 1f\n\t"
18664 " call call_rwsem_wake\n" /* expects old value in %edx */
18665 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18666 long tmp;
18667 asm volatile("# beginning __up_write\n\t"
18668 LOCK_PREFIX " xadd %1,(%2)\n\t"
18669 +
18670 +#ifdef CONFIG_PAX_REFCOUNT
18671 + "jno 0f\n"
18672 + "mov %1,(%2)\n"
18673 + "int $4\n0:\n"
18674 + _ASM_EXTABLE(0b, 0b)
18675 +#endif
18676 +
18677 /* subtracts 0xffff0001, returns the old value */
18678 " jns 1f\n\t"
18679 " call call_rwsem_wake\n" /* expects old value in %edx */
18680 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18681 {
18682 asm volatile("# beginning __downgrade_write\n\t"
18683 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18684 +
18685 +#ifdef CONFIG_PAX_REFCOUNT
18686 + "jno 0f\n"
18687 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18688 + "int $4\n0:\n"
18689 + _ASM_EXTABLE(0b, 0b)
18690 +#endif
18691 +
18692 /*
18693 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18694 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18695 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18696 */
18697 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18698 {
18699 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18700 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18701 +
18702 +#ifdef CONFIG_PAX_REFCOUNT
18703 + "jno 0f\n"
18704 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18705 + "int $4\n0:\n"
18706 + _ASM_EXTABLE(0b, 0b)
18707 +#endif
18708 +
18709 : "+m" (sem->count)
18710 : "er" (delta));
18711 }
18712 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18713 */
18714 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18715 {
18716 - return delta + xadd(&sem->count, delta);
18717 + return delta + xadd_check_overflow(&sem->count, delta);
18718 }
18719
18720 #endif /* __KERNEL__ */
18721 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18722 index 6f1c3a8..7744f19 100644
18723 --- a/arch/x86/include/asm/segment.h
18724 +++ b/arch/x86/include/asm/segment.h
18725 @@ -64,10 +64,15 @@
18726 * 26 - ESPFIX small SS
18727 * 27 - per-cpu [ offset to per-cpu data area ]
18728 * 28 - stack_canary-20 [ for stack protector ]
18729 - * 29 - unused
18730 - * 30 - unused
18731 + * 29 - PCI BIOS CS
18732 + * 30 - PCI BIOS DS
18733 * 31 - TSS for double fault handler
18734 */
18735 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18736 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18737 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18738 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18739 +
18740 #define GDT_ENTRY_TLS_MIN 6
18741 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18742
18743 @@ -79,6 +84,8 @@
18744
18745 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18746
18747 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18748 +
18749 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18750
18751 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18752 @@ -104,6 +111,12 @@
18753 #define __KERNEL_STACK_CANARY 0
18754 #endif
18755
18756 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18757 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18758 +
18759 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18760 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18761 +
18762 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18763
18764 /*
18765 @@ -141,7 +154,7 @@
18766 */
18767
18768 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18769 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18770 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18771
18772
18773 #else
18774 @@ -165,6 +178,8 @@
18775 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18776 #define __USER32_DS __USER_DS
18777
18778 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18779 +
18780 #define GDT_ENTRY_TSS 8 /* needs two entries */
18781 #define GDT_ENTRY_LDT 10 /* needs two entries */
18782 #define GDT_ENTRY_TLS_MIN 12
18783 @@ -173,6 +188,8 @@
18784 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18785 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18786
18787 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18788 +
18789 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18790 #define FS_TLS 0
18791 #define GS_TLS 1
18792 @@ -180,12 +197,14 @@
18793 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18794 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18795
18796 -#define GDT_ENTRIES 16
18797 +#define GDT_ENTRIES 17
18798
18799 #endif
18800
18801 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18802 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18803 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18804 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18805 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18806 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18807 #ifndef CONFIG_PARAVIRT
18808 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18809 {
18810 unsigned long __limit;
18811 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18812 - return __limit + 1;
18813 + return __limit;
18814 }
18815
18816 #endif /* !__ASSEMBLY__ */
18817 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18818 index 8d3120f..352b440 100644
18819 --- a/arch/x86/include/asm/smap.h
18820 +++ b/arch/x86/include/asm/smap.h
18821 @@ -25,11 +25,40 @@
18822
18823 #include <asm/alternative-asm.h>
18824
18825 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18826 +#define ASM_PAX_OPEN_USERLAND \
18827 + 661: jmp 663f; \
18828 + .pushsection .altinstr_replacement, "a" ; \
18829 + 662: pushq %rax; nop; \
18830 + .popsection ; \
18831 + .pushsection .altinstructions, "a" ; \
18832 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18833 + .popsection ; \
18834 + call __pax_open_userland; \
18835 + popq %rax; \
18836 + 663:
18837 +
18838 +#define ASM_PAX_CLOSE_USERLAND \
18839 + 661: jmp 663f; \
18840 + .pushsection .altinstr_replacement, "a" ; \
18841 + 662: pushq %rax; nop; \
18842 + .popsection; \
18843 + .pushsection .altinstructions, "a" ; \
18844 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18845 + .popsection; \
18846 + call __pax_close_userland; \
18847 + popq %rax; \
18848 + 663:
18849 +#else
18850 +#define ASM_PAX_OPEN_USERLAND
18851 +#define ASM_PAX_CLOSE_USERLAND
18852 +#endif
18853 +
18854 #ifdef CONFIG_X86_SMAP
18855
18856 #define ASM_CLAC \
18857 661: ASM_NOP3 ; \
18858 - .pushsection .altinstr_replacement, "ax" ; \
18859 + .pushsection .altinstr_replacement, "a" ; \
18860 662: __ASM_CLAC ; \
18861 .popsection ; \
18862 .pushsection .altinstructions, "a" ; \
18863 @@ -38,7 +67,7 @@
18864
18865 #define ASM_STAC \
18866 661: ASM_NOP3 ; \
18867 - .pushsection .altinstr_replacement, "ax" ; \
18868 + .pushsection .altinstr_replacement, "a" ; \
18869 662: __ASM_STAC ; \
18870 .popsection ; \
18871 .pushsection .altinstructions, "a" ; \
18872 @@ -56,6 +85,37 @@
18873
18874 #include <asm/alternative.h>
18875
18876 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
18877 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18878 +
18879 +extern void __pax_open_userland(void);
18880 +static __always_inline unsigned long pax_open_userland(void)
18881 +{
18882 +
18883 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18884 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18885 + :
18886 + : [open] "i" (__pax_open_userland)
18887 + : "memory", "rax");
18888 +#endif
18889 +
18890 + return 0;
18891 +}
18892 +
18893 +extern void __pax_close_userland(void);
18894 +static __always_inline unsigned long pax_close_userland(void)
18895 +{
18896 +
18897 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18898 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18899 + :
18900 + : [close] "i" (__pax_close_userland)
18901 + : "memory", "rax");
18902 +#endif
18903 +
18904 + return 0;
18905 +}
18906 +
18907 #ifdef CONFIG_X86_SMAP
18908
18909 static __always_inline void clac(void)
18910 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18911 index 8cd27e0..7f05ec8 100644
18912 --- a/arch/x86/include/asm/smp.h
18913 +++ b/arch/x86/include/asm/smp.h
18914 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18915 /* cpus sharing the last level cache: */
18916 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18917 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18918 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18919 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18920
18921 static inline struct cpumask *cpu_sibling_mask(int cpu)
18922 {
18923 @@ -78,7 +78,7 @@ struct smp_ops {
18924
18925 void (*send_call_func_ipi)(const struct cpumask *mask);
18926 void (*send_call_func_single_ipi)(int cpu);
18927 -};
18928 +} __no_const;
18929
18930 /* Globals due to paravirt */
18931 extern void set_cpu_sibling_map(int cpu);
18932 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
18933 extern int safe_smp_processor_id(void);
18934
18935 #elif defined(CONFIG_X86_64_SMP)
18936 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18937 -
18938 -#define stack_smp_processor_id() \
18939 -({ \
18940 - struct thread_info *ti; \
18941 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18942 - ti->cpu; \
18943 -})
18944 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18945 +#define stack_smp_processor_id() raw_smp_processor_id()
18946 #define safe_smp_processor_id() smp_processor_id()
18947
18948 #endif
18949 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18950 index 0f62f54..cb5d0dd 100644
18951 --- a/arch/x86/include/asm/spinlock.h
18952 +++ b/arch/x86/include/asm/spinlock.h
18953 @@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18954 static inline void arch_read_lock(arch_rwlock_t *rw)
18955 {
18956 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18957 +
18958 +#ifdef CONFIG_PAX_REFCOUNT
18959 + "jno 0f\n"
18960 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18961 + "int $4\n0:\n"
18962 + _ASM_EXTABLE(0b, 0b)
18963 +#endif
18964 +
18965 "jns 1f\n"
18966 "call __read_lock_failed\n\t"
18967 "1:\n"
18968 @@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18969 static inline void arch_write_lock(arch_rwlock_t *rw)
18970 {
18971 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18972 +
18973 +#ifdef CONFIG_PAX_REFCOUNT
18974 + "jno 0f\n"
18975 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18976 + "int $4\n0:\n"
18977 + _ASM_EXTABLE(0b, 0b)
18978 +#endif
18979 +
18980 "jz 1f\n"
18981 "call __write_lock_failed\n\t"
18982 "1:\n"
18983 @@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18984
18985 static inline void arch_read_unlock(arch_rwlock_t *rw)
18986 {
18987 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18988 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18989 +
18990 +#ifdef CONFIG_PAX_REFCOUNT
18991 + "jno 0f\n"
18992 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18993 + "int $4\n0:\n"
18994 + _ASM_EXTABLE(0b, 0b)
18995 +#endif
18996 +
18997 :"+m" (rw->lock) : : "memory");
18998 }
18999
19000 static inline void arch_write_unlock(arch_rwlock_t *rw)
19001 {
19002 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19003 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19004 +
19005 +#ifdef CONFIG_PAX_REFCOUNT
19006 + "jno 0f\n"
19007 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19008 + "int $4\n0:\n"
19009 + _ASM_EXTABLE(0b, 0b)
19010 +#endif
19011 +
19012 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19013 }
19014
19015 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19016 index 6a99859..03cb807 100644
19017 --- a/arch/x86/include/asm/stackprotector.h
19018 +++ b/arch/x86/include/asm/stackprotector.h
19019 @@ -47,7 +47,7 @@
19020 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19021 */
19022 #define GDT_STACK_CANARY_INIT \
19023 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19024 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19025
19026 /*
19027 * Initialize the stackprotector canary value.
19028 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19029
19030 static inline void load_stack_canary_segment(void)
19031 {
19032 -#ifdef CONFIG_X86_32
19033 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19034 asm volatile ("mov %0, %%gs" : : "r" (0));
19035 #endif
19036 }
19037 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19038 index 70bbe39..4ae2bd4 100644
19039 --- a/arch/x86/include/asm/stacktrace.h
19040 +++ b/arch/x86/include/asm/stacktrace.h
19041 @@ -11,28 +11,20 @@
19042
19043 extern int kstack_depth_to_print;
19044
19045 -struct thread_info;
19046 +struct task_struct;
19047 struct stacktrace_ops;
19048
19049 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19050 - unsigned long *stack,
19051 - unsigned long bp,
19052 - const struct stacktrace_ops *ops,
19053 - void *data,
19054 - unsigned long *end,
19055 - int *graph);
19056 +typedef unsigned long walk_stack_t(struct task_struct *task,
19057 + void *stack_start,
19058 + unsigned long *stack,
19059 + unsigned long bp,
19060 + const struct stacktrace_ops *ops,
19061 + void *data,
19062 + unsigned long *end,
19063 + int *graph);
19064
19065 -extern unsigned long
19066 -print_context_stack(struct thread_info *tinfo,
19067 - unsigned long *stack, unsigned long bp,
19068 - const struct stacktrace_ops *ops, void *data,
19069 - unsigned long *end, int *graph);
19070 -
19071 -extern unsigned long
19072 -print_context_stack_bp(struct thread_info *tinfo,
19073 - unsigned long *stack, unsigned long bp,
19074 - const struct stacktrace_ops *ops, void *data,
19075 - unsigned long *end, int *graph);
19076 +extern walk_stack_t print_context_stack;
19077 +extern walk_stack_t print_context_stack_bp;
19078
19079 /* Generic stack tracer with callbacks */
19080
19081 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19082 void (*address)(void *data, unsigned long address, int reliable);
19083 /* On negative return stop dumping */
19084 int (*stack)(void *data, char *name);
19085 - walk_stack_t walk_stack;
19086 + walk_stack_t *walk_stack;
19087 };
19088
19089 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19090 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19091 index d7f3b3b..3cc39f1 100644
19092 --- a/arch/x86/include/asm/switch_to.h
19093 +++ b/arch/x86/include/asm/switch_to.h
19094 @@ -108,7 +108,7 @@ do { \
19095 "call __switch_to\n\t" \
19096 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19097 __switch_canary \
19098 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19099 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19100 "movq %%rax,%%rdi\n\t" \
19101 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19102 "jnz ret_from_fork\n\t" \
19103 @@ -119,7 +119,7 @@ do { \
19104 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19105 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19106 [_tif_fork] "i" (_TIF_FORK), \
19107 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19108 + [thread_info] "m" (current_tinfo), \
19109 [current_task] "m" (current_task) \
19110 __switch_canary_iparam \
19111 : "memory", "cc" __EXTRA_CLOBBER)
19112 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19113 index 47e5de2..d3dda54 100644
19114 --- a/arch/x86/include/asm/thread_info.h
19115 +++ b/arch/x86/include/asm/thread_info.h
19116 @@ -24,7 +24,6 @@ struct exec_domain;
19117 #include <linux/atomic.h>
19118
19119 struct thread_info {
19120 - struct task_struct *task; /* main task structure */
19121 struct exec_domain *exec_domain; /* execution domain */
19122 __u32 flags; /* low level flags */
19123 __u32 status; /* thread synchronous flags */
19124 @@ -33,13 +32,13 @@ struct thread_info {
19125 mm_segment_t addr_limit;
19126 struct restart_block restart_block;
19127 void __user *sysenter_return;
19128 + unsigned long lowest_stack;
19129 unsigned int sig_on_uaccess_error:1;
19130 unsigned int uaccess_err:1; /* uaccess failed */
19131 };
19132
19133 -#define INIT_THREAD_INFO(tsk) \
19134 +#define INIT_THREAD_INFO \
19135 { \
19136 - .task = &tsk, \
19137 .exec_domain = &default_exec_domain, \
19138 .flags = 0, \
19139 .cpu = 0, \
19140 @@ -50,7 +49,7 @@ struct thread_info {
19141 }, \
19142 }
19143
19144 -#define init_thread_info (init_thread_union.thread_info)
19145 +#define init_thread_info (init_thread_union.stack)
19146 #define init_stack (init_thread_union.stack)
19147
19148 #else /* !__ASSEMBLY__ */
19149 @@ -90,6 +89,7 @@ struct thread_info {
19150 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19151 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19152 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19153 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19154
19155 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19156 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19157 @@ -113,17 +113,18 @@ struct thread_info {
19158 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19159 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19160 #define _TIF_X32 (1 << TIF_X32)
19161 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19162
19163 /* work to do in syscall_trace_enter() */
19164 #define _TIF_WORK_SYSCALL_ENTRY \
19165 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19166 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19167 - _TIF_NOHZ)
19168 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19169
19170 /* work to do in syscall_trace_leave() */
19171 #define _TIF_WORK_SYSCALL_EXIT \
19172 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19173 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19174 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19175
19176 /* work to do on interrupt/exception return */
19177 #define _TIF_WORK_MASK \
19178 @@ -134,7 +135,7 @@ struct thread_info {
19179 /* work to do on any return to user space */
19180 #define _TIF_ALLWORK_MASK \
19181 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19182 - _TIF_NOHZ)
19183 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19184
19185 /* Only used for 64 bit */
19186 #define _TIF_DO_NOTIFY_MASK \
19187 @@ -149,7 +150,6 @@ struct thread_info {
19188 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19189
19190 #define STACK_WARN (THREAD_SIZE/8)
19191 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19192
19193 /*
19194 * macros/functions for gaining access to the thread information structure
19195 @@ -160,26 +160,18 @@ struct thread_info {
19196
19197 DECLARE_PER_CPU(unsigned long, kernel_stack);
19198
19199 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19200 +
19201 static inline struct thread_info *current_thread_info(void)
19202 {
19203 - struct thread_info *ti;
19204 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19205 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19206 - return ti;
19207 + return this_cpu_read_stable(current_tinfo);
19208 }
19209
19210 #else /* !__ASSEMBLY__ */
19211
19212 /* how to get the thread information struct from ASM */
19213 #define GET_THREAD_INFO(reg) \
19214 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19215 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19216 -
19217 -/*
19218 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19219 - * a certain register (to be used in assembler memory operands).
19220 - */
19221 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19222 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19223
19224 #endif
19225
19226 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19227 extern void arch_task_cache_init(void);
19228 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19229 extern void arch_release_task_struct(struct task_struct *tsk);
19230 +
19231 +#define __HAVE_THREAD_FUNCTIONS
19232 +#define task_thread_info(task) (&(task)->tinfo)
19233 +#define task_stack_page(task) ((task)->stack)
19234 +#define setup_thread_stack(p, org) do {} while (0)
19235 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19236 +
19237 #endif
19238 #endif /* _ASM_X86_THREAD_INFO_H */
19239 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19240 index 04905bf..49203ca 100644
19241 --- a/arch/x86/include/asm/tlbflush.h
19242 +++ b/arch/x86/include/asm/tlbflush.h
19243 @@ -17,18 +17,44 @@
19244
19245 static inline void __native_flush_tlb(void)
19246 {
19247 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19248 + u64 descriptor[2];
19249 +
19250 + descriptor[0] = PCID_KERNEL;
19251 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19252 + return;
19253 + }
19254 +
19255 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19256 + if (static_cpu_has(X86_FEATURE_PCID)) {
19257 + unsigned int cpu = raw_get_cpu();
19258 +
19259 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19260 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19261 + raw_put_cpu_no_resched();
19262 + return;
19263 + }
19264 +#endif
19265 +
19266 native_write_cr3(native_read_cr3());
19267 }
19268
19269 static inline void __native_flush_tlb_global_irq_disabled(void)
19270 {
19271 - unsigned long cr4;
19272 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19273 + u64 descriptor[2];
19274
19275 - cr4 = native_read_cr4();
19276 - /* clear PGE */
19277 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19278 - /* write old PGE again and flush TLBs */
19279 - native_write_cr4(cr4);
19280 + descriptor[0] = PCID_KERNEL;
19281 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19282 + } else {
19283 + unsigned long cr4;
19284 +
19285 + cr4 = native_read_cr4();
19286 + /* clear PGE */
19287 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19288 + /* write old PGE again and flush TLBs */
19289 + native_write_cr4(cr4);
19290 + }
19291 }
19292
19293 static inline void __native_flush_tlb_global(void)
19294 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19295
19296 static inline void __native_flush_tlb_single(unsigned long addr)
19297 {
19298 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19299 + u64 descriptor[2];
19300 +
19301 + descriptor[0] = PCID_KERNEL;
19302 + descriptor[1] = addr;
19303 +
19304 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19305 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19306 + if (addr < TASK_SIZE_MAX)
19307 + descriptor[1] += pax_user_shadow_base;
19308 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19309 + }
19310 +
19311 + descriptor[0] = PCID_USER;
19312 + descriptor[1] = addr;
19313 +#endif
19314 +
19315 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19316 + return;
19317 + }
19318 +
19319 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19320 + if (static_cpu_has(X86_FEATURE_PCID)) {
19321 + unsigned int cpu = raw_get_cpu();
19322 +
19323 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19324 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19325 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19326 + raw_put_cpu_no_resched();
19327 +
19328 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19329 + addr += pax_user_shadow_base;
19330 + }
19331 +#endif
19332 +
19333 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19334 }
19335
19336 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19337 index 0d592e0..7437fcc 100644
19338 --- a/arch/x86/include/asm/uaccess.h
19339 +++ b/arch/x86/include/asm/uaccess.h
19340 @@ -7,6 +7,7 @@
19341 #include <linux/compiler.h>
19342 #include <linux/thread_info.h>
19343 #include <linux/string.h>
19344 +#include <linux/spinlock.h>
19345 #include <asm/asm.h>
19346 #include <asm/page.h>
19347 #include <asm/smap.h>
19348 @@ -29,7 +30,12 @@
19349
19350 #define get_ds() (KERNEL_DS)
19351 #define get_fs() (current_thread_info()->addr_limit)
19352 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19353 +void __set_fs(mm_segment_t x);
19354 +void set_fs(mm_segment_t x);
19355 +#else
19356 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19357 +#endif
19358
19359 #define segment_eq(a, b) ((a).seg == (b).seg)
19360
19361 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19362 * checks that the pointer is in the user space range - after calling
19363 * this function, memory access functions may still return -EFAULT.
19364 */
19365 -#define access_ok(type, addr, size) \
19366 - likely(!__range_not_ok(addr, size, user_addr_max()))
19367 +extern int _cond_resched(void);
19368 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19369 +#define access_ok(type, addr, size) \
19370 +({ \
19371 + unsigned long __size = size; \
19372 + unsigned long __addr = (unsigned long)addr; \
19373 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19374 + if (__ret_ao && __size) { \
19375 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19376 + unsigned long __end_ao = __addr + __size - 1; \
19377 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19378 + while (__addr_ao <= __end_ao) { \
19379 + char __c_ao; \
19380 + __addr_ao += PAGE_SIZE; \
19381 + if (__size > PAGE_SIZE) \
19382 + _cond_resched(); \
19383 + if (__get_user(__c_ao, (char __user *)__addr)) \
19384 + break; \
19385 + if (type != VERIFY_WRITE) { \
19386 + __addr = __addr_ao; \
19387 + continue; \
19388 + } \
19389 + if (__put_user(__c_ao, (char __user *)__addr)) \
19390 + break; \
19391 + __addr = __addr_ao; \
19392 + } \
19393 + } \
19394 + } \
19395 + __ret_ao; \
19396 +})
19397
19398 /*
19399 * The exception table consists of pairs of addresses relative to the
19400 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19401 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19402 __chk_user_ptr(ptr); \
19403 might_fault(); \
19404 + pax_open_userland(); \
19405 asm volatile("call __get_user_%P3" \
19406 : "=a" (__ret_gu), "=r" (__val_gu) \
19407 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19408 (x) = (__typeof__(*(ptr))) __val_gu; \
19409 + pax_close_userland(); \
19410 __ret_gu; \
19411 })
19412
19413 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19414 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19415 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19416
19417 -
19418 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19419 +#define __copyuser_seg "gs;"
19420 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19421 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19422 +#else
19423 +#define __copyuser_seg
19424 +#define __COPYUSER_SET_ES
19425 +#define __COPYUSER_RESTORE_ES
19426 +#endif
19427
19428 #ifdef CONFIG_X86_32
19429 #define __put_user_asm_u64(x, addr, err, errret) \
19430 asm volatile(ASM_STAC "\n" \
19431 - "1: movl %%eax,0(%2)\n" \
19432 - "2: movl %%edx,4(%2)\n" \
19433 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19434 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19435 "3: " ASM_CLAC "\n" \
19436 ".section .fixup,\"ax\"\n" \
19437 "4: movl %3,%0\n" \
19438 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19439
19440 #define __put_user_asm_ex_u64(x, addr) \
19441 asm volatile(ASM_STAC "\n" \
19442 - "1: movl %%eax,0(%1)\n" \
19443 - "2: movl %%edx,4(%1)\n" \
19444 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19445 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19446 "3: " ASM_CLAC "\n" \
19447 _ASM_EXTABLE_EX(1b, 2b) \
19448 _ASM_EXTABLE_EX(2b, 3b) \
19449 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
19450 __typeof__(*(ptr)) __pu_val; \
19451 __chk_user_ptr(ptr); \
19452 might_fault(); \
19453 - __pu_val = x; \
19454 + __pu_val = (x); \
19455 + pax_open_userland(); \
19456 switch (sizeof(*(ptr))) { \
19457 case 1: \
19458 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19459 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
19460 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19461 break; \
19462 } \
19463 + pax_close_userland(); \
19464 __ret_pu; \
19465 })
19466
19467 @@ -355,8 +401,10 @@ do { \
19468 } while (0)
19469
19470 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19471 +do { \
19472 + pax_open_userland(); \
19473 asm volatile(ASM_STAC "\n" \
19474 - "1: mov"itype" %2,%"rtype"1\n" \
19475 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19476 "2: " ASM_CLAC "\n" \
19477 ".section .fixup,\"ax\"\n" \
19478 "3: mov %3,%0\n" \
19479 @@ -364,8 +412,10 @@ do { \
19480 " jmp 2b\n" \
19481 ".previous\n" \
19482 _ASM_EXTABLE(1b, 3b) \
19483 - : "=r" (err), ltype(x) \
19484 - : "m" (__m(addr)), "i" (errret), "0" (err))
19485 + : "=r" (err), ltype (x) \
19486 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19487 + pax_close_userland(); \
19488 +} while (0)
19489
19490 #define __get_user_size_ex(x, ptr, size) \
19491 do { \
19492 @@ -389,7 +439,7 @@ do { \
19493 } while (0)
19494
19495 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19496 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19497 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19498 "2:\n" \
19499 _ASM_EXTABLE_EX(1b, 2b) \
19500 : ltype(x) : "m" (__m(addr)))
19501 @@ -406,13 +456,24 @@ do { \
19502 int __gu_err; \
19503 unsigned long __gu_val; \
19504 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19505 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19506 + (x) = (__typeof__(*(ptr)))__gu_val; \
19507 __gu_err; \
19508 })
19509
19510 /* FIXME: this hack is definitely wrong -AK */
19511 struct __large_struct { unsigned long buf[100]; };
19512 -#define __m(x) (*(struct __large_struct __user *)(x))
19513 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19514 +#define ____m(x) \
19515 +({ \
19516 + unsigned long ____x = (unsigned long)(x); \
19517 + if (____x < pax_user_shadow_base) \
19518 + ____x += pax_user_shadow_base; \
19519 + (typeof(x))____x; \
19520 +})
19521 +#else
19522 +#define ____m(x) (x)
19523 +#endif
19524 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19525
19526 /*
19527 * Tell gcc we read from memory instead of writing: this is because
19528 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19529 * aliasing issues.
19530 */
19531 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19532 +do { \
19533 + pax_open_userland(); \
19534 asm volatile(ASM_STAC "\n" \
19535 - "1: mov"itype" %"rtype"1,%2\n" \
19536 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19537 "2: " ASM_CLAC "\n" \
19538 ".section .fixup,\"ax\"\n" \
19539 "3: mov %3,%0\n" \
19540 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19541 ".previous\n" \
19542 _ASM_EXTABLE(1b, 3b) \
19543 : "=r"(err) \
19544 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19545 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19546 + pax_close_userland(); \
19547 +} while (0)
19548
19549 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19550 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19551 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19552 "2:\n" \
19553 _ASM_EXTABLE_EX(1b, 2b) \
19554 : : ltype(x), "m" (__m(addr)))
19555 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19556 */
19557 #define uaccess_try do { \
19558 current_thread_info()->uaccess_err = 0; \
19559 + pax_open_userland(); \
19560 stac(); \
19561 barrier();
19562
19563 #define uaccess_catch(err) \
19564 clac(); \
19565 + pax_close_userland(); \
19566 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19567 } while (0)
19568
19569 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19570 * On error, the variable @x is set to zero.
19571 */
19572
19573 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19574 +#define __get_user(x, ptr) get_user((x), (ptr))
19575 +#else
19576 #define __get_user(x, ptr) \
19577 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19578 +#endif
19579
19580 /**
19581 * __put_user: - Write a simple value into user space, with less checking.
19582 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19583 * Returns zero on success, or -EFAULT on error.
19584 */
19585
19586 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19587 +#define __put_user(x, ptr) put_user((x), (ptr))
19588 +#else
19589 #define __put_user(x, ptr) \
19590 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19591 +#endif
19592
19593 #define __get_user_unaligned __get_user
19594 #define __put_user_unaligned __put_user
19595 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19596 #define get_user_ex(x, ptr) do { \
19597 unsigned long __gue_val; \
19598 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19599 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19600 + (x) = (__typeof__(*(ptr)))__gue_val; \
19601 } while (0)
19602
19603 #define put_user_try uaccess_try
19604 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19605 __typeof__(ptr) __uval = (uval); \
19606 __typeof__(*(ptr)) __old = (old); \
19607 __typeof__(*(ptr)) __new = (new); \
19608 + pax_open_userland(); \
19609 switch (size) { \
19610 case 1: \
19611 { \
19612 asm volatile("\t" ASM_STAC "\n" \
19613 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19614 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19615 "2:\t" ASM_CLAC "\n" \
19616 "\t.section .fixup, \"ax\"\n" \
19617 "3:\tmov %3, %0\n" \
19618 "\tjmp 2b\n" \
19619 "\t.previous\n" \
19620 _ASM_EXTABLE(1b, 3b) \
19621 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19622 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19623 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19624 : "memory" \
19625 ); \
19626 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19627 case 2: \
19628 { \
19629 asm volatile("\t" ASM_STAC "\n" \
19630 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19631 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19632 "2:\t" ASM_CLAC "\n" \
19633 "\t.section .fixup, \"ax\"\n" \
19634 "3:\tmov %3, %0\n" \
19635 "\tjmp 2b\n" \
19636 "\t.previous\n" \
19637 _ASM_EXTABLE(1b, 3b) \
19638 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19639 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19640 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19641 : "memory" \
19642 ); \
19643 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19644 case 4: \
19645 { \
19646 asm volatile("\t" ASM_STAC "\n" \
19647 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19648 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19649 "2:\t" ASM_CLAC "\n" \
19650 "\t.section .fixup, \"ax\"\n" \
19651 "3:\tmov %3, %0\n" \
19652 "\tjmp 2b\n" \
19653 "\t.previous\n" \
19654 _ASM_EXTABLE(1b, 3b) \
19655 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19656 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19657 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19658 : "memory" \
19659 ); \
19660 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19661 __cmpxchg_wrong_size(); \
19662 \
19663 asm volatile("\t" ASM_STAC "\n" \
19664 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19665 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19666 "2:\t" ASM_CLAC "\n" \
19667 "\t.section .fixup, \"ax\"\n" \
19668 "3:\tmov %3, %0\n" \
19669 "\tjmp 2b\n" \
19670 "\t.previous\n" \
19671 _ASM_EXTABLE(1b, 3b) \
19672 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19673 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19674 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19675 : "memory" \
19676 ); \
19677 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19678 default: \
19679 __cmpxchg_wrong_size(); \
19680 } \
19681 + pax_close_userland(); \
19682 *__uval = __old; \
19683 __ret; \
19684 })
19685 @@ -636,17 +713,6 @@ extern struct movsl_mask {
19686
19687 #define ARCH_HAS_NOCACHE_UACCESS 1
19688
19689 -#ifdef CONFIG_X86_32
19690 -# include <asm/uaccess_32.h>
19691 -#else
19692 -# include <asm/uaccess_64.h>
19693 -#endif
19694 -
19695 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19696 - unsigned n);
19697 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19698 - unsigned n);
19699 -
19700 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19701 # define copy_user_diag __compiletime_error
19702 #else
19703 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19704 extern void copy_user_diag("copy_from_user() buffer size is too small")
19705 copy_from_user_overflow(void);
19706 extern void copy_user_diag("copy_to_user() buffer size is too small")
19707 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19708 +copy_to_user_overflow(void);
19709
19710 #undef copy_user_diag
19711
19712 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19713
19714 extern void
19715 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19716 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19717 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19718 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19719
19720 #else
19721 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19722
19723 #endif
19724
19725 +#ifdef CONFIG_X86_32
19726 +# include <asm/uaccess_32.h>
19727 +#else
19728 +# include <asm/uaccess_64.h>
19729 +#endif
19730 +
19731 static inline unsigned long __must_check
19732 copy_from_user(void *to, const void __user *from, unsigned long n)
19733 {
19734 - int sz = __compiletime_object_size(to);
19735 + size_t sz = __compiletime_object_size(to);
19736
19737 might_fault();
19738
19739 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19740 * case, and do only runtime checking for non-constant sizes.
19741 */
19742
19743 - if (likely(sz < 0 || sz >= n))
19744 - n = _copy_from_user(to, from, n);
19745 - else if(__builtin_constant_p(n))
19746 - copy_from_user_overflow();
19747 - else
19748 - __copy_from_user_overflow(sz, n);
19749 + if (likely(sz != (size_t)-1 && sz < n)) {
19750 + if(__builtin_constant_p(n))
19751 + copy_from_user_overflow();
19752 + else
19753 + __copy_from_user_overflow(sz, n);
19754 + } if (access_ok(VERIFY_READ, from, n))
19755 + n = __copy_from_user(to, from, n);
19756 + else if ((long)n > 0)
19757 + memset(to, 0, n);
19758
19759 return n;
19760 }
19761 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19762 static inline unsigned long __must_check
19763 copy_to_user(void __user *to, const void *from, unsigned long n)
19764 {
19765 - int sz = __compiletime_object_size(from);
19766 + size_t sz = __compiletime_object_size(from);
19767
19768 might_fault();
19769
19770 /* See the comment in copy_from_user() above. */
19771 - if (likely(sz < 0 || sz >= n))
19772 - n = _copy_to_user(to, from, n);
19773 - else if(__builtin_constant_p(n))
19774 - copy_to_user_overflow();
19775 - else
19776 - __copy_to_user_overflow(sz, n);
19777 + if (likely(sz != (size_t)-1 && sz < n)) {
19778 + if(__builtin_constant_p(n))
19779 + copy_to_user_overflow();
19780 + else
19781 + __copy_to_user_overflow(sz, n);
19782 + } else if (access_ok(VERIFY_WRITE, to, n))
19783 + n = __copy_to_user(to, from, n);
19784
19785 return n;
19786 }
19787 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19788 index 3c03a5d..1071638 100644
19789 --- a/arch/x86/include/asm/uaccess_32.h
19790 +++ b/arch/x86/include/asm/uaccess_32.h
19791 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19792 static __always_inline unsigned long __must_check
19793 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19794 {
19795 + if ((long)n < 0)
19796 + return n;
19797 +
19798 + check_object_size(from, n, true);
19799 +
19800 if (__builtin_constant_p(n)) {
19801 unsigned long ret;
19802
19803 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19804 __copy_to_user(void __user *to, const void *from, unsigned long n)
19805 {
19806 might_fault();
19807 +
19808 return __copy_to_user_inatomic(to, from, n);
19809 }
19810
19811 static __always_inline unsigned long
19812 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19813 {
19814 + if ((long)n < 0)
19815 + return n;
19816 +
19817 /* Avoid zeroing the tail if the copy fails..
19818 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19819 * but as the zeroing behaviour is only significant when n is not
19820 @@ -137,6 +146,12 @@ static __always_inline unsigned long
19821 __copy_from_user(void *to, const void __user *from, unsigned long n)
19822 {
19823 might_fault();
19824 +
19825 + if ((long)n < 0)
19826 + return n;
19827 +
19828 + check_object_size(to, n, false);
19829 +
19830 if (__builtin_constant_p(n)) {
19831 unsigned long ret;
19832
19833 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19834 const void __user *from, unsigned long n)
19835 {
19836 might_fault();
19837 +
19838 + if ((long)n < 0)
19839 + return n;
19840 +
19841 if (__builtin_constant_p(n)) {
19842 unsigned long ret;
19843
19844 @@ -181,7 +200,10 @@ static __always_inline unsigned long
19845 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19846 unsigned long n)
19847 {
19848 - return __copy_from_user_ll_nocache_nozero(to, from, n);
19849 + if ((long)n < 0)
19850 + return n;
19851 +
19852 + return __copy_from_user_ll_nocache_nozero(to, from, n);
19853 }
19854
19855 #endif /* _ASM_X86_UACCESS_32_H */
19856 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19857 index 12a26b9..206c200 100644
19858 --- a/arch/x86/include/asm/uaccess_64.h
19859 +++ b/arch/x86/include/asm/uaccess_64.h
19860 @@ -10,6 +10,9 @@
19861 #include <asm/alternative.h>
19862 #include <asm/cpufeature.h>
19863 #include <asm/page.h>
19864 +#include <asm/pgtable.h>
19865 +
19866 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
19867
19868 /*
19869 * Copy To/From Userspace
19870 @@ -17,14 +20,14 @@
19871
19872 /* Handles exceptions in both to and from, but doesn't do access_ok */
19873 __must_check unsigned long
19874 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19875 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19876 __must_check unsigned long
19877 -copy_user_generic_string(void *to, const void *from, unsigned len);
19878 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19879 __must_check unsigned long
19880 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19881 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19882
19883 static __always_inline __must_check unsigned long
19884 -copy_user_generic(void *to, const void *from, unsigned len)
19885 +copy_user_generic(void *to, const void *from, unsigned long len)
19886 {
19887 unsigned ret;
19888
19889 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19890 }
19891
19892 __must_check unsigned long
19893 -copy_in_user(void __user *to, const void __user *from, unsigned len);
19894 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
19895
19896 static __always_inline __must_check
19897 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19898 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19899 {
19900 - int ret = 0;
19901 + size_t sz = __compiletime_object_size(dst);
19902 + unsigned ret = 0;
19903 +
19904 + if (size > INT_MAX)
19905 + return size;
19906 +
19907 + check_object_size(dst, size, false);
19908 +
19909 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19910 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19911 + return size;
19912 +#endif
19913 +
19914 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19915 + if(__builtin_constant_p(size))
19916 + copy_from_user_overflow();
19917 + else
19918 + __copy_from_user_overflow(sz, size);
19919 + return size;
19920 + }
19921
19922 if (!__builtin_constant_p(size))
19923 - return copy_user_generic(dst, (__force void *)src, size);
19924 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19925 switch (size) {
19926 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19927 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19928 ret, "b", "b", "=q", 1);
19929 return ret;
19930 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19931 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19932 ret, "w", "w", "=r", 2);
19933 return ret;
19934 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19935 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19936 ret, "l", "k", "=r", 4);
19937 return ret;
19938 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19939 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19940 ret, "q", "", "=r", 8);
19941 return ret;
19942 case 10:
19943 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19944 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19945 ret, "q", "", "=r", 10);
19946 if (unlikely(ret))
19947 return ret;
19948 __get_user_asm(*(u16 *)(8 + (char *)dst),
19949 - (u16 __user *)(8 + (char __user *)src),
19950 + (const u16 __user *)(8 + (const char __user *)src),
19951 ret, "w", "w", "=r", 2);
19952 return ret;
19953 case 16:
19954 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19955 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19956 ret, "q", "", "=r", 16);
19957 if (unlikely(ret))
19958 return ret;
19959 __get_user_asm(*(u64 *)(8 + (char *)dst),
19960 - (u64 __user *)(8 + (char __user *)src),
19961 + (const u64 __user *)(8 + (const char __user *)src),
19962 ret, "q", "", "=r", 8);
19963 return ret;
19964 default:
19965 - return copy_user_generic(dst, (__force void *)src, size);
19966 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19967 }
19968 }
19969
19970 static __always_inline __must_check
19971 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
19972 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19973 {
19974 might_fault();
19975 return __copy_from_user_nocheck(dst, src, size);
19976 }
19977
19978 static __always_inline __must_check
19979 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19980 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19981 {
19982 - int ret = 0;
19983 + size_t sz = __compiletime_object_size(src);
19984 + unsigned ret = 0;
19985 +
19986 + if (size > INT_MAX)
19987 + return size;
19988 +
19989 + check_object_size(src, size, true);
19990 +
19991 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19992 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19993 + return size;
19994 +#endif
19995 +
19996 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19997 + if(__builtin_constant_p(size))
19998 + copy_to_user_overflow();
19999 + else
20000 + __copy_to_user_overflow(sz, size);
20001 + return size;
20002 + }
20003
20004 if (!__builtin_constant_p(size))
20005 - return copy_user_generic((__force void *)dst, src, size);
20006 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20007 switch (size) {
20008 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20009 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20010 ret, "b", "b", "iq", 1);
20011 return ret;
20012 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20013 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20014 ret, "w", "w", "ir", 2);
20015 return ret;
20016 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20017 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20018 ret, "l", "k", "ir", 4);
20019 return ret;
20020 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20021 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20022 ret, "q", "", "er", 8);
20023 return ret;
20024 case 10:
20025 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20026 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20027 ret, "q", "", "er", 10);
20028 if (unlikely(ret))
20029 return ret;
20030 asm("":::"memory");
20031 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20032 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20033 ret, "w", "w", "ir", 2);
20034 return ret;
20035 case 16:
20036 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20037 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20038 ret, "q", "", "er", 16);
20039 if (unlikely(ret))
20040 return ret;
20041 asm("":::"memory");
20042 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20043 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20044 ret, "q", "", "er", 8);
20045 return ret;
20046 default:
20047 - return copy_user_generic((__force void *)dst, src, size);
20048 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20049 }
20050 }
20051
20052 static __always_inline __must_check
20053 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20054 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20055 {
20056 might_fault();
20057 return __copy_to_user_nocheck(dst, src, size);
20058 }
20059
20060 static __always_inline __must_check
20061 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20062 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20063 {
20064 - int ret = 0;
20065 + unsigned ret = 0;
20066
20067 might_fault();
20068 +
20069 + if (size > INT_MAX)
20070 + return size;
20071 +
20072 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20073 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20074 + return size;
20075 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20076 + return size;
20077 +#endif
20078 +
20079 if (!__builtin_constant_p(size))
20080 - return copy_user_generic((__force void *)dst,
20081 - (__force void *)src, size);
20082 + return copy_user_generic((__force_kernel void *)____m(dst),
20083 + (__force_kernel const void *)____m(src), size);
20084 switch (size) {
20085 case 1: {
20086 u8 tmp;
20087 - __get_user_asm(tmp, (u8 __user *)src,
20088 + __get_user_asm(tmp, (const u8 __user *)src,
20089 ret, "b", "b", "=q", 1);
20090 if (likely(!ret))
20091 __put_user_asm(tmp, (u8 __user *)dst,
20092 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20093 }
20094 case 2: {
20095 u16 tmp;
20096 - __get_user_asm(tmp, (u16 __user *)src,
20097 + __get_user_asm(tmp, (const u16 __user *)src,
20098 ret, "w", "w", "=r", 2);
20099 if (likely(!ret))
20100 __put_user_asm(tmp, (u16 __user *)dst,
20101 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20102
20103 case 4: {
20104 u32 tmp;
20105 - __get_user_asm(tmp, (u32 __user *)src,
20106 + __get_user_asm(tmp, (const u32 __user *)src,
20107 ret, "l", "k", "=r", 4);
20108 if (likely(!ret))
20109 __put_user_asm(tmp, (u32 __user *)dst,
20110 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20111 }
20112 case 8: {
20113 u64 tmp;
20114 - __get_user_asm(tmp, (u64 __user *)src,
20115 + __get_user_asm(tmp, (const u64 __user *)src,
20116 ret, "q", "", "=r", 8);
20117 if (likely(!ret))
20118 __put_user_asm(tmp, (u64 __user *)dst,
20119 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20120 return ret;
20121 }
20122 default:
20123 - return copy_user_generic((__force void *)dst,
20124 - (__force void *)src, size);
20125 + return copy_user_generic((__force_kernel void *)____m(dst),
20126 + (__force_kernel const void *)____m(src), size);
20127 }
20128 }
20129
20130 -static __must_check __always_inline int
20131 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20132 +static __must_check __always_inline unsigned long
20133 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20134 {
20135 return __copy_from_user_nocheck(dst, src, size);
20136 }
20137
20138 -static __must_check __always_inline int
20139 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20140 +static __must_check __always_inline unsigned long
20141 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20142 {
20143 return __copy_to_user_nocheck(dst, src, size);
20144 }
20145
20146 -extern long __copy_user_nocache(void *dst, const void __user *src,
20147 - unsigned size, int zerorest);
20148 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20149 + unsigned long size, int zerorest);
20150
20151 -static inline int
20152 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20153 +static inline unsigned long
20154 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20155 {
20156 might_fault();
20157 +
20158 + if (size > INT_MAX)
20159 + return size;
20160 +
20161 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20162 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20163 + return size;
20164 +#endif
20165 +
20166 return __copy_user_nocache(dst, src, size, 1);
20167 }
20168
20169 -static inline int
20170 +static inline unsigned long
20171 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20172 - unsigned size)
20173 + unsigned long size)
20174 {
20175 + if (size > INT_MAX)
20176 + return size;
20177 +
20178 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20179 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20180 + return size;
20181 +#endif
20182 +
20183 return __copy_user_nocache(dst, src, size, 0);
20184 }
20185
20186 unsigned long
20187 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20188 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20189
20190 #endif /* _ASM_X86_UACCESS_64_H */
20191 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20192 index 5b238981..77fdd78 100644
20193 --- a/arch/x86/include/asm/word-at-a-time.h
20194 +++ b/arch/x86/include/asm/word-at-a-time.h
20195 @@ -11,7 +11,7 @@
20196 * and shift, for example.
20197 */
20198 struct word_at_a_time {
20199 - const unsigned long one_bits, high_bits;
20200 + unsigned long one_bits, high_bits;
20201 };
20202
20203 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20204 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20205 index e45e4da..44e8572 100644
20206 --- a/arch/x86/include/asm/x86_init.h
20207 +++ b/arch/x86/include/asm/x86_init.h
20208 @@ -129,7 +129,7 @@ struct x86_init_ops {
20209 struct x86_init_timers timers;
20210 struct x86_init_iommu iommu;
20211 struct x86_init_pci pci;
20212 -};
20213 +} __no_const;
20214
20215 /**
20216 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20217 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20218 void (*setup_percpu_clockev)(void);
20219 void (*early_percpu_clock_init)(void);
20220 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20221 -};
20222 +} __no_const;
20223
20224 struct timespec;
20225
20226 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20227 void (*save_sched_clock_state)(void);
20228 void (*restore_sched_clock_state)(void);
20229 void (*apic_post_init)(void);
20230 -};
20231 +} __no_const;
20232
20233 struct pci_dev;
20234 struct msi_msg;
20235 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20236 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20237 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20238 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20239 -};
20240 +} __no_const;
20241
20242 struct IO_APIC_route_entry;
20243 struct io_apic_irq_attr;
20244 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20245 unsigned int destination, int vector,
20246 struct io_apic_irq_attr *attr);
20247 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20248 -};
20249 +} __no_const;
20250
20251 extern struct x86_init_ops x86_init;
20252 extern struct x86_cpuinit_ops x86_cpuinit;
20253 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20254 index c949923..c22bfa4 100644
20255 --- a/arch/x86/include/asm/xen/page.h
20256 +++ b/arch/x86/include/asm/xen/page.h
20257 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20258 extern struct page *m2p_find_override(unsigned long mfn);
20259 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20260
20261 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20262 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20263 {
20264 unsigned long mfn;
20265
20266 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20267 index d949ef2..479b9d1 100644
20268 --- a/arch/x86/include/asm/xsave.h
20269 +++ b/arch/x86/include/asm/xsave.h
20270 @@ -82,8 +82,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20271 if (unlikely(err))
20272 return -EFAULT;
20273
20274 + pax_open_userland();
20275 __asm__ __volatile__(ASM_STAC "\n"
20276 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20277 + "1:"
20278 + __copyuser_seg
20279 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20280 "2: " ASM_CLAC "\n"
20281 ".section .fixup,\"ax\"\n"
20282 "3: movl $-1,%[err]\n"
20283 @@ -93,18 +96,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20284 : [err] "=r" (err)
20285 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20286 : "memory");
20287 + pax_close_userland();
20288 return err;
20289 }
20290
20291 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20292 {
20293 int err;
20294 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20295 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20296 u32 lmask = mask;
20297 u32 hmask = mask >> 32;
20298
20299 + pax_open_userland();
20300 __asm__ __volatile__(ASM_STAC "\n"
20301 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20302 + "1:"
20303 + __copyuser_seg
20304 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20305 "2: " ASM_CLAC "\n"
20306 ".section .fixup,\"ax\"\n"
20307 "3: movl $-1,%[err]\n"
20308 @@ -114,6 +121,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20309 : [err] "=r" (err)
20310 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20311 : "memory"); /* memory required? */
20312 + pax_close_userland();
20313 return err;
20314 }
20315
20316 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20317 index bbae024..e1528f9 100644
20318 --- a/arch/x86/include/uapi/asm/e820.h
20319 +++ b/arch/x86/include/uapi/asm/e820.h
20320 @@ -63,7 +63,7 @@ struct e820map {
20321 #define ISA_START_ADDRESS 0xa0000
20322 #define ISA_END_ADDRESS 0x100000
20323
20324 -#define BIOS_BEGIN 0x000a0000
20325 +#define BIOS_BEGIN 0x000c0000
20326 #define BIOS_END 0x00100000
20327
20328 #define BIOS_ROM_BASE 0xffe00000
20329 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20330 index 7b0a55a..ad115bf 100644
20331 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20332 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20333 @@ -49,7 +49,6 @@
20334 #define EFLAGS 144
20335 #define RSP 152
20336 #define SS 160
20337 -#define ARGOFFSET R11
20338 #endif /* __ASSEMBLY__ */
20339
20340 /* top of stack page */
20341 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20342 index f4d9600..b45af01 100644
20343 --- a/arch/x86/kernel/Makefile
20344 +++ b/arch/x86/kernel/Makefile
20345 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20346 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20347 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20348 obj-y += probe_roms.o
20349 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20350 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20351 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20352 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20353 obj-$(CONFIG_X86_64) += vsyscall_64.o
20354 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20355 index 86281ff..e046fc2 100644
20356 --- a/arch/x86/kernel/acpi/boot.c
20357 +++ b/arch/x86/kernel/acpi/boot.c
20358 @@ -1296,7 +1296,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20359 * If your system is blacklisted here, but you find that acpi=force
20360 * works for you, please contact linux-acpi@vger.kernel.org
20361 */
20362 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20363 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20364 /*
20365 * Boxes that need ACPI disabled
20366 */
20367 @@ -1371,7 +1371,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20368 };
20369
20370 /* second table for DMI checks that should run after early-quirks */
20371 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20372 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20373 /*
20374 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20375 * which includes some code which overrides all temperature
20376 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20377 index 3136820..e2c6577 100644
20378 --- a/arch/x86/kernel/acpi/sleep.c
20379 +++ b/arch/x86/kernel/acpi/sleep.c
20380 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20381 #else /* CONFIG_64BIT */
20382 #ifdef CONFIG_SMP
20383 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20384 +
20385 + pax_open_kernel();
20386 early_gdt_descr.address =
20387 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20388 + pax_close_kernel();
20389 +
20390 initial_gs = per_cpu_offset(smp_processor_id());
20391 #endif
20392 initial_code = (unsigned long)wakeup_long64;
20393 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20394 index 665c6b7..eae4d56 100644
20395 --- a/arch/x86/kernel/acpi/wakeup_32.S
20396 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20397 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20398 # and restore the stack ... but you need gdt for this to work
20399 movl saved_context_esp, %esp
20400
20401 - movl %cs:saved_magic, %eax
20402 - cmpl $0x12345678, %eax
20403 + cmpl $0x12345678, saved_magic
20404 jne bogus_magic
20405
20406 # jump to place where we left off
20407 - movl saved_eip, %eax
20408 - jmp *%eax
20409 + jmp *(saved_eip)
20410
20411 bogus_magic:
20412 jmp bogus_magic
20413 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20414 index df94598..b7162f9 100644
20415 --- a/arch/x86/kernel/alternative.c
20416 +++ b/arch/x86/kernel/alternative.c
20417 @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20418 */
20419 for (a = start; a < end; a++) {
20420 instr = (u8 *)&a->instr_offset + a->instr_offset;
20421 +
20422 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20423 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20424 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20425 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20426 +#endif
20427 +
20428 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20429 BUG_ON(a->replacementlen > a->instrlen);
20430 BUG_ON(a->instrlen > sizeof(insnbuf));
20431 @@ -285,6 +292,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20432 add_nops(insnbuf + a->replacementlen,
20433 a->instrlen - a->replacementlen);
20434
20435 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20436 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20437 + instr = ktva_ktla(instr);
20438 +#endif
20439 +
20440 text_poke_early(instr, insnbuf, a->instrlen);
20441 }
20442 }
20443 @@ -300,10 +312,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20444 for (poff = start; poff < end; poff++) {
20445 u8 *ptr = (u8 *)poff + *poff;
20446
20447 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20448 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20449 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20450 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20451 +#endif
20452 +
20453 if (!*poff || ptr < text || ptr >= text_end)
20454 continue;
20455 /* turn DS segment override prefix into lock prefix */
20456 - if (*ptr == 0x3e)
20457 + if (*ktla_ktva(ptr) == 0x3e)
20458 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20459 }
20460 mutex_unlock(&text_mutex);
20461 @@ -318,10 +336,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20462 for (poff = start; poff < end; poff++) {
20463 u8 *ptr = (u8 *)poff + *poff;
20464
20465 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20466 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20467 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20468 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20469 +#endif
20470 +
20471 if (!*poff || ptr < text || ptr >= text_end)
20472 continue;
20473 /* turn lock prefix into DS segment override prefix */
20474 - if (*ptr == 0xf0)
20475 + if (*ktla_ktva(ptr) == 0xf0)
20476 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20477 }
20478 mutex_unlock(&text_mutex);
20479 @@ -458,7 +482,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20480
20481 BUG_ON(p->len > MAX_PATCH_LEN);
20482 /* prep the buffer with the original instructions */
20483 - memcpy(insnbuf, p->instr, p->len);
20484 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20485 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20486 (unsigned long)p->instr, p->len);
20487
20488 @@ -505,7 +529,7 @@ void __init alternative_instructions(void)
20489 if (!uniproc_patched || num_possible_cpus() == 1)
20490 free_init_pages("SMP alternatives",
20491 (unsigned long)__smp_locks,
20492 - (unsigned long)__smp_locks_end);
20493 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20494 #endif
20495
20496 apply_paravirt(__parainstructions, __parainstructions_end);
20497 @@ -525,13 +549,17 @@ void __init alternative_instructions(void)
20498 * instructions. And on the local CPU you need to be protected again NMI or MCE
20499 * handlers seeing an inconsistent instruction while you patch.
20500 */
20501 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20502 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20503 size_t len)
20504 {
20505 unsigned long flags;
20506 local_irq_save(flags);
20507 - memcpy(addr, opcode, len);
20508 +
20509 + pax_open_kernel();
20510 + memcpy(ktla_ktva(addr), opcode, len);
20511 sync_core();
20512 + pax_close_kernel();
20513 +
20514 local_irq_restore(flags);
20515 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20516 that causes hangs on some VIA CPUs. */
20517 @@ -553,36 +581,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20518 */
20519 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20520 {
20521 - unsigned long flags;
20522 - char *vaddr;
20523 + unsigned char *vaddr = ktla_ktva(addr);
20524 struct page *pages[2];
20525 - int i;
20526 + size_t i;
20527
20528 if (!core_kernel_text((unsigned long)addr)) {
20529 - pages[0] = vmalloc_to_page(addr);
20530 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20531 + pages[0] = vmalloc_to_page(vaddr);
20532 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20533 } else {
20534 - pages[0] = virt_to_page(addr);
20535 + pages[0] = virt_to_page(vaddr);
20536 WARN_ON(!PageReserved(pages[0]));
20537 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20538 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20539 }
20540 BUG_ON(!pages[0]);
20541 - local_irq_save(flags);
20542 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20543 - if (pages[1])
20544 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20545 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20546 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20547 - clear_fixmap(FIX_TEXT_POKE0);
20548 - if (pages[1])
20549 - clear_fixmap(FIX_TEXT_POKE1);
20550 - local_flush_tlb();
20551 - sync_core();
20552 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20553 - that causes hangs on some VIA CPUs. */
20554 + text_poke_early(addr, opcode, len);
20555 for (i = 0; i < len; i++)
20556 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20557 - local_irq_restore(flags);
20558 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20559 return addr;
20560 }
20561
20562 @@ -602,7 +616,7 @@ int poke_int3_handler(struct pt_regs *regs)
20563 if (likely(!bp_patching_in_progress))
20564 return 0;
20565
20566 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20567 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20568 return 0;
20569
20570 /* set up the specified breakpoint handler */
20571 @@ -636,7 +650,7 @@ int poke_int3_handler(struct pt_regs *regs)
20572 */
20573 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20574 {
20575 - unsigned char int3 = 0xcc;
20576 + const unsigned char int3 = 0xcc;
20577
20578 bp_int3_handler = handler;
20579 bp_int3_addr = (u8 *)addr + sizeof(int3);
20580 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20581 index ad28db7..c538b2c 100644
20582 --- a/arch/x86/kernel/apic/apic.c
20583 +++ b/arch/x86/kernel/apic/apic.c
20584 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20585 /*
20586 * Debug level, exported for io_apic.c
20587 */
20588 -unsigned int apic_verbosity;
20589 +int apic_verbosity;
20590
20591 int pic_mode;
20592
20593 @@ -2000,7 +2000,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20594 apic_write(APIC_ESR, 0);
20595 v = apic_read(APIC_ESR);
20596 ack_APIC_irq();
20597 - atomic_inc(&irq_err_count);
20598 + atomic_inc_unchecked(&irq_err_count);
20599
20600 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20601 smp_processor_id(), v);
20602 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20603 index 7c1b294..e71d27f 100644
20604 --- a/arch/x86/kernel/apic/apic_flat_64.c
20605 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20606 @@ -154,7 +154,7 @@ static int flat_probe(void)
20607 return 1;
20608 }
20609
20610 -static struct apic apic_flat = {
20611 +static struct apic apic_flat __read_only = {
20612 .name = "flat",
20613 .probe = flat_probe,
20614 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20615 @@ -268,7 +268,7 @@ static int physflat_probe(void)
20616 return 0;
20617 }
20618
20619 -static struct apic apic_physflat = {
20620 +static struct apic apic_physflat __read_only = {
20621
20622 .name = "physical flat",
20623 .probe = physflat_probe,
20624 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20625 index 8c7c982..a225910 100644
20626 --- a/arch/x86/kernel/apic/apic_noop.c
20627 +++ b/arch/x86/kernel/apic/apic_noop.c
20628 @@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20629 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20630 }
20631
20632 -struct apic apic_noop = {
20633 +struct apic apic_noop __read_only = {
20634 .name = "noop",
20635 .probe = noop_probe,
20636 .acpi_madt_oem_check = NULL,
20637 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20638 index e4840aa..e7d9dac 100644
20639 --- a/arch/x86/kernel/apic/bigsmp_32.c
20640 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20641 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20642 return dmi_bigsmp;
20643 }
20644
20645 -static struct apic apic_bigsmp = {
20646 +static struct apic apic_bigsmp __read_only = {
20647
20648 .name = "bigsmp",
20649 .probe = probe_bigsmp,
20650 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20651 index 992060e..ecdc3b3 100644
20652 --- a/arch/x86/kernel/apic/io_apic.c
20653 +++ b/arch/x86/kernel/apic/io_apic.c
20654 @@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20655 }
20656 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20657
20658 -void lock_vector_lock(void)
20659 +void lock_vector_lock(void) __acquires(vector_lock)
20660 {
20661 /* Used to the online set of cpus does not change
20662 * during assign_irq_vector.
20663 @@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20664 raw_spin_lock(&vector_lock);
20665 }
20666
20667 -void unlock_vector_lock(void)
20668 +void unlock_vector_lock(void) __releases(vector_lock)
20669 {
20670 raw_spin_unlock(&vector_lock);
20671 }
20672 @@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20673 ack_APIC_irq();
20674 }
20675
20676 -atomic_t irq_mis_count;
20677 +atomic_unchecked_t irq_mis_count;
20678
20679 #ifdef CONFIG_GENERIC_PENDING_IRQ
20680 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20681 @@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20682 * at the cpu.
20683 */
20684 if (!(v & (1 << (i & 0x1f)))) {
20685 - atomic_inc(&irq_mis_count);
20686 + atomic_inc_unchecked(&irq_mis_count);
20687
20688 eoi_ioapic_irq(irq, cfg);
20689 }
20690 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20691 index cceb352..a635fd8 100644
20692 --- a/arch/x86/kernel/apic/probe_32.c
20693 +++ b/arch/x86/kernel/apic/probe_32.c
20694 @@ -72,7 +72,7 @@ static int probe_default(void)
20695 return 1;
20696 }
20697
20698 -static struct apic apic_default = {
20699 +static struct apic apic_default __read_only = {
20700
20701 .name = "default",
20702 .probe = probe_default,
20703 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20704 index e66766b..1c008ba 100644
20705 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20706 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20707 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20708 return notifier_from_errno(err);
20709 }
20710
20711 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20712 +static struct notifier_block x2apic_cpu_notifier = {
20713 .notifier_call = update_clusterinfo,
20714 };
20715
20716 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20717 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20718 }
20719
20720 -static struct apic apic_x2apic_cluster = {
20721 +static struct apic apic_x2apic_cluster __read_only = {
20722
20723 .name = "cluster x2apic",
20724 .probe = x2apic_cluster_probe,
20725 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20726 index 6d600eb..0300c00 100644
20727 --- a/arch/x86/kernel/apic/x2apic_phys.c
20728 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20729 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20730 return apic == &apic_x2apic_phys;
20731 }
20732
20733 -static struct apic apic_x2apic_phys = {
20734 +static struct apic apic_x2apic_phys __read_only = {
20735
20736 .name = "physical x2apic",
20737 .probe = x2apic_phys_probe,
20738 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20739 index 7834389..4ffc9c8 100644
20740 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20741 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20742 @@ -350,7 +350,7 @@ static int uv_probe(void)
20743 return apic == &apic_x2apic_uv_x;
20744 }
20745
20746 -static struct apic __refdata apic_x2apic_uv_x = {
20747 +static struct apic apic_x2apic_uv_x __read_only = {
20748
20749 .name = "UV large system",
20750 .probe = uv_probe,
20751 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20752 index 3ab0343..814c4787 100644
20753 --- a/arch/x86/kernel/apm_32.c
20754 +++ b/arch/x86/kernel/apm_32.c
20755 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20756 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20757 * even though they are called in protected mode.
20758 */
20759 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20760 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20761 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20762
20763 static const char driver_version[] = "1.16ac"; /* no spaces */
20764 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20765 BUG_ON(cpu != 0);
20766 gdt = get_cpu_gdt_table(cpu);
20767 save_desc_40 = gdt[0x40 / 8];
20768 +
20769 + pax_open_kernel();
20770 gdt[0x40 / 8] = bad_bios_desc;
20771 + pax_close_kernel();
20772
20773 apm_irq_save(flags);
20774 APM_DO_SAVE_SEGS;
20775 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20776 &call->esi);
20777 APM_DO_RESTORE_SEGS;
20778 apm_irq_restore(flags);
20779 +
20780 + pax_open_kernel();
20781 gdt[0x40 / 8] = save_desc_40;
20782 + pax_close_kernel();
20783 +
20784 put_cpu();
20785
20786 return call->eax & 0xff;
20787 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20788 BUG_ON(cpu != 0);
20789 gdt = get_cpu_gdt_table(cpu);
20790 save_desc_40 = gdt[0x40 / 8];
20791 +
20792 + pax_open_kernel();
20793 gdt[0x40 / 8] = bad_bios_desc;
20794 + pax_close_kernel();
20795
20796 apm_irq_save(flags);
20797 APM_DO_SAVE_SEGS;
20798 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20799 &call->eax);
20800 APM_DO_RESTORE_SEGS;
20801 apm_irq_restore(flags);
20802 +
20803 + pax_open_kernel();
20804 gdt[0x40 / 8] = save_desc_40;
20805 + pax_close_kernel();
20806 +
20807 put_cpu();
20808 return error;
20809 }
20810 @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20811 * code to that CPU.
20812 */
20813 gdt = get_cpu_gdt_table(0);
20814 +
20815 + pax_open_kernel();
20816 set_desc_base(&gdt[APM_CS >> 3],
20817 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20818 set_desc_base(&gdt[APM_CS_16 >> 3],
20819 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20820 set_desc_base(&gdt[APM_DS >> 3],
20821 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20822 + pax_close_kernel();
20823
20824 proc_create("apm", 0, NULL, &apm_file_ops);
20825
20826 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20827 index 9f6b934..cf5ffb3 100644
20828 --- a/arch/x86/kernel/asm-offsets.c
20829 +++ b/arch/x86/kernel/asm-offsets.c
20830 @@ -32,6 +32,8 @@ void common(void) {
20831 OFFSET(TI_flags, thread_info, flags);
20832 OFFSET(TI_status, thread_info, status);
20833 OFFSET(TI_addr_limit, thread_info, addr_limit);
20834 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20835 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20836
20837 BLANK();
20838 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20839 @@ -52,8 +54,26 @@ void common(void) {
20840 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20841 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20842 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20843 +
20844 +#ifdef CONFIG_PAX_KERNEXEC
20845 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20846 #endif
20847
20848 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20849 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20850 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20851 +#ifdef CONFIG_X86_64
20852 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20853 +#endif
20854 +#endif
20855 +
20856 +#endif
20857 +
20858 + BLANK();
20859 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20860 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20861 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20862 +
20863 #ifdef CONFIG_XEN
20864 BLANK();
20865 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20866 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20867 index e7c798b..2b2019b 100644
20868 --- a/arch/x86/kernel/asm-offsets_64.c
20869 +++ b/arch/x86/kernel/asm-offsets_64.c
20870 @@ -77,6 +77,7 @@ int main(void)
20871 BLANK();
20872 #undef ENTRY
20873
20874 + DEFINE(TSS_size, sizeof(struct tss_struct));
20875 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20876 BLANK();
20877
20878 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20879 index 7fd54f0..0691410 100644
20880 --- a/arch/x86/kernel/cpu/Makefile
20881 +++ b/arch/x86/kernel/cpu/Makefile
20882 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20883 CFLAGS_REMOVE_perf_event.o = -pg
20884 endif
20885
20886 -# Make sure load_percpu_segment has no stackprotector
20887 -nostackp := $(call cc-option, -fno-stack-protector)
20888 -CFLAGS_common.o := $(nostackp)
20889 -
20890 obj-y := intel_cacheinfo.o scattered.o topology.o
20891 obj-y += proc.o capflags.o powerflags.o common.o
20892 obj-y += rdrand.o
20893 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20894 index ce8b8ff..d7d8851 100644
20895 --- a/arch/x86/kernel/cpu/amd.c
20896 +++ b/arch/x86/kernel/cpu/amd.c
20897 @@ -728,7 +728,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20898 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20899 {
20900 /* AMD errata T13 (order #21922) */
20901 - if ((c->x86 == 6)) {
20902 + if (c->x86 == 6) {
20903 /* Duron Rev A0 */
20904 if (c->x86_model == 3 && c->x86_mask == 0)
20905 size = 64;
20906 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20907 index a135239..41fb30a 100644
20908 --- a/arch/x86/kernel/cpu/common.c
20909 +++ b/arch/x86/kernel/cpu/common.c
20910 @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20911
20912 static const struct cpu_dev *this_cpu = &default_cpu;
20913
20914 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20915 -#ifdef CONFIG_X86_64
20916 - /*
20917 - * We need valid kernel segments for data and code in long mode too
20918 - * IRET will check the segment types kkeil 2000/10/28
20919 - * Also sysret mandates a special GDT layout
20920 - *
20921 - * TLS descriptors are currently at a different place compared to i386.
20922 - * Hopefully nobody expects them at a fixed place (Wine?)
20923 - */
20924 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20925 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20926 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20927 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20928 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20929 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20930 -#else
20931 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20932 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20933 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20934 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20935 - /*
20936 - * Segments used for calling PnP BIOS have byte granularity.
20937 - * They code segments and data segments have fixed 64k limits,
20938 - * the transfer segment sizes are set at run time.
20939 - */
20940 - /* 32-bit code */
20941 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20942 - /* 16-bit code */
20943 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20944 - /* 16-bit data */
20945 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20946 - /* 16-bit data */
20947 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20948 - /* 16-bit data */
20949 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20950 - /*
20951 - * The APM segments have byte granularity and their bases
20952 - * are set at run time. All have 64k limits.
20953 - */
20954 - /* 32-bit code */
20955 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20956 - /* 16-bit code */
20957 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20958 - /* data */
20959 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20960 -
20961 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20962 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20963 - GDT_STACK_CANARY_INIT
20964 -#endif
20965 -} };
20966 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20967 -
20968 static int __init x86_xsave_setup(char *s)
20969 {
20970 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20971 @@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20972 }
20973 }
20974
20975 +#ifdef CONFIG_X86_64
20976 +static __init int setup_disable_pcid(char *arg)
20977 +{
20978 + setup_clear_cpu_cap(X86_FEATURE_PCID);
20979 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20980 +
20981 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20982 + if (clone_pgd_mask != ~(pgdval_t)0UL)
20983 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20984 +#endif
20985 +
20986 + return 1;
20987 +}
20988 +__setup("nopcid", setup_disable_pcid);
20989 +
20990 +static void setup_pcid(struct cpuinfo_x86 *c)
20991 +{
20992 + if (!cpu_has(c, X86_FEATURE_PCID)) {
20993 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
20994 +
20995 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20996 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
20997 + pax_open_kernel();
20998 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20999 + pax_close_kernel();
21000 + printk("PAX: slow and weak UDEREF enabled\n");
21001 + } else
21002 + printk("PAX: UDEREF disabled\n");
21003 +#endif
21004 +
21005 + return;
21006 + }
21007 +
21008 + printk("PAX: PCID detected\n");
21009 + set_in_cr4(X86_CR4_PCIDE);
21010 +
21011 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21012 + pax_open_kernel();
21013 + clone_pgd_mask = ~(pgdval_t)0UL;
21014 + pax_close_kernel();
21015 + if (pax_user_shadow_base)
21016 + printk("PAX: weak UDEREF enabled\n");
21017 + else {
21018 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21019 + printk("PAX: strong UDEREF enabled\n");
21020 + }
21021 +#endif
21022 +
21023 + if (cpu_has(c, X86_FEATURE_INVPCID))
21024 + printk("PAX: INVPCID detected\n");
21025 +}
21026 +#endif
21027 +
21028 /*
21029 * Some CPU features depend on higher CPUID levels, which may not always
21030 * be available due to CPUID level capping or broken virtualization
21031 @@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
21032 {
21033 struct desc_ptr gdt_descr;
21034
21035 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21036 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21037 gdt_descr.size = GDT_SIZE - 1;
21038 load_gdt(&gdt_descr);
21039 /* Reload the per-cpu base */
21040 @@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21041 setup_smep(c);
21042 setup_smap(c);
21043
21044 +#ifdef CONFIG_X86_64
21045 + setup_pcid(c);
21046 +#endif
21047 +
21048 /*
21049 * The vendor-specific functions might have changed features.
21050 * Now we do "generic changes."
21051 @@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21052 /* Filter out anything that depends on CPUID levels we don't have */
21053 filter_cpuid_features(c, true);
21054
21055 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21056 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21057 +#endif
21058 +
21059 /* If the model name is still unset, do table lookup. */
21060 if (!c->x86_model_id[0]) {
21061 const char *p;
21062 @@ -1079,14 +1086,16 @@ static __init int setup_disablecpuid(char *arg)
21063 }
21064 __setup("clearcpuid=", setup_disablecpuid);
21065
21066 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21067 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21068 +
21069 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21070 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21071 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21072 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21073
21074 #ifdef CONFIG_X86_64
21075 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21076 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21077 - (unsigned long) debug_idt_table };
21078 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21079 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21080
21081 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21082 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21083 @@ -1246,7 +1255,7 @@ void cpu_init(void)
21084 load_ucode_ap();
21085
21086 cpu = stack_smp_processor_id();
21087 - t = &per_cpu(init_tss, cpu);
21088 + t = init_tss + cpu;
21089 oist = &per_cpu(orig_ist, cpu);
21090
21091 #ifdef CONFIG_NUMA
21092 @@ -1281,7 +1290,6 @@ void cpu_init(void)
21093 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21094 barrier();
21095
21096 - x86_configure_nx();
21097 enable_x2apic();
21098
21099 /*
21100 @@ -1333,7 +1341,7 @@ void cpu_init(void)
21101 {
21102 int cpu = smp_processor_id();
21103 struct task_struct *curr = current;
21104 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21105 + struct tss_struct *t = init_tss + cpu;
21106 struct thread_struct *thread = &curr->thread;
21107
21108 show_ucode_info_early();
21109 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21110 index a952e9c..58a4cbb 100644
21111 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21112 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21113 @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21114 };
21115
21116 #ifdef CONFIG_AMD_NB
21117 +static struct attribute *default_attrs_amd_nb[] = {
21118 + &type.attr,
21119 + &level.attr,
21120 + &coherency_line_size.attr,
21121 + &physical_line_partition.attr,
21122 + &ways_of_associativity.attr,
21123 + &number_of_sets.attr,
21124 + &size.attr,
21125 + &shared_cpu_map.attr,
21126 + &shared_cpu_list.attr,
21127 + NULL,
21128 + NULL,
21129 + NULL,
21130 + NULL
21131 +};
21132 +
21133 static struct attribute **amd_l3_attrs(void)
21134 {
21135 static struct attribute **attrs;
21136 @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21137
21138 n = ARRAY_SIZE(default_attrs);
21139
21140 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21141 - n += 2;
21142 -
21143 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21144 - n += 1;
21145 -
21146 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21147 - if (attrs == NULL)
21148 - return attrs = default_attrs;
21149 -
21150 - for (n = 0; default_attrs[n]; n++)
21151 - attrs[n] = default_attrs[n];
21152 + attrs = default_attrs_amd_nb;
21153
21154 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21155 attrs[n++] = &cache_disable_0.attr;
21156 @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21157 .default_attrs = default_attrs,
21158 };
21159
21160 +#ifdef CONFIG_AMD_NB
21161 +static struct kobj_type ktype_cache_amd_nb = {
21162 + .sysfs_ops = &sysfs_ops,
21163 + .default_attrs = default_attrs_amd_nb,
21164 +};
21165 +#endif
21166 +
21167 static struct kobj_type ktype_percpu_entry = {
21168 .sysfs_ops = &sysfs_ops,
21169 };
21170 @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21171 return retval;
21172 }
21173
21174 +#ifdef CONFIG_AMD_NB
21175 + amd_l3_attrs();
21176 +#endif
21177 +
21178 for (i = 0; i < num_cache_leaves; i++) {
21179 + struct kobj_type *ktype;
21180 +
21181 this_object = INDEX_KOBJECT_PTR(cpu, i);
21182 this_object->cpu = cpu;
21183 this_object->index = i;
21184
21185 this_leaf = CPUID4_INFO_IDX(cpu, i);
21186
21187 - ktype_cache.default_attrs = default_attrs;
21188 + ktype = &ktype_cache;
21189 #ifdef CONFIG_AMD_NB
21190 if (this_leaf->base.nb)
21191 - ktype_cache.default_attrs = amd_l3_attrs();
21192 + ktype = &ktype_cache_amd_nb;
21193 #endif
21194 retval = kobject_init_and_add(&(this_object->kobj),
21195 - &ktype_cache,
21196 + ktype,
21197 per_cpu(ici_cache_kobject, cpu),
21198 "index%1lu", i);
21199 if (unlikely(retval)) {
21200 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21201 index 68317c8..c860d41 100644
21202 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21203 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21204 @@ -45,6 +45,7 @@
21205 #include <asm/processor.h>
21206 #include <asm/mce.h>
21207 #include <asm/msr.h>
21208 +#include <asm/local.h>
21209
21210 #include "mce-internal.h"
21211
21212 @@ -261,7 +262,7 @@ static void print_mce(struct mce *m)
21213 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21214 m->cs, m->ip);
21215
21216 - if (m->cs == __KERNEL_CS)
21217 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21218 print_symbol("{%s}", m->ip);
21219 pr_cont("\n");
21220 }
21221 @@ -294,10 +295,10 @@ static void print_mce(struct mce *m)
21222
21223 #define PANIC_TIMEOUT 5 /* 5 seconds */
21224
21225 -static atomic_t mce_paniced;
21226 +static atomic_unchecked_t mce_paniced;
21227
21228 static int fake_panic;
21229 -static atomic_t mce_fake_paniced;
21230 +static atomic_unchecked_t mce_fake_paniced;
21231
21232 /* Panic in progress. Enable interrupts and wait for final IPI */
21233 static void wait_for_panic(void)
21234 @@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21235 /*
21236 * Make sure only one CPU runs in machine check panic
21237 */
21238 - if (atomic_inc_return(&mce_paniced) > 1)
21239 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21240 wait_for_panic();
21241 barrier();
21242
21243 @@ -329,7 +330,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21244 console_verbose();
21245 } else {
21246 /* Don't log too much for fake panic */
21247 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21248 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21249 return;
21250 }
21251 /* First print corrected ones that are still unlogged */
21252 @@ -368,7 +369,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21253 if (!fake_panic) {
21254 if (panic_timeout == 0)
21255 panic_timeout = mca_cfg.panic_timeout;
21256 - panic(msg);
21257 + panic("%s", msg);
21258 } else
21259 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21260 }
21261 @@ -699,7 +700,7 @@ static int mce_timed_out(u64 *t)
21262 * might have been modified by someone else.
21263 */
21264 rmb();
21265 - if (atomic_read(&mce_paniced))
21266 + if (atomic_read_unchecked(&mce_paniced))
21267 wait_for_panic();
21268 if (!mca_cfg.monarch_timeout)
21269 goto out;
21270 @@ -1680,7 +1681,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21271 }
21272
21273 /* Call the installed machine check handler for this CPU setup. */
21274 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21275 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21276 unexpected_machine_check;
21277
21278 /*
21279 @@ -1703,7 +1704,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21280 return;
21281 }
21282
21283 + pax_open_kernel();
21284 machine_check_vector = do_machine_check;
21285 + pax_close_kernel();
21286
21287 __mcheck_cpu_init_generic();
21288 __mcheck_cpu_init_vendor(c);
21289 @@ -1717,7 +1720,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21290 */
21291
21292 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21293 -static int mce_chrdev_open_count; /* #times opened */
21294 +static local_t mce_chrdev_open_count; /* #times opened */
21295 static int mce_chrdev_open_exclu; /* already open exclusive? */
21296
21297 static int mce_chrdev_open(struct inode *inode, struct file *file)
21298 @@ -1725,7 +1728,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21299 spin_lock(&mce_chrdev_state_lock);
21300
21301 if (mce_chrdev_open_exclu ||
21302 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21303 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21304 spin_unlock(&mce_chrdev_state_lock);
21305
21306 return -EBUSY;
21307 @@ -1733,7 +1736,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21308
21309 if (file->f_flags & O_EXCL)
21310 mce_chrdev_open_exclu = 1;
21311 - mce_chrdev_open_count++;
21312 + local_inc(&mce_chrdev_open_count);
21313
21314 spin_unlock(&mce_chrdev_state_lock);
21315
21316 @@ -1744,7 +1747,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21317 {
21318 spin_lock(&mce_chrdev_state_lock);
21319
21320 - mce_chrdev_open_count--;
21321 + local_dec(&mce_chrdev_open_count);
21322 mce_chrdev_open_exclu = 0;
21323
21324 spin_unlock(&mce_chrdev_state_lock);
21325 @@ -2420,7 +2423,7 @@ static __init void mce_init_banks(void)
21326
21327 for (i = 0; i < mca_cfg.banks; i++) {
21328 struct mce_bank *b = &mce_banks[i];
21329 - struct device_attribute *a = &b->attr;
21330 + device_attribute_no_const *a = &b->attr;
21331
21332 sysfs_attr_init(&a->attr);
21333 a->attr.name = b->attrname;
21334 @@ -2492,7 +2495,7 @@ struct dentry *mce_get_debugfs_dir(void)
21335 static void mce_reset(void)
21336 {
21337 cpu_missing = 0;
21338 - atomic_set(&mce_fake_paniced, 0);
21339 + atomic_set_unchecked(&mce_fake_paniced, 0);
21340 atomic_set(&mce_executing, 0);
21341 atomic_set(&mce_callin, 0);
21342 atomic_set(&global_nwo, 0);
21343 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21344 index a304298..49b6d06 100644
21345 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21346 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21347 @@ -10,6 +10,7 @@
21348 #include <asm/processor.h>
21349 #include <asm/mce.h>
21350 #include <asm/msr.h>
21351 +#include <asm/pgtable.h>
21352
21353 /* By default disabled */
21354 int mce_p5_enabled __read_mostly;
21355 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21356 if (!cpu_has(c, X86_FEATURE_MCE))
21357 return;
21358
21359 + pax_open_kernel();
21360 machine_check_vector = pentium_machine_check;
21361 + pax_close_kernel();
21362 /* Make sure the vector pointer is visible before we enable MCEs: */
21363 wmb();
21364
21365 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21366 index 7dc5564..1273569 100644
21367 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21368 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21369 @@ -9,6 +9,7 @@
21370 #include <asm/processor.h>
21371 #include <asm/mce.h>
21372 #include <asm/msr.h>
21373 +#include <asm/pgtable.h>
21374
21375 /* Machine check handler for WinChip C6: */
21376 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21377 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21378 {
21379 u32 lo, hi;
21380
21381 + pax_open_kernel();
21382 machine_check_vector = winchip_machine_check;
21383 + pax_close_kernel();
21384 /* Make sure the vector pointer is visible before we enable MCEs: */
21385 wmb();
21386
21387 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21388 index 15c9876..0a43909 100644
21389 --- a/arch/x86/kernel/cpu/microcode/core.c
21390 +++ b/arch/x86/kernel/cpu/microcode/core.c
21391 @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21392 return NOTIFY_OK;
21393 }
21394
21395 -static struct notifier_block __refdata mc_cpu_notifier = {
21396 +static struct notifier_block mc_cpu_notifier = {
21397 .notifier_call = mc_cpu_callback,
21398 };
21399
21400 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21401 index a276fa7..e66810f 100644
21402 --- a/arch/x86/kernel/cpu/microcode/intel.c
21403 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21404 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21405
21406 static int get_ucode_user(void *to, const void *from, size_t n)
21407 {
21408 - return copy_from_user(to, from, n);
21409 + return copy_from_user(to, (const void __force_user *)from, n);
21410 }
21411
21412 static enum ucode_state
21413 request_microcode_user(int cpu, const void __user *buf, size_t size)
21414 {
21415 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21416 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21417 }
21418
21419 static void microcode_fini_cpu(int cpu)
21420 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21421 index f961de9..8a9d332 100644
21422 --- a/arch/x86/kernel/cpu/mtrr/main.c
21423 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21424 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21425 u64 size_or_mask, size_and_mask;
21426 static bool mtrr_aps_delayed_init;
21427
21428 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21429 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21430
21431 const struct mtrr_ops *mtrr_if;
21432
21433 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21434 index df5e41f..816c719 100644
21435 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21436 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21437 @@ -25,7 +25,7 @@ struct mtrr_ops {
21438 int (*validate_add_page)(unsigned long base, unsigned long size,
21439 unsigned int type);
21440 int (*have_wrcomb)(void);
21441 -};
21442 +} __do_const;
21443
21444 extern int generic_get_free_region(unsigned long base, unsigned long size,
21445 int replace_reg);
21446 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21447 index ae407f7..39c5b00 100644
21448 --- a/arch/x86/kernel/cpu/perf_event.c
21449 +++ b/arch/x86/kernel/cpu/perf_event.c
21450 @@ -1367,7 +1367,7 @@ static void __init pmu_check_apic(void)
21451 pr_info("no hardware sampling interrupt available.\n");
21452 }
21453
21454 -static struct attribute_group x86_pmu_format_group = {
21455 +static attribute_group_no_const x86_pmu_format_group = {
21456 .name = "format",
21457 .attrs = NULL,
21458 };
21459 @@ -1466,7 +1466,7 @@ static struct attribute *events_attr[] = {
21460 NULL,
21461 };
21462
21463 -static struct attribute_group x86_pmu_events_group = {
21464 +static attribute_group_no_const x86_pmu_events_group = {
21465 .name = "events",
21466 .attrs = events_attr,
21467 };
21468 @@ -1990,7 +1990,7 @@ static unsigned long get_segment_base(unsigned int segment)
21469 if (idx > GDT_ENTRIES)
21470 return 0;
21471
21472 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21473 + desc = get_cpu_gdt_table(smp_processor_id());
21474 }
21475
21476 return get_desc_base(desc + idx);
21477 @@ -2080,7 +2080,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21478 break;
21479
21480 perf_callchain_store(entry, frame.return_address);
21481 - fp = frame.next_frame;
21482 + fp = (const void __force_user *)frame.next_frame;
21483 }
21484 }
21485
21486 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21487 index 639d128..e92d7e5 100644
21488 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21489 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21490 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21491 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21492 {
21493 struct attribute **attrs;
21494 - struct attribute_group *attr_group;
21495 + attribute_group_no_const *attr_group;
21496 int i = 0, j;
21497
21498 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21499 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21500 index adb02aa..9688c02 100644
21501 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21502 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21503 @@ -2308,10 +2308,10 @@ __init int intel_pmu_init(void)
21504 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21505
21506 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21507 - u64 capabilities;
21508 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21509
21510 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21511 - x86_pmu.intel_cap.capabilities = capabilities;
21512 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21513 + x86_pmu.intel_cap.capabilities = capabilities;
21514 }
21515
21516 intel_ds_init();
21517 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21518 index 619f769..d510008 100644
21519 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21520 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21521 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21522 NULL,
21523 };
21524
21525 -static struct attribute_group rapl_pmu_events_group = {
21526 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
21527 .name = "events",
21528 .attrs = NULL, /* patched at runtime */
21529 };
21530 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21531 index 65bbbea..1438d9e 100644
21532 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21533 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21534 @@ -3693,7 +3693,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21535 static int __init uncore_type_init(struct intel_uncore_type *type)
21536 {
21537 struct intel_uncore_pmu *pmus;
21538 - struct attribute_group *attr_group;
21539 + attribute_group_no_const *attr_group;
21540 struct attribute **attrs;
21541 int i, j;
21542
21543 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21544 index 90236f0..54cb20d 100644
21545 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21546 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21547 @@ -503,7 +503,7 @@ struct intel_uncore_box {
21548 struct uncore_event_desc {
21549 struct kobj_attribute attr;
21550 const char *config;
21551 -};
21552 +} __do_const;
21553
21554 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21555 { \
21556 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21557 index 3225ae6c..ee3c6db 100644
21558 --- a/arch/x86/kernel/cpuid.c
21559 +++ b/arch/x86/kernel/cpuid.c
21560 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21561 return notifier_from_errno(err);
21562 }
21563
21564 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21565 +static struct notifier_block cpuid_class_cpu_notifier =
21566 {
21567 .notifier_call = cpuid_class_cpu_callback,
21568 };
21569 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21570 index 507de80..ebaae2a 100644
21571 --- a/arch/x86/kernel/crash.c
21572 +++ b/arch/x86/kernel/crash.c
21573 @@ -58,7 +58,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21574 #ifdef CONFIG_X86_32
21575 struct pt_regs fixed_regs;
21576
21577 - if (!user_mode_vm(regs)) {
21578 + if (!user_mode(regs)) {
21579 crash_fixup_ss_esp(&fixed_regs, regs);
21580 regs = &fixed_regs;
21581 }
21582 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21583 index afa64ad..dce67dd 100644
21584 --- a/arch/x86/kernel/crash_dump_64.c
21585 +++ b/arch/x86/kernel/crash_dump_64.c
21586 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21587 return -ENOMEM;
21588
21589 if (userbuf) {
21590 - if (copy_to_user(buf, vaddr + offset, csize)) {
21591 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21592 iounmap(vaddr);
21593 return -EFAULT;
21594 }
21595 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21596 index f6dfd93..892ade4 100644
21597 --- a/arch/x86/kernel/doublefault.c
21598 +++ b/arch/x86/kernel/doublefault.c
21599 @@ -12,7 +12,7 @@
21600
21601 #define DOUBLEFAULT_STACKSIZE (1024)
21602 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21603 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21604 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21605
21606 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21607
21608 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
21609 unsigned long gdt, tss;
21610
21611 native_store_gdt(&gdt_desc);
21612 - gdt = gdt_desc.address;
21613 + gdt = (unsigned long)gdt_desc.address;
21614
21615 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21616
21617 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21618 /* 0x2 bit is always set */
21619 .flags = X86_EFLAGS_SF | 0x2,
21620 .sp = STACK_START,
21621 - .es = __USER_DS,
21622 + .es = __KERNEL_DS,
21623 .cs = __KERNEL_CS,
21624 .ss = __KERNEL_DS,
21625 - .ds = __USER_DS,
21626 + .ds = __KERNEL_DS,
21627 .fs = __KERNEL_PERCPU,
21628
21629 .__cr3 = __pa_nodebug(swapper_pg_dir),
21630 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21631 index d9c12d3..7858b62 100644
21632 --- a/arch/x86/kernel/dumpstack.c
21633 +++ b/arch/x86/kernel/dumpstack.c
21634 @@ -2,6 +2,9 @@
21635 * Copyright (C) 1991, 1992 Linus Torvalds
21636 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21637 */
21638 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21639 +#define __INCLUDED_BY_HIDESYM 1
21640 +#endif
21641 #include <linux/kallsyms.h>
21642 #include <linux/kprobes.h>
21643 #include <linux/uaccess.h>
21644 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21645 static void
21646 print_ftrace_graph_addr(unsigned long addr, void *data,
21647 const struct stacktrace_ops *ops,
21648 - struct thread_info *tinfo, int *graph)
21649 + struct task_struct *task, int *graph)
21650 {
21651 - struct task_struct *task;
21652 unsigned long ret_addr;
21653 int index;
21654
21655 if (addr != (unsigned long)return_to_handler)
21656 return;
21657
21658 - task = tinfo->task;
21659 index = task->curr_ret_stack;
21660
21661 if (!task->ret_stack || index < *graph)
21662 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21663 static inline void
21664 print_ftrace_graph_addr(unsigned long addr, void *data,
21665 const struct stacktrace_ops *ops,
21666 - struct thread_info *tinfo, int *graph)
21667 + struct task_struct *task, int *graph)
21668 { }
21669 #endif
21670
21671 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21672 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21673 */
21674
21675 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21676 - void *p, unsigned int size, void *end)
21677 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21678 {
21679 - void *t = tinfo;
21680 if (end) {
21681 if (p < end && p >= (end-THREAD_SIZE))
21682 return 1;
21683 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21684 }
21685
21686 unsigned long
21687 -print_context_stack(struct thread_info *tinfo,
21688 +print_context_stack(struct task_struct *task, void *stack_start,
21689 unsigned long *stack, unsigned long bp,
21690 const struct stacktrace_ops *ops, void *data,
21691 unsigned long *end, int *graph)
21692 {
21693 struct stack_frame *frame = (struct stack_frame *)bp;
21694
21695 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21696 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21697 unsigned long addr;
21698
21699 addr = *stack;
21700 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21701 } else {
21702 ops->address(data, addr, 0);
21703 }
21704 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21705 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21706 }
21707 stack++;
21708 }
21709 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21710 EXPORT_SYMBOL_GPL(print_context_stack);
21711
21712 unsigned long
21713 -print_context_stack_bp(struct thread_info *tinfo,
21714 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21715 unsigned long *stack, unsigned long bp,
21716 const struct stacktrace_ops *ops, void *data,
21717 unsigned long *end, int *graph)
21718 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21719 struct stack_frame *frame = (struct stack_frame *)bp;
21720 unsigned long *ret_addr = &frame->return_address;
21721
21722 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21723 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21724 unsigned long addr = *ret_addr;
21725
21726 if (!__kernel_text_address(addr))
21727 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21728 ops->address(data, addr, 1);
21729 frame = frame->next_frame;
21730 ret_addr = &frame->return_address;
21731 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21732 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21733 }
21734
21735 return (unsigned long)frame;
21736 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21737 static void print_trace_address(void *data, unsigned long addr, int reliable)
21738 {
21739 touch_nmi_watchdog();
21740 - printk(data);
21741 + printk("%s", (char *)data);
21742 printk_stack_address(addr, reliable);
21743 }
21744
21745 @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21746 }
21747 EXPORT_SYMBOL_GPL(oops_begin);
21748
21749 +extern void gr_handle_kernel_exploit(void);
21750 +
21751 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21752 {
21753 if (regs && kexec_should_crash(current))
21754 @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21755 panic("Fatal exception in interrupt");
21756 if (panic_on_oops)
21757 panic("Fatal exception");
21758 - do_exit(signr);
21759 +
21760 + gr_handle_kernel_exploit();
21761 +
21762 + do_group_exit(signr);
21763 }
21764
21765 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21766 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21767 print_modules();
21768 show_regs(regs);
21769 #ifdef CONFIG_X86_32
21770 - if (user_mode_vm(regs)) {
21771 + if (user_mode(regs)) {
21772 sp = regs->sp;
21773 ss = regs->ss & 0xffff;
21774 } else {
21775 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21776 unsigned long flags = oops_begin();
21777 int sig = SIGSEGV;
21778
21779 - if (!user_mode_vm(regs))
21780 + if (!user_mode(regs))
21781 report_bug(regs->ip, regs);
21782
21783 if (__die(str, regs, err))
21784 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21785 index 5abd4cd..c65733b 100644
21786 --- a/arch/x86/kernel/dumpstack_32.c
21787 +++ b/arch/x86/kernel/dumpstack_32.c
21788 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21789 bp = stack_frame(task, regs);
21790
21791 for (;;) {
21792 - struct thread_info *context;
21793 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21794 void *end_stack;
21795
21796 end_stack = is_hardirq_stack(stack, cpu);
21797 if (!end_stack)
21798 end_stack = is_softirq_stack(stack, cpu);
21799
21800 - context = task_thread_info(task);
21801 - bp = ops->walk_stack(context, stack, bp, ops, data,
21802 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
21803 end_stack, &graph);
21804
21805 /* Stop if not on irq stack */
21806 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
21807 int i;
21808
21809 show_regs_print_info(KERN_EMERG);
21810 - __show_regs(regs, !user_mode_vm(regs));
21811 + __show_regs(regs, !user_mode(regs));
21812
21813 /*
21814 * When in-kernel, we also print out the stack and code at the
21815 * time of the fault..
21816 */
21817 - if (!user_mode_vm(regs)) {
21818 + if (!user_mode(regs)) {
21819 unsigned int code_prologue = code_bytes * 43 / 64;
21820 unsigned int code_len = code_bytes;
21821 unsigned char c;
21822 u8 *ip;
21823 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21824
21825 pr_emerg("Stack:\n");
21826 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21827
21828 pr_emerg("Code:");
21829
21830 - ip = (u8 *)regs->ip - code_prologue;
21831 + ip = (u8 *)regs->ip - code_prologue + cs_base;
21832 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21833 /* try starting at IP */
21834 - ip = (u8 *)regs->ip;
21835 + ip = (u8 *)regs->ip + cs_base;
21836 code_len = code_len - code_prologue + 1;
21837 }
21838 for (i = 0; i < code_len; i++, ip++) {
21839 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
21840 pr_cont(" Bad EIP value.");
21841 break;
21842 }
21843 - if (ip == (u8 *)regs->ip)
21844 + if (ip == (u8 *)regs->ip + cs_base)
21845 pr_cont(" <%02x>", c);
21846 else
21847 pr_cont(" %02x", c);
21848 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
21849 {
21850 unsigned short ud2;
21851
21852 + ip = ktla_ktva(ip);
21853 if (ip < PAGE_OFFSET)
21854 return 0;
21855 if (probe_kernel_address((unsigned short *)ip, ud2))
21856 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
21857
21858 return ud2 == 0x0b0f;
21859 }
21860 +
21861 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21862 +void pax_check_alloca(unsigned long size)
21863 +{
21864 + unsigned long sp = (unsigned long)&sp, stack_left;
21865 +
21866 + /* all kernel stacks are of the same size */
21867 + stack_left = sp & (THREAD_SIZE - 1);
21868 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21869 +}
21870 +EXPORT_SYMBOL(pax_check_alloca);
21871 +#endif
21872 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21873 index 1abcb50..6c8d702 100644
21874 --- a/arch/x86/kernel/dumpstack_64.c
21875 +++ b/arch/x86/kernel/dumpstack_64.c
21876 @@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21877 const struct stacktrace_ops *ops, void *data)
21878 {
21879 const unsigned cpu = get_cpu();
21880 - struct thread_info *tinfo;
21881 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21882 unsigned long dummy;
21883 unsigned used = 0;
21884 int graph = 0;
21885 int done = 0;
21886 + void *stack_start;
21887
21888 if (!task)
21889 task = current;
21890 @@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21891 * current stack address. If the stacks consist of nested
21892 * exceptions
21893 */
21894 - tinfo = task_thread_info(task);
21895 while (!done) {
21896 unsigned long *stack_end;
21897 enum stack_type stype;
21898 @@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21899 if (ops->stack(data, id) < 0)
21900 break;
21901
21902 - bp = ops->walk_stack(tinfo, stack, bp, ops,
21903 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
21904 data, stack_end, &graph);
21905 ops->stack(data, "<EOE>");
21906 /*
21907 @@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21908 * second-to-last pointer (index -2 to end) in the
21909 * exception stack:
21910 */
21911 + if ((u16)stack_end[-1] != __KERNEL_DS)
21912 + goto out;
21913 stack = (unsigned long *) stack_end[-2];
21914 done = 0;
21915 break;
21916 @@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21917
21918 if (ops->stack(data, "IRQ") < 0)
21919 break;
21920 - bp = ops->walk_stack(tinfo, stack, bp,
21921 + bp = ops->walk_stack(task, irq_stack, stack, bp,
21922 ops, data, stack_end, &graph);
21923 /*
21924 * We link to the next stack (which would be
21925 @@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21926 /*
21927 * This handles the process stack:
21928 */
21929 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21930 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21931 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21932 +out:
21933 put_cpu();
21934 }
21935 EXPORT_SYMBOL(dump_trace);
21936 @@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
21937
21938 return ud2 == 0x0b0f;
21939 }
21940 +
21941 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21942 +void pax_check_alloca(unsigned long size)
21943 +{
21944 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21945 + unsigned cpu, used;
21946 + char *id;
21947 +
21948 + /* check the process stack first */
21949 + stack_start = (unsigned long)task_stack_page(current);
21950 + stack_end = stack_start + THREAD_SIZE;
21951 + if (likely(stack_start <= sp && sp < stack_end)) {
21952 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
21953 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21954 + return;
21955 + }
21956 +
21957 + cpu = get_cpu();
21958 +
21959 + /* check the irq stacks */
21960 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21961 + stack_start = stack_end - IRQ_STACK_SIZE;
21962 + if (stack_start <= sp && sp < stack_end) {
21963 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21964 + put_cpu();
21965 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21966 + return;
21967 + }
21968 +
21969 + /* check the exception stacks */
21970 + used = 0;
21971 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21972 + stack_start = stack_end - EXCEPTION_STKSZ;
21973 + if (stack_end && stack_start <= sp && sp < stack_end) {
21974 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21975 + put_cpu();
21976 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21977 + return;
21978 + }
21979 +
21980 + put_cpu();
21981 +
21982 + /* unknown stack */
21983 + BUG();
21984 +}
21985 +EXPORT_SYMBOL(pax_check_alloca);
21986 +#endif
21987 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21988 index 988c00a..4f673b6 100644
21989 --- a/arch/x86/kernel/e820.c
21990 +++ b/arch/x86/kernel/e820.c
21991 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21992
21993 static void early_panic(char *msg)
21994 {
21995 - early_printk(msg);
21996 - panic(msg);
21997 + early_printk("%s", msg);
21998 + panic("%s", msg);
21999 }
22000
22001 static int userdef __initdata;
22002 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22003 index 01d1c18..8073693 100644
22004 --- a/arch/x86/kernel/early_printk.c
22005 +++ b/arch/x86/kernel/early_printk.c
22006 @@ -7,6 +7,7 @@
22007 #include <linux/pci_regs.h>
22008 #include <linux/pci_ids.h>
22009 #include <linux/errno.h>
22010 +#include <linux/sched.h>
22011 #include <asm/io.h>
22012 #include <asm/processor.h>
22013 #include <asm/fcntl.h>
22014 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22015 index 6491353..a918952 100644
22016 --- a/arch/x86/kernel/entry_32.S
22017 +++ b/arch/x86/kernel/entry_32.S
22018 @@ -177,13 +177,153 @@
22019 /*CFI_REL_OFFSET gs, PT_GS*/
22020 .endm
22021 .macro SET_KERNEL_GS reg
22022 +
22023 +#ifdef CONFIG_CC_STACKPROTECTOR
22024 movl $(__KERNEL_STACK_CANARY), \reg
22025 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22026 + movl $(__USER_DS), \reg
22027 +#else
22028 + xorl \reg, \reg
22029 +#endif
22030 +
22031 movl \reg, %gs
22032 .endm
22033
22034 #endif /* CONFIG_X86_32_LAZY_GS */
22035
22036 -.macro SAVE_ALL
22037 +.macro pax_enter_kernel
22038 +#ifdef CONFIG_PAX_KERNEXEC
22039 + call pax_enter_kernel
22040 +#endif
22041 +.endm
22042 +
22043 +.macro pax_exit_kernel
22044 +#ifdef CONFIG_PAX_KERNEXEC
22045 + call pax_exit_kernel
22046 +#endif
22047 +.endm
22048 +
22049 +#ifdef CONFIG_PAX_KERNEXEC
22050 +ENTRY(pax_enter_kernel)
22051 +#ifdef CONFIG_PARAVIRT
22052 + pushl %eax
22053 + pushl %ecx
22054 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22055 + mov %eax, %esi
22056 +#else
22057 + mov %cr0, %esi
22058 +#endif
22059 + bts $16, %esi
22060 + jnc 1f
22061 + mov %cs, %esi
22062 + cmp $__KERNEL_CS, %esi
22063 + jz 3f
22064 + ljmp $__KERNEL_CS, $3f
22065 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22066 +2:
22067 +#ifdef CONFIG_PARAVIRT
22068 + mov %esi, %eax
22069 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22070 +#else
22071 + mov %esi, %cr0
22072 +#endif
22073 +3:
22074 +#ifdef CONFIG_PARAVIRT
22075 + popl %ecx
22076 + popl %eax
22077 +#endif
22078 + ret
22079 +ENDPROC(pax_enter_kernel)
22080 +
22081 +ENTRY(pax_exit_kernel)
22082 +#ifdef CONFIG_PARAVIRT
22083 + pushl %eax
22084 + pushl %ecx
22085 +#endif
22086 + mov %cs, %esi
22087 + cmp $__KERNEXEC_KERNEL_CS, %esi
22088 + jnz 2f
22089 +#ifdef CONFIG_PARAVIRT
22090 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22091 + mov %eax, %esi
22092 +#else
22093 + mov %cr0, %esi
22094 +#endif
22095 + btr $16, %esi
22096 + ljmp $__KERNEL_CS, $1f
22097 +1:
22098 +#ifdef CONFIG_PARAVIRT
22099 + mov %esi, %eax
22100 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22101 +#else
22102 + mov %esi, %cr0
22103 +#endif
22104 +2:
22105 +#ifdef CONFIG_PARAVIRT
22106 + popl %ecx
22107 + popl %eax
22108 +#endif
22109 + ret
22110 +ENDPROC(pax_exit_kernel)
22111 +#endif
22112 +
22113 + .macro pax_erase_kstack
22114 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22115 + call pax_erase_kstack
22116 +#endif
22117 + .endm
22118 +
22119 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22120 +/*
22121 + * ebp: thread_info
22122 + */
22123 +ENTRY(pax_erase_kstack)
22124 + pushl %edi
22125 + pushl %ecx
22126 + pushl %eax
22127 +
22128 + mov TI_lowest_stack(%ebp), %edi
22129 + mov $-0xBEEF, %eax
22130 + std
22131 +
22132 +1: mov %edi, %ecx
22133 + and $THREAD_SIZE_asm - 1, %ecx
22134 + shr $2, %ecx
22135 + repne scasl
22136 + jecxz 2f
22137 +
22138 + cmp $2*16, %ecx
22139 + jc 2f
22140 +
22141 + mov $2*16, %ecx
22142 + repe scasl
22143 + jecxz 2f
22144 + jne 1b
22145 +
22146 +2: cld
22147 + mov %esp, %ecx
22148 + sub %edi, %ecx
22149 +
22150 + cmp $THREAD_SIZE_asm, %ecx
22151 + jb 3f
22152 + ud2
22153 +3:
22154 +
22155 + shr $2, %ecx
22156 + rep stosl
22157 +
22158 + mov TI_task_thread_sp0(%ebp), %edi
22159 + sub $128, %edi
22160 + mov %edi, TI_lowest_stack(%ebp)
22161 +
22162 + popl %eax
22163 + popl %ecx
22164 + popl %edi
22165 + ret
22166 +ENDPROC(pax_erase_kstack)
22167 +#endif
22168 +
22169 +.macro __SAVE_ALL _DS
22170 cld
22171 PUSH_GS
22172 pushl_cfi %fs
22173 @@ -206,7 +346,7 @@
22174 CFI_REL_OFFSET ecx, 0
22175 pushl_cfi %ebx
22176 CFI_REL_OFFSET ebx, 0
22177 - movl $(__USER_DS), %edx
22178 + movl $\_DS, %edx
22179 movl %edx, %ds
22180 movl %edx, %es
22181 movl $(__KERNEL_PERCPU), %edx
22182 @@ -214,6 +354,15 @@
22183 SET_KERNEL_GS %edx
22184 .endm
22185
22186 +.macro SAVE_ALL
22187 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22188 + __SAVE_ALL __KERNEL_DS
22189 + pax_enter_kernel
22190 +#else
22191 + __SAVE_ALL __USER_DS
22192 +#endif
22193 +.endm
22194 +
22195 .macro RESTORE_INT_REGS
22196 popl_cfi %ebx
22197 CFI_RESTORE ebx
22198 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22199 popfl_cfi
22200 jmp syscall_exit
22201 CFI_ENDPROC
22202 -END(ret_from_fork)
22203 +ENDPROC(ret_from_fork)
22204
22205 ENTRY(ret_from_kernel_thread)
22206 CFI_STARTPROC
22207 @@ -344,7 +493,15 @@ ret_from_intr:
22208 andl $SEGMENT_RPL_MASK, %eax
22209 #endif
22210 cmpl $USER_RPL, %eax
22211 +
22212 +#ifdef CONFIG_PAX_KERNEXEC
22213 + jae resume_userspace
22214 +
22215 + pax_exit_kernel
22216 + jmp resume_kernel
22217 +#else
22218 jb resume_kernel # not returning to v8086 or userspace
22219 +#endif
22220
22221 ENTRY(resume_userspace)
22222 LOCKDEP_SYS_EXIT
22223 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22224 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22225 # int/exception return?
22226 jne work_pending
22227 - jmp restore_all
22228 -END(ret_from_exception)
22229 + jmp restore_all_pax
22230 +ENDPROC(ret_from_exception)
22231
22232 #ifdef CONFIG_PREEMPT
22233 ENTRY(resume_kernel)
22234 @@ -369,7 +526,7 @@ need_resched:
22235 jz restore_all
22236 call preempt_schedule_irq
22237 jmp need_resched
22238 -END(resume_kernel)
22239 +ENDPROC(resume_kernel)
22240 #endif
22241 CFI_ENDPROC
22242 /*
22243 @@ -403,30 +560,45 @@ sysenter_past_esp:
22244 /*CFI_REL_OFFSET cs, 0*/
22245 /*
22246 * Push current_thread_info()->sysenter_return to the stack.
22247 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22248 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22249 */
22250 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22251 + pushl_cfi $0
22252 CFI_REL_OFFSET eip, 0
22253
22254 pushl_cfi %eax
22255 SAVE_ALL
22256 + GET_THREAD_INFO(%ebp)
22257 + movl TI_sysenter_return(%ebp),%ebp
22258 + movl %ebp,PT_EIP(%esp)
22259 ENABLE_INTERRUPTS(CLBR_NONE)
22260
22261 /*
22262 * Load the potential sixth argument from user stack.
22263 * Careful about security.
22264 */
22265 + movl PT_OLDESP(%esp),%ebp
22266 +
22267 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22268 + mov PT_OLDSS(%esp),%ds
22269 +1: movl %ds:(%ebp),%ebp
22270 + push %ss
22271 + pop %ds
22272 +#else
22273 cmpl $__PAGE_OFFSET-3,%ebp
22274 jae syscall_fault
22275 ASM_STAC
22276 1: movl (%ebp),%ebp
22277 ASM_CLAC
22278 +#endif
22279 +
22280 movl %ebp,PT_EBP(%esp)
22281 _ASM_EXTABLE(1b,syscall_fault)
22282
22283 GET_THREAD_INFO(%ebp)
22284
22285 +#ifdef CONFIG_PAX_RANDKSTACK
22286 + pax_erase_kstack
22287 +#endif
22288 +
22289 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22290 jnz sysenter_audit
22291 sysenter_do_call:
22292 @@ -442,12 +614,24 @@ sysenter_after_call:
22293 testl $_TIF_ALLWORK_MASK, %ecx
22294 jne sysexit_audit
22295 sysenter_exit:
22296 +
22297 +#ifdef CONFIG_PAX_RANDKSTACK
22298 + pushl_cfi %eax
22299 + movl %esp, %eax
22300 + call pax_randomize_kstack
22301 + popl_cfi %eax
22302 +#endif
22303 +
22304 + pax_erase_kstack
22305 +
22306 /* if something modifies registers it must also disable sysexit */
22307 movl PT_EIP(%esp), %edx
22308 movl PT_OLDESP(%esp), %ecx
22309 xorl %ebp,%ebp
22310 TRACE_IRQS_ON
22311 1: mov PT_FS(%esp), %fs
22312 +2: mov PT_DS(%esp), %ds
22313 +3: mov PT_ES(%esp), %es
22314 PTGS_TO_GS
22315 ENABLE_INTERRUPTS_SYSEXIT
22316
22317 @@ -464,6 +648,9 @@ sysenter_audit:
22318 movl %eax,%edx /* 2nd arg: syscall number */
22319 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22320 call __audit_syscall_entry
22321 +
22322 + pax_erase_kstack
22323 +
22324 pushl_cfi %ebx
22325 movl PT_EAX(%esp),%eax /* reload syscall number */
22326 jmp sysenter_do_call
22327 @@ -489,10 +676,16 @@ sysexit_audit:
22328
22329 CFI_ENDPROC
22330 .pushsection .fixup,"ax"
22331 -2: movl $0,PT_FS(%esp)
22332 +4: movl $0,PT_FS(%esp)
22333 + jmp 1b
22334 +5: movl $0,PT_DS(%esp)
22335 + jmp 1b
22336 +6: movl $0,PT_ES(%esp)
22337 jmp 1b
22338 .popsection
22339 - _ASM_EXTABLE(1b,2b)
22340 + _ASM_EXTABLE(1b,4b)
22341 + _ASM_EXTABLE(2b,5b)
22342 + _ASM_EXTABLE(3b,6b)
22343 PTGS_TO_GS_EX
22344 ENDPROC(ia32_sysenter_target)
22345
22346 @@ -507,6 +700,11 @@ ENTRY(system_call)
22347 pushl_cfi %eax # save orig_eax
22348 SAVE_ALL
22349 GET_THREAD_INFO(%ebp)
22350 +
22351 +#ifdef CONFIG_PAX_RANDKSTACK
22352 + pax_erase_kstack
22353 +#endif
22354 +
22355 # system call tracing in operation / emulation
22356 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22357 jnz syscall_trace_entry
22358 @@ -525,6 +723,15 @@ syscall_exit:
22359 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22360 jne syscall_exit_work
22361
22362 +restore_all_pax:
22363 +
22364 +#ifdef CONFIG_PAX_RANDKSTACK
22365 + movl %esp, %eax
22366 + call pax_randomize_kstack
22367 +#endif
22368 +
22369 + pax_erase_kstack
22370 +
22371 restore_all:
22372 TRACE_IRQS_IRET
22373 restore_all_notrace:
22374 @@ -576,14 +783,34 @@ ldt_ss:
22375 * compensating for the offset by changing to the ESPFIX segment with
22376 * a base address that matches for the difference.
22377 */
22378 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22379 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22380 mov %esp, %edx /* load kernel esp */
22381 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22382 mov %dx, %ax /* eax: new kernel esp */
22383 sub %eax, %edx /* offset (low word is 0) */
22384 +#ifdef CONFIG_SMP
22385 + movl PER_CPU_VAR(cpu_number), %ebx
22386 + shll $PAGE_SHIFT_asm, %ebx
22387 + addl $cpu_gdt_table, %ebx
22388 +#else
22389 + movl $cpu_gdt_table, %ebx
22390 +#endif
22391 shr $16, %edx
22392 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22393 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22394 +
22395 +#ifdef CONFIG_PAX_KERNEXEC
22396 + mov %cr0, %esi
22397 + btr $16, %esi
22398 + mov %esi, %cr0
22399 +#endif
22400 +
22401 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22402 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22403 +
22404 +#ifdef CONFIG_PAX_KERNEXEC
22405 + bts $16, %esi
22406 + mov %esi, %cr0
22407 +#endif
22408 +
22409 pushl_cfi $__ESPFIX_SS
22410 pushl_cfi %eax /* new kernel esp */
22411 /* Disable interrupts, but do not irqtrace this section: we
22412 @@ -612,20 +839,18 @@ work_resched:
22413 movl TI_flags(%ebp), %ecx
22414 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22415 # than syscall tracing?
22416 - jz restore_all
22417 + jz restore_all_pax
22418 testb $_TIF_NEED_RESCHED, %cl
22419 jnz work_resched
22420
22421 work_notifysig: # deal with pending signals and
22422 # notify-resume requests
22423 + movl %esp, %eax
22424 #ifdef CONFIG_VM86
22425 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22426 - movl %esp, %eax
22427 jne work_notifysig_v86 # returning to kernel-space or
22428 # vm86-space
22429 1:
22430 -#else
22431 - movl %esp, %eax
22432 #endif
22433 TRACE_IRQS_ON
22434 ENABLE_INTERRUPTS(CLBR_NONE)
22435 @@ -646,7 +871,7 @@ work_notifysig_v86:
22436 movl %eax, %esp
22437 jmp 1b
22438 #endif
22439 -END(work_pending)
22440 +ENDPROC(work_pending)
22441
22442 # perform syscall exit tracing
22443 ALIGN
22444 @@ -654,11 +879,14 @@ syscall_trace_entry:
22445 movl $-ENOSYS,PT_EAX(%esp)
22446 movl %esp, %eax
22447 call syscall_trace_enter
22448 +
22449 + pax_erase_kstack
22450 +
22451 /* What it returned is what we'll actually use. */
22452 cmpl $(NR_syscalls), %eax
22453 jnae syscall_call
22454 jmp syscall_exit
22455 -END(syscall_trace_entry)
22456 +ENDPROC(syscall_trace_entry)
22457
22458 # perform syscall exit tracing
22459 ALIGN
22460 @@ -671,26 +899,30 @@ syscall_exit_work:
22461 movl %esp, %eax
22462 call syscall_trace_leave
22463 jmp resume_userspace
22464 -END(syscall_exit_work)
22465 +ENDPROC(syscall_exit_work)
22466 CFI_ENDPROC
22467
22468 RING0_INT_FRAME # can't unwind into user space anyway
22469 syscall_fault:
22470 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22471 + push %ss
22472 + pop %ds
22473 +#endif
22474 ASM_CLAC
22475 GET_THREAD_INFO(%ebp)
22476 movl $-EFAULT,PT_EAX(%esp)
22477 jmp resume_userspace
22478 -END(syscall_fault)
22479 +ENDPROC(syscall_fault)
22480
22481 syscall_badsys:
22482 movl $-ENOSYS,PT_EAX(%esp)
22483 jmp syscall_exit
22484 -END(syscall_badsys)
22485 +ENDPROC(syscall_badsys)
22486
22487 sysenter_badsys:
22488 movl $-ENOSYS,PT_EAX(%esp)
22489 jmp sysenter_after_call
22490 -END(syscall_badsys)
22491 +ENDPROC(sysenter_badsys)
22492 CFI_ENDPROC
22493 /*
22494 * End of kprobes section
22495 @@ -706,8 +938,15 @@ END(syscall_badsys)
22496 * normal stack and adjusts ESP with the matching offset.
22497 */
22498 /* fixup the stack */
22499 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22500 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22501 +#ifdef CONFIG_SMP
22502 + movl PER_CPU_VAR(cpu_number), %ebx
22503 + shll $PAGE_SHIFT_asm, %ebx
22504 + addl $cpu_gdt_table, %ebx
22505 +#else
22506 + movl $cpu_gdt_table, %ebx
22507 +#endif
22508 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22509 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22510 shl $16, %eax
22511 addl %esp, %eax /* the adjusted stack pointer */
22512 pushl_cfi $__KERNEL_DS
22513 @@ -760,7 +999,7 @@ vector=vector+1
22514 .endr
22515 2: jmp common_interrupt
22516 .endr
22517 -END(irq_entries_start)
22518 +ENDPROC(irq_entries_start)
22519
22520 .previous
22521 END(interrupt)
22522 @@ -821,7 +1060,7 @@ ENTRY(coprocessor_error)
22523 pushl_cfi $do_coprocessor_error
22524 jmp error_code
22525 CFI_ENDPROC
22526 -END(coprocessor_error)
22527 +ENDPROC(coprocessor_error)
22528
22529 ENTRY(simd_coprocessor_error)
22530 RING0_INT_FRAME
22531 @@ -834,7 +1073,7 @@ ENTRY(simd_coprocessor_error)
22532 .section .altinstructions,"a"
22533 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22534 .previous
22535 -.section .altinstr_replacement,"ax"
22536 +.section .altinstr_replacement,"a"
22537 663: pushl $do_simd_coprocessor_error
22538 664:
22539 .previous
22540 @@ -843,7 +1082,7 @@ ENTRY(simd_coprocessor_error)
22541 #endif
22542 jmp error_code
22543 CFI_ENDPROC
22544 -END(simd_coprocessor_error)
22545 +ENDPROC(simd_coprocessor_error)
22546
22547 ENTRY(device_not_available)
22548 RING0_INT_FRAME
22549 @@ -852,18 +1091,18 @@ ENTRY(device_not_available)
22550 pushl_cfi $do_device_not_available
22551 jmp error_code
22552 CFI_ENDPROC
22553 -END(device_not_available)
22554 +ENDPROC(device_not_available)
22555
22556 #ifdef CONFIG_PARAVIRT
22557 ENTRY(native_iret)
22558 iret
22559 _ASM_EXTABLE(native_iret, iret_exc)
22560 -END(native_iret)
22561 +ENDPROC(native_iret)
22562
22563 ENTRY(native_irq_enable_sysexit)
22564 sti
22565 sysexit
22566 -END(native_irq_enable_sysexit)
22567 +ENDPROC(native_irq_enable_sysexit)
22568 #endif
22569
22570 ENTRY(overflow)
22571 @@ -873,7 +1112,7 @@ ENTRY(overflow)
22572 pushl_cfi $do_overflow
22573 jmp error_code
22574 CFI_ENDPROC
22575 -END(overflow)
22576 +ENDPROC(overflow)
22577
22578 ENTRY(bounds)
22579 RING0_INT_FRAME
22580 @@ -882,7 +1121,7 @@ ENTRY(bounds)
22581 pushl_cfi $do_bounds
22582 jmp error_code
22583 CFI_ENDPROC
22584 -END(bounds)
22585 +ENDPROC(bounds)
22586
22587 ENTRY(invalid_op)
22588 RING0_INT_FRAME
22589 @@ -891,7 +1130,7 @@ ENTRY(invalid_op)
22590 pushl_cfi $do_invalid_op
22591 jmp error_code
22592 CFI_ENDPROC
22593 -END(invalid_op)
22594 +ENDPROC(invalid_op)
22595
22596 ENTRY(coprocessor_segment_overrun)
22597 RING0_INT_FRAME
22598 @@ -900,7 +1139,7 @@ ENTRY(coprocessor_segment_overrun)
22599 pushl_cfi $do_coprocessor_segment_overrun
22600 jmp error_code
22601 CFI_ENDPROC
22602 -END(coprocessor_segment_overrun)
22603 +ENDPROC(coprocessor_segment_overrun)
22604
22605 ENTRY(invalid_TSS)
22606 RING0_EC_FRAME
22607 @@ -908,7 +1147,7 @@ ENTRY(invalid_TSS)
22608 pushl_cfi $do_invalid_TSS
22609 jmp error_code
22610 CFI_ENDPROC
22611 -END(invalid_TSS)
22612 +ENDPROC(invalid_TSS)
22613
22614 ENTRY(segment_not_present)
22615 RING0_EC_FRAME
22616 @@ -916,7 +1155,7 @@ ENTRY(segment_not_present)
22617 pushl_cfi $do_segment_not_present
22618 jmp error_code
22619 CFI_ENDPROC
22620 -END(segment_not_present)
22621 +ENDPROC(segment_not_present)
22622
22623 ENTRY(stack_segment)
22624 RING0_EC_FRAME
22625 @@ -924,7 +1163,7 @@ ENTRY(stack_segment)
22626 pushl_cfi $do_stack_segment
22627 jmp error_code
22628 CFI_ENDPROC
22629 -END(stack_segment)
22630 +ENDPROC(stack_segment)
22631
22632 ENTRY(alignment_check)
22633 RING0_EC_FRAME
22634 @@ -932,7 +1171,7 @@ ENTRY(alignment_check)
22635 pushl_cfi $do_alignment_check
22636 jmp error_code
22637 CFI_ENDPROC
22638 -END(alignment_check)
22639 +ENDPROC(alignment_check)
22640
22641 ENTRY(divide_error)
22642 RING0_INT_FRAME
22643 @@ -941,7 +1180,7 @@ ENTRY(divide_error)
22644 pushl_cfi $do_divide_error
22645 jmp error_code
22646 CFI_ENDPROC
22647 -END(divide_error)
22648 +ENDPROC(divide_error)
22649
22650 #ifdef CONFIG_X86_MCE
22651 ENTRY(machine_check)
22652 @@ -951,7 +1190,7 @@ ENTRY(machine_check)
22653 pushl_cfi machine_check_vector
22654 jmp error_code
22655 CFI_ENDPROC
22656 -END(machine_check)
22657 +ENDPROC(machine_check)
22658 #endif
22659
22660 ENTRY(spurious_interrupt_bug)
22661 @@ -961,7 +1200,7 @@ ENTRY(spurious_interrupt_bug)
22662 pushl_cfi $do_spurious_interrupt_bug
22663 jmp error_code
22664 CFI_ENDPROC
22665 -END(spurious_interrupt_bug)
22666 +ENDPROC(spurious_interrupt_bug)
22667 /*
22668 * End of kprobes section
22669 */
22670 @@ -1071,7 +1310,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22671
22672 ENTRY(mcount)
22673 ret
22674 -END(mcount)
22675 +ENDPROC(mcount)
22676
22677 ENTRY(ftrace_caller)
22678 cmpl $0, function_trace_stop
22679 @@ -1104,7 +1343,7 @@ ftrace_graph_call:
22680 .globl ftrace_stub
22681 ftrace_stub:
22682 ret
22683 -END(ftrace_caller)
22684 +ENDPROC(ftrace_caller)
22685
22686 ENTRY(ftrace_regs_caller)
22687 pushf /* push flags before compare (in cs location) */
22688 @@ -1208,7 +1447,7 @@ trace:
22689 popl %ecx
22690 popl %eax
22691 jmp ftrace_stub
22692 -END(mcount)
22693 +ENDPROC(mcount)
22694 #endif /* CONFIG_DYNAMIC_FTRACE */
22695 #endif /* CONFIG_FUNCTION_TRACER */
22696
22697 @@ -1226,7 +1465,7 @@ ENTRY(ftrace_graph_caller)
22698 popl %ecx
22699 popl %eax
22700 ret
22701 -END(ftrace_graph_caller)
22702 +ENDPROC(ftrace_graph_caller)
22703
22704 .globl return_to_handler
22705 return_to_handler:
22706 @@ -1292,15 +1531,18 @@ error_code:
22707 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22708 REG_TO_PTGS %ecx
22709 SET_KERNEL_GS %ecx
22710 - movl $(__USER_DS), %ecx
22711 + movl $(__KERNEL_DS), %ecx
22712 movl %ecx, %ds
22713 movl %ecx, %es
22714 +
22715 + pax_enter_kernel
22716 +
22717 TRACE_IRQS_OFF
22718 movl %esp,%eax # pt_regs pointer
22719 call *%edi
22720 jmp ret_from_exception
22721 CFI_ENDPROC
22722 -END(page_fault)
22723 +ENDPROC(page_fault)
22724
22725 /*
22726 * Debug traps and NMI can happen at the one SYSENTER instruction
22727 @@ -1343,7 +1585,7 @@ debug_stack_correct:
22728 call do_debug
22729 jmp ret_from_exception
22730 CFI_ENDPROC
22731 -END(debug)
22732 +ENDPROC(debug)
22733
22734 /*
22735 * NMI is doubly nasty. It can happen _while_ we're handling
22736 @@ -1381,6 +1623,9 @@ nmi_stack_correct:
22737 xorl %edx,%edx # zero error code
22738 movl %esp,%eax # pt_regs pointer
22739 call do_nmi
22740 +
22741 + pax_exit_kernel
22742 +
22743 jmp restore_all_notrace
22744 CFI_ENDPROC
22745
22746 @@ -1417,12 +1662,15 @@ nmi_espfix_stack:
22747 FIXUP_ESPFIX_STACK # %eax == %esp
22748 xorl %edx,%edx # zero error code
22749 call do_nmi
22750 +
22751 + pax_exit_kernel
22752 +
22753 RESTORE_REGS
22754 lss 12+4(%esp), %esp # back to espfix stack
22755 CFI_ADJUST_CFA_OFFSET -24
22756 jmp irq_return
22757 CFI_ENDPROC
22758 -END(nmi)
22759 +ENDPROC(nmi)
22760
22761 ENTRY(int3)
22762 RING0_INT_FRAME
22763 @@ -1435,14 +1683,14 @@ ENTRY(int3)
22764 call do_int3
22765 jmp ret_from_exception
22766 CFI_ENDPROC
22767 -END(int3)
22768 +ENDPROC(int3)
22769
22770 ENTRY(general_protection)
22771 RING0_EC_FRAME
22772 pushl_cfi $do_general_protection
22773 jmp error_code
22774 CFI_ENDPROC
22775 -END(general_protection)
22776 +ENDPROC(general_protection)
22777
22778 #ifdef CONFIG_KVM_GUEST
22779 ENTRY(async_page_fault)
22780 @@ -1451,7 +1699,7 @@ ENTRY(async_page_fault)
22781 pushl_cfi $do_async_page_fault
22782 jmp error_code
22783 CFI_ENDPROC
22784 -END(async_page_fault)
22785 +ENDPROC(async_page_fault)
22786 #endif
22787
22788 /*
22789 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22790 index 1e96c36..3ff710a 100644
22791 --- a/arch/x86/kernel/entry_64.S
22792 +++ b/arch/x86/kernel/entry_64.S
22793 @@ -59,6 +59,8 @@
22794 #include <asm/context_tracking.h>
22795 #include <asm/smap.h>
22796 #include <linux/err.h>
22797 +#include <asm/pgtable.h>
22798 +#include <asm/alternative-asm.h>
22799
22800 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22801 #include <linux/elf-em.h>
22802 @@ -80,8 +82,9 @@
22803 #ifdef CONFIG_DYNAMIC_FTRACE
22804
22805 ENTRY(function_hook)
22806 + pax_force_retaddr
22807 retq
22808 -END(function_hook)
22809 +ENDPROC(function_hook)
22810
22811 /* skip is set if stack has been adjusted */
22812 .macro ftrace_caller_setup skip=0
22813 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22814 #endif
22815
22816 GLOBAL(ftrace_stub)
22817 + pax_force_retaddr
22818 retq
22819 -END(ftrace_caller)
22820 +ENDPROC(ftrace_caller)
22821
22822 ENTRY(ftrace_regs_caller)
22823 /* Save the current flags before compare (in SS location)*/
22824 @@ -191,7 +195,7 @@ ftrace_restore_flags:
22825 popfq
22826 jmp ftrace_stub
22827
22828 -END(ftrace_regs_caller)
22829 +ENDPROC(ftrace_regs_caller)
22830
22831
22832 #else /* ! CONFIG_DYNAMIC_FTRACE */
22833 @@ -212,6 +216,7 @@ ENTRY(function_hook)
22834 #endif
22835
22836 GLOBAL(ftrace_stub)
22837 + pax_force_retaddr
22838 retq
22839
22840 trace:
22841 @@ -225,12 +230,13 @@ trace:
22842 #endif
22843 subq $MCOUNT_INSN_SIZE, %rdi
22844
22845 + pax_force_fptr ftrace_trace_function
22846 call *ftrace_trace_function
22847
22848 MCOUNT_RESTORE_FRAME
22849
22850 jmp ftrace_stub
22851 -END(function_hook)
22852 +ENDPROC(function_hook)
22853 #endif /* CONFIG_DYNAMIC_FTRACE */
22854 #endif /* CONFIG_FUNCTION_TRACER */
22855
22856 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22857
22858 MCOUNT_RESTORE_FRAME
22859
22860 + pax_force_retaddr
22861 retq
22862 -END(ftrace_graph_caller)
22863 +ENDPROC(ftrace_graph_caller)
22864
22865 GLOBAL(return_to_handler)
22866 subq $24, %rsp
22867 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22868 movq 8(%rsp), %rdx
22869 movq (%rsp), %rax
22870 addq $24, %rsp
22871 + pax_force_fptr %rdi
22872 jmp *%rdi
22873 +ENDPROC(return_to_handler)
22874 #endif
22875
22876
22877 @@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22878 ENDPROC(native_usergs_sysret64)
22879 #endif /* CONFIG_PARAVIRT */
22880
22881 + .macro ljmpq sel, off
22882 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22883 + .byte 0x48; ljmp *1234f(%rip)
22884 + .pushsection .rodata
22885 + .align 16
22886 + 1234: .quad \off; .word \sel
22887 + .popsection
22888 +#else
22889 + pushq $\sel
22890 + pushq $\off
22891 + lretq
22892 +#endif
22893 + .endm
22894 +
22895 + .macro pax_enter_kernel
22896 + pax_set_fptr_mask
22897 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22898 + call pax_enter_kernel
22899 +#endif
22900 + .endm
22901 +
22902 + .macro pax_exit_kernel
22903 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22904 + call pax_exit_kernel
22905 +#endif
22906 +
22907 + .endm
22908 +
22909 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22910 +ENTRY(pax_enter_kernel)
22911 + pushq %rdi
22912 +
22913 +#ifdef CONFIG_PARAVIRT
22914 + PV_SAVE_REGS(CLBR_RDI)
22915 +#endif
22916 +
22917 +#ifdef CONFIG_PAX_KERNEXEC
22918 + GET_CR0_INTO_RDI
22919 + bts $16,%rdi
22920 + jnc 3f
22921 + mov %cs,%edi
22922 + cmp $__KERNEL_CS,%edi
22923 + jnz 2f
22924 +1:
22925 +#endif
22926 +
22927 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22928 + 661: jmp 111f
22929 + .pushsection .altinstr_replacement, "a"
22930 + 662: ASM_NOP2
22931 + .popsection
22932 + .pushsection .altinstructions, "a"
22933 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22934 + .popsection
22935 + GET_CR3_INTO_RDI
22936 + cmp $0,%dil
22937 + jnz 112f
22938 + mov $__KERNEL_DS,%edi
22939 + mov %edi,%ss
22940 + jmp 111f
22941 +112: cmp $1,%dil
22942 + jz 113f
22943 + ud2
22944 +113: sub $4097,%rdi
22945 + bts $63,%rdi
22946 + SET_RDI_INTO_CR3
22947 + mov $__UDEREF_KERNEL_DS,%edi
22948 + mov %edi,%ss
22949 +111:
22950 +#endif
22951 +
22952 +#ifdef CONFIG_PARAVIRT
22953 + PV_RESTORE_REGS(CLBR_RDI)
22954 +#endif
22955 +
22956 + popq %rdi
22957 + pax_force_retaddr
22958 + retq
22959 +
22960 +#ifdef CONFIG_PAX_KERNEXEC
22961 +2: ljmpq __KERNEL_CS,1b
22962 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
22963 +4: SET_RDI_INTO_CR0
22964 + jmp 1b
22965 +#endif
22966 +ENDPROC(pax_enter_kernel)
22967 +
22968 +ENTRY(pax_exit_kernel)
22969 + pushq %rdi
22970 +
22971 +#ifdef CONFIG_PARAVIRT
22972 + PV_SAVE_REGS(CLBR_RDI)
22973 +#endif
22974 +
22975 +#ifdef CONFIG_PAX_KERNEXEC
22976 + mov %cs,%rdi
22977 + cmp $__KERNEXEC_KERNEL_CS,%edi
22978 + jz 2f
22979 + GET_CR0_INTO_RDI
22980 + bts $16,%rdi
22981 + jnc 4f
22982 +1:
22983 +#endif
22984 +
22985 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22986 + 661: jmp 111f
22987 + .pushsection .altinstr_replacement, "a"
22988 + 662: ASM_NOP2
22989 + .popsection
22990 + .pushsection .altinstructions, "a"
22991 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22992 + .popsection
22993 + mov %ss,%edi
22994 + cmp $__UDEREF_KERNEL_DS,%edi
22995 + jnz 111f
22996 + GET_CR3_INTO_RDI
22997 + cmp $0,%dil
22998 + jz 112f
22999 + ud2
23000 +112: add $4097,%rdi
23001 + bts $63,%rdi
23002 + SET_RDI_INTO_CR3
23003 + mov $__KERNEL_DS,%edi
23004 + mov %edi,%ss
23005 +111:
23006 +#endif
23007 +
23008 +#ifdef CONFIG_PARAVIRT
23009 + PV_RESTORE_REGS(CLBR_RDI);
23010 +#endif
23011 +
23012 + popq %rdi
23013 + pax_force_retaddr
23014 + retq
23015 +
23016 +#ifdef CONFIG_PAX_KERNEXEC
23017 +2: GET_CR0_INTO_RDI
23018 + btr $16,%rdi
23019 + jnc 4f
23020 + ljmpq __KERNEL_CS,3f
23021 +3: SET_RDI_INTO_CR0
23022 + jmp 1b
23023 +4: ud2
23024 + jmp 4b
23025 +#endif
23026 +ENDPROC(pax_exit_kernel)
23027 +#endif
23028 +
23029 + .macro pax_enter_kernel_user
23030 + pax_set_fptr_mask
23031 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23032 + call pax_enter_kernel_user
23033 +#endif
23034 + .endm
23035 +
23036 + .macro pax_exit_kernel_user
23037 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23038 + call pax_exit_kernel_user
23039 +#endif
23040 +#ifdef CONFIG_PAX_RANDKSTACK
23041 + pushq %rax
23042 + pushq %r11
23043 + call pax_randomize_kstack
23044 + popq %r11
23045 + popq %rax
23046 +#endif
23047 + .endm
23048 +
23049 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23050 +ENTRY(pax_enter_kernel_user)
23051 + pushq %rdi
23052 + pushq %rbx
23053 +
23054 +#ifdef CONFIG_PARAVIRT
23055 + PV_SAVE_REGS(CLBR_RDI)
23056 +#endif
23057 +
23058 + 661: jmp 111f
23059 + .pushsection .altinstr_replacement, "a"
23060 + 662: ASM_NOP2
23061 + .popsection
23062 + .pushsection .altinstructions, "a"
23063 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23064 + .popsection
23065 + GET_CR3_INTO_RDI
23066 + cmp $1,%dil
23067 + jnz 4f
23068 + sub $4097,%rdi
23069 + bts $63,%rdi
23070 + SET_RDI_INTO_CR3
23071 + jmp 3f
23072 +111:
23073 +
23074 + GET_CR3_INTO_RDI
23075 + mov %rdi,%rbx
23076 + add $__START_KERNEL_map,%rbx
23077 + sub phys_base(%rip),%rbx
23078 +
23079 +#ifdef CONFIG_PARAVIRT
23080 + cmpl $0, pv_info+PARAVIRT_enabled
23081 + jz 1f
23082 + pushq %rdi
23083 + i = 0
23084 + .rept USER_PGD_PTRS
23085 + mov i*8(%rbx),%rsi
23086 + mov $0,%sil
23087 + lea i*8(%rbx),%rdi
23088 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23089 + i = i + 1
23090 + .endr
23091 + popq %rdi
23092 + jmp 2f
23093 +1:
23094 +#endif
23095 +
23096 + i = 0
23097 + .rept USER_PGD_PTRS
23098 + movb $0,i*8(%rbx)
23099 + i = i + 1
23100 + .endr
23101 +
23102 +2: SET_RDI_INTO_CR3
23103 +
23104 +#ifdef CONFIG_PAX_KERNEXEC
23105 + GET_CR0_INTO_RDI
23106 + bts $16,%rdi
23107 + SET_RDI_INTO_CR0
23108 +#endif
23109 +
23110 +3:
23111 +
23112 +#ifdef CONFIG_PARAVIRT
23113 + PV_RESTORE_REGS(CLBR_RDI)
23114 +#endif
23115 +
23116 + popq %rbx
23117 + popq %rdi
23118 + pax_force_retaddr
23119 + retq
23120 +4: ud2
23121 +ENDPROC(pax_enter_kernel_user)
23122 +
23123 +ENTRY(pax_exit_kernel_user)
23124 + pushq %rdi
23125 + pushq %rbx
23126 +
23127 +#ifdef CONFIG_PARAVIRT
23128 + PV_SAVE_REGS(CLBR_RDI)
23129 +#endif
23130 +
23131 + GET_CR3_INTO_RDI
23132 + 661: jmp 1f
23133 + .pushsection .altinstr_replacement, "a"
23134 + 662: ASM_NOP2
23135 + .popsection
23136 + .pushsection .altinstructions, "a"
23137 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23138 + .popsection
23139 + cmp $0,%dil
23140 + jnz 3f
23141 + add $4097,%rdi
23142 + bts $63,%rdi
23143 + SET_RDI_INTO_CR3
23144 + jmp 2f
23145 +1:
23146 +
23147 + mov %rdi,%rbx
23148 +
23149 +#ifdef CONFIG_PAX_KERNEXEC
23150 + GET_CR0_INTO_RDI
23151 + btr $16,%rdi
23152 + jnc 3f
23153 + SET_RDI_INTO_CR0
23154 +#endif
23155 +
23156 + add $__START_KERNEL_map,%rbx
23157 + sub phys_base(%rip),%rbx
23158 +
23159 +#ifdef CONFIG_PARAVIRT
23160 + cmpl $0, pv_info+PARAVIRT_enabled
23161 + jz 1f
23162 + i = 0
23163 + .rept USER_PGD_PTRS
23164 + mov i*8(%rbx),%rsi
23165 + mov $0x67,%sil
23166 + lea i*8(%rbx),%rdi
23167 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23168 + i = i + 1
23169 + .endr
23170 + jmp 2f
23171 +1:
23172 +#endif
23173 +
23174 + i = 0
23175 + .rept USER_PGD_PTRS
23176 + movb $0x67,i*8(%rbx)
23177 + i = i + 1
23178 + .endr
23179 +2:
23180 +
23181 +#ifdef CONFIG_PARAVIRT
23182 + PV_RESTORE_REGS(CLBR_RDI)
23183 +#endif
23184 +
23185 + popq %rbx
23186 + popq %rdi
23187 + pax_force_retaddr
23188 + retq
23189 +3: ud2
23190 +ENDPROC(pax_exit_kernel_user)
23191 +#endif
23192 +
23193 + .macro pax_enter_kernel_nmi
23194 + pax_set_fptr_mask
23195 +
23196 +#ifdef CONFIG_PAX_KERNEXEC
23197 + GET_CR0_INTO_RDI
23198 + bts $16,%rdi
23199 + jc 110f
23200 + SET_RDI_INTO_CR0
23201 + or $2,%ebx
23202 +110:
23203 +#endif
23204 +
23205 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23206 + 661: jmp 111f
23207 + .pushsection .altinstr_replacement, "a"
23208 + 662: ASM_NOP2
23209 + .popsection
23210 + .pushsection .altinstructions, "a"
23211 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23212 + .popsection
23213 + GET_CR3_INTO_RDI
23214 + cmp $0,%dil
23215 + jz 111f
23216 + sub $4097,%rdi
23217 + or $4,%ebx
23218 + bts $63,%rdi
23219 + SET_RDI_INTO_CR3
23220 + mov $__UDEREF_KERNEL_DS,%edi
23221 + mov %edi,%ss
23222 +111:
23223 +#endif
23224 + .endm
23225 +
23226 + .macro pax_exit_kernel_nmi
23227 +#ifdef CONFIG_PAX_KERNEXEC
23228 + btr $1,%ebx
23229 + jnc 110f
23230 + GET_CR0_INTO_RDI
23231 + btr $16,%rdi
23232 + SET_RDI_INTO_CR0
23233 +110:
23234 +#endif
23235 +
23236 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23237 + btr $2,%ebx
23238 + jnc 111f
23239 + GET_CR3_INTO_RDI
23240 + add $4097,%rdi
23241 + bts $63,%rdi
23242 + SET_RDI_INTO_CR3
23243 + mov $__KERNEL_DS,%edi
23244 + mov %edi,%ss
23245 +111:
23246 +#endif
23247 + .endm
23248 +
23249 + .macro pax_erase_kstack
23250 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23251 + call pax_erase_kstack
23252 +#endif
23253 + .endm
23254 +
23255 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23256 +ENTRY(pax_erase_kstack)
23257 + pushq %rdi
23258 + pushq %rcx
23259 + pushq %rax
23260 + pushq %r11
23261 +
23262 + GET_THREAD_INFO(%r11)
23263 + mov TI_lowest_stack(%r11), %rdi
23264 + mov $-0xBEEF, %rax
23265 + std
23266 +
23267 +1: mov %edi, %ecx
23268 + and $THREAD_SIZE_asm - 1, %ecx
23269 + shr $3, %ecx
23270 + repne scasq
23271 + jecxz 2f
23272 +
23273 + cmp $2*8, %ecx
23274 + jc 2f
23275 +
23276 + mov $2*8, %ecx
23277 + repe scasq
23278 + jecxz 2f
23279 + jne 1b
23280 +
23281 +2: cld
23282 + mov %esp, %ecx
23283 + sub %edi, %ecx
23284 +
23285 + cmp $THREAD_SIZE_asm, %rcx
23286 + jb 3f
23287 + ud2
23288 +3:
23289 +
23290 + shr $3, %ecx
23291 + rep stosq
23292 +
23293 + mov TI_task_thread_sp0(%r11), %rdi
23294 + sub $256, %rdi
23295 + mov %rdi, TI_lowest_stack(%r11)
23296 +
23297 + popq %r11
23298 + popq %rax
23299 + popq %rcx
23300 + popq %rdi
23301 + pax_force_retaddr
23302 + ret
23303 +ENDPROC(pax_erase_kstack)
23304 +#endif
23305
23306 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23307 #ifdef CONFIG_TRACE_IRQFLAGS
23308 @@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23309 .endm
23310
23311 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23312 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23313 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23314 jnc 1f
23315 TRACE_IRQS_ON_DEBUG
23316 1:
23317 @@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23318 movq \tmp,R11+\offset(%rsp)
23319 .endm
23320
23321 - .macro FAKE_STACK_FRAME child_rip
23322 - /* push in order ss, rsp, eflags, cs, rip */
23323 - xorl %eax, %eax
23324 - pushq_cfi $__KERNEL_DS /* ss */
23325 - /*CFI_REL_OFFSET ss,0*/
23326 - pushq_cfi %rax /* rsp */
23327 - CFI_REL_OFFSET rsp,0
23328 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23329 - /*CFI_REL_OFFSET rflags,0*/
23330 - pushq_cfi $__KERNEL_CS /* cs */
23331 - /*CFI_REL_OFFSET cs,0*/
23332 - pushq_cfi \child_rip /* rip */
23333 - CFI_REL_OFFSET rip,0
23334 - pushq_cfi %rax /* orig rax */
23335 - .endm
23336 -
23337 - .macro UNFAKE_STACK_FRAME
23338 - addq $8*6, %rsp
23339 - CFI_ADJUST_CFA_OFFSET -(6*8)
23340 - .endm
23341 -
23342 /*
23343 * initial frame state for interrupts (and exceptions without error code)
23344 */
23345 @@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23346 /* save partial stack frame */
23347 .macro SAVE_ARGS_IRQ
23348 cld
23349 - /* start from rbp in pt_regs and jump over */
23350 - movq_cfi rdi, (RDI-RBP)
23351 - movq_cfi rsi, (RSI-RBP)
23352 - movq_cfi rdx, (RDX-RBP)
23353 - movq_cfi rcx, (RCX-RBP)
23354 - movq_cfi rax, (RAX-RBP)
23355 - movq_cfi r8, (R8-RBP)
23356 - movq_cfi r9, (R9-RBP)
23357 - movq_cfi r10, (R10-RBP)
23358 - movq_cfi r11, (R11-RBP)
23359 + /* start from r15 in pt_regs and jump over */
23360 + movq_cfi rdi, RDI
23361 + movq_cfi rsi, RSI
23362 + movq_cfi rdx, RDX
23363 + movq_cfi rcx, RCX
23364 + movq_cfi rax, RAX
23365 + movq_cfi r8, R8
23366 + movq_cfi r9, R9
23367 + movq_cfi r10, R10
23368 + movq_cfi r11, R11
23369 + movq_cfi r12, R12
23370
23371 /* Save rbp so that we can unwind from get_irq_regs() */
23372 - movq_cfi rbp, 0
23373 + movq_cfi rbp, RBP
23374
23375 /* Save previous stack value */
23376 movq %rsp, %rsi
23377
23378 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23379 - testl $3, CS-RBP(%rsi)
23380 + movq %rsp,%rdi /* arg1 for handler */
23381 + testb $3, CS(%rsi)
23382 je 1f
23383 SWAPGS
23384 /*
23385 @@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23386 0x06 /* DW_OP_deref */, \
23387 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23388 0x22 /* DW_OP_plus */
23389 +
23390 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23391 + testb $3, CS(%rdi)
23392 + jnz 1f
23393 + pax_enter_kernel
23394 + jmp 2f
23395 +1: pax_enter_kernel_user
23396 +2:
23397 +#else
23398 + pax_enter_kernel
23399 +#endif
23400 +
23401 /* We entered an interrupt context - irqs are off: */
23402 TRACE_IRQS_OFF
23403 .endm
23404 @@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23405 js 1f /* negative -> in kernel */
23406 SWAPGS
23407 xorl %ebx,%ebx
23408 -1: ret
23409 +1:
23410 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23411 + testb $3, CS+8(%rsp)
23412 + jnz 1f
23413 + pax_enter_kernel
23414 + jmp 2f
23415 +1: pax_enter_kernel_user
23416 +2:
23417 +#else
23418 + pax_enter_kernel
23419 +#endif
23420 + pax_force_retaddr
23421 + ret
23422 CFI_ENDPROC
23423 -END(save_paranoid)
23424 +ENDPROC(save_paranoid)
23425 +
23426 +ENTRY(save_paranoid_nmi)
23427 + XCPT_FRAME 1 RDI+8
23428 + cld
23429 + movq_cfi rdi, RDI+8
23430 + movq_cfi rsi, RSI+8
23431 + movq_cfi rdx, RDX+8
23432 + movq_cfi rcx, RCX+8
23433 + movq_cfi rax, RAX+8
23434 + movq_cfi r8, R8+8
23435 + movq_cfi r9, R9+8
23436 + movq_cfi r10, R10+8
23437 + movq_cfi r11, R11+8
23438 + movq_cfi rbx, RBX+8
23439 + movq_cfi rbp, RBP+8
23440 + movq_cfi r12, R12+8
23441 + movq_cfi r13, R13+8
23442 + movq_cfi r14, R14+8
23443 + movq_cfi r15, R15+8
23444 + movl $1,%ebx
23445 + movl $MSR_GS_BASE,%ecx
23446 + rdmsr
23447 + testl %edx,%edx
23448 + js 1f /* negative -> in kernel */
23449 + SWAPGS
23450 + xorl %ebx,%ebx
23451 +1: pax_enter_kernel_nmi
23452 + pax_force_retaddr
23453 + ret
23454 + CFI_ENDPROC
23455 +ENDPROC(save_paranoid_nmi)
23456 .popsection
23457
23458 /*
23459 @@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23460
23461 RESTORE_REST
23462
23463 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23464 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23465 jz 1f
23466
23467 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23468 @@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23469 jmp ret_from_sys_call # go to the SYSRET fastpath
23470
23471 1:
23472 - subq $REST_SKIP, %rsp # leave space for volatiles
23473 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23474 movq %rbp, %rdi
23475 call *%rbx
23476 movl $0, RAX(%rsp)
23477 RESTORE_REST
23478 jmp int_ret_from_sys_call
23479 CFI_ENDPROC
23480 -END(ret_from_fork)
23481 +ENDPROC(ret_from_fork)
23482
23483 /*
23484 * System call entry. Up to 6 arguments in registers are supported.
23485 @@ -593,7 +1059,7 @@ END(ret_from_fork)
23486 ENTRY(system_call)
23487 CFI_STARTPROC simple
23488 CFI_SIGNAL_FRAME
23489 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23490 + CFI_DEF_CFA rsp,0
23491 CFI_REGISTER rip,rcx
23492 /*CFI_REGISTER rflags,r11*/
23493 SWAPGS_UNSAFE_STACK
23494 @@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23495
23496 movq %rsp,PER_CPU_VAR(old_rsp)
23497 movq PER_CPU_VAR(kernel_stack),%rsp
23498 + SAVE_ARGS 8*6,0
23499 + pax_enter_kernel_user
23500 +
23501 +#ifdef CONFIG_PAX_RANDKSTACK
23502 + pax_erase_kstack
23503 +#endif
23504 +
23505 /*
23506 * No need to follow this irqs off/on section - it's straight
23507 * and short:
23508 */
23509 ENABLE_INTERRUPTS(CLBR_NONE)
23510 - SAVE_ARGS 8,0
23511 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23512 movq %rcx,RIP-ARGOFFSET(%rsp)
23513 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23514 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23515 + GET_THREAD_INFO(%rcx)
23516 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23517 jnz tracesys
23518 system_call_fastpath:
23519 #if __SYSCALL_MASK == ~0
23520 @@ -639,10 +1112,13 @@ sysret_check:
23521 LOCKDEP_SYS_EXIT
23522 DISABLE_INTERRUPTS(CLBR_NONE)
23523 TRACE_IRQS_OFF
23524 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23525 + GET_THREAD_INFO(%rcx)
23526 + movl TI_flags(%rcx),%edx
23527 andl %edi,%edx
23528 jnz sysret_careful
23529 CFI_REMEMBER_STATE
23530 + pax_exit_kernel_user
23531 + pax_erase_kstack
23532 /*
23533 * sysretq will re-enable interrupts:
23534 */
23535 @@ -701,6 +1177,9 @@ auditsys:
23536 movq %rax,%rsi /* 2nd arg: syscall number */
23537 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23538 call __audit_syscall_entry
23539 +
23540 + pax_erase_kstack
23541 +
23542 LOAD_ARGS 0 /* reload call-clobbered registers */
23543 jmp system_call_fastpath
23544
23545 @@ -722,7 +1201,7 @@ sysret_audit:
23546 /* Do syscall tracing */
23547 tracesys:
23548 #ifdef CONFIG_AUDITSYSCALL
23549 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23550 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23551 jz auditsys
23552 #endif
23553 SAVE_REST
23554 @@ -730,12 +1209,15 @@ tracesys:
23555 FIXUP_TOP_OF_STACK %rdi
23556 movq %rsp,%rdi
23557 call syscall_trace_enter
23558 +
23559 + pax_erase_kstack
23560 +
23561 /*
23562 * Reload arg registers from stack in case ptrace changed them.
23563 * We don't reload %rax because syscall_trace_enter() returned
23564 * the value it wants us to use in the table lookup.
23565 */
23566 - LOAD_ARGS ARGOFFSET, 1
23567 + LOAD_ARGS 1
23568 RESTORE_REST
23569 #if __SYSCALL_MASK == ~0
23570 cmpq $__NR_syscall_max,%rax
23571 @@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23572 andl %edi,%edx
23573 jnz int_careful
23574 andl $~TS_COMPAT,TI_status(%rcx)
23575 - jmp retint_swapgs
23576 + pax_exit_kernel_user
23577 + pax_erase_kstack
23578 + jmp retint_swapgs_pax
23579
23580 /* Either reschedule or signal or syscall exit tracking needed. */
23581 /* First do a reschedule test. */
23582 @@ -811,7 +1295,7 @@ int_restore_rest:
23583 TRACE_IRQS_OFF
23584 jmp int_with_check
23585 CFI_ENDPROC
23586 -END(system_call)
23587 +ENDPROC(system_call)
23588
23589 .macro FORK_LIKE func
23590 ENTRY(stub_\func)
23591 @@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23592 DEFAULT_FRAME 0 8 /* offset 8: return address */
23593 call sys_\func
23594 RESTORE_TOP_OF_STACK %r11, 8
23595 - ret $REST_SKIP /* pop extended registers */
23596 + pax_force_retaddr
23597 + ret
23598 CFI_ENDPROC
23599 -END(stub_\func)
23600 +ENDPROC(stub_\func)
23601 .endm
23602
23603 .macro FIXED_FRAME label,func
23604 @@ -836,9 +1321,10 @@ ENTRY(\label)
23605 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23606 call \func
23607 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23608 + pax_force_retaddr
23609 ret
23610 CFI_ENDPROC
23611 -END(\label)
23612 +ENDPROC(\label)
23613 .endm
23614
23615 FORK_LIKE clone
23616 @@ -846,19 +1332,6 @@ END(\label)
23617 FORK_LIKE vfork
23618 FIXED_FRAME stub_iopl, sys_iopl
23619
23620 -ENTRY(ptregscall_common)
23621 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23622 - RESTORE_TOP_OF_STACK %r11, 8
23623 - movq_cfi_restore R15+8, r15
23624 - movq_cfi_restore R14+8, r14
23625 - movq_cfi_restore R13+8, r13
23626 - movq_cfi_restore R12+8, r12
23627 - movq_cfi_restore RBP+8, rbp
23628 - movq_cfi_restore RBX+8, rbx
23629 - ret $REST_SKIP /* pop extended registers */
23630 - CFI_ENDPROC
23631 -END(ptregscall_common)
23632 -
23633 ENTRY(stub_execve)
23634 CFI_STARTPROC
23635 addq $8, %rsp
23636 @@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23637 RESTORE_REST
23638 jmp int_ret_from_sys_call
23639 CFI_ENDPROC
23640 -END(stub_execve)
23641 +ENDPROC(stub_execve)
23642
23643 /*
23644 * sigreturn is special because it needs to restore all registers on return.
23645 @@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23646 RESTORE_REST
23647 jmp int_ret_from_sys_call
23648 CFI_ENDPROC
23649 -END(stub_rt_sigreturn)
23650 +ENDPROC(stub_rt_sigreturn)
23651
23652 #ifdef CONFIG_X86_X32_ABI
23653 ENTRY(stub_x32_rt_sigreturn)
23654 @@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23655 RESTORE_REST
23656 jmp int_ret_from_sys_call
23657 CFI_ENDPROC
23658 -END(stub_x32_rt_sigreturn)
23659 +ENDPROC(stub_x32_rt_sigreturn)
23660
23661 ENTRY(stub_x32_execve)
23662 CFI_STARTPROC
23663 @@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23664 RESTORE_REST
23665 jmp int_ret_from_sys_call
23666 CFI_ENDPROC
23667 -END(stub_x32_execve)
23668 +ENDPROC(stub_x32_execve)
23669
23670 #endif
23671
23672 @@ -952,7 +1425,7 @@ vector=vector+1
23673 2: jmp common_interrupt
23674 .endr
23675 CFI_ENDPROC
23676 -END(irq_entries_start)
23677 +ENDPROC(irq_entries_start)
23678
23679 .previous
23680 END(interrupt)
23681 @@ -969,8 +1442,8 @@ END(interrupt)
23682 /* 0(%rsp): ~(interrupt number) */
23683 .macro interrupt func
23684 /* reserve pt_regs for scratch regs and rbp */
23685 - subq $ORIG_RAX-RBP, %rsp
23686 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23687 + subq $ORIG_RAX, %rsp
23688 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23689 SAVE_ARGS_IRQ
23690 call \func
23691 .endm
23692 @@ -997,14 +1470,14 @@ ret_from_intr:
23693
23694 /* Restore saved previous stack */
23695 popq %rsi
23696 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23697 - leaq ARGOFFSET-RBP(%rsi), %rsp
23698 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23699 + movq %rsi, %rsp
23700 CFI_DEF_CFA_REGISTER rsp
23701 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23702 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23703
23704 exit_intr:
23705 GET_THREAD_INFO(%rcx)
23706 - testl $3,CS-ARGOFFSET(%rsp)
23707 + testb $3,CS-ARGOFFSET(%rsp)
23708 je retint_kernel
23709
23710 /* Interrupt came from user space */
23711 @@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23712 * The iretq could re-enable interrupts:
23713 */
23714 DISABLE_INTERRUPTS(CLBR_ANY)
23715 + pax_exit_kernel_user
23716 +retint_swapgs_pax:
23717 TRACE_IRQS_IRETQ
23718 SWAPGS
23719 jmp restore_args
23720
23721 retint_restore_args: /* return to kernel space */
23722 DISABLE_INTERRUPTS(CLBR_ANY)
23723 + pax_exit_kernel
23724 + pax_force_retaddr (RIP-ARGOFFSET)
23725 /*
23726 * The iretq could re-enable interrupts:
23727 */
23728 @@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23729 #endif
23730
23731 CFI_ENDPROC
23732 -END(common_interrupt)
23733 +ENDPROC(common_interrupt)
23734 /*
23735 * End of kprobes section
23736 */
23737 @@ -1130,7 +1607,7 @@ ENTRY(\sym)
23738 interrupt \do_sym
23739 jmp ret_from_intr
23740 CFI_ENDPROC
23741 -END(\sym)
23742 +ENDPROC(\sym)
23743 .endm
23744
23745 #ifdef CONFIG_TRACING
23746 @@ -1218,7 +1695,7 @@ ENTRY(\sym)
23747 call \do_sym
23748 jmp error_exit /* %ebx: no swapgs flag */
23749 CFI_ENDPROC
23750 -END(\sym)
23751 +ENDPROC(\sym)
23752 .endm
23753
23754 .macro paranoidzeroentry sym do_sym
23755 @@ -1236,10 +1713,10 @@ ENTRY(\sym)
23756 call \do_sym
23757 jmp paranoid_exit /* %ebx: no swapgs flag */
23758 CFI_ENDPROC
23759 -END(\sym)
23760 +ENDPROC(\sym)
23761 .endm
23762
23763 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23764 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23765 .macro paranoidzeroentry_ist sym do_sym ist
23766 ENTRY(\sym)
23767 INTR_FRAME
23768 @@ -1252,12 +1729,18 @@ ENTRY(\sym)
23769 TRACE_IRQS_OFF_DEBUG
23770 movq %rsp,%rdi /* pt_regs pointer */
23771 xorl %esi,%esi /* no error code */
23772 +#ifdef CONFIG_SMP
23773 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23774 + lea init_tss(%r13), %r13
23775 +#else
23776 + lea init_tss(%rip), %r13
23777 +#endif
23778 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23779 call \do_sym
23780 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23781 jmp paranoid_exit /* %ebx: no swapgs flag */
23782 CFI_ENDPROC
23783 -END(\sym)
23784 +ENDPROC(\sym)
23785 .endm
23786
23787 .macro errorentry sym do_sym
23788 @@ -1275,7 +1758,7 @@ ENTRY(\sym)
23789 call \do_sym
23790 jmp error_exit /* %ebx: no swapgs flag */
23791 CFI_ENDPROC
23792 -END(\sym)
23793 +ENDPROC(\sym)
23794 .endm
23795
23796 #ifdef CONFIG_TRACING
23797 @@ -1306,7 +1789,7 @@ ENTRY(\sym)
23798 call \do_sym
23799 jmp paranoid_exit /* %ebx: no swapgs flag */
23800 CFI_ENDPROC
23801 -END(\sym)
23802 +ENDPROC(\sym)
23803 .endm
23804
23805 zeroentry divide_error do_divide_error
23806 @@ -1336,9 +1819,10 @@ gs_change:
23807 2: mfence /* workaround */
23808 SWAPGS
23809 popfq_cfi
23810 + pax_force_retaddr
23811 ret
23812 CFI_ENDPROC
23813 -END(native_load_gs_index)
23814 +ENDPROC(native_load_gs_index)
23815
23816 _ASM_EXTABLE(gs_change,bad_gs)
23817 .section .fixup,"ax"
23818 @@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23819 CFI_DEF_CFA_REGISTER rsp
23820 CFI_ADJUST_CFA_OFFSET -8
23821 decl PER_CPU_VAR(irq_count)
23822 + pax_force_retaddr
23823 ret
23824 CFI_ENDPROC
23825 -END(do_softirq_own_stack)
23826 +ENDPROC(do_softirq_own_stack)
23827
23828 #ifdef CONFIG_XEN
23829 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23830 @@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23831 decl PER_CPU_VAR(irq_count)
23832 jmp error_exit
23833 CFI_ENDPROC
23834 -END(xen_do_hypervisor_callback)
23835 +ENDPROC(xen_do_hypervisor_callback)
23836
23837 /*
23838 * Hypervisor uses this for application faults while it executes.
23839 @@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23840 SAVE_ALL
23841 jmp error_exit
23842 CFI_ENDPROC
23843 -END(xen_failsafe_callback)
23844 +ENDPROC(xen_failsafe_callback)
23845
23846 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23847 xen_hvm_callback_vector xen_evtchn_do_upcall
23848 @@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23849 DEFAULT_FRAME
23850 DISABLE_INTERRUPTS(CLBR_NONE)
23851 TRACE_IRQS_OFF_DEBUG
23852 - testl %ebx,%ebx /* swapgs needed? */
23853 + testl $1,%ebx /* swapgs needed? */
23854 jnz paranoid_restore
23855 - testl $3,CS(%rsp)
23856 + testb $3,CS(%rsp)
23857 jnz paranoid_userspace
23858 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23859 + pax_exit_kernel
23860 + TRACE_IRQS_IRETQ 0
23861 + SWAPGS_UNSAFE_STACK
23862 + RESTORE_ALL 8
23863 + pax_force_retaddr_bts
23864 + jmp irq_return
23865 +#endif
23866 paranoid_swapgs:
23867 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23868 + pax_exit_kernel_user
23869 +#else
23870 + pax_exit_kernel
23871 +#endif
23872 TRACE_IRQS_IRETQ 0
23873 SWAPGS_UNSAFE_STACK
23874 RESTORE_ALL 8
23875 jmp irq_return
23876 paranoid_restore:
23877 + pax_exit_kernel
23878 TRACE_IRQS_IRETQ_DEBUG 0
23879 RESTORE_ALL 8
23880 + pax_force_retaddr_bts
23881 jmp irq_return
23882 paranoid_userspace:
23883 GET_THREAD_INFO(%rcx)
23884 @@ -1557,7 +2057,7 @@ paranoid_schedule:
23885 TRACE_IRQS_OFF
23886 jmp paranoid_userspace
23887 CFI_ENDPROC
23888 -END(paranoid_exit)
23889 +ENDPROC(paranoid_exit)
23890
23891 /*
23892 * Exception entry point. This expects an error code/orig_rax on the stack.
23893 @@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23894 movq_cfi r14, R14+8
23895 movq_cfi r15, R15+8
23896 xorl %ebx,%ebx
23897 - testl $3,CS+8(%rsp)
23898 + testb $3,CS+8(%rsp)
23899 je error_kernelspace
23900 error_swapgs:
23901 SWAPGS
23902 error_sti:
23903 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23904 + testb $3, CS+8(%rsp)
23905 + jnz 1f
23906 + pax_enter_kernel
23907 + jmp 2f
23908 +1: pax_enter_kernel_user
23909 +2:
23910 +#else
23911 + pax_enter_kernel
23912 +#endif
23913 TRACE_IRQS_OFF
23914 + pax_force_retaddr
23915 ret
23916
23917 /*
23918 @@ -1616,7 +2127,7 @@ bstep_iret:
23919 movq %rcx,RIP+8(%rsp)
23920 jmp error_swapgs
23921 CFI_ENDPROC
23922 -END(error_entry)
23923 +ENDPROC(error_entry)
23924
23925
23926 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23927 @@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23928 DISABLE_INTERRUPTS(CLBR_NONE)
23929 TRACE_IRQS_OFF
23930 GET_THREAD_INFO(%rcx)
23931 - testl %eax,%eax
23932 + testl $1,%eax
23933 jne retint_kernel
23934 LOCKDEP_SYS_EXIT_IRQ
23935 movl TI_flags(%rcx),%edx
23936 @@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23937 jnz retint_careful
23938 jmp retint_swapgs
23939 CFI_ENDPROC
23940 -END(error_exit)
23941 +ENDPROC(error_exit)
23942
23943 /*
23944 * Test if a given stack is an NMI stack or not.
23945 @@ -1694,9 +2205,11 @@ ENTRY(nmi)
23946 * If %cs was not the kernel segment, then the NMI triggered in user
23947 * space, which means it is definitely not nested.
23948 */
23949 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23950 + je 1f
23951 cmpl $__KERNEL_CS, 16(%rsp)
23952 jne first_nmi
23953 -
23954 +1:
23955 /*
23956 * Check the special variable on the stack to see if NMIs are
23957 * executing.
23958 @@ -1730,8 +2243,7 @@ nested_nmi:
23959
23960 1:
23961 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23962 - leaq -1*8(%rsp), %rdx
23963 - movq %rdx, %rsp
23964 + subq $8, %rsp
23965 CFI_ADJUST_CFA_OFFSET 1*8
23966 leaq -10*8(%rsp), %rdx
23967 pushq_cfi $__KERNEL_DS
23968 @@ -1749,6 +2261,7 @@ nested_nmi_out:
23969 CFI_RESTORE rdx
23970
23971 /* No need to check faults here */
23972 +# pax_force_retaddr_bts
23973 INTERRUPT_RETURN
23974
23975 CFI_RESTORE_STATE
23976 @@ -1845,13 +2358,13 @@ end_repeat_nmi:
23977 subq $ORIG_RAX-R15, %rsp
23978 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23979 /*
23980 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23981 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23982 * as we should not be calling schedule in NMI context.
23983 * Even with normal interrupts enabled. An NMI should not be
23984 * setting NEED_RESCHED or anything that normal interrupts and
23985 * exceptions might do.
23986 */
23987 - call save_paranoid
23988 + call save_paranoid_nmi
23989 DEFAULT_FRAME 0
23990
23991 /*
23992 @@ -1861,9 +2374,9 @@ end_repeat_nmi:
23993 * NMI itself takes a page fault, the page fault that was preempted
23994 * will read the information from the NMI page fault and not the
23995 * origin fault. Save it off and restore it if it changes.
23996 - * Use the r12 callee-saved register.
23997 + * Use the r13 callee-saved register.
23998 */
23999 - movq %cr2, %r12
24000 + movq %cr2, %r13
24001
24002 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24003 movq %rsp,%rdi
24004 @@ -1872,31 +2385,36 @@ end_repeat_nmi:
24005
24006 /* Did the NMI take a page fault? Restore cr2 if it did */
24007 movq %cr2, %rcx
24008 - cmpq %rcx, %r12
24009 + cmpq %rcx, %r13
24010 je 1f
24011 - movq %r12, %cr2
24012 + movq %r13, %cr2
24013 1:
24014
24015 - testl %ebx,%ebx /* swapgs needed? */
24016 + testl $1,%ebx /* swapgs needed? */
24017 jnz nmi_restore
24018 nmi_swapgs:
24019 SWAPGS_UNSAFE_STACK
24020 nmi_restore:
24021 + pax_exit_kernel_nmi
24022 /* Pop the extra iret frame at once */
24023 RESTORE_ALL 6*8
24024 + testb $3, 8(%rsp)
24025 + jnz 1f
24026 + pax_force_retaddr_bts
24027 +1:
24028
24029 /* Clear the NMI executing stack variable */
24030 movq $0, 5*8(%rsp)
24031 jmp irq_return
24032 CFI_ENDPROC
24033 -END(nmi)
24034 +ENDPROC(nmi)
24035
24036 ENTRY(ignore_sysret)
24037 CFI_STARTPROC
24038 mov $-ENOSYS,%eax
24039 sysret
24040 CFI_ENDPROC
24041 -END(ignore_sysret)
24042 +ENDPROC(ignore_sysret)
24043
24044 /*
24045 * End of kprobes section
24046 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24047 index 52819e8..b6d1dbd 100644
24048 --- a/arch/x86/kernel/ftrace.c
24049 +++ b/arch/x86/kernel/ftrace.c
24050 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24051 {
24052 unsigned char replaced[MCOUNT_INSN_SIZE];
24053
24054 + ip = ktla_ktva(ip);
24055 +
24056 /*
24057 * Note: Due to modules and __init, code can
24058 * disappear and change, we need to protect against faulting
24059 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24060 unsigned char old[MCOUNT_INSN_SIZE];
24061 int ret;
24062
24063 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24064 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24065
24066 ftrace_update_func = ip;
24067 /* Make sure the breakpoints see the ftrace_update_func update */
24068 @@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
24069 * kernel identity mapping to modify code.
24070 */
24071 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24072 - ip = (unsigned long)__va(__pa_symbol(ip));
24073 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24074
24075 if (probe_kernel_write((void *)ip, val, size))
24076 return -EPERM;
24077 @@ -319,7 +321,7 @@ static int add_break(unsigned long ip, const char *old)
24078 unsigned char replaced[MCOUNT_INSN_SIZE];
24079 unsigned char brk = BREAKPOINT_INSTRUCTION;
24080
24081 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24082 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24083 return -EFAULT;
24084
24085 /* Make sure it is what we expect it to be */
24086 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24087 index 068054f..c248bcd 100644
24088 --- a/arch/x86/kernel/head64.c
24089 +++ b/arch/x86/kernel/head64.c
24090 @@ -67,12 +67,12 @@ again:
24091 pgd = *pgd_p;
24092
24093 /*
24094 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24095 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24096 + * The use of __early_va rather than __va here is critical:
24097 + * __va would point us back into the dynamic
24098 * range and we might end up looping forever...
24099 */
24100 if (pgd)
24101 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24102 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24103 else {
24104 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24105 reset_early_page_tables();
24106 @@ -82,13 +82,13 @@ again:
24107 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24108 for (i = 0; i < PTRS_PER_PUD; i++)
24109 pud_p[i] = 0;
24110 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24111 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24112 }
24113 pud_p += pud_index(address);
24114 pud = *pud_p;
24115
24116 if (pud)
24117 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24118 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24119 else {
24120 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24121 reset_early_page_tables();
24122 @@ -98,7 +98,7 @@ again:
24123 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24124 for (i = 0; i < PTRS_PER_PMD; i++)
24125 pmd_p[i] = 0;
24126 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24127 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24128 }
24129 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24130 pmd_p[pmd_index(address)] = pmd;
24131 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24132 if (console_loglevel == 10)
24133 early_printk("Kernel alive\n");
24134
24135 - clear_page(init_level4_pgt);
24136 /* set init_level4_pgt kernel high mapping*/
24137 init_level4_pgt[511] = early_level4_pgt[511];
24138
24139 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24140 index f36bd42..56ee1534 100644
24141 --- a/arch/x86/kernel/head_32.S
24142 +++ b/arch/x86/kernel/head_32.S
24143 @@ -26,6 +26,12 @@
24144 /* Physical address */
24145 #define pa(X) ((X) - __PAGE_OFFSET)
24146
24147 +#ifdef CONFIG_PAX_KERNEXEC
24148 +#define ta(X) (X)
24149 +#else
24150 +#define ta(X) ((X) - __PAGE_OFFSET)
24151 +#endif
24152 +
24153 /*
24154 * References to members of the new_cpu_data structure.
24155 */
24156 @@ -55,11 +61,7 @@
24157 * and small than max_low_pfn, otherwise will waste some page table entries
24158 */
24159
24160 -#if PTRS_PER_PMD > 1
24161 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24162 -#else
24163 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24164 -#endif
24165 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24166
24167 /* Number of possible pages in the lowmem region */
24168 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24169 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24170 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24171
24172 /*
24173 + * Real beginning of normal "text" segment
24174 + */
24175 +ENTRY(stext)
24176 +ENTRY(_stext)
24177 +
24178 +/*
24179 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24180 * %esi points to the real-mode code as a 32-bit pointer.
24181 * CS and DS must be 4 GB flat segments, but we don't depend on
24182 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24183 * can.
24184 */
24185 __HEAD
24186 +
24187 +#ifdef CONFIG_PAX_KERNEXEC
24188 + jmp startup_32
24189 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24190 +.fill PAGE_SIZE-5,1,0xcc
24191 +#endif
24192 +
24193 ENTRY(startup_32)
24194 movl pa(stack_start),%ecx
24195
24196 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24197 2:
24198 leal -__PAGE_OFFSET(%ecx),%esp
24199
24200 +#ifdef CONFIG_SMP
24201 + movl $pa(cpu_gdt_table),%edi
24202 + movl $__per_cpu_load,%eax
24203 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24204 + rorl $16,%eax
24205 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24206 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24207 + movl $__per_cpu_end - 1,%eax
24208 + subl $__per_cpu_start,%eax
24209 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24210 +#endif
24211 +
24212 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24213 + movl $NR_CPUS,%ecx
24214 + movl $pa(cpu_gdt_table),%edi
24215 +1:
24216 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24217 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24218 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24219 + addl $PAGE_SIZE_asm,%edi
24220 + loop 1b
24221 +#endif
24222 +
24223 +#ifdef CONFIG_PAX_KERNEXEC
24224 + movl $pa(boot_gdt),%edi
24225 + movl $__LOAD_PHYSICAL_ADDR,%eax
24226 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24227 + rorl $16,%eax
24228 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24229 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24230 + rorl $16,%eax
24231 +
24232 + ljmp $(__BOOT_CS),$1f
24233 +1:
24234 +
24235 + movl $NR_CPUS,%ecx
24236 + movl $pa(cpu_gdt_table),%edi
24237 + addl $__PAGE_OFFSET,%eax
24238 +1:
24239 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24240 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24241 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24242 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24243 + rorl $16,%eax
24244 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24245 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24246 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24247 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24248 + rorl $16,%eax
24249 + addl $PAGE_SIZE_asm,%edi
24250 + loop 1b
24251 +#endif
24252 +
24253 /*
24254 * Clear BSS first so that there are no surprises...
24255 */
24256 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24257 movl %eax, pa(max_pfn_mapped)
24258
24259 /* Do early initialization of the fixmap area */
24260 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24261 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24262 +#ifdef CONFIG_COMPAT_VDSO
24263 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24264 +#else
24265 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24266 +#endif
24267 #else /* Not PAE */
24268
24269 page_pde_offset = (__PAGE_OFFSET >> 20);
24270 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24271 movl %eax, pa(max_pfn_mapped)
24272
24273 /* Do early initialization of the fixmap area */
24274 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24275 - movl %eax,pa(initial_page_table+0xffc)
24276 +#ifdef CONFIG_COMPAT_VDSO
24277 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24278 +#else
24279 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24280 +#endif
24281 #endif
24282
24283 #ifdef CONFIG_PARAVIRT
24284 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24285 cmpl $num_subarch_entries, %eax
24286 jae bad_subarch
24287
24288 - movl pa(subarch_entries)(,%eax,4), %eax
24289 - subl $__PAGE_OFFSET, %eax
24290 - jmp *%eax
24291 + jmp *pa(subarch_entries)(,%eax,4)
24292
24293 bad_subarch:
24294 WEAK(lguest_entry)
24295 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24296 __INITDATA
24297
24298 subarch_entries:
24299 - .long default_entry /* normal x86/PC */
24300 - .long lguest_entry /* lguest hypervisor */
24301 - .long xen_entry /* Xen hypervisor */
24302 - .long default_entry /* Moorestown MID */
24303 + .long ta(default_entry) /* normal x86/PC */
24304 + .long ta(lguest_entry) /* lguest hypervisor */
24305 + .long ta(xen_entry) /* Xen hypervisor */
24306 + .long ta(default_entry) /* Moorestown MID */
24307 num_subarch_entries = (. - subarch_entries) / 4
24308 .previous
24309 #else
24310 @@ -354,6 +426,7 @@ default_entry:
24311 movl pa(mmu_cr4_features),%eax
24312 movl %eax,%cr4
24313
24314 +#ifdef CONFIG_X86_PAE
24315 testb $X86_CR4_PAE, %al # check if PAE is enabled
24316 jz enable_paging
24317
24318 @@ -382,6 +455,9 @@ default_entry:
24319 /* Make changes effective */
24320 wrmsr
24321
24322 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24323 +#endif
24324 +
24325 enable_paging:
24326
24327 /*
24328 @@ -449,14 +525,20 @@ is486:
24329 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24330 movl %eax,%ss # after changing gdt.
24331
24332 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24333 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24334 movl %eax,%ds
24335 movl %eax,%es
24336
24337 movl $(__KERNEL_PERCPU), %eax
24338 movl %eax,%fs # set this cpu's percpu
24339
24340 +#ifdef CONFIG_CC_STACKPROTECTOR
24341 movl $(__KERNEL_STACK_CANARY),%eax
24342 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24343 + movl $(__USER_DS),%eax
24344 +#else
24345 + xorl %eax,%eax
24346 +#endif
24347 movl %eax,%gs
24348
24349 xorl %eax,%eax # Clear LDT
24350 @@ -512,8 +594,11 @@ setup_once:
24351 * relocation. Manually set base address in stack canary
24352 * segment descriptor.
24353 */
24354 - movl $gdt_page,%eax
24355 + movl $cpu_gdt_table,%eax
24356 movl $stack_canary,%ecx
24357 +#ifdef CONFIG_SMP
24358 + addl $__per_cpu_load,%ecx
24359 +#endif
24360 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24361 shrl $16, %ecx
24362 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24363 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24364 cmpl $2,(%esp) # X86_TRAP_NMI
24365 je is_nmi # Ignore NMI
24366
24367 - cmpl $2,%ss:early_recursion_flag
24368 + cmpl $1,%ss:early_recursion_flag
24369 je hlt_loop
24370 incl %ss:early_recursion_flag
24371
24372 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24373 pushl (20+6*4)(%esp) /* trapno */
24374 pushl $fault_msg
24375 call printk
24376 -#endif
24377 call dump_stack
24378 +#endif
24379 hlt_loop:
24380 hlt
24381 jmp hlt_loop
24382 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24383 /* This is the default interrupt "handler" :-) */
24384 ALIGN
24385 ignore_int:
24386 - cld
24387 #ifdef CONFIG_PRINTK
24388 + cmpl $2,%ss:early_recursion_flag
24389 + je hlt_loop
24390 + incl %ss:early_recursion_flag
24391 + cld
24392 pushl %eax
24393 pushl %ecx
24394 pushl %edx
24395 @@ -617,9 +705,6 @@ ignore_int:
24396 movl $(__KERNEL_DS),%eax
24397 movl %eax,%ds
24398 movl %eax,%es
24399 - cmpl $2,early_recursion_flag
24400 - je hlt_loop
24401 - incl early_recursion_flag
24402 pushl 16(%esp)
24403 pushl 24(%esp)
24404 pushl 32(%esp)
24405 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24406 /*
24407 * BSS section
24408 */
24409 -__PAGE_ALIGNED_BSS
24410 - .align PAGE_SIZE
24411 #ifdef CONFIG_X86_PAE
24412 +.section .initial_pg_pmd,"a",@progbits
24413 initial_pg_pmd:
24414 .fill 1024*KPMDS,4,0
24415 #else
24416 +.section .initial_page_table,"a",@progbits
24417 ENTRY(initial_page_table)
24418 .fill 1024,4,0
24419 #endif
24420 +.section .initial_pg_fixmap,"a",@progbits
24421 initial_pg_fixmap:
24422 .fill 1024,4,0
24423 +.section .empty_zero_page,"a",@progbits
24424 ENTRY(empty_zero_page)
24425 .fill 4096,1,0
24426 +.section .swapper_pg_dir,"a",@progbits
24427 ENTRY(swapper_pg_dir)
24428 +#ifdef CONFIG_X86_PAE
24429 + .fill 4,8,0
24430 +#else
24431 .fill 1024,4,0
24432 +#endif
24433
24434 /*
24435 * This starts the data section.
24436 */
24437 #ifdef CONFIG_X86_PAE
24438 -__PAGE_ALIGNED_DATA
24439 - /* Page-aligned for the benefit of paravirt? */
24440 - .align PAGE_SIZE
24441 +.section .initial_page_table,"a",@progbits
24442 ENTRY(initial_page_table)
24443 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24444 # if KPMDS == 3
24445 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24446 # error "Kernel PMDs should be 1, 2 or 3"
24447 # endif
24448 .align PAGE_SIZE /* needs to be page-sized too */
24449 +
24450 +#ifdef CONFIG_PAX_PER_CPU_PGD
24451 +ENTRY(cpu_pgd)
24452 + .rept 2*NR_CPUS
24453 + .fill 4,8,0
24454 + .endr
24455 +#endif
24456 +
24457 #endif
24458
24459 .data
24460 .balign 4
24461 ENTRY(stack_start)
24462 - .long init_thread_union+THREAD_SIZE
24463 + .long init_thread_union+THREAD_SIZE-8
24464
24465 __INITRODATA
24466 int_msg:
24467 @@ -727,7 +825,7 @@ fault_msg:
24468 * segment size, and 32-bit linear address value:
24469 */
24470
24471 - .data
24472 +.section .rodata,"a",@progbits
24473 .globl boot_gdt_descr
24474 .globl idt_descr
24475
24476 @@ -736,7 +834,7 @@ fault_msg:
24477 .word 0 # 32 bit align gdt_desc.address
24478 boot_gdt_descr:
24479 .word __BOOT_DS+7
24480 - .long boot_gdt - __PAGE_OFFSET
24481 + .long pa(boot_gdt)
24482
24483 .word 0 # 32-bit align idt_desc.address
24484 idt_descr:
24485 @@ -747,7 +845,7 @@ idt_descr:
24486 .word 0 # 32 bit align gdt_desc.address
24487 ENTRY(early_gdt_descr)
24488 .word GDT_ENTRIES*8-1
24489 - .long gdt_page /* Overwritten for secondary CPUs */
24490 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24491
24492 /*
24493 * The boot_gdt must mirror the equivalent in setup.S and is
24494 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24495 .align L1_CACHE_BYTES
24496 ENTRY(boot_gdt)
24497 .fill GDT_ENTRY_BOOT_CS,8,0
24498 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24499 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24500 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24501 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24502 +
24503 + .align PAGE_SIZE_asm
24504 +ENTRY(cpu_gdt_table)
24505 + .rept NR_CPUS
24506 + .quad 0x0000000000000000 /* NULL descriptor */
24507 + .quad 0x0000000000000000 /* 0x0b reserved */
24508 + .quad 0x0000000000000000 /* 0x13 reserved */
24509 + .quad 0x0000000000000000 /* 0x1b reserved */
24510 +
24511 +#ifdef CONFIG_PAX_KERNEXEC
24512 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24513 +#else
24514 + .quad 0x0000000000000000 /* 0x20 unused */
24515 +#endif
24516 +
24517 + .quad 0x0000000000000000 /* 0x28 unused */
24518 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24519 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24520 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24521 + .quad 0x0000000000000000 /* 0x4b reserved */
24522 + .quad 0x0000000000000000 /* 0x53 reserved */
24523 + .quad 0x0000000000000000 /* 0x5b reserved */
24524 +
24525 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24526 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24527 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24528 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24529 +
24530 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24531 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24532 +
24533 + /*
24534 + * Segments used for calling PnP BIOS have byte granularity.
24535 + * The code segments and data segments have fixed 64k limits,
24536 + * the transfer segment sizes are set at run time.
24537 + */
24538 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24539 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24540 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24541 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24542 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24543 +
24544 + /*
24545 + * The APM segments have byte granularity and their bases
24546 + * are set at run time. All have 64k limits.
24547 + */
24548 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24549 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24550 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24551 +
24552 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24553 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24554 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24555 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24556 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24557 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24558 +
24559 + /* Be sure this is zeroed to avoid false validations in Xen */
24560 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24561 + .endr
24562 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24563 index a468c0a..c7dec74 100644
24564 --- a/arch/x86/kernel/head_64.S
24565 +++ b/arch/x86/kernel/head_64.S
24566 @@ -20,6 +20,8 @@
24567 #include <asm/processor-flags.h>
24568 #include <asm/percpu.h>
24569 #include <asm/nops.h>
24570 +#include <asm/cpufeature.h>
24571 +#include <asm/alternative-asm.h>
24572
24573 #ifdef CONFIG_PARAVIRT
24574 #include <asm/asm-offsets.h>
24575 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24576 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24577 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24578 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24579 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24580 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24581 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24582 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24583 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24584 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24585
24586 .text
24587 __HEAD
24588 @@ -89,11 +97,24 @@ startup_64:
24589 * Fixup the physical addresses in the page table
24590 */
24591 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24592 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24593 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24594 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24595 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24596 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24597
24598 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24599 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24600 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24601 +#ifndef CONFIG_XEN
24602 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24603 +#endif
24604 +
24605 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24606 +
24607 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24608 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24609
24610 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24611 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24612
24613 /*
24614 * Set up the identity mapping for the switchover. These
24615 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24616 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24617 1:
24618
24619 - /* Enable PAE mode and PGE */
24620 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24621 + /* Enable PAE mode and PSE/PGE */
24622 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24623 movq %rcx, %cr4
24624
24625 /* Setup early boot stage 4 level pagetables. */
24626 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24627 movl $MSR_EFER, %ecx
24628 rdmsr
24629 btsl $_EFER_SCE, %eax /* Enable System Call */
24630 - btl $20,%edi /* No Execute supported? */
24631 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24632 jnc 1f
24633 btsl $_EFER_NX, %eax
24634 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24635 +#ifndef CONFIG_EFI
24636 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24637 +#endif
24638 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24639 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24640 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24641 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24642 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24643 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24644 1: wrmsr /* Make changes effective */
24645
24646 /* Setup cr0 */
24647 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24648 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24649 * address given in m16:64.
24650 */
24651 + pax_set_fptr_mask
24652 movq initial_code(%rip),%rax
24653 pushq $0 # fake return address to stop unwinder
24654 pushq $__KERNEL_CS # set correct cs
24655 @@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24656 .quad INIT_PER_CPU_VAR(irq_stack_union)
24657
24658 GLOBAL(stack_start)
24659 - .quad init_thread_union+THREAD_SIZE-8
24660 + .quad init_thread_union+THREAD_SIZE-16
24661 .word 0
24662 __FINITDATA
24663
24664 @@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24665 call dump_stack
24666 #ifdef CONFIG_KALLSYMS
24667 leaq early_idt_ripmsg(%rip),%rdi
24668 - movq 40(%rsp),%rsi # %rip again
24669 + movq 88(%rsp),%rsi # %rip again
24670 call __print_symbol
24671 #endif
24672 #endif /* EARLY_PRINTK */
24673 @@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24674 early_recursion_flag:
24675 .long 0
24676
24677 + .section .rodata,"a",@progbits
24678 #ifdef CONFIG_EARLY_PRINTK
24679 early_idt_msg:
24680 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24681 @@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24682 NEXT_PAGE(early_dynamic_pgts)
24683 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24684
24685 - .data
24686 + .section .rodata,"a",@progbits
24687
24688 -#ifndef CONFIG_XEN
24689 NEXT_PAGE(init_level4_pgt)
24690 - .fill 512,8,0
24691 -#else
24692 -NEXT_PAGE(init_level4_pgt)
24693 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24694 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24695 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24696 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24697 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24698 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24699 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24700 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24701 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24702 .org init_level4_pgt + L4_START_KERNEL*8, 0
24703 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24704 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24705
24706 +#ifdef CONFIG_PAX_PER_CPU_PGD
24707 +NEXT_PAGE(cpu_pgd)
24708 + .rept 2*NR_CPUS
24709 + .fill 512,8,0
24710 + .endr
24711 +#endif
24712 +
24713 NEXT_PAGE(level3_ident_pgt)
24714 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24715 +#ifdef CONFIG_XEN
24716 .fill 511, 8, 0
24717 +#else
24718 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24719 + .fill 510,8,0
24720 +#endif
24721 +
24722 +NEXT_PAGE(level3_vmalloc_start_pgt)
24723 + .fill 512,8,0
24724 +
24725 +NEXT_PAGE(level3_vmalloc_end_pgt)
24726 + .fill 512,8,0
24727 +
24728 +NEXT_PAGE(level3_vmemmap_pgt)
24729 + .fill L3_VMEMMAP_START,8,0
24730 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24731 +
24732 NEXT_PAGE(level2_ident_pgt)
24733 - /* Since I easily can, map the first 1G.
24734 + /* Since I easily can, map the first 2G.
24735 * Don't set NX because code runs from these pages.
24736 */
24737 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24738 -#endif
24739 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24740
24741 NEXT_PAGE(level3_kernel_pgt)
24742 .fill L3_START_KERNEL,8,0
24743 @@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24744 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24745 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24746
24747 +NEXT_PAGE(level2_vmemmap_pgt)
24748 + .fill 512,8,0
24749 +
24750 NEXT_PAGE(level2_kernel_pgt)
24751 /*
24752 * 512 MB kernel mapping. We spend a full page on this pagetable
24753 @@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24754 NEXT_PAGE(level2_fixmap_pgt)
24755 .fill 506,8,0
24756 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24757 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24758 - .fill 5,8,0
24759 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24760 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24761 + .fill 4,8,0
24762
24763 NEXT_PAGE(level1_fixmap_pgt)
24764 .fill 512,8,0
24765
24766 +NEXT_PAGE(level1_vsyscall_pgt)
24767 + .fill 512,8,0
24768 +
24769 #undef PMDS
24770
24771 - .data
24772 + .align PAGE_SIZE
24773 +ENTRY(cpu_gdt_table)
24774 + .rept NR_CPUS
24775 + .quad 0x0000000000000000 /* NULL descriptor */
24776 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24777 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
24778 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
24779 + .quad 0x00cffb000000ffff /* __USER32_CS */
24780 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24781 + .quad 0x00affb000000ffff /* __USER_CS */
24782 +
24783 +#ifdef CONFIG_PAX_KERNEXEC
24784 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24785 +#else
24786 + .quad 0x0 /* unused */
24787 +#endif
24788 +
24789 + .quad 0,0 /* TSS */
24790 + .quad 0,0 /* LDT */
24791 + .quad 0,0,0 /* three TLS descriptors */
24792 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
24793 + /* asm/segment.h:GDT_ENTRIES must match this */
24794 +
24795 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24796 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24797 +#else
24798 + .quad 0x0 /* unused */
24799 +#endif
24800 +
24801 + /* zero the remaining page */
24802 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24803 + .endr
24804 +
24805 .align 16
24806 .globl early_gdt_descr
24807 early_gdt_descr:
24808 .word GDT_ENTRIES*8-1
24809 early_gdt_descr_base:
24810 - .quad INIT_PER_CPU_VAR(gdt_page)
24811 + .quad cpu_gdt_table
24812
24813 ENTRY(phys_base)
24814 /* This must match the first entry in level2_kernel_pgt */
24815 .quad 0x0000000000000000
24816
24817 #include "../../x86/xen/xen-head.S"
24818 -
24819 - __PAGE_ALIGNED_BSS
24820 +
24821 + .section .rodata,"a",@progbits
24822 NEXT_PAGE(empty_zero_page)
24823 .skip PAGE_SIZE
24824 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24825 index 05fd74f..c3548b1 100644
24826 --- a/arch/x86/kernel/i386_ksyms_32.c
24827 +++ b/arch/x86/kernel/i386_ksyms_32.c
24828 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24829 EXPORT_SYMBOL(cmpxchg8b_emu);
24830 #endif
24831
24832 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
24833 +
24834 /* Networking helper routines. */
24835 EXPORT_SYMBOL(csum_partial_copy_generic);
24836 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24837 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24838
24839 EXPORT_SYMBOL(__get_user_1);
24840 EXPORT_SYMBOL(__get_user_2);
24841 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24842 EXPORT_SYMBOL(___preempt_schedule_context);
24843 #endif
24844 #endif
24845 +
24846 +#ifdef CONFIG_PAX_KERNEXEC
24847 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24848 +#endif
24849 +
24850 +#ifdef CONFIG_PAX_PER_CPU_PGD
24851 +EXPORT_SYMBOL(cpu_pgd);
24852 +#endif
24853 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24854 index d5dd808..b6432cf 100644
24855 --- a/arch/x86/kernel/i387.c
24856 +++ b/arch/x86/kernel/i387.c
24857 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24858 static inline bool interrupted_user_mode(void)
24859 {
24860 struct pt_regs *regs = get_irq_regs();
24861 - return regs && user_mode_vm(regs);
24862 + return regs && user_mode(regs);
24863 }
24864
24865 /*
24866 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24867 index 2e977b5..5f2c273 100644
24868 --- a/arch/x86/kernel/i8259.c
24869 +++ b/arch/x86/kernel/i8259.c
24870 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24871 static void make_8259A_irq(unsigned int irq)
24872 {
24873 disable_irq_nosync(irq);
24874 - io_apic_irqs &= ~(1<<irq);
24875 + io_apic_irqs &= ~(1UL<<irq);
24876 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24877 i8259A_chip.name);
24878 enable_irq(irq);
24879 @@ -209,7 +209,7 @@ spurious_8259A_irq:
24880 "spurious 8259A interrupt: IRQ%d.\n", irq);
24881 spurious_irq_mask |= irqmask;
24882 }
24883 - atomic_inc(&irq_err_count);
24884 + atomic_inc_unchecked(&irq_err_count);
24885 /*
24886 * Theoretically we do not have to handle this IRQ,
24887 * but in Linux this does not cause problems and is
24888 @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24889 /* (slave's support for AEOI in flat mode is to be investigated) */
24890 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24891
24892 + pax_open_kernel();
24893 if (auto_eoi)
24894 /*
24895 * In AEOI mode we just have to mask the interrupt
24896 * when acking.
24897 */
24898 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
24899 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24900 else
24901 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24902 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24903 + pax_close_kernel();
24904
24905 udelay(100); /* wait for 8259A to initialize */
24906
24907 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24908 index a979b5b..1d6db75 100644
24909 --- a/arch/x86/kernel/io_delay.c
24910 +++ b/arch/x86/kernel/io_delay.c
24911 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24912 * Quirk table for systems that misbehave (lock up, etc.) if port
24913 * 0x80 is used:
24914 */
24915 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24916 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24917 {
24918 .callback = dmi_io_delay_0xed_port,
24919 .ident = "Compaq Presario V6000",
24920 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24921 index 4ddaf66..49d5c18 100644
24922 --- a/arch/x86/kernel/ioport.c
24923 +++ b/arch/x86/kernel/ioport.c
24924 @@ -6,6 +6,7 @@
24925 #include <linux/sched.h>
24926 #include <linux/kernel.h>
24927 #include <linux/capability.h>
24928 +#include <linux/security.h>
24929 #include <linux/errno.h>
24930 #include <linux/types.h>
24931 #include <linux/ioport.h>
24932 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24933 return -EINVAL;
24934 if (turn_on && !capable(CAP_SYS_RAWIO))
24935 return -EPERM;
24936 +#ifdef CONFIG_GRKERNSEC_IO
24937 + if (turn_on && grsec_disable_privio) {
24938 + gr_handle_ioperm();
24939 + return -ENODEV;
24940 + }
24941 +#endif
24942
24943 /*
24944 * If it's the first ioperm() call in this thread's lifetime, set the
24945 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24946 * because the ->io_bitmap_max value must match the bitmap
24947 * contents:
24948 */
24949 - tss = &per_cpu(init_tss, get_cpu());
24950 + tss = init_tss + get_cpu();
24951
24952 if (turn_on)
24953 bitmap_clear(t->io_bitmap_ptr, from, num);
24954 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24955 if (level > old) {
24956 if (!capable(CAP_SYS_RAWIO))
24957 return -EPERM;
24958 +#ifdef CONFIG_GRKERNSEC_IO
24959 + if (grsec_disable_privio) {
24960 + gr_handle_iopl();
24961 + return -ENODEV;
24962 + }
24963 +#endif
24964 }
24965 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24966 t->iopl = level << 12;
24967 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24968 index 11ccfb0..ec1e46f 100644
24969 --- a/arch/x86/kernel/irq.c
24970 +++ b/arch/x86/kernel/irq.c
24971 @@ -22,7 +22,7 @@
24972 #define CREATE_TRACE_POINTS
24973 #include <asm/trace/irq_vectors.h>
24974
24975 -atomic_t irq_err_count;
24976 +atomic_unchecked_t irq_err_count;
24977
24978 /* Function pointer for generic interrupt vector handling */
24979 void (*x86_platform_ipi_callback)(void) = NULL;
24980 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24981 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
24982 seq_printf(p, " Hypervisor callback interrupts\n");
24983 #endif
24984 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24985 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24986 #if defined(CONFIG_X86_IO_APIC)
24987 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24988 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24989 #endif
24990 return 0;
24991 }
24992 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24993
24994 u64 arch_irq_stat(void)
24995 {
24996 - u64 sum = atomic_read(&irq_err_count);
24997 + u64 sum = atomic_read_unchecked(&irq_err_count);
24998 return sum;
24999 }
25000
25001 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25002 index 63ce838..2ea3e06 100644
25003 --- a/arch/x86/kernel/irq_32.c
25004 +++ b/arch/x86/kernel/irq_32.c
25005 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25006
25007 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25008
25009 +extern void gr_handle_kernel_exploit(void);
25010 +
25011 int sysctl_panic_on_stackoverflow __read_mostly;
25012
25013 /* Debugging check for stack overflow: is there less than 1KB free? */
25014 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25015 __asm__ __volatile__("andl %%esp,%0" :
25016 "=r" (sp) : "0" (THREAD_SIZE - 1));
25017
25018 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25019 + return sp < STACK_WARN;
25020 }
25021
25022 static void print_stack_overflow(void)
25023 {
25024 printk(KERN_WARNING "low stack detected by irq handler\n");
25025 dump_stack();
25026 + gr_handle_kernel_exploit();
25027 if (sysctl_panic_on_stackoverflow)
25028 panic("low stack detected by irq handler - check messages\n");
25029 }
25030 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25031 static inline int
25032 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25033 {
25034 - struct irq_stack *curstk, *irqstk;
25035 + struct irq_stack *irqstk;
25036 u32 *isp, *prev_esp, arg1, arg2;
25037
25038 - curstk = (struct irq_stack *) current_stack();
25039 irqstk = __this_cpu_read(hardirq_stack);
25040
25041 /*
25042 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25043 * handler) we can't do that and just have to keep using the
25044 * current stack (which is the irq stack already after all)
25045 */
25046 - if (unlikely(curstk == irqstk))
25047 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25048 return 0;
25049
25050 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25051 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25052
25053 /* Save the next esp at the bottom of the stack */
25054 prev_esp = (u32 *)irqstk;
25055 *prev_esp = current_stack_pointer;
25056
25057 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25058 + __set_fs(MAKE_MM_SEG(0));
25059 +#endif
25060 +
25061 if (unlikely(overflow))
25062 call_on_stack(print_stack_overflow, isp);
25063
25064 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25065 : "0" (irq), "1" (desc), "2" (isp),
25066 "D" (desc->handle_irq)
25067 : "memory", "cc", "ecx");
25068 +
25069 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25070 + __set_fs(current_thread_info()->addr_limit);
25071 +#endif
25072 +
25073 return 1;
25074 }
25075
25076 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25077 */
25078 void irq_ctx_init(int cpu)
25079 {
25080 - struct irq_stack *irqstk;
25081 -
25082 if (per_cpu(hardirq_stack, cpu))
25083 return;
25084
25085 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25086 - THREADINFO_GFP,
25087 - THREAD_SIZE_ORDER));
25088 - per_cpu(hardirq_stack, cpu) = irqstk;
25089 -
25090 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25091 - THREADINFO_GFP,
25092 - THREAD_SIZE_ORDER));
25093 - per_cpu(softirq_stack, cpu) = irqstk;
25094 -
25095 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25096 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25097 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25098 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25099 }
25100
25101 void do_softirq_own_stack(void)
25102 {
25103 - struct thread_info *curstk;
25104 struct irq_stack *irqstk;
25105 u32 *isp, *prev_esp;
25106
25107 - curstk = current_stack();
25108 irqstk = __this_cpu_read(softirq_stack);
25109
25110 /* build the stack frame on the softirq stack */
25111 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25112 prev_esp = (u32 *)irqstk;
25113 *prev_esp = current_stack_pointer;
25114
25115 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25116 + __set_fs(MAKE_MM_SEG(0));
25117 +#endif
25118 +
25119 call_on_stack(__do_softirq, isp);
25120 +
25121 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25122 + __set_fs(current_thread_info()->addr_limit);
25123 +#endif
25124 +
25125 }
25126
25127 bool handle_irq(unsigned irq, struct pt_regs *regs)
25128 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25129 if (unlikely(!desc))
25130 return false;
25131
25132 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25133 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25134 if (unlikely(overflow))
25135 print_stack_overflow();
25136 desc->handle_irq(irq, desc);
25137 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25138 index 4d1c746..55a22d6 100644
25139 --- a/arch/x86/kernel/irq_64.c
25140 +++ b/arch/x86/kernel/irq_64.c
25141 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25142 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25143 EXPORT_PER_CPU_SYMBOL(irq_regs);
25144
25145 +extern void gr_handle_kernel_exploit(void);
25146 +
25147 int sysctl_panic_on_stackoverflow;
25148
25149 /*
25150 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25151 u64 estack_top, estack_bottom;
25152 u64 curbase = (u64)task_stack_page(current);
25153
25154 - if (user_mode_vm(regs))
25155 + if (user_mode(regs))
25156 return;
25157
25158 if (regs->sp >= curbase + sizeof(struct thread_info) +
25159 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25160 irq_stack_top, irq_stack_bottom,
25161 estack_top, estack_bottom);
25162
25163 + gr_handle_kernel_exploit();
25164 +
25165 if (sysctl_panic_on_stackoverflow)
25166 panic("low stack detected by irq handler - check messages\n");
25167 #endif
25168 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25169 index 26d5a55..a01160a 100644
25170 --- a/arch/x86/kernel/jump_label.c
25171 +++ b/arch/x86/kernel/jump_label.c
25172 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25173 * Jump label is enabled for the first time.
25174 * So we expect a default_nop...
25175 */
25176 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25177 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25178 != 0))
25179 bug_at((void *)entry->code, __LINE__);
25180 } else {
25181 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25182 * ...otherwise expect an ideal_nop. Otherwise
25183 * something went horribly wrong.
25184 */
25185 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25186 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25187 != 0))
25188 bug_at((void *)entry->code, __LINE__);
25189 }
25190 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25191 * are converting the default nop to the ideal nop.
25192 */
25193 if (init) {
25194 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25195 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25196 bug_at((void *)entry->code, __LINE__);
25197 } else {
25198 code.jump = 0xe9;
25199 code.offset = entry->target -
25200 (entry->code + JUMP_LABEL_NOP_SIZE);
25201 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25202 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25203 bug_at((void *)entry->code, __LINE__);
25204 }
25205 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25206 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25207 index 7ec1d5f..5a7d130 100644
25208 --- a/arch/x86/kernel/kgdb.c
25209 +++ b/arch/x86/kernel/kgdb.c
25210 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25211 #ifdef CONFIG_X86_32
25212 switch (regno) {
25213 case GDB_SS:
25214 - if (!user_mode_vm(regs))
25215 + if (!user_mode(regs))
25216 *(unsigned long *)mem = __KERNEL_DS;
25217 break;
25218 case GDB_SP:
25219 - if (!user_mode_vm(regs))
25220 + if (!user_mode(regs))
25221 *(unsigned long *)mem = kernel_stack_pointer(regs);
25222 break;
25223 case GDB_GS:
25224 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25225 bp->attr.bp_addr = breakinfo[breakno].addr;
25226 bp->attr.bp_len = breakinfo[breakno].len;
25227 bp->attr.bp_type = breakinfo[breakno].type;
25228 - info->address = breakinfo[breakno].addr;
25229 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25230 + info->address = ktla_ktva(breakinfo[breakno].addr);
25231 + else
25232 + info->address = breakinfo[breakno].addr;
25233 info->len = breakinfo[breakno].len;
25234 info->type = breakinfo[breakno].type;
25235 val = arch_install_hw_breakpoint(bp);
25236 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25237 case 'k':
25238 /* clear the trace bit */
25239 linux_regs->flags &= ~X86_EFLAGS_TF;
25240 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25241 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25242
25243 /* set the trace bit if we're stepping */
25244 if (remcomInBuffer[0] == 's') {
25245 linux_regs->flags |= X86_EFLAGS_TF;
25246 - atomic_set(&kgdb_cpu_doing_single_step,
25247 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25248 raw_smp_processor_id());
25249 }
25250
25251 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25252
25253 switch (cmd) {
25254 case DIE_DEBUG:
25255 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25256 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25257 if (user_mode(regs))
25258 return single_step_cont(regs, args);
25259 break;
25260 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25261 #endif /* CONFIG_DEBUG_RODATA */
25262
25263 bpt->type = BP_BREAKPOINT;
25264 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25265 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25266 BREAK_INSTR_SIZE);
25267 if (err)
25268 return err;
25269 - err = probe_kernel_write((char *)bpt->bpt_addr,
25270 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25271 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25272 #ifdef CONFIG_DEBUG_RODATA
25273 if (!err)
25274 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25275 return -EBUSY;
25276 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25277 BREAK_INSTR_SIZE);
25278 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25279 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25280 if (err)
25281 return err;
25282 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25283 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25284 if (mutex_is_locked(&text_mutex))
25285 goto knl_write;
25286 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25287 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25288 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25289 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25290 goto knl_write;
25291 return err;
25292 knl_write:
25293 #endif /* CONFIG_DEBUG_RODATA */
25294 - return probe_kernel_write((char *)bpt->bpt_addr,
25295 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25296 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25297 }
25298
25299 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25300 index 61b17dc..784bfe9 100644
25301 --- a/arch/x86/kernel/kprobes/core.c
25302 +++ b/arch/x86/kernel/kprobes/core.c
25303 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25304 s32 raddr;
25305 } __packed *insn;
25306
25307 - insn = (struct __arch_relative_insn *)from;
25308 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25309 +
25310 + pax_open_kernel();
25311 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25312 insn->op = op;
25313 + pax_close_kernel();
25314 }
25315
25316 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25317 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25318 kprobe_opcode_t opcode;
25319 kprobe_opcode_t *orig_opcodes = opcodes;
25320
25321 - if (search_exception_tables((unsigned long)opcodes))
25322 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25323 return 0; /* Page fault may occur on this address. */
25324
25325 retry:
25326 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25327 * for the first byte, we can recover the original instruction
25328 * from it and kp->opcode.
25329 */
25330 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25331 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25332 buf[0] = kp->opcode;
25333 - return (unsigned long)buf;
25334 + return ktva_ktla((unsigned long)buf);
25335 }
25336
25337 /*
25338 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25339 /* Another subsystem puts a breakpoint, failed to recover */
25340 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25341 return 0;
25342 + pax_open_kernel();
25343 memcpy(dest, insn.kaddr, insn.length);
25344 + pax_close_kernel();
25345
25346 #ifdef CONFIG_X86_64
25347 if (insn_rip_relative(&insn)) {
25348 @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25349 return 0;
25350 }
25351 disp = (u8 *) dest + insn_offset_displacement(&insn);
25352 + pax_open_kernel();
25353 *(s32 *) disp = (s32) newdisp;
25354 + pax_close_kernel();
25355 }
25356 #endif
25357 return insn.length;
25358 @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25359 * nor set current_kprobe, because it doesn't use single
25360 * stepping.
25361 */
25362 - regs->ip = (unsigned long)p->ainsn.insn;
25363 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25364 preempt_enable_no_resched();
25365 return;
25366 }
25367 @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25368 regs->flags &= ~X86_EFLAGS_IF;
25369 /* single step inline if the instruction is an int3 */
25370 if (p->opcode == BREAKPOINT_INSTRUCTION)
25371 - regs->ip = (unsigned long)p->addr;
25372 + regs->ip = ktla_ktva((unsigned long)p->addr);
25373 else
25374 - regs->ip = (unsigned long)p->ainsn.insn;
25375 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25376 }
25377
25378 /*
25379 @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25380 setup_singlestep(p, regs, kcb, 0);
25381 return 1;
25382 }
25383 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25384 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25385 /*
25386 * The breakpoint instruction was removed right
25387 * after we hit it. Another cpu has removed
25388 @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25389 " movq %rax, 152(%rsp)\n"
25390 RESTORE_REGS_STRING
25391 " popfq\n"
25392 +#ifdef KERNEXEC_PLUGIN
25393 + " btsq $63,(%rsp)\n"
25394 +#endif
25395 #else
25396 " pushf\n"
25397 SAVE_REGS_STRING
25398 @@ -779,7 +789,7 @@ static void __kprobes
25399 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25400 {
25401 unsigned long *tos = stack_addr(regs);
25402 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25403 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25404 unsigned long orig_ip = (unsigned long)p->addr;
25405 kprobe_opcode_t *insn = p->ainsn.insn;
25406
25407 @@ -959,7 +969,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25408 struct die_args *args = data;
25409 int ret = NOTIFY_DONE;
25410
25411 - if (args->regs && user_mode_vm(args->regs))
25412 + if (args->regs && user_mode(args->regs))
25413 return ret;
25414
25415 switch (val) {
25416 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25417 index 898160b..758cde8 100644
25418 --- a/arch/x86/kernel/kprobes/opt.c
25419 +++ b/arch/x86/kernel/kprobes/opt.c
25420 @@ -79,6 +79,7 @@ found:
25421 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25422 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25423 {
25424 + pax_open_kernel();
25425 #ifdef CONFIG_X86_64
25426 *addr++ = 0x48;
25427 *addr++ = 0xbf;
25428 @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25429 *addr++ = 0xb8;
25430 #endif
25431 *(unsigned long *)addr = val;
25432 + pax_close_kernel();
25433 }
25434
25435 asm (
25436 @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25437 * Verify if the address gap is in 2GB range, because this uses
25438 * a relative jump.
25439 */
25440 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25441 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25442 if (abs(rel) > 0x7fffffff)
25443 return -ERANGE;
25444
25445 @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25446 op->optinsn.size = ret;
25447
25448 /* Copy arch-dep-instance from template */
25449 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25450 + pax_open_kernel();
25451 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25452 + pax_close_kernel();
25453
25454 /* Set probe information */
25455 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25456
25457 /* Set probe function call */
25458 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25459 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25460
25461 /* Set returning jmp instruction at the tail of out-of-line buffer */
25462 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25463 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25464 (u8 *)op->kp.addr + op->optinsn.size);
25465
25466 flush_icache_range((unsigned long) buf,
25467 @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25468 WARN_ON(kprobe_disabled(&op->kp));
25469
25470 /* Backup instructions which will be replaced by jump address */
25471 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25472 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25473 RELATIVE_ADDR_SIZE);
25474
25475 insn_buf[0] = RELATIVEJUMP_OPCODE;
25476 @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25477 /* This kprobe is really able to run optimized path. */
25478 op = container_of(p, struct optimized_kprobe, kp);
25479 /* Detour through copied instructions */
25480 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25481 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25482 if (!reenter)
25483 reset_current_kprobe();
25484 preempt_enable_no_resched();
25485 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25486 index c2bedae..25e7ab60 100644
25487 --- a/arch/x86/kernel/ksysfs.c
25488 +++ b/arch/x86/kernel/ksysfs.c
25489 @@ -184,7 +184,7 @@ out:
25490
25491 static struct kobj_attribute type_attr = __ATTR_RO(type);
25492
25493 -static struct bin_attribute data_attr = {
25494 +static bin_attribute_no_const data_attr __read_only = {
25495 .attr = {
25496 .name = "data",
25497 .mode = S_IRUGO,
25498 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25499 index dcbbaa1..81ae763 100644
25500 --- a/arch/x86/kernel/ldt.c
25501 +++ b/arch/x86/kernel/ldt.c
25502 @@ -68,13 +68,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25503 if (reload) {
25504 #ifdef CONFIG_SMP
25505 preempt_disable();
25506 - load_LDT(pc);
25507 + load_LDT_nolock(pc);
25508 if (!cpumask_equal(mm_cpumask(current->mm),
25509 cpumask_of(smp_processor_id())))
25510 smp_call_function(flush_ldt, current->mm, 1);
25511 preempt_enable();
25512 #else
25513 - load_LDT(pc);
25514 + load_LDT_nolock(pc);
25515 #endif
25516 }
25517 if (oldsize) {
25518 @@ -96,7 +96,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25519 return err;
25520
25521 for (i = 0; i < old->size; i++)
25522 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25523 + write_ldt_entry(new->ldt, i, old->ldt + i);
25524 return 0;
25525 }
25526
25527 @@ -117,6 +117,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25528 retval = copy_ldt(&mm->context, &old_mm->context);
25529 mutex_unlock(&old_mm->context.lock);
25530 }
25531 +
25532 + if (tsk == current) {
25533 + mm->context.vdso = 0;
25534 +
25535 +#ifdef CONFIG_X86_32
25536 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25537 + mm->context.user_cs_base = 0UL;
25538 + mm->context.user_cs_limit = ~0UL;
25539 +
25540 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25541 + cpus_clear(mm->context.cpu_user_cs_mask);
25542 +#endif
25543 +
25544 +#endif
25545 +#endif
25546 +
25547 + }
25548 +
25549 return retval;
25550 }
25551
25552 @@ -231,6 +249,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25553 }
25554 }
25555
25556 +#ifdef CONFIG_PAX_SEGMEXEC
25557 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25558 + error = -EINVAL;
25559 + goto out_unlock;
25560 + }
25561 +#endif
25562 +
25563 /*
25564 * On x86-64 we do not support 16-bit segments due to
25565 * IRET leaking the high bits of the kernel stack address.
25566 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25567 index 1667b1d..16492c5 100644
25568 --- a/arch/x86/kernel/machine_kexec_32.c
25569 +++ b/arch/x86/kernel/machine_kexec_32.c
25570 @@ -25,7 +25,7 @@
25571 #include <asm/cacheflush.h>
25572 #include <asm/debugreg.h>
25573
25574 -static void set_idt(void *newidt, __u16 limit)
25575 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25576 {
25577 struct desc_ptr curidt;
25578
25579 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25580 }
25581
25582
25583 -static void set_gdt(void *newgdt, __u16 limit)
25584 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25585 {
25586 struct desc_ptr curgdt;
25587
25588 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25589 }
25590
25591 control_page = page_address(image->control_code_page);
25592 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25593 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25594
25595 relocate_kernel_ptr = control_page;
25596 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25597 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25598 index e69f988..da078ea 100644
25599 --- a/arch/x86/kernel/module.c
25600 +++ b/arch/x86/kernel/module.c
25601 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25602 }
25603 #endif
25604
25605 -void *module_alloc(unsigned long size)
25606 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25607 {
25608 - if (PAGE_ALIGN(size) > MODULES_LEN)
25609 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25610 return NULL;
25611 return __vmalloc_node_range(size, 1,
25612 MODULES_VADDR + get_module_load_offset(),
25613 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25614 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25615 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25616 + prot, NUMA_NO_NODE,
25617 __builtin_return_address(0));
25618 }
25619
25620 +void *module_alloc(unsigned long size)
25621 +{
25622 +
25623 +#ifdef CONFIG_PAX_KERNEXEC
25624 + return __module_alloc(size, PAGE_KERNEL);
25625 +#else
25626 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25627 +#endif
25628 +
25629 +}
25630 +
25631 +#ifdef CONFIG_PAX_KERNEXEC
25632 +#ifdef CONFIG_X86_32
25633 +void *module_alloc_exec(unsigned long size)
25634 +{
25635 + struct vm_struct *area;
25636 +
25637 + if (size == 0)
25638 + return NULL;
25639 +
25640 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25641 +return area ? area->addr : NULL;
25642 +}
25643 +EXPORT_SYMBOL(module_alloc_exec);
25644 +
25645 +void module_free_exec(struct module *mod, void *module_region)
25646 +{
25647 + vunmap(module_region);
25648 +}
25649 +EXPORT_SYMBOL(module_free_exec);
25650 +#else
25651 +void module_free_exec(struct module *mod, void *module_region)
25652 +{
25653 + module_free(mod, module_region);
25654 +}
25655 +EXPORT_SYMBOL(module_free_exec);
25656 +
25657 +void *module_alloc_exec(unsigned long size)
25658 +{
25659 + return __module_alloc(size, PAGE_KERNEL_RX);
25660 +}
25661 +EXPORT_SYMBOL(module_alloc_exec);
25662 +#endif
25663 +#endif
25664 +
25665 #ifdef CONFIG_X86_32
25666 int apply_relocate(Elf32_Shdr *sechdrs,
25667 const char *strtab,
25668 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25669 unsigned int i;
25670 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25671 Elf32_Sym *sym;
25672 - uint32_t *location;
25673 + uint32_t *plocation, location;
25674
25675 DEBUGP("Applying relocate section %u to %u\n",
25676 relsec, sechdrs[relsec].sh_info);
25677 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25678 /* This is where to make the change */
25679 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25680 - + rel[i].r_offset;
25681 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25682 + location = (uint32_t)plocation;
25683 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25684 + plocation = ktla_ktva((void *)plocation);
25685 /* This is the symbol it is referring to. Note that all
25686 undefined symbols have been resolved. */
25687 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25688 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25689 switch (ELF32_R_TYPE(rel[i].r_info)) {
25690 case R_386_32:
25691 /* We add the value into the location given */
25692 - *location += sym->st_value;
25693 + pax_open_kernel();
25694 + *plocation += sym->st_value;
25695 + pax_close_kernel();
25696 break;
25697 case R_386_PC32:
25698 /* Add the value, subtract its position */
25699 - *location += sym->st_value - (uint32_t)location;
25700 + pax_open_kernel();
25701 + *plocation += sym->st_value - location;
25702 + pax_close_kernel();
25703 break;
25704 default:
25705 pr_err("%s: Unknown relocation: %u\n",
25706 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25707 case R_X86_64_NONE:
25708 break;
25709 case R_X86_64_64:
25710 + pax_open_kernel();
25711 *(u64 *)loc = val;
25712 + pax_close_kernel();
25713 break;
25714 case R_X86_64_32:
25715 + pax_open_kernel();
25716 *(u32 *)loc = val;
25717 + pax_close_kernel();
25718 if (val != *(u32 *)loc)
25719 goto overflow;
25720 break;
25721 case R_X86_64_32S:
25722 + pax_open_kernel();
25723 *(s32 *)loc = val;
25724 + pax_close_kernel();
25725 if ((s64)val != *(s32 *)loc)
25726 goto overflow;
25727 break;
25728 case R_X86_64_PC32:
25729 val -= (u64)loc;
25730 + pax_open_kernel();
25731 *(u32 *)loc = val;
25732 + pax_close_kernel();
25733 +
25734 #if 0
25735 if ((s64)val != *(s32 *)loc)
25736 goto overflow;
25737 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25738 index c9603ac..9f88728 100644
25739 --- a/arch/x86/kernel/msr.c
25740 +++ b/arch/x86/kernel/msr.c
25741 @@ -37,6 +37,7 @@
25742 #include <linux/notifier.h>
25743 #include <linux/uaccess.h>
25744 #include <linux/gfp.h>
25745 +#include <linux/grsecurity.h>
25746
25747 #include <asm/processor.h>
25748 #include <asm/msr.h>
25749 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25750 int err = 0;
25751 ssize_t bytes = 0;
25752
25753 +#ifdef CONFIG_GRKERNSEC_KMEM
25754 + gr_handle_msr_write();
25755 + return -EPERM;
25756 +#endif
25757 +
25758 if (count % 8)
25759 return -EINVAL; /* Invalid chunk size */
25760
25761 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25762 err = -EBADF;
25763 break;
25764 }
25765 +#ifdef CONFIG_GRKERNSEC_KMEM
25766 + gr_handle_msr_write();
25767 + return -EPERM;
25768 +#endif
25769 if (copy_from_user(&regs, uregs, sizeof regs)) {
25770 err = -EFAULT;
25771 break;
25772 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25773 return notifier_from_errno(err);
25774 }
25775
25776 -static struct notifier_block __refdata msr_class_cpu_notifier = {
25777 +static struct notifier_block msr_class_cpu_notifier = {
25778 .notifier_call = msr_class_cpu_callback,
25779 };
25780
25781 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25782 index b4872b9..5bf0684 100644
25783 --- a/arch/x86/kernel/nmi.c
25784 +++ b/arch/x86/kernel/nmi.c
25785 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
25786
25787 static void nmi_max_handler(struct irq_work *w)
25788 {
25789 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
25790 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
25791 int remainder_ns, decimal_msecs;
25792 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
25793 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
25794
25795 remainder_ns = do_div(whole_msecs, (1000 * 1000));
25796 decimal_msecs = remainder_ns / 1000;
25797
25798 printk_ratelimited(KERN_INFO
25799 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
25800 - a->handler, whole_msecs, decimal_msecs);
25801 + n->action->handler, whole_msecs, decimal_msecs);
25802 }
25803
25804 static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
25805 @@ -134,11 +134,11 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25806 delta = sched_clock() - delta;
25807 trace_nmi_handler(a->handler, (int)delta, thishandled);
25808
25809 - if (delta < nmi_longest_ns || delta < a->max_duration)
25810 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
25811 continue;
25812
25813 - a->max_duration = delta;
25814 - irq_work_queue(&a->irq_work);
25815 + a->work->max_duration = delta;
25816 + irq_work_queue(&a->work->irq_work);
25817 }
25818
25819 rcu_read_unlock();
25820 @@ -147,7 +147,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25821 return handled;
25822 }
25823
25824 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25825 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25826 {
25827 struct nmi_desc *desc = nmi_to_desc(type);
25828 unsigned long flags;
25829 @@ -155,7 +155,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25830 if (!action->handler)
25831 return -EINVAL;
25832
25833 - init_irq_work(&action->irq_work, nmi_max_handler);
25834 + action->work->action = action;
25835 + init_irq_work(&action->work->irq_work, nmi_max_handler);
25836
25837 spin_lock_irqsave(&desc->lock, flags);
25838
25839 @@ -173,9 +174,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25840 * event confuses some handlers (kdump uses this flag)
25841 */
25842 if (action->flags & NMI_FLAG_FIRST)
25843 - list_add_rcu(&action->list, &desc->head);
25844 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25845 else
25846 - list_add_tail_rcu(&action->list, &desc->head);
25847 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25848
25849 spin_unlock_irqrestore(&desc->lock, flags);
25850 return 0;
25851 @@ -198,7 +199,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25852 if (!strcmp(n->name, name)) {
25853 WARN(in_nmi(),
25854 "Trying to free NMI (%s) from NMI context!\n", n->name);
25855 - list_del_rcu(&n->list);
25856 + pax_list_del_rcu((struct list_head *)&n->list);
25857 break;
25858 }
25859 }
25860 @@ -523,6 +524,17 @@ static inline void nmi_nesting_postprocess(void)
25861 dotraplinkage notrace __kprobes void
25862 do_nmi(struct pt_regs *regs, long error_code)
25863 {
25864 +
25865 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25866 + if (!user_mode(regs)) {
25867 + unsigned long cs = regs->cs & 0xFFFF;
25868 + unsigned long ip = ktva_ktla(regs->ip);
25869 +
25870 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25871 + regs->ip = ip;
25872 + }
25873 +#endif
25874 +
25875 nmi_nesting_preprocess(regs);
25876
25877 nmi_enter();
25878 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25879 index 6d9582e..f746287 100644
25880 --- a/arch/x86/kernel/nmi_selftest.c
25881 +++ b/arch/x86/kernel/nmi_selftest.c
25882 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25883 {
25884 /* trap all the unknown NMIs we may generate */
25885 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25886 - __initdata);
25887 + __initconst);
25888 }
25889
25890 static void __init cleanup_nmi_testsuite(void)
25891 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25892 unsigned long timeout;
25893
25894 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25895 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25896 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25897 nmi_fail = FAILURE;
25898 return;
25899 }
25900 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25901 index bbb6c73..24a58ef 100644
25902 --- a/arch/x86/kernel/paravirt-spinlocks.c
25903 +++ b/arch/x86/kernel/paravirt-spinlocks.c
25904 @@ -8,7 +8,7 @@
25905
25906 #include <asm/paravirt.h>
25907
25908 -struct pv_lock_ops pv_lock_ops = {
25909 +struct pv_lock_ops pv_lock_ops __read_only = {
25910 #ifdef CONFIG_SMP
25911 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25912 .unlock_kick = paravirt_nop,
25913 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25914 index 1b10af8..45bfbec 100644
25915 --- a/arch/x86/kernel/paravirt.c
25916 +++ b/arch/x86/kernel/paravirt.c
25917 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25918 {
25919 return x;
25920 }
25921 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25922 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25923 +#endif
25924
25925 void __init default_banner(void)
25926 {
25927 @@ -141,16 +144,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25928
25929 if (opfunc == NULL)
25930 /* If there's no function, patch it with a ud2a (BUG) */
25931 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25932 - else if (opfunc == _paravirt_nop)
25933 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
25934 + else if (opfunc == (void *)_paravirt_nop)
25935 /* If the operation is a nop, then nop the callsite */
25936 ret = paravirt_patch_nop();
25937
25938 /* identity functions just return their single argument */
25939 - else if (opfunc == _paravirt_ident_32)
25940 + else if (opfunc == (void *)_paravirt_ident_32)
25941 ret = paravirt_patch_ident_32(insnbuf, len);
25942 - else if (opfunc == _paravirt_ident_64)
25943 + else if (opfunc == (void *)_paravirt_ident_64)
25944 ret = paravirt_patch_ident_64(insnbuf, len);
25945 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25946 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25947 + ret = paravirt_patch_ident_64(insnbuf, len);
25948 +#endif
25949
25950 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25951 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25952 @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25953 if (insn_len > len || start == NULL)
25954 insn_len = len;
25955 else
25956 - memcpy(insnbuf, start, insn_len);
25957 + memcpy(insnbuf, ktla_ktva(start), insn_len);
25958
25959 return insn_len;
25960 }
25961 @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25962 return this_cpu_read(paravirt_lazy_mode);
25963 }
25964
25965 -struct pv_info pv_info = {
25966 +struct pv_info pv_info __read_only = {
25967 .name = "bare hardware",
25968 .paravirt_enabled = 0,
25969 .kernel_rpl = 0,
25970 @@ -310,16 +317,16 @@ struct pv_info pv_info = {
25971 #endif
25972 };
25973
25974 -struct pv_init_ops pv_init_ops = {
25975 +struct pv_init_ops pv_init_ops __read_only = {
25976 .patch = native_patch,
25977 };
25978
25979 -struct pv_time_ops pv_time_ops = {
25980 +struct pv_time_ops pv_time_ops __read_only = {
25981 .sched_clock = native_sched_clock,
25982 .steal_clock = native_steal_clock,
25983 };
25984
25985 -__visible struct pv_irq_ops pv_irq_ops = {
25986 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
25987 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25988 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25989 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25990 @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25991 #endif
25992 };
25993
25994 -__visible struct pv_cpu_ops pv_cpu_ops = {
25995 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25996 .cpuid = native_cpuid,
25997 .get_debugreg = native_get_debugreg,
25998 .set_debugreg = native_set_debugreg,
25999 @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
26000 .end_context_switch = paravirt_nop,
26001 };
26002
26003 -struct pv_apic_ops pv_apic_ops = {
26004 +struct pv_apic_ops pv_apic_ops __read_only= {
26005 #ifdef CONFIG_X86_LOCAL_APIC
26006 .startup_ipi_hook = paravirt_nop,
26007 #endif
26008 };
26009
26010 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26011 +#ifdef CONFIG_X86_32
26012 +#ifdef CONFIG_X86_PAE
26013 +/* 64-bit pagetable entries */
26014 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26015 +#else
26016 /* 32-bit pagetable entries */
26017 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26018 +#endif
26019 #else
26020 /* 64-bit pagetable entries */
26021 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26022 #endif
26023
26024 -struct pv_mmu_ops pv_mmu_ops = {
26025 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26026
26027 .read_cr2 = native_read_cr2,
26028 .write_cr2 = native_write_cr2,
26029 @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26030 .make_pud = PTE_IDENT,
26031
26032 .set_pgd = native_set_pgd,
26033 + .set_pgd_batched = native_set_pgd_batched,
26034 #endif
26035 #endif /* PAGETABLE_LEVELS >= 3 */
26036
26037 @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26038 },
26039
26040 .set_fixmap = native_set_fixmap,
26041 +
26042 +#ifdef CONFIG_PAX_KERNEXEC
26043 + .pax_open_kernel = native_pax_open_kernel,
26044 + .pax_close_kernel = native_pax_close_kernel,
26045 +#endif
26046 +
26047 };
26048
26049 EXPORT_SYMBOL_GPL(pv_time_ops);
26050 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26051 index 0497f71..7186c0d 100644
26052 --- a/arch/x86/kernel/pci-calgary_64.c
26053 +++ b/arch/x86/kernel/pci-calgary_64.c
26054 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26055 tce_space = be64_to_cpu(readq(target));
26056 tce_space = tce_space & TAR_SW_BITS;
26057
26058 - tce_space = tce_space & (~specified_table_size);
26059 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26060 info->tce_space = (u64 *)__va(tce_space);
26061 }
26062 }
26063 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26064 index 35ccf75..7a15747 100644
26065 --- a/arch/x86/kernel/pci-iommu_table.c
26066 +++ b/arch/x86/kernel/pci-iommu_table.c
26067 @@ -2,7 +2,7 @@
26068 #include <asm/iommu_table.h>
26069 #include <linux/string.h>
26070 #include <linux/kallsyms.h>
26071 -
26072 +#include <linux/sched.h>
26073
26074 #define DEBUG 1
26075
26076 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26077 index 6c483ba..d10ce2f 100644
26078 --- a/arch/x86/kernel/pci-swiotlb.c
26079 +++ b/arch/x86/kernel/pci-swiotlb.c
26080 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26081 void *vaddr, dma_addr_t dma_addr,
26082 struct dma_attrs *attrs)
26083 {
26084 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26085 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26086 }
26087
26088 static struct dma_map_ops swiotlb_dma_ops = {
26089 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26090 index ca7f0d5..8996469 100644
26091 --- a/arch/x86/kernel/preempt.S
26092 +++ b/arch/x86/kernel/preempt.S
26093 @@ -3,12 +3,14 @@
26094 #include <asm/dwarf2.h>
26095 #include <asm/asm.h>
26096 #include <asm/calling.h>
26097 +#include <asm/alternative-asm.h>
26098
26099 ENTRY(___preempt_schedule)
26100 CFI_STARTPROC
26101 SAVE_ALL
26102 call preempt_schedule
26103 RESTORE_ALL
26104 + pax_force_retaddr
26105 ret
26106 CFI_ENDPROC
26107
26108 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26109 SAVE_ALL
26110 call preempt_schedule_context
26111 RESTORE_ALL
26112 + pax_force_retaddr
26113 ret
26114 CFI_ENDPROC
26115
26116 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26117 index 4505e2a..ae28b0d 100644
26118 --- a/arch/x86/kernel/process.c
26119 +++ b/arch/x86/kernel/process.c
26120 @@ -36,7 +36,8 @@
26121 * section. Since TSS's are completely CPU-local, we want them
26122 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26123 */
26124 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26125 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26126 +EXPORT_SYMBOL(init_tss);
26127
26128 #ifdef CONFIG_X86_64
26129 static DEFINE_PER_CPU(unsigned char, is_idle);
26130 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26131 task_xstate_cachep =
26132 kmem_cache_create("task_xstate", xstate_size,
26133 __alignof__(union thread_xstate),
26134 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26135 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26136 }
26137
26138 /*
26139 @@ -105,7 +106,7 @@ void exit_thread(void)
26140 unsigned long *bp = t->io_bitmap_ptr;
26141
26142 if (bp) {
26143 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26144 + struct tss_struct *tss = init_tss + get_cpu();
26145
26146 t->io_bitmap_ptr = NULL;
26147 clear_thread_flag(TIF_IO_BITMAP);
26148 @@ -125,6 +126,9 @@ void flush_thread(void)
26149 {
26150 struct task_struct *tsk = current;
26151
26152 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26153 + loadsegment(gs, 0);
26154 +#endif
26155 flush_ptrace_hw_breakpoint(tsk);
26156 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26157 drop_init_fpu(tsk);
26158 @@ -271,7 +275,7 @@ static void __exit_idle(void)
26159 void exit_idle(void)
26160 {
26161 /* idle loop has pid 0 */
26162 - if (current->pid)
26163 + if (task_pid_nr(current))
26164 return;
26165 __exit_idle();
26166 }
26167 @@ -324,7 +328,7 @@ bool xen_set_default_idle(void)
26168 return ret;
26169 }
26170 #endif
26171 -void stop_this_cpu(void *dummy)
26172 +__noreturn void stop_this_cpu(void *dummy)
26173 {
26174 local_irq_disable();
26175 /*
26176 @@ -453,16 +457,37 @@ static int __init idle_setup(char *str)
26177 }
26178 early_param("idle", idle_setup);
26179
26180 -unsigned long arch_align_stack(unsigned long sp)
26181 +#ifdef CONFIG_PAX_RANDKSTACK
26182 +void pax_randomize_kstack(struct pt_regs *regs)
26183 {
26184 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26185 - sp -= get_random_int() % 8192;
26186 - return sp & ~0xf;
26187 -}
26188 + struct thread_struct *thread = &current->thread;
26189 + unsigned long time;
26190
26191 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26192 -{
26193 - unsigned long range_end = mm->brk + 0x02000000;
26194 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26195 -}
26196 + if (!randomize_va_space)
26197 + return;
26198 +
26199 + if (v8086_mode(regs))
26200 + return;
26201
26202 + rdtscl(time);
26203 +
26204 + /* P4 seems to return a 0 LSB, ignore it */
26205 +#ifdef CONFIG_MPENTIUM4
26206 + time &= 0x3EUL;
26207 + time <<= 2;
26208 +#elif defined(CONFIG_X86_64)
26209 + time &= 0xFUL;
26210 + time <<= 4;
26211 +#else
26212 + time &= 0x1FUL;
26213 + time <<= 3;
26214 +#endif
26215 +
26216 + thread->sp0 ^= time;
26217 + load_sp0(init_tss + smp_processor_id(), thread);
26218 +
26219 +#ifdef CONFIG_X86_64
26220 + this_cpu_write(kernel_stack, thread->sp0);
26221 +#endif
26222 +}
26223 +#endif
26224 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26225 index 7bc86bb..0ea06e8 100644
26226 --- a/arch/x86/kernel/process_32.c
26227 +++ b/arch/x86/kernel/process_32.c
26228 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26229 unsigned long thread_saved_pc(struct task_struct *tsk)
26230 {
26231 return ((unsigned long *)tsk->thread.sp)[3];
26232 +//XXX return tsk->thread.eip;
26233 }
26234
26235 void __show_regs(struct pt_regs *regs, int all)
26236 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26237 unsigned long sp;
26238 unsigned short ss, gs;
26239
26240 - if (user_mode_vm(regs)) {
26241 + if (user_mode(regs)) {
26242 sp = regs->sp;
26243 ss = regs->ss & 0xffff;
26244 - gs = get_user_gs(regs);
26245 } else {
26246 sp = kernel_stack_pointer(regs);
26247 savesegment(ss, ss);
26248 - savesegment(gs, gs);
26249 }
26250 + gs = get_user_gs(regs);
26251
26252 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26253 (u16)regs->cs, regs->ip, regs->flags,
26254 - smp_processor_id());
26255 + raw_smp_processor_id());
26256 print_symbol("EIP is at %s\n", regs->ip);
26257
26258 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26259 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26260 int copy_thread(unsigned long clone_flags, unsigned long sp,
26261 unsigned long arg, struct task_struct *p)
26262 {
26263 - struct pt_regs *childregs = task_pt_regs(p);
26264 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26265 struct task_struct *tsk;
26266 int err;
26267
26268 p->thread.sp = (unsigned long) childregs;
26269 p->thread.sp0 = (unsigned long) (childregs+1);
26270 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26271
26272 if (unlikely(p->flags & PF_KTHREAD)) {
26273 /* kernel thread */
26274 memset(childregs, 0, sizeof(struct pt_regs));
26275 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26276 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26277 - childregs->ds = __USER_DS;
26278 - childregs->es = __USER_DS;
26279 + savesegment(gs, childregs->gs);
26280 + childregs->ds = __KERNEL_DS;
26281 + childregs->es = __KERNEL_DS;
26282 childregs->fs = __KERNEL_PERCPU;
26283 childregs->bx = sp; /* function */
26284 childregs->bp = arg;
26285 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26286 struct thread_struct *prev = &prev_p->thread,
26287 *next = &next_p->thread;
26288 int cpu = smp_processor_id();
26289 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26290 + struct tss_struct *tss = init_tss + cpu;
26291 fpu_switch_t fpu;
26292
26293 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26294 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26295 */
26296 lazy_save_gs(prev->gs);
26297
26298 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26299 + __set_fs(task_thread_info(next_p)->addr_limit);
26300 +#endif
26301 +
26302 /*
26303 * Load the per-thread Thread-Local Storage descriptor.
26304 */
26305 @@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26306 */
26307 arch_end_context_switch(next_p);
26308
26309 - this_cpu_write(kernel_stack,
26310 - (unsigned long)task_stack_page(next_p) +
26311 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26312 + this_cpu_write(current_task, next_p);
26313 + this_cpu_write(current_tinfo, &next_p->tinfo);
26314 + this_cpu_write(kernel_stack, next->sp0);
26315
26316 /*
26317 * Restore %gs if needed (which is common)
26318 @@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26319
26320 switch_fpu_finish(next_p, fpu);
26321
26322 - this_cpu_write(current_task, next_p);
26323 -
26324 return prev_p;
26325 }
26326
26327 @@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26328 } while (count++ < 16);
26329 return 0;
26330 }
26331 -
26332 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26333 index 898d077..4c458ff 100644
26334 --- a/arch/x86/kernel/process_64.c
26335 +++ b/arch/x86/kernel/process_64.c
26336 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26337 struct pt_regs *childregs;
26338 struct task_struct *me = current;
26339
26340 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26341 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26342 childregs = task_pt_regs(p);
26343 p->thread.sp = (unsigned long) childregs;
26344 p->thread.usersp = me->thread.usersp;
26345 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26346 set_tsk_thread_flag(p, TIF_FORK);
26347 p->thread.fpu_counter = 0;
26348 p->thread.io_bitmap_ptr = NULL;
26349 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26350 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26351 savesegment(es, p->thread.es);
26352 savesegment(ds, p->thread.ds);
26353 + savesegment(ss, p->thread.ss);
26354 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26355 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26356
26357 if (unlikely(p->flags & PF_KTHREAD)) {
26358 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26359 struct thread_struct *prev = &prev_p->thread;
26360 struct thread_struct *next = &next_p->thread;
26361 int cpu = smp_processor_id();
26362 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26363 + struct tss_struct *tss = init_tss + cpu;
26364 unsigned fsindex, gsindex;
26365 fpu_switch_t fpu;
26366
26367 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26368 if (unlikely(next->ds | prev->ds))
26369 loadsegment(ds, next->ds);
26370
26371 + savesegment(ss, prev->ss);
26372 + if (unlikely(next->ss != prev->ss))
26373 + loadsegment(ss, next->ss);
26374
26375 /* We must save %fs and %gs before load_TLS() because
26376 * %fs and %gs may be cleared by load_TLS().
26377 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26378 prev->usersp = this_cpu_read(old_rsp);
26379 this_cpu_write(old_rsp, next->usersp);
26380 this_cpu_write(current_task, next_p);
26381 + this_cpu_write(current_tinfo, &next_p->tinfo);
26382
26383 /*
26384 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26385 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26386 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26387 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26388
26389 - this_cpu_write(kernel_stack,
26390 - (unsigned long)task_stack_page(next_p) +
26391 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26392 + this_cpu_write(kernel_stack, next->sp0);
26393
26394 /*
26395 * Now maybe reload the debug registers and handle I/O bitmaps
26396 @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26397 if (!p || p == current || p->state == TASK_RUNNING)
26398 return 0;
26399 stack = (unsigned long)task_stack_page(p);
26400 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26401 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26402 return 0;
26403 fp = *(u64 *)(p->thread.sp);
26404 do {
26405 - if (fp < (unsigned long)stack ||
26406 - fp >= (unsigned long)stack+THREAD_SIZE)
26407 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26408 return 0;
26409 ip = *(u64 *)(fp+8);
26410 if (!in_sched_functions(ip))
26411 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26412 index 678c0ad..2fc2a7b 100644
26413 --- a/arch/x86/kernel/ptrace.c
26414 +++ b/arch/x86/kernel/ptrace.c
26415 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26416 unsigned long sp = (unsigned long)&regs->sp;
26417 u32 *prev_esp;
26418
26419 - if (context == (sp & ~(THREAD_SIZE - 1)))
26420 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26421 return sp;
26422
26423 - prev_esp = (u32 *)(context);
26424 + prev_esp = *(u32 **)(context);
26425 if (prev_esp)
26426 return (unsigned long)prev_esp;
26427
26428 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26429 if (child->thread.gs != value)
26430 return do_arch_prctl(child, ARCH_SET_GS, value);
26431 return 0;
26432 +
26433 + case offsetof(struct user_regs_struct,ip):
26434 + /*
26435 + * Protect against any attempt to set ip to an
26436 + * impossible address. There are dragons lurking if the
26437 + * address is noncanonical. (This explicitly allows
26438 + * setting ip to TASK_SIZE_MAX, because user code can do
26439 + * that all by itself by running off the end of its
26440 + * address space.
26441 + */
26442 + if (value > TASK_SIZE_MAX)
26443 + return -EIO;
26444 + break;
26445 +
26446 #endif
26447 }
26448
26449 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26450 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26451 {
26452 int i;
26453 - int dr7 = 0;
26454 + unsigned long dr7 = 0;
26455 struct arch_hw_breakpoint *info;
26456
26457 for (i = 0; i < HBP_NUM; i++) {
26458 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26459 unsigned long addr, unsigned long data)
26460 {
26461 int ret;
26462 - unsigned long __user *datap = (unsigned long __user *)data;
26463 + unsigned long __user *datap = (__force unsigned long __user *)data;
26464
26465 switch (request) {
26466 /* read the word at location addr in the USER area. */
26467 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26468 if ((int) addr < 0)
26469 return -EIO;
26470 ret = do_get_thread_area(child, addr,
26471 - (struct user_desc __user *)data);
26472 + (__force struct user_desc __user *) data);
26473 break;
26474
26475 case PTRACE_SET_THREAD_AREA:
26476 if ((int) addr < 0)
26477 return -EIO;
26478 ret = do_set_thread_area(child, addr,
26479 - (struct user_desc __user *)data, 0);
26480 + (__force struct user_desc __user *) data, 0);
26481 break;
26482 #endif
26483
26484 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26485
26486 #ifdef CONFIG_X86_64
26487
26488 -static struct user_regset x86_64_regsets[] __read_mostly = {
26489 +static user_regset_no_const x86_64_regsets[] __read_only = {
26490 [REGSET_GENERAL] = {
26491 .core_note_type = NT_PRSTATUS,
26492 .n = sizeof(struct user_regs_struct) / sizeof(long),
26493 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
26494 #endif /* CONFIG_X86_64 */
26495
26496 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26497 -static struct user_regset x86_32_regsets[] __read_mostly = {
26498 +static user_regset_no_const x86_32_regsets[] __read_only = {
26499 [REGSET_GENERAL] = {
26500 .core_note_type = NT_PRSTATUS,
26501 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26502 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
26503 */
26504 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26505
26506 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26507 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26508 {
26509 #ifdef CONFIG_X86_64
26510 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26511 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26512 memset(info, 0, sizeof(*info));
26513 info->si_signo = SIGTRAP;
26514 info->si_code = si_code;
26515 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26516 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26517 }
26518
26519 void user_single_step_siginfo(struct task_struct *tsk,
26520 @@ -1450,6 +1464,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26521 # define IS_IA32 0
26522 #endif
26523
26524 +#ifdef CONFIG_GRKERNSEC_SETXID
26525 +extern void gr_delayed_cred_worker(void);
26526 +#endif
26527 +
26528 /*
26529 * We must return the syscall number to actually look up in the table.
26530 * This can be -1L to skip running any syscall at all.
26531 @@ -1460,6 +1478,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26532
26533 user_exit();
26534
26535 +#ifdef CONFIG_GRKERNSEC_SETXID
26536 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26537 + gr_delayed_cred_worker();
26538 +#endif
26539 +
26540 /*
26541 * If we stepped into a sysenter/syscall insn, it trapped in
26542 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26543 @@ -1515,6 +1538,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26544 */
26545 user_exit();
26546
26547 +#ifdef CONFIG_GRKERNSEC_SETXID
26548 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26549 + gr_delayed_cred_worker();
26550 +#endif
26551 +
26552 audit_syscall_exit(regs);
26553
26554 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26555 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26556 index 2f355d2..e75ed0a 100644
26557 --- a/arch/x86/kernel/pvclock.c
26558 +++ b/arch/x86/kernel/pvclock.c
26559 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26560 reset_hung_task_detector();
26561 }
26562
26563 -static atomic64_t last_value = ATOMIC64_INIT(0);
26564 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26565
26566 void pvclock_resume(void)
26567 {
26568 - atomic64_set(&last_value, 0);
26569 + atomic64_set_unchecked(&last_value, 0);
26570 }
26571
26572 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26573 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26574 * updating at the same time, and one of them could be slightly behind,
26575 * making the assumption that last_value always go forward fail to hold.
26576 */
26577 - last = atomic64_read(&last_value);
26578 + last = atomic64_read_unchecked(&last_value);
26579 do {
26580 if (ret < last)
26581 return last;
26582 - last = atomic64_cmpxchg(&last_value, last, ret);
26583 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26584 } while (unlikely(last != ret));
26585
26586 return ret;
26587 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26588 index 52b1157..c6e67c4 100644
26589 --- a/arch/x86/kernel/reboot.c
26590 +++ b/arch/x86/kernel/reboot.c
26591 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26592
26593 void __noreturn machine_real_restart(unsigned int type)
26594 {
26595 +
26596 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26597 + struct desc_struct *gdt;
26598 +#endif
26599 +
26600 local_irq_disable();
26601
26602 /*
26603 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26604
26605 /* Jump to the identity-mapped low memory code */
26606 #ifdef CONFIG_X86_32
26607 - asm volatile("jmpl *%0" : :
26608 +
26609 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26610 + gdt = get_cpu_gdt_table(smp_processor_id());
26611 + pax_open_kernel();
26612 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26613 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26614 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26615 + loadsegment(ds, __KERNEL_DS);
26616 + loadsegment(es, __KERNEL_DS);
26617 + loadsegment(ss, __KERNEL_DS);
26618 +#endif
26619 +#ifdef CONFIG_PAX_KERNEXEC
26620 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26621 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26622 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26623 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26624 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26625 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26626 +#endif
26627 + pax_close_kernel();
26628 +#endif
26629 +
26630 + asm volatile("ljmpl *%0" : :
26631 "rm" (real_mode_header->machine_real_restart_asm),
26632 "a" (type));
26633 #else
26634 @@ -486,7 +513,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26635 * This means that this function can never return, it can misbehave
26636 * by not rebooting properly and hanging.
26637 */
26638 -static void native_machine_emergency_restart(void)
26639 +static void __noreturn native_machine_emergency_restart(void)
26640 {
26641 int i;
26642 int attempt = 0;
26643 @@ -610,13 +637,13 @@ void native_machine_shutdown(void)
26644 #endif
26645 }
26646
26647 -static void __machine_emergency_restart(int emergency)
26648 +static void __noreturn __machine_emergency_restart(int emergency)
26649 {
26650 reboot_emergency = emergency;
26651 machine_ops.emergency_restart();
26652 }
26653
26654 -static void native_machine_restart(char *__unused)
26655 +static void __noreturn native_machine_restart(char *__unused)
26656 {
26657 pr_notice("machine restart\n");
26658
26659 @@ -625,7 +652,7 @@ static void native_machine_restart(char *__unused)
26660 __machine_emergency_restart(0);
26661 }
26662
26663 -static void native_machine_halt(void)
26664 +static void __noreturn native_machine_halt(void)
26665 {
26666 /* Stop other cpus and apics */
26667 machine_shutdown();
26668 @@ -635,7 +662,7 @@ static void native_machine_halt(void)
26669 stop_this_cpu(NULL);
26670 }
26671
26672 -static void native_machine_power_off(void)
26673 +static void __noreturn native_machine_power_off(void)
26674 {
26675 if (pm_power_off) {
26676 if (!reboot_force)
26677 @@ -644,9 +671,10 @@ static void native_machine_power_off(void)
26678 }
26679 /* A fallback in case there is no PM info available */
26680 tboot_shutdown(TB_SHUTDOWN_HALT);
26681 + unreachable();
26682 }
26683
26684 -struct machine_ops machine_ops = {
26685 +struct machine_ops machine_ops __read_only = {
26686 .power_off = native_machine_power_off,
26687 .shutdown = native_machine_shutdown,
26688 .emergency_restart = native_machine_emergency_restart,
26689 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26690 index c8e41e9..64049ef 100644
26691 --- a/arch/x86/kernel/reboot_fixups_32.c
26692 +++ b/arch/x86/kernel/reboot_fixups_32.c
26693 @@ -57,7 +57,7 @@ struct device_fixup {
26694 unsigned int vendor;
26695 unsigned int device;
26696 void (*reboot_fixup)(struct pci_dev *);
26697 -};
26698 +} __do_const;
26699
26700 /*
26701 * PCI ids solely used for fixups_table go here
26702 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26703 index 3fd2c69..a444264 100644
26704 --- a/arch/x86/kernel/relocate_kernel_64.S
26705 +++ b/arch/x86/kernel/relocate_kernel_64.S
26706 @@ -96,8 +96,7 @@ relocate_kernel:
26707
26708 /* jump to identity mapped page */
26709 addq $(identity_mapped - relocate_kernel), %r8
26710 - pushq %r8
26711 - ret
26712 + jmp *%r8
26713
26714 identity_mapped:
26715 /* set return address to 0 if not preserving context */
26716 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26717 index 09c76d2..7f33fc2 100644
26718 --- a/arch/x86/kernel/setup.c
26719 +++ b/arch/x86/kernel/setup.c
26720 @@ -110,6 +110,7 @@
26721 #include <asm/mce.h>
26722 #include <asm/alternative.h>
26723 #include <asm/prom.h>
26724 +#include <asm/boot.h>
26725
26726 /*
26727 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26728 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26729 #endif
26730
26731
26732 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26733 -__visible unsigned long mmu_cr4_features;
26734 +#ifdef CONFIG_X86_64
26735 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26736 +#elif defined(CONFIG_X86_PAE)
26737 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26738 #else
26739 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26740 +__visible unsigned long mmu_cr4_features __read_only;
26741 #endif
26742
26743 +void set_in_cr4(unsigned long mask)
26744 +{
26745 + unsigned long cr4 = read_cr4();
26746 +
26747 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26748 + return;
26749 +
26750 + pax_open_kernel();
26751 + mmu_cr4_features |= mask;
26752 + pax_close_kernel();
26753 +
26754 + if (trampoline_cr4_features)
26755 + *trampoline_cr4_features = mmu_cr4_features;
26756 + cr4 |= mask;
26757 + write_cr4(cr4);
26758 +}
26759 +EXPORT_SYMBOL(set_in_cr4);
26760 +
26761 +void clear_in_cr4(unsigned long mask)
26762 +{
26763 + unsigned long cr4 = read_cr4();
26764 +
26765 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26766 + return;
26767 +
26768 + pax_open_kernel();
26769 + mmu_cr4_features &= ~mask;
26770 + pax_close_kernel();
26771 +
26772 + if (trampoline_cr4_features)
26773 + *trampoline_cr4_features = mmu_cr4_features;
26774 + cr4 &= ~mask;
26775 + write_cr4(cr4);
26776 +}
26777 +EXPORT_SYMBOL(clear_in_cr4);
26778 +
26779 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26780 int bootloader_type, bootloader_version;
26781
26782 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
26783 * area (640->1Mb) as ram even though it is not.
26784 * take them out.
26785 */
26786 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26787 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26788
26789 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26790 }
26791 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
26792 /* called before trim_bios_range() to spare extra sanitize */
26793 static void __init e820_add_kernel_range(void)
26794 {
26795 - u64 start = __pa_symbol(_text);
26796 + u64 start = __pa_symbol(ktla_ktva(_text));
26797 u64 size = __pa_symbol(_end) - start;
26798
26799 /*
26800 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
26801
26802 void __init setup_arch(char **cmdline_p)
26803 {
26804 +#ifdef CONFIG_X86_32
26805 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26806 +#else
26807 memblock_reserve(__pa_symbol(_text),
26808 (unsigned long)__bss_stop - (unsigned long)_text);
26809 +#endif
26810
26811 early_reserve_initrd();
26812
26813 @@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
26814
26815 if (!boot_params.hdr.root_flags)
26816 root_mountflags &= ~MS_RDONLY;
26817 - init_mm.start_code = (unsigned long) _text;
26818 - init_mm.end_code = (unsigned long) _etext;
26819 + init_mm.start_code = ktla_ktva((unsigned long) _text);
26820 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
26821 init_mm.end_data = (unsigned long) _edata;
26822 init_mm.brk = _brk_end;
26823
26824 - code_resource.start = __pa_symbol(_text);
26825 - code_resource.end = __pa_symbol(_etext)-1;
26826 - data_resource.start = __pa_symbol(_etext);
26827 + code_resource.start = __pa_symbol(ktla_ktva(_text));
26828 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26829 + data_resource.start = __pa_symbol(_sdata);
26830 data_resource.end = __pa_symbol(_edata)-1;
26831 bss_resource.start = __pa_symbol(__bss_start);
26832 bss_resource.end = __pa_symbol(__bss_stop)-1;
26833 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26834 index 5cdff03..80fa283 100644
26835 --- a/arch/x86/kernel/setup_percpu.c
26836 +++ b/arch/x86/kernel/setup_percpu.c
26837 @@ -21,19 +21,17 @@
26838 #include <asm/cpu.h>
26839 #include <asm/stackprotector.h>
26840
26841 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26842 +#ifdef CONFIG_SMP
26843 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26844 EXPORT_PER_CPU_SYMBOL(cpu_number);
26845 +#endif
26846
26847 -#ifdef CONFIG_X86_64
26848 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26849 -#else
26850 -#define BOOT_PERCPU_OFFSET 0
26851 -#endif
26852
26853 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26854 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26855
26856 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26857 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26858 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26859 };
26860 EXPORT_SYMBOL(__per_cpu_offset);
26861 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26862 {
26863 #ifdef CONFIG_NEED_MULTIPLE_NODES
26864 pg_data_t *last = NULL;
26865 - unsigned int cpu;
26866 + int cpu;
26867
26868 for_each_possible_cpu(cpu) {
26869 int node = early_cpu_to_node(cpu);
26870 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26871 {
26872 #ifdef CONFIG_X86_32
26873 struct desc_struct gdt;
26874 + unsigned long base = per_cpu_offset(cpu);
26875
26876 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26877 - 0x2 | DESCTYPE_S, 0x8);
26878 - gdt.s = 1;
26879 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26880 + 0x83 | DESCTYPE_S, 0xC);
26881 write_gdt_entry(get_cpu_gdt_table(cpu),
26882 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26883 #endif
26884 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26885 /* alrighty, percpu areas up and running */
26886 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26887 for_each_possible_cpu(cpu) {
26888 +#ifdef CONFIG_CC_STACKPROTECTOR
26889 +#ifdef CONFIG_X86_32
26890 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
26891 +#endif
26892 +#endif
26893 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26894 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26895 per_cpu(cpu_number, cpu) = cpu;
26896 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26897 */
26898 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26899 #endif
26900 +#ifdef CONFIG_CC_STACKPROTECTOR
26901 +#ifdef CONFIG_X86_32
26902 + if (!cpu)
26903 + per_cpu(stack_canary.canary, cpu) = canary;
26904 +#endif
26905 +#endif
26906 /*
26907 * Up to this point, the boot CPU has been using .init.data
26908 * area. Reload any changed state for the boot CPU.
26909 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26910 index 9e5de68..16c53cb 100644
26911 --- a/arch/x86/kernel/signal.c
26912 +++ b/arch/x86/kernel/signal.c
26913 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26914 * Align the stack pointer according to the i386 ABI,
26915 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26916 */
26917 - sp = ((sp + 4) & -16ul) - 4;
26918 + sp = ((sp - 12) & -16ul) - 4;
26919 #else /* !CONFIG_X86_32 */
26920 sp = round_down(sp, 16) - 8;
26921 #endif
26922 @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26923 }
26924
26925 if (current->mm->context.vdso)
26926 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26927 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26928 else
26929 - restorer = &frame->retcode;
26930 + restorer = (void __user *)&frame->retcode;
26931 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26932 restorer = ksig->ka.sa.sa_restorer;
26933
26934 @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26935 * reasons and because gdb uses it as a signature to notice
26936 * signal handler stack frames.
26937 */
26938 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26939 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26940
26941 if (err)
26942 return -EFAULT;
26943 @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26944 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26945
26946 /* Set up to return from userspace. */
26947 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26948 + if (current->mm->context.vdso)
26949 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26950 + else
26951 + restorer = (void __user *)&frame->retcode;
26952 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26953 restorer = ksig->ka.sa.sa_restorer;
26954 put_user_ex(restorer, &frame->pretcode);
26955 @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26956 * reasons and because gdb uses it as a signature to notice
26957 * signal handler stack frames.
26958 */
26959 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26960 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26961 } put_user_catch(err);
26962
26963 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26964 @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26965 {
26966 int usig = signr_convert(ksig->sig);
26967 sigset_t *set = sigmask_to_save();
26968 - compat_sigset_t *cset = (compat_sigset_t *) set;
26969 + sigset_t sigcopy;
26970 + compat_sigset_t *cset;
26971 +
26972 + sigcopy = *set;
26973 +
26974 + cset = (compat_sigset_t *) &sigcopy;
26975
26976 /* Set up the stack frame */
26977 if (is_ia32_frame()) {
26978 @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26979 } else if (is_x32_frame()) {
26980 return x32_setup_rt_frame(ksig, cset, regs);
26981 } else {
26982 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
26983 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26984 }
26985 }
26986
26987 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26988 index be8e1bd..a3d93fa 100644
26989 --- a/arch/x86/kernel/smp.c
26990 +++ b/arch/x86/kernel/smp.c
26991 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26992
26993 __setup("nonmi_ipi", nonmi_ipi_setup);
26994
26995 -struct smp_ops smp_ops = {
26996 +struct smp_ops smp_ops __read_only = {
26997 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26998 .smp_prepare_cpus = native_smp_prepare_cpus,
26999 .smp_cpus_done = native_smp_cpus_done,
27000 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27001 index ae2fd975..c0c8d10 100644
27002 --- a/arch/x86/kernel/smpboot.c
27003 +++ b/arch/x86/kernel/smpboot.c
27004 @@ -230,14 +230,17 @@ static void notrace start_secondary(void *unused)
27005
27006 enable_start_cpu0 = 0;
27007
27008 -#ifdef CONFIG_X86_32
27009 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
27010 + barrier();
27011 +
27012 /* switch away from the initial page table */
27013 +#ifdef CONFIG_PAX_PER_CPU_PGD
27014 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27015 +#else
27016 load_cr3(swapper_pg_dir);
27017 +#endif
27018 __flush_tlb_all();
27019 -#endif
27020
27021 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
27022 - barrier();
27023 /*
27024 * Check TSC synchronization with the BP:
27025 */
27026 @@ -757,8 +760,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27027 alternatives_enable_smp();
27028
27029 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27030 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27031 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27032 per_cpu(current_task, cpu) = idle;
27033 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27034
27035 #ifdef CONFIG_X86_32
27036 /* Stack for startup_32 can be just as for start_secondary onwards */
27037 @@ -767,10 +771,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27038 clear_tsk_thread_flag(idle, TIF_FORK);
27039 initial_gs = per_cpu_offset(cpu);
27040 #endif
27041 - per_cpu(kernel_stack, cpu) =
27042 - (unsigned long)task_stack_page(idle) -
27043 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27044 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27045 + pax_open_kernel();
27046 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27047 + pax_close_kernel();
27048 initial_code = (unsigned long)start_secondary;
27049 stack_start = idle->thread.sp;
27050
27051 @@ -916,6 +920,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27052 /* the FPU context is blank, nobody can own it */
27053 __cpu_disable_lazy_restore(cpu);
27054
27055 +#ifdef CONFIG_PAX_PER_CPU_PGD
27056 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27057 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27058 + KERNEL_PGD_PTRS);
27059 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27060 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27061 + KERNEL_PGD_PTRS);
27062 +#endif
27063 +
27064 err = do_boot_cpu(apicid, cpu, tidle);
27065 if (err) {
27066 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27067 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27068 index 9b4d51d..5d28b58 100644
27069 --- a/arch/x86/kernel/step.c
27070 +++ b/arch/x86/kernel/step.c
27071 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27072 struct desc_struct *desc;
27073 unsigned long base;
27074
27075 - seg &= ~7UL;
27076 + seg >>= 3;
27077
27078 mutex_lock(&child->mm->context.lock);
27079 - if (unlikely((seg >> 3) >= child->mm->context.size))
27080 + if (unlikely(seg >= child->mm->context.size))
27081 addr = -1L; /* bogus selector, access would fault */
27082 else {
27083 desc = child->mm->context.ldt + seg;
27084 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27085 addr += base;
27086 }
27087 mutex_unlock(&child->mm->context.lock);
27088 - }
27089 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27090 + addr = ktla_ktva(addr);
27091
27092 return addr;
27093 }
27094 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27095 unsigned char opcode[15];
27096 unsigned long addr = convert_ip_to_linear(child, regs);
27097
27098 + if (addr == -EINVAL)
27099 + return 0;
27100 +
27101 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27102 for (i = 0; i < copied; i++) {
27103 switch (opcode[i]) {
27104 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27105 new file mode 100644
27106 index 0000000..5877189
27107 --- /dev/null
27108 +++ b/arch/x86/kernel/sys_i386_32.c
27109 @@ -0,0 +1,189 @@
27110 +/*
27111 + * This file contains various random system calls that
27112 + * have a non-standard calling sequence on the Linux/i386
27113 + * platform.
27114 + */
27115 +
27116 +#include <linux/errno.h>
27117 +#include <linux/sched.h>
27118 +#include <linux/mm.h>
27119 +#include <linux/fs.h>
27120 +#include <linux/smp.h>
27121 +#include <linux/sem.h>
27122 +#include <linux/msg.h>
27123 +#include <linux/shm.h>
27124 +#include <linux/stat.h>
27125 +#include <linux/syscalls.h>
27126 +#include <linux/mman.h>
27127 +#include <linux/file.h>
27128 +#include <linux/utsname.h>
27129 +#include <linux/ipc.h>
27130 +#include <linux/elf.h>
27131 +
27132 +#include <linux/uaccess.h>
27133 +#include <linux/unistd.h>
27134 +
27135 +#include <asm/syscalls.h>
27136 +
27137 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27138 +{
27139 + unsigned long pax_task_size = TASK_SIZE;
27140 +
27141 +#ifdef CONFIG_PAX_SEGMEXEC
27142 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27143 + pax_task_size = SEGMEXEC_TASK_SIZE;
27144 +#endif
27145 +
27146 + if (flags & MAP_FIXED)
27147 + if (len > pax_task_size || addr > pax_task_size - len)
27148 + return -EINVAL;
27149 +
27150 + return 0;
27151 +}
27152 +
27153 +/*
27154 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27155 + */
27156 +static unsigned long get_align_mask(void)
27157 +{
27158 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27159 + return 0;
27160 +
27161 + if (!(current->flags & PF_RANDOMIZE))
27162 + return 0;
27163 +
27164 + return va_align.mask;
27165 +}
27166 +
27167 +unsigned long
27168 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27169 + unsigned long len, unsigned long pgoff, unsigned long flags)
27170 +{
27171 + struct mm_struct *mm = current->mm;
27172 + struct vm_area_struct *vma;
27173 + unsigned long pax_task_size = TASK_SIZE;
27174 + struct vm_unmapped_area_info info;
27175 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27176 +
27177 +#ifdef CONFIG_PAX_SEGMEXEC
27178 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27179 + pax_task_size = SEGMEXEC_TASK_SIZE;
27180 +#endif
27181 +
27182 + pax_task_size -= PAGE_SIZE;
27183 +
27184 + if (len > pax_task_size)
27185 + return -ENOMEM;
27186 +
27187 + if (flags & MAP_FIXED)
27188 + return addr;
27189 +
27190 +#ifdef CONFIG_PAX_RANDMMAP
27191 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27192 +#endif
27193 +
27194 + if (addr) {
27195 + addr = PAGE_ALIGN(addr);
27196 + if (pax_task_size - len >= addr) {
27197 + vma = find_vma(mm, addr);
27198 + if (check_heap_stack_gap(vma, addr, len, offset))
27199 + return addr;
27200 + }
27201 + }
27202 +
27203 + info.flags = 0;
27204 + info.length = len;
27205 + info.align_mask = filp ? get_align_mask() : 0;
27206 + info.align_offset = pgoff << PAGE_SHIFT;
27207 + info.threadstack_offset = offset;
27208 +
27209 +#ifdef CONFIG_PAX_PAGEEXEC
27210 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27211 + info.low_limit = 0x00110000UL;
27212 + info.high_limit = mm->start_code;
27213 +
27214 +#ifdef CONFIG_PAX_RANDMMAP
27215 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27216 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27217 +#endif
27218 +
27219 + if (info.low_limit < info.high_limit) {
27220 + addr = vm_unmapped_area(&info);
27221 + if (!IS_ERR_VALUE(addr))
27222 + return addr;
27223 + }
27224 + } else
27225 +#endif
27226 +
27227 + info.low_limit = mm->mmap_base;
27228 + info.high_limit = pax_task_size;
27229 +
27230 + return vm_unmapped_area(&info);
27231 +}
27232 +
27233 +unsigned long
27234 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27235 + const unsigned long len, const unsigned long pgoff,
27236 + const unsigned long flags)
27237 +{
27238 + struct vm_area_struct *vma;
27239 + struct mm_struct *mm = current->mm;
27240 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27241 + struct vm_unmapped_area_info info;
27242 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27243 +
27244 +#ifdef CONFIG_PAX_SEGMEXEC
27245 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27246 + pax_task_size = SEGMEXEC_TASK_SIZE;
27247 +#endif
27248 +
27249 + pax_task_size -= PAGE_SIZE;
27250 +
27251 + /* requested length too big for entire address space */
27252 + if (len > pax_task_size)
27253 + return -ENOMEM;
27254 +
27255 + if (flags & MAP_FIXED)
27256 + return addr;
27257 +
27258 +#ifdef CONFIG_PAX_PAGEEXEC
27259 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27260 + goto bottomup;
27261 +#endif
27262 +
27263 +#ifdef CONFIG_PAX_RANDMMAP
27264 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27265 +#endif
27266 +
27267 + /* requesting a specific address */
27268 + if (addr) {
27269 + addr = PAGE_ALIGN(addr);
27270 + if (pax_task_size - len >= addr) {
27271 + vma = find_vma(mm, addr);
27272 + if (check_heap_stack_gap(vma, addr, len, offset))
27273 + return addr;
27274 + }
27275 + }
27276 +
27277 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27278 + info.length = len;
27279 + info.low_limit = PAGE_SIZE;
27280 + info.high_limit = mm->mmap_base;
27281 + info.align_mask = filp ? get_align_mask() : 0;
27282 + info.align_offset = pgoff << PAGE_SHIFT;
27283 + info.threadstack_offset = offset;
27284 +
27285 + addr = vm_unmapped_area(&info);
27286 + if (!(addr & ~PAGE_MASK))
27287 + return addr;
27288 + VM_BUG_ON(addr != -ENOMEM);
27289 +
27290 +bottomup:
27291 + /*
27292 + * A failed mmap() very likely causes application failure,
27293 + * so fall back to the bottom-up function here. This scenario
27294 + * can happen with large stack limits and large mmap()
27295 + * allocations.
27296 + */
27297 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27298 +}
27299 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27300 index 30277e2..5664a29 100644
27301 --- a/arch/x86/kernel/sys_x86_64.c
27302 +++ b/arch/x86/kernel/sys_x86_64.c
27303 @@ -81,8 +81,8 @@ out:
27304 return error;
27305 }
27306
27307 -static void find_start_end(unsigned long flags, unsigned long *begin,
27308 - unsigned long *end)
27309 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27310 + unsigned long *begin, unsigned long *end)
27311 {
27312 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27313 unsigned long new_begin;
27314 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27315 *begin = new_begin;
27316 }
27317 } else {
27318 - *begin = current->mm->mmap_legacy_base;
27319 + *begin = mm->mmap_legacy_base;
27320 *end = TASK_SIZE;
27321 }
27322 }
27323 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27324 struct vm_area_struct *vma;
27325 struct vm_unmapped_area_info info;
27326 unsigned long begin, end;
27327 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27328
27329 if (flags & MAP_FIXED)
27330 return addr;
27331
27332 - find_start_end(flags, &begin, &end);
27333 + find_start_end(mm, flags, &begin, &end);
27334
27335 if (len > end)
27336 return -ENOMEM;
27337
27338 +#ifdef CONFIG_PAX_RANDMMAP
27339 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27340 +#endif
27341 +
27342 if (addr) {
27343 addr = PAGE_ALIGN(addr);
27344 vma = find_vma(mm, addr);
27345 - if (end - len >= addr &&
27346 - (!vma || addr + len <= vma->vm_start))
27347 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27348 return addr;
27349 }
27350
27351 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27352 info.high_limit = end;
27353 info.align_mask = filp ? get_align_mask() : 0;
27354 info.align_offset = pgoff << PAGE_SHIFT;
27355 + info.threadstack_offset = offset;
27356 return vm_unmapped_area(&info);
27357 }
27358
27359 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27360 struct mm_struct *mm = current->mm;
27361 unsigned long addr = addr0;
27362 struct vm_unmapped_area_info info;
27363 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27364
27365 /* requested length too big for entire address space */
27366 if (len > TASK_SIZE)
27367 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27368 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27369 goto bottomup;
27370
27371 +#ifdef CONFIG_PAX_RANDMMAP
27372 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27373 +#endif
27374 +
27375 /* requesting a specific address */
27376 if (addr) {
27377 addr = PAGE_ALIGN(addr);
27378 vma = find_vma(mm, addr);
27379 - if (TASK_SIZE - len >= addr &&
27380 - (!vma || addr + len <= vma->vm_start))
27381 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27382 return addr;
27383 }
27384
27385 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27386 info.high_limit = mm->mmap_base;
27387 info.align_mask = filp ? get_align_mask() : 0;
27388 info.align_offset = pgoff << PAGE_SHIFT;
27389 + info.threadstack_offset = offset;
27390 addr = vm_unmapped_area(&info);
27391 if (!(addr & ~PAGE_MASK))
27392 return addr;
27393 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27394 index 91a4496..bb87552 100644
27395 --- a/arch/x86/kernel/tboot.c
27396 +++ b/arch/x86/kernel/tboot.c
27397 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27398
27399 void tboot_shutdown(u32 shutdown_type)
27400 {
27401 - void (*shutdown)(void);
27402 + void (* __noreturn shutdown)(void);
27403
27404 if (!tboot_enabled())
27405 return;
27406 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27407
27408 switch_to_tboot_pt();
27409
27410 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27411 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27412 shutdown();
27413
27414 /* should not reach here */
27415 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27416 return -ENODEV;
27417 }
27418
27419 -static atomic_t ap_wfs_count;
27420 +static atomic_unchecked_t ap_wfs_count;
27421
27422 static int tboot_wait_for_aps(int num_aps)
27423 {
27424 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27425 {
27426 switch (action) {
27427 case CPU_DYING:
27428 - atomic_inc(&ap_wfs_count);
27429 + atomic_inc_unchecked(&ap_wfs_count);
27430 if (num_online_cpus() == 1)
27431 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27432 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27433 return NOTIFY_BAD;
27434 break;
27435 }
27436 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27437
27438 tboot_create_trampoline();
27439
27440 - atomic_set(&ap_wfs_count, 0);
27441 + atomic_set_unchecked(&ap_wfs_count, 0);
27442 register_hotcpu_notifier(&tboot_cpu_notifier);
27443
27444 #ifdef CONFIG_DEBUG_FS
27445 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27446 index bf7ef5c..59d0ac9 100644
27447 --- a/arch/x86/kernel/time.c
27448 +++ b/arch/x86/kernel/time.c
27449 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27450 {
27451 unsigned long pc = instruction_pointer(regs);
27452
27453 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27454 + if (!user_mode(regs) && in_lock_functions(pc)) {
27455 #ifdef CONFIG_FRAME_POINTER
27456 - return *(unsigned long *)(regs->bp + sizeof(long));
27457 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27458 #else
27459 unsigned long *sp =
27460 (unsigned long *)kernel_stack_pointer(regs);
27461 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27462 * or above a saved flags. Eflags has bits 22-31 zero,
27463 * kernel addresses don't.
27464 */
27465 +
27466 +#ifdef CONFIG_PAX_KERNEXEC
27467 + return ktla_ktva(sp[0]);
27468 +#else
27469 if (sp[0] >> 22)
27470 return sp[0];
27471 if (sp[1] >> 22)
27472 return sp[1];
27473 #endif
27474 +
27475 +#endif
27476 }
27477 return pc;
27478 }
27479 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27480 index f7fec09..9991981 100644
27481 --- a/arch/x86/kernel/tls.c
27482 +++ b/arch/x86/kernel/tls.c
27483 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27484 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27485 return -EINVAL;
27486
27487 +#ifdef CONFIG_PAX_SEGMEXEC
27488 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27489 + return -EINVAL;
27490 +#endif
27491 +
27492 set_tls_desc(p, idx, &info, 1);
27493
27494 return 0;
27495 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27496
27497 if (kbuf)
27498 info = kbuf;
27499 - else if (__copy_from_user(infobuf, ubuf, count))
27500 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27501 return -EFAULT;
27502 else
27503 info = infobuf;
27504 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27505 index 1c113db..287b42e 100644
27506 --- a/arch/x86/kernel/tracepoint.c
27507 +++ b/arch/x86/kernel/tracepoint.c
27508 @@ -9,11 +9,11 @@
27509 #include <linux/atomic.h>
27510
27511 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27512 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27513 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27514 (unsigned long) trace_idt_table };
27515
27516 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27517 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27518 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27519
27520 static int trace_irq_vector_refcount;
27521 static DEFINE_MUTEX(irq_vector_mutex);
27522 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27523 index f73b5d4..0adcc9a 100644
27524 --- a/arch/x86/kernel/traps.c
27525 +++ b/arch/x86/kernel/traps.c
27526 @@ -66,7 +66,7 @@
27527 #include <asm/proto.h>
27528
27529 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27530 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27531 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27532 #else
27533 #include <asm/processor-flags.h>
27534 #include <asm/setup.h>
27535 @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27536 #endif
27537
27538 /* Must be page-aligned because the real IDT is used in a fixmap. */
27539 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27540 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27541
27542 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27543 EXPORT_SYMBOL_GPL(used_vectors);
27544 @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27545 }
27546
27547 static int __kprobes
27548 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27549 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27550 struct pt_regs *regs, long error_code)
27551 {
27552 #ifdef CONFIG_X86_32
27553 - if (regs->flags & X86_VM_MASK) {
27554 + if (v8086_mode(regs)) {
27555 /*
27556 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27557 * On nmi (interrupt 2), do_trap should not be called.
27558 @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27559 return -1;
27560 }
27561 #endif
27562 - if (!user_mode(regs)) {
27563 + if (!user_mode_novm(regs)) {
27564 if (!fixup_exception(regs)) {
27565 tsk->thread.error_code = error_code;
27566 tsk->thread.trap_nr = trapnr;
27567 +
27568 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27569 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27570 + str = "PAX: suspicious stack segment fault";
27571 +#endif
27572 +
27573 die(str, regs, error_code);
27574 }
27575 +
27576 +#ifdef CONFIG_PAX_REFCOUNT
27577 + if (trapnr == X86_TRAP_OF)
27578 + pax_report_refcount_overflow(regs);
27579 +#endif
27580 +
27581 return 0;
27582 }
27583
27584 @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27585 }
27586
27587 static void __kprobes
27588 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27589 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27590 long error_code, siginfo_t *info)
27591 {
27592 struct task_struct *tsk = current;
27593 @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27594 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27595 printk_ratelimit()) {
27596 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27597 - tsk->comm, tsk->pid, str,
27598 + tsk->comm, task_pid_nr(tsk), str,
27599 regs->ip, regs->sp, error_code);
27600 print_vma_addr(" in ", regs->ip);
27601 pr_cont("\n");
27602 @@ -251,6 +263,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27603 tsk->thread.error_code = error_code;
27604 tsk->thread.trap_nr = X86_TRAP_DF;
27605
27606 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
27607 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
27608 + die("grsec: kernel stack overflow detected", regs, error_code);
27609 +#endif
27610 +
27611 #ifdef CONFIG_DOUBLEFAULT
27612 df_debug(regs, error_code);
27613 #endif
27614 @@ -273,7 +290,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27615 conditional_sti(regs);
27616
27617 #ifdef CONFIG_X86_32
27618 - if (regs->flags & X86_VM_MASK) {
27619 + if (v8086_mode(regs)) {
27620 local_irq_enable();
27621 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27622 goto exit;
27623 @@ -281,18 +298,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27624 #endif
27625
27626 tsk = current;
27627 - if (!user_mode(regs)) {
27628 + if (!user_mode_novm(regs)) {
27629 if (fixup_exception(regs))
27630 goto exit;
27631
27632 tsk->thread.error_code = error_code;
27633 tsk->thread.trap_nr = X86_TRAP_GP;
27634 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27635 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27636 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27637 +
27638 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27639 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27640 + die("PAX: suspicious general protection fault", regs, error_code);
27641 + else
27642 +#endif
27643 +
27644 die("general protection fault", regs, error_code);
27645 + }
27646 goto exit;
27647 }
27648
27649 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27650 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27651 + struct mm_struct *mm = tsk->mm;
27652 + unsigned long limit;
27653 +
27654 + down_write(&mm->mmap_sem);
27655 + limit = mm->context.user_cs_limit;
27656 + if (limit < TASK_SIZE) {
27657 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27658 + up_write(&mm->mmap_sem);
27659 + return;
27660 + }
27661 + up_write(&mm->mmap_sem);
27662 + }
27663 +#endif
27664 +
27665 tsk->thread.error_code = error_code;
27666 tsk->thread.trap_nr = X86_TRAP_GP;
27667
27668 @@ -453,7 +494,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27669 /* It's safe to allow irq's after DR6 has been saved */
27670 preempt_conditional_sti(regs);
27671
27672 - if (regs->flags & X86_VM_MASK) {
27673 + if (v8086_mode(regs)) {
27674 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27675 X86_TRAP_DB);
27676 preempt_conditional_cli(regs);
27677 @@ -468,7 +509,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27678 * We already checked v86 mode above, so we can check for kernel mode
27679 * by just checking the CPL of CS.
27680 */
27681 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
27682 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27683 tsk->thread.debugreg6 &= ~DR_STEP;
27684 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27685 regs->flags &= ~X86_EFLAGS_TF;
27686 @@ -500,7 +541,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27687 return;
27688 conditional_sti(regs);
27689
27690 - if (!user_mode_vm(regs))
27691 + if (!user_mode(regs))
27692 {
27693 if (!fixup_exception(regs)) {
27694 task->thread.error_code = error_code;
27695 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27696 index 57e5ce1..20b0040 100644
27697 --- a/arch/x86/kernel/tsc.c
27698 +++ b/arch/x86/kernel/tsc.c
27699 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27700 */
27701 smp_wmb();
27702
27703 - ACCESS_ONCE(c2n->head) = data;
27704 + ACCESS_ONCE_RW(c2n->head) = data;
27705 }
27706
27707 /*
27708 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27709 index 2ed8459..7cf329f 100644
27710 --- a/arch/x86/kernel/uprobes.c
27711 +++ b/arch/x86/kernel/uprobes.c
27712 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27713 int ret = NOTIFY_DONE;
27714
27715 /* We are only interested in userspace traps */
27716 - if (regs && !user_mode_vm(regs))
27717 + if (regs && !user_mode(regs))
27718 return NOTIFY_DONE;
27719
27720 switch (val) {
27721 @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27722
27723 if (ncopied != rasize) {
27724 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27725 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27726 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27727
27728 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27729 }
27730 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27731 index b9242ba..50c5edd 100644
27732 --- a/arch/x86/kernel/verify_cpu.S
27733 +++ b/arch/x86/kernel/verify_cpu.S
27734 @@ -20,6 +20,7 @@
27735 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27736 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27737 * arch/x86/kernel/head_32.S: processor startup
27738 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27739 *
27740 * verify_cpu, returns the status of longmode and SSE in register %eax.
27741 * 0: Success 1: Failure
27742 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27743 index e8edcf5..27f9344 100644
27744 --- a/arch/x86/kernel/vm86_32.c
27745 +++ b/arch/x86/kernel/vm86_32.c
27746 @@ -44,6 +44,7 @@
27747 #include <linux/ptrace.h>
27748 #include <linux/audit.h>
27749 #include <linux/stddef.h>
27750 +#include <linux/grsecurity.h>
27751
27752 #include <asm/uaccess.h>
27753 #include <asm/io.h>
27754 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27755 do_exit(SIGSEGV);
27756 }
27757
27758 - tss = &per_cpu(init_tss, get_cpu());
27759 + tss = init_tss + get_cpu();
27760 current->thread.sp0 = current->thread.saved_sp0;
27761 current->thread.sysenter_cs = __KERNEL_CS;
27762 load_sp0(tss, &current->thread);
27763 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27764
27765 if (tsk->thread.saved_sp0)
27766 return -EPERM;
27767 +
27768 +#ifdef CONFIG_GRKERNSEC_VM86
27769 + if (!capable(CAP_SYS_RAWIO)) {
27770 + gr_handle_vm86();
27771 + return -EPERM;
27772 + }
27773 +#endif
27774 +
27775 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27776 offsetof(struct kernel_vm86_struct, vm86plus) -
27777 sizeof(info.regs));
27778 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27779 int tmp;
27780 struct vm86plus_struct __user *v86;
27781
27782 +#ifdef CONFIG_GRKERNSEC_VM86
27783 + if (!capable(CAP_SYS_RAWIO)) {
27784 + gr_handle_vm86();
27785 + return -EPERM;
27786 + }
27787 +#endif
27788 +
27789 tsk = current;
27790 switch (cmd) {
27791 case VM86_REQUEST_IRQ:
27792 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27793 tsk->thread.saved_fs = info->regs32->fs;
27794 tsk->thread.saved_gs = get_user_gs(info->regs32);
27795
27796 - tss = &per_cpu(init_tss, get_cpu());
27797 + tss = init_tss + get_cpu();
27798 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27799 if (cpu_has_sep)
27800 tsk->thread.sysenter_cs = 0;
27801 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27802 goto cannot_handle;
27803 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27804 goto cannot_handle;
27805 - intr_ptr = (unsigned long __user *) (i << 2);
27806 + intr_ptr = (__force unsigned long __user *) (i << 2);
27807 if (get_user(segoffs, intr_ptr))
27808 goto cannot_handle;
27809 if ((segoffs >> 16) == BIOSSEG)
27810 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27811 index 49edf2d..c0d1362 100644
27812 --- a/arch/x86/kernel/vmlinux.lds.S
27813 +++ b/arch/x86/kernel/vmlinux.lds.S
27814 @@ -26,6 +26,13 @@
27815 #include <asm/page_types.h>
27816 #include <asm/cache.h>
27817 #include <asm/boot.h>
27818 +#include <asm/segment.h>
27819 +
27820 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27821 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27822 +#else
27823 +#define __KERNEL_TEXT_OFFSET 0
27824 +#endif
27825
27826 #undef i386 /* in case the preprocessor is a 32bit one */
27827
27828 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27829
27830 PHDRS {
27831 text PT_LOAD FLAGS(5); /* R_E */
27832 +#ifdef CONFIG_X86_32
27833 + module PT_LOAD FLAGS(5); /* R_E */
27834 +#endif
27835 +#ifdef CONFIG_XEN
27836 + rodata PT_LOAD FLAGS(5); /* R_E */
27837 +#else
27838 + rodata PT_LOAD FLAGS(4); /* R__ */
27839 +#endif
27840 data PT_LOAD FLAGS(6); /* RW_ */
27841 -#ifdef CONFIG_X86_64
27842 + init.begin PT_LOAD FLAGS(6); /* RW_ */
27843 #ifdef CONFIG_SMP
27844 percpu PT_LOAD FLAGS(6); /* RW_ */
27845 #endif
27846 + text.init PT_LOAD FLAGS(5); /* R_E */
27847 + text.exit PT_LOAD FLAGS(5); /* R_E */
27848 init PT_LOAD FLAGS(7); /* RWE */
27849 -#endif
27850 note PT_NOTE FLAGS(0); /* ___ */
27851 }
27852
27853 SECTIONS
27854 {
27855 #ifdef CONFIG_X86_32
27856 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27857 - phys_startup_32 = startup_32 - LOAD_OFFSET;
27858 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27859 #else
27860 - . = __START_KERNEL;
27861 - phys_startup_64 = startup_64 - LOAD_OFFSET;
27862 + . = __START_KERNEL;
27863 #endif
27864
27865 /* Text and read-only data */
27866 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
27867 - _text = .;
27868 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27869 /* bootstrapping code */
27870 +#ifdef CONFIG_X86_32
27871 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27872 +#else
27873 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27874 +#endif
27875 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27876 + _text = .;
27877 HEAD_TEXT
27878 . = ALIGN(8);
27879 _stext = .;
27880 @@ -104,13 +124,47 @@ SECTIONS
27881 IRQENTRY_TEXT
27882 *(.fixup)
27883 *(.gnu.warning)
27884 - /* End of text section */
27885 - _etext = .;
27886 } :text = 0x9090
27887
27888 - NOTES :text :note
27889 + . += __KERNEL_TEXT_OFFSET;
27890
27891 - EXCEPTION_TABLE(16) :text = 0x9090
27892 +#ifdef CONFIG_X86_32
27893 + . = ALIGN(PAGE_SIZE);
27894 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27895 +
27896 +#ifdef CONFIG_PAX_KERNEXEC
27897 + MODULES_EXEC_VADDR = .;
27898 + BYTE(0)
27899 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27900 + . = ALIGN(HPAGE_SIZE) - 1;
27901 + MODULES_EXEC_END = .;
27902 +#endif
27903 +
27904 + } :module
27905 +#endif
27906 +
27907 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27908 + /* End of text section */
27909 + BYTE(0)
27910 + _etext = . - __KERNEL_TEXT_OFFSET;
27911 + }
27912 +
27913 +#ifdef CONFIG_X86_32
27914 + . = ALIGN(PAGE_SIZE);
27915 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27916 + . = ALIGN(PAGE_SIZE);
27917 + *(.empty_zero_page)
27918 + *(.initial_pg_fixmap)
27919 + *(.initial_pg_pmd)
27920 + *(.initial_page_table)
27921 + *(.swapper_pg_dir)
27922 + } :rodata
27923 +#endif
27924 +
27925 + . = ALIGN(PAGE_SIZE);
27926 + NOTES :rodata :note
27927 +
27928 + EXCEPTION_TABLE(16) :rodata
27929
27930 #if defined(CONFIG_DEBUG_RODATA)
27931 /* .text should occupy whole number of pages */
27932 @@ -122,16 +176,20 @@ SECTIONS
27933
27934 /* Data */
27935 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27936 +
27937 +#ifdef CONFIG_PAX_KERNEXEC
27938 + . = ALIGN(HPAGE_SIZE);
27939 +#else
27940 + . = ALIGN(PAGE_SIZE);
27941 +#endif
27942 +
27943 /* Start of data section */
27944 _sdata = .;
27945
27946 /* init_task */
27947 INIT_TASK_DATA(THREAD_SIZE)
27948
27949 -#ifdef CONFIG_X86_32
27950 - /* 32 bit has nosave before _edata */
27951 NOSAVE_DATA
27952 -#endif
27953
27954 PAGE_ALIGNED_DATA(PAGE_SIZE)
27955
27956 @@ -174,12 +232,19 @@ SECTIONS
27957 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
27958
27959 /* Init code and data - will be freed after init */
27960 - . = ALIGN(PAGE_SIZE);
27961 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27962 + BYTE(0)
27963 +
27964 +#ifdef CONFIG_PAX_KERNEXEC
27965 + . = ALIGN(HPAGE_SIZE);
27966 +#else
27967 + . = ALIGN(PAGE_SIZE);
27968 +#endif
27969 +
27970 __init_begin = .; /* paired with __init_end */
27971 - }
27972 + } :init.begin
27973
27974 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27975 +#ifdef CONFIG_SMP
27976 /*
27977 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27978 * output PHDR, so the next output section - .init.text - should
27979 @@ -188,12 +253,27 @@ SECTIONS
27980 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27981 #endif
27982
27983 - INIT_TEXT_SECTION(PAGE_SIZE)
27984 -#ifdef CONFIG_X86_64
27985 - :init
27986 -#endif
27987 + . = ALIGN(PAGE_SIZE);
27988 + init_begin = .;
27989 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27990 + VMLINUX_SYMBOL(_sinittext) = .;
27991 + INIT_TEXT
27992 + VMLINUX_SYMBOL(_einittext) = .;
27993 + . = ALIGN(PAGE_SIZE);
27994 + } :text.init
27995
27996 - INIT_DATA_SECTION(16)
27997 + /*
27998 + * .exit.text is discard at runtime, not link time, to deal with
27999 + * references from .altinstructions and .eh_frame
28000 + */
28001 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28002 + EXIT_TEXT
28003 + . = ALIGN(16);
28004 + } :text.exit
28005 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28006 +
28007 + . = ALIGN(PAGE_SIZE);
28008 + INIT_DATA_SECTION(16) :init
28009
28010 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28011 __x86_cpu_dev_start = .;
28012 @@ -264,19 +344,12 @@ SECTIONS
28013 }
28014
28015 . = ALIGN(8);
28016 - /*
28017 - * .exit.text is discard at runtime, not link time, to deal with
28018 - * references from .altinstructions and .eh_frame
28019 - */
28020 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28021 - EXIT_TEXT
28022 - }
28023
28024 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28025 EXIT_DATA
28026 }
28027
28028 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28029 +#ifndef CONFIG_SMP
28030 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28031 #endif
28032
28033 @@ -295,16 +368,10 @@ SECTIONS
28034 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28035 __smp_locks = .;
28036 *(.smp_locks)
28037 - . = ALIGN(PAGE_SIZE);
28038 __smp_locks_end = .;
28039 + . = ALIGN(PAGE_SIZE);
28040 }
28041
28042 -#ifdef CONFIG_X86_64
28043 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28044 - NOSAVE_DATA
28045 - }
28046 -#endif
28047 -
28048 /* BSS */
28049 . = ALIGN(PAGE_SIZE);
28050 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28051 @@ -320,6 +387,7 @@ SECTIONS
28052 __brk_base = .;
28053 . += 64 * 1024; /* 64k alignment slop space */
28054 *(.brk_reservation) /* areas brk users have reserved */
28055 + . = ALIGN(HPAGE_SIZE);
28056 __brk_limit = .;
28057 }
28058
28059 @@ -346,13 +414,12 @@ SECTIONS
28060 * for the boot processor.
28061 */
28062 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28063 -INIT_PER_CPU(gdt_page);
28064 INIT_PER_CPU(irq_stack_union);
28065
28066 /*
28067 * Build-time check on the image size:
28068 */
28069 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28070 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28071 "kernel image bigger than KERNEL_IMAGE_SIZE");
28072
28073 #ifdef CONFIG_SMP
28074 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28075 index 8b3b3eb..9395aa9 100644
28076 --- a/arch/x86/kernel/vsyscall_64.c
28077 +++ b/arch/x86/kernel/vsyscall_64.c
28078 @@ -54,15 +54,13 @@
28079
28080 DEFINE_VVAR(int, vgetcpu_mode);
28081
28082 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28083 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28084
28085 static int __init vsyscall_setup(char *str)
28086 {
28087 if (str) {
28088 if (!strcmp("emulate", str))
28089 vsyscall_mode = EMULATE;
28090 - else if (!strcmp("native", str))
28091 - vsyscall_mode = NATIVE;
28092 else if (!strcmp("none", str))
28093 vsyscall_mode = NONE;
28094 else
28095 @@ -279,8 +277,7 @@ do_ret:
28096 return true;
28097
28098 sigsegv:
28099 - force_sig(SIGSEGV, current);
28100 - return true;
28101 + do_group_exit(SIGKILL);
28102 }
28103
28104 /*
28105 @@ -332,10 +329,7 @@ void __init map_vsyscall(void)
28106 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28107 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
28108
28109 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
28110 - vsyscall_mode == NATIVE
28111 - ? PAGE_KERNEL_VSYSCALL
28112 - : PAGE_KERNEL_VVAR);
28113 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28114 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
28115 (unsigned long)VSYSCALL_START);
28116
28117 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28118 index 04068192..4d75aa6 100644
28119 --- a/arch/x86/kernel/x8664_ksyms_64.c
28120 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28121 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28122 EXPORT_SYMBOL(copy_user_generic_unrolled);
28123 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28124 EXPORT_SYMBOL(__copy_user_nocache);
28125 -EXPORT_SYMBOL(_copy_from_user);
28126 -EXPORT_SYMBOL(_copy_to_user);
28127
28128 EXPORT_SYMBOL(copy_page);
28129 EXPORT_SYMBOL(clear_page);
28130 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28131 EXPORT_SYMBOL(___preempt_schedule_context);
28132 #endif
28133 #endif
28134 +
28135 +#ifdef CONFIG_PAX_PER_CPU_PGD
28136 +EXPORT_SYMBOL(cpu_pgd);
28137 +#endif
28138 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28139 index e48b674..a451dd9 100644
28140 --- a/arch/x86/kernel/x86_init.c
28141 +++ b/arch/x86/kernel/x86_init.c
28142 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28143 static void default_nmi_init(void) { };
28144 static int default_i8042_detect(void) { return 1; };
28145
28146 -struct x86_platform_ops x86_platform = {
28147 +struct x86_platform_ops x86_platform __read_only = {
28148 .calibrate_tsc = native_calibrate_tsc,
28149 .get_wallclock = mach_get_cmos_time,
28150 .set_wallclock = mach_set_rtc_mmss,
28151 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28152 EXPORT_SYMBOL_GPL(x86_platform);
28153
28154 #if defined(CONFIG_PCI_MSI)
28155 -struct x86_msi_ops x86_msi = {
28156 +struct x86_msi_ops x86_msi __read_only = {
28157 .setup_msi_irqs = native_setup_msi_irqs,
28158 .compose_msi_msg = native_compose_msi_msg,
28159 .teardown_msi_irq = native_teardown_msi_irq,
28160 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28161 }
28162 #endif
28163
28164 -struct x86_io_apic_ops x86_io_apic_ops = {
28165 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28166 .init = native_io_apic_init_mappings,
28167 .read = native_io_apic_read,
28168 .write = native_io_apic_write,
28169 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28170 index a4b451c..8dfe1ad 100644
28171 --- a/arch/x86/kernel/xsave.c
28172 +++ b/arch/x86/kernel/xsave.c
28173 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28174
28175 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28176 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28177 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28178 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28179
28180 if (!use_xsave())
28181 return err;
28182
28183 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28184 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28185
28186 /*
28187 * Read the xstate_bv which we copied (directly from the cpu or
28188 * from the state in task struct) to the user buffers.
28189 */
28190 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28191 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28192
28193 /*
28194 * For legacy compatible, we always set FP/SSE bits in the bit
28195 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28196 */
28197 xstate_bv |= XSTATE_FPSSE;
28198
28199 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28200 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28201
28202 return err;
28203 }
28204 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28205 {
28206 int err;
28207
28208 + buf = (struct xsave_struct __user *)____m(buf);
28209 if (use_xsave())
28210 err = xsave_user(buf);
28211 else if (use_fxsr())
28212 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28213 */
28214 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28215 {
28216 + buf = (void __user *)____m(buf);
28217 if (use_xsave()) {
28218 if ((unsigned long)buf % 64 || fx_only) {
28219 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28220 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28221 index f47a104..5ce59a8 100644
28222 --- a/arch/x86/kvm/cpuid.c
28223 +++ b/arch/x86/kvm/cpuid.c
28224 @@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28225 struct kvm_cpuid2 *cpuid,
28226 struct kvm_cpuid_entry2 __user *entries)
28227 {
28228 - int r;
28229 + int r, i;
28230
28231 r = -E2BIG;
28232 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28233 goto out;
28234 r = -EFAULT;
28235 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28236 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28237 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28238 goto out;
28239 + for (i = 0; i < cpuid->nent; ++i) {
28240 + struct kvm_cpuid_entry2 cpuid_entry;
28241 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28242 + goto out;
28243 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28244 + }
28245 vcpu->arch.cpuid_nent = cpuid->nent;
28246 kvm_apic_set_version(vcpu);
28247 kvm_x86_ops->cpuid_update(vcpu);
28248 @@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28249 struct kvm_cpuid2 *cpuid,
28250 struct kvm_cpuid_entry2 __user *entries)
28251 {
28252 - int r;
28253 + int r, i;
28254
28255 r = -E2BIG;
28256 if (cpuid->nent < vcpu->arch.cpuid_nent)
28257 goto out;
28258 r = -EFAULT;
28259 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28260 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28261 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28262 goto out;
28263 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28264 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28265 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28266 + goto out;
28267 + }
28268 return 0;
28269
28270 out:
28271 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28272 index 0069118..c28ec0a 100644
28273 --- a/arch/x86/kvm/lapic.c
28274 +++ b/arch/x86/kvm/lapic.c
28275 @@ -55,7 +55,7 @@
28276 #define APIC_BUS_CYCLE_NS 1
28277
28278 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28279 -#define apic_debug(fmt, arg...)
28280 +#define apic_debug(fmt, arg...) do {} while (0)
28281
28282 #define APIC_LVT_NUM 6
28283 /* 14 is the version for Xeon and Pentium 8.4.8*/
28284 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28285 index 123efd3..ad7726e 100644
28286 --- a/arch/x86/kvm/paging_tmpl.h
28287 +++ b/arch/x86/kvm/paging_tmpl.h
28288 @@ -331,7 +331,7 @@ retry_walk:
28289 if (unlikely(kvm_is_error_hva(host_addr)))
28290 goto error;
28291
28292 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28293 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28294 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28295 goto error;
28296 walker->ptep_user[walker->level - 1] = ptep_user;
28297 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28298 index 7f4f9c2..67b1db0 100644
28299 --- a/arch/x86/kvm/svm.c
28300 +++ b/arch/x86/kvm/svm.c
28301 @@ -3535,7 +3535,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28302 int cpu = raw_smp_processor_id();
28303
28304 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28305 +
28306 + pax_open_kernel();
28307 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28308 + pax_close_kernel();
28309 +
28310 load_TR_desc();
28311 }
28312
28313 @@ -3936,6 +3940,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28314 #endif
28315 #endif
28316
28317 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28318 + __set_fs(current_thread_info()->addr_limit);
28319 +#endif
28320 +
28321 reload_tss(vcpu);
28322
28323 local_irq_disable();
28324 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28325 index 138ceff..2e584f0 100644
28326 --- a/arch/x86/kvm/vmx.c
28327 +++ b/arch/x86/kvm/vmx.c
28328 @@ -1339,12 +1339,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28329 #endif
28330 }
28331
28332 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28333 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28334 {
28335 vmcs_writel(field, vmcs_readl(field) & ~mask);
28336 }
28337
28338 -static void vmcs_set_bits(unsigned long field, u32 mask)
28339 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28340 {
28341 vmcs_writel(field, vmcs_readl(field) | mask);
28342 }
28343 @@ -1604,7 +1604,11 @@ static void reload_tss(void)
28344 struct desc_struct *descs;
28345
28346 descs = (void *)gdt->address;
28347 +
28348 + pax_open_kernel();
28349 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28350 + pax_close_kernel();
28351 +
28352 load_TR_desc();
28353 }
28354
28355 @@ -1832,6 +1836,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28356 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28357 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28358
28359 +#ifdef CONFIG_PAX_PER_CPU_PGD
28360 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28361 +#endif
28362 +
28363 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28364 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28365 vmx->loaded_vmcs->cpu = cpu;
28366 @@ -2121,7 +2129,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28367 * reads and returns guest's timestamp counter "register"
28368 * guest_tsc = host_tsc + tsc_offset -- 21.3
28369 */
28370 -static u64 guest_read_tsc(void)
28371 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28372 {
28373 u64 host_tsc, tsc_offset;
28374
28375 @@ -3093,8 +3101,11 @@ static __init int hardware_setup(void)
28376 if (!cpu_has_vmx_flexpriority())
28377 flexpriority_enabled = 0;
28378
28379 - if (!cpu_has_vmx_tpr_shadow())
28380 - kvm_x86_ops->update_cr8_intercept = NULL;
28381 + if (!cpu_has_vmx_tpr_shadow()) {
28382 + pax_open_kernel();
28383 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28384 + pax_close_kernel();
28385 + }
28386
28387 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28388 kvm_disable_largepages();
28389 @@ -3105,13 +3116,15 @@ static __init int hardware_setup(void)
28390 if (!cpu_has_vmx_apicv())
28391 enable_apicv = 0;
28392
28393 + pax_open_kernel();
28394 if (enable_apicv)
28395 - kvm_x86_ops->update_cr8_intercept = NULL;
28396 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28397 else {
28398 - kvm_x86_ops->hwapic_irr_update = NULL;
28399 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28400 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28401 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28402 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28403 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28404 }
28405 + pax_close_kernel();
28406
28407 if (nested)
28408 nested_vmx_setup_ctls_msrs();
28409 @@ -4235,7 +4248,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28410
28411 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28412 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28413 +
28414 +#ifndef CONFIG_PAX_PER_CPU_PGD
28415 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28416 +#endif
28417
28418 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28419 #ifdef CONFIG_X86_64
28420 @@ -4257,7 +4273,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28421 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28422 vmx->host_idt_base = dt.address;
28423
28424 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28425 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28426
28427 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28428 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28429 @@ -7333,6 +7349,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28430 "jmp 2f \n\t"
28431 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28432 "2: "
28433 +
28434 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28435 + "ljmp %[cs],$3f\n\t"
28436 + "3: "
28437 +#endif
28438 +
28439 /* Save guest registers, load host registers, keep flags */
28440 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28441 "pop %0 \n\t"
28442 @@ -7385,6 +7407,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28443 #endif
28444 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28445 [wordsize]"i"(sizeof(ulong))
28446 +
28447 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28448 + ,[cs]"i"(__KERNEL_CS)
28449 +#endif
28450 +
28451 : "cc", "memory"
28452 #ifdef CONFIG_X86_64
28453 , "rax", "rbx", "rdi", "rsi"
28454 @@ -7398,7 +7425,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28455 if (debugctlmsr)
28456 update_debugctlmsr(debugctlmsr);
28457
28458 -#ifndef CONFIG_X86_64
28459 +#ifdef CONFIG_X86_32
28460 /*
28461 * The sysexit path does not restore ds/es, so we must set them to
28462 * a reasonable value ourselves.
28463 @@ -7407,8 +7434,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28464 * may be executed in interrupt context, which saves and restore segments
28465 * around it, nullifying its effect.
28466 */
28467 - loadsegment(ds, __USER_DS);
28468 - loadsegment(es, __USER_DS);
28469 + loadsegment(ds, __KERNEL_DS);
28470 + loadsegment(es, __KERNEL_DS);
28471 + loadsegment(ss, __KERNEL_DS);
28472 +
28473 +#ifdef CONFIG_PAX_KERNEXEC
28474 + loadsegment(fs, __KERNEL_PERCPU);
28475 +#endif
28476 +
28477 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28478 + __set_fs(current_thread_info()->addr_limit);
28479 +#endif
28480 +
28481 #endif
28482
28483 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28484 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28485 index 5521f7c..691b7a3 100644
28486 --- a/arch/x86/kvm/x86.c
28487 +++ b/arch/x86/kvm/x86.c
28488 @@ -1822,8 +1822,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28489 {
28490 struct kvm *kvm = vcpu->kvm;
28491 int lm = is_long_mode(vcpu);
28492 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28493 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28494 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28495 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28496 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28497 : kvm->arch.xen_hvm_config.blob_size_32;
28498 u32 page_num = data & ~PAGE_MASK;
28499 @@ -2738,6 +2738,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28500 if (n < msr_list.nmsrs)
28501 goto out;
28502 r = -EFAULT;
28503 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28504 + goto out;
28505 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28506 num_msrs_to_save * sizeof(u32)))
28507 goto out;
28508 @@ -5574,7 +5576,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28509 };
28510 #endif
28511
28512 -int kvm_arch_init(void *opaque)
28513 +int kvm_arch_init(const void *opaque)
28514 {
28515 int r;
28516 struct kvm_x86_ops *ops = opaque;
28517 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28518 index aae9413..d11e829 100644
28519 --- a/arch/x86/lguest/boot.c
28520 +++ b/arch/x86/lguest/boot.c
28521 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28522 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28523 * Launcher to reboot us.
28524 */
28525 -static void lguest_restart(char *reason)
28526 +static __noreturn void lguest_restart(char *reason)
28527 {
28528 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28529 + BUG();
28530 }
28531
28532 /*G:050
28533 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28534 index 00933d5..3a64af9 100644
28535 --- a/arch/x86/lib/atomic64_386_32.S
28536 +++ b/arch/x86/lib/atomic64_386_32.S
28537 @@ -48,6 +48,10 @@ BEGIN(read)
28538 movl (v), %eax
28539 movl 4(v), %edx
28540 RET_ENDP
28541 +BEGIN(read_unchecked)
28542 + movl (v), %eax
28543 + movl 4(v), %edx
28544 +RET_ENDP
28545 #undef v
28546
28547 #define v %esi
28548 @@ -55,6 +59,10 @@ BEGIN(set)
28549 movl %ebx, (v)
28550 movl %ecx, 4(v)
28551 RET_ENDP
28552 +BEGIN(set_unchecked)
28553 + movl %ebx, (v)
28554 + movl %ecx, 4(v)
28555 +RET_ENDP
28556 #undef v
28557
28558 #define v %esi
28559 @@ -70,6 +78,20 @@ RET_ENDP
28560 BEGIN(add)
28561 addl %eax, (v)
28562 adcl %edx, 4(v)
28563 +
28564 +#ifdef CONFIG_PAX_REFCOUNT
28565 + jno 0f
28566 + subl %eax, (v)
28567 + sbbl %edx, 4(v)
28568 + int $4
28569 +0:
28570 + _ASM_EXTABLE(0b, 0b)
28571 +#endif
28572 +
28573 +RET_ENDP
28574 +BEGIN(add_unchecked)
28575 + addl %eax, (v)
28576 + adcl %edx, 4(v)
28577 RET_ENDP
28578 #undef v
28579
28580 @@ -77,6 +99,24 @@ RET_ENDP
28581 BEGIN(add_return)
28582 addl (v), %eax
28583 adcl 4(v), %edx
28584 +
28585 +#ifdef CONFIG_PAX_REFCOUNT
28586 + into
28587 +1234:
28588 + _ASM_EXTABLE(1234b, 2f)
28589 +#endif
28590 +
28591 + movl %eax, (v)
28592 + movl %edx, 4(v)
28593 +
28594 +#ifdef CONFIG_PAX_REFCOUNT
28595 +2:
28596 +#endif
28597 +
28598 +RET_ENDP
28599 +BEGIN(add_return_unchecked)
28600 + addl (v), %eax
28601 + adcl 4(v), %edx
28602 movl %eax, (v)
28603 movl %edx, 4(v)
28604 RET_ENDP
28605 @@ -86,6 +126,20 @@ RET_ENDP
28606 BEGIN(sub)
28607 subl %eax, (v)
28608 sbbl %edx, 4(v)
28609 +
28610 +#ifdef CONFIG_PAX_REFCOUNT
28611 + jno 0f
28612 + addl %eax, (v)
28613 + adcl %edx, 4(v)
28614 + int $4
28615 +0:
28616 + _ASM_EXTABLE(0b, 0b)
28617 +#endif
28618 +
28619 +RET_ENDP
28620 +BEGIN(sub_unchecked)
28621 + subl %eax, (v)
28622 + sbbl %edx, 4(v)
28623 RET_ENDP
28624 #undef v
28625
28626 @@ -96,6 +150,27 @@ BEGIN(sub_return)
28627 sbbl $0, %edx
28628 addl (v), %eax
28629 adcl 4(v), %edx
28630 +
28631 +#ifdef CONFIG_PAX_REFCOUNT
28632 + into
28633 +1234:
28634 + _ASM_EXTABLE(1234b, 2f)
28635 +#endif
28636 +
28637 + movl %eax, (v)
28638 + movl %edx, 4(v)
28639 +
28640 +#ifdef CONFIG_PAX_REFCOUNT
28641 +2:
28642 +#endif
28643 +
28644 +RET_ENDP
28645 +BEGIN(sub_return_unchecked)
28646 + negl %edx
28647 + negl %eax
28648 + sbbl $0, %edx
28649 + addl (v), %eax
28650 + adcl 4(v), %edx
28651 movl %eax, (v)
28652 movl %edx, 4(v)
28653 RET_ENDP
28654 @@ -105,6 +180,20 @@ RET_ENDP
28655 BEGIN(inc)
28656 addl $1, (v)
28657 adcl $0, 4(v)
28658 +
28659 +#ifdef CONFIG_PAX_REFCOUNT
28660 + jno 0f
28661 + subl $1, (v)
28662 + sbbl $0, 4(v)
28663 + int $4
28664 +0:
28665 + _ASM_EXTABLE(0b, 0b)
28666 +#endif
28667 +
28668 +RET_ENDP
28669 +BEGIN(inc_unchecked)
28670 + addl $1, (v)
28671 + adcl $0, 4(v)
28672 RET_ENDP
28673 #undef v
28674
28675 @@ -114,6 +203,26 @@ BEGIN(inc_return)
28676 movl 4(v), %edx
28677 addl $1, %eax
28678 adcl $0, %edx
28679 +
28680 +#ifdef CONFIG_PAX_REFCOUNT
28681 + into
28682 +1234:
28683 + _ASM_EXTABLE(1234b, 2f)
28684 +#endif
28685 +
28686 + movl %eax, (v)
28687 + movl %edx, 4(v)
28688 +
28689 +#ifdef CONFIG_PAX_REFCOUNT
28690 +2:
28691 +#endif
28692 +
28693 +RET_ENDP
28694 +BEGIN(inc_return_unchecked)
28695 + movl (v), %eax
28696 + movl 4(v), %edx
28697 + addl $1, %eax
28698 + adcl $0, %edx
28699 movl %eax, (v)
28700 movl %edx, 4(v)
28701 RET_ENDP
28702 @@ -123,6 +232,20 @@ RET_ENDP
28703 BEGIN(dec)
28704 subl $1, (v)
28705 sbbl $0, 4(v)
28706 +
28707 +#ifdef CONFIG_PAX_REFCOUNT
28708 + jno 0f
28709 + addl $1, (v)
28710 + adcl $0, 4(v)
28711 + int $4
28712 +0:
28713 + _ASM_EXTABLE(0b, 0b)
28714 +#endif
28715 +
28716 +RET_ENDP
28717 +BEGIN(dec_unchecked)
28718 + subl $1, (v)
28719 + sbbl $0, 4(v)
28720 RET_ENDP
28721 #undef v
28722
28723 @@ -132,6 +255,26 @@ BEGIN(dec_return)
28724 movl 4(v), %edx
28725 subl $1, %eax
28726 sbbl $0, %edx
28727 +
28728 +#ifdef CONFIG_PAX_REFCOUNT
28729 + into
28730 +1234:
28731 + _ASM_EXTABLE(1234b, 2f)
28732 +#endif
28733 +
28734 + movl %eax, (v)
28735 + movl %edx, 4(v)
28736 +
28737 +#ifdef CONFIG_PAX_REFCOUNT
28738 +2:
28739 +#endif
28740 +
28741 +RET_ENDP
28742 +BEGIN(dec_return_unchecked)
28743 + movl (v), %eax
28744 + movl 4(v), %edx
28745 + subl $1, %eax
28746 + sbbl $0, %edx
28747 movl %eax, (v)
28748 movl %edx, 4(v)
28749 RET_ENDP
28750 @@ -143,6 +286,13 @@ BEGIN(add_unless)
28751 adcl %edx, %edi
28752 addl (v), %eax
28753 adcl 4(v), %edx
28754 +
28755 +#ifdef CONFIG_PAX_REFCOUNT
28756 + into
28757 +1234:
28758 + _ASM_EXTABLE(1234b, 2f)
28759 +#endif
28760 +
28761 cmpl %eax, %ecx
28762 je 3f
28763 1:
28764 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28765 1:
28766 addl $1, %eax
28767 adcl $0, %edx
28768 +
28769 +#ifdef CONFIG_PAX_REFCOUNT
28770 + into
28771 +1234:
28772 + _ASM_EXTABLE(1234b, 2f)
28773 +#endif
28774 +
28775 movl %eax, (v)
28776 movl %edx, 4(v)
28777 movl $1, %eax
28778 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28779 movl 4(v), %edx
28780 subl $1, %eax
28781 sbbl $0, %edx
28782 +
28783 +#ifdef CONFIG_PAX_REFCOUNT
28784 + into
28785 +1234:
28786 + _ASM_EXTABLE(1234b, 1f)
28787 +#endif
28788 +
28789 js 1f
28790 movl %eax, (v)
28791 movl %edx, 4(v)
28792 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28793 index f5cc9eb..51fa319 100644
28794 --- a/arch/x86/lib/atomic64_cx8_32.S
28795 +++ b/arch/x86/lib/atomic64_cx8_32.S
28796 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28797 CFI_STARTPROC
28798
28799 read64 %ecx
28800 + pax_force_retaddr
28801 ret
28802 CFI_ENDPROC
28803 ENDPROC(atomic64_read_cx8)
28804
28805 +ENTRY(atomic64_read_unchecked_cx8)
28806 + CFI_STARTPROC
28807 +
28808 + read64 %ecx
28809 + pax_force_retaddr
28810 + ret
28811 + CFI_ENDPROC
28812 +ENDPROC(atomic64_read_unchecked_cx8)
28813 +
28814 ENTRY(atomic64_set_cx8)
28815 CFI_STARTPROC
28816
28817 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28818 cmpxchg8b (%esi)
28819 jne 1b
28820
28821 + pax_force_retaddr
28822 ret
28823 CFI_ENDPROC
28824 ENDPROC(atomic64_set_cx8)
28825
28826 +ENTRY(atomic64_set_unchecked_cx8)
28827 + CFI_STARTPROC
28828 +
28829 +1:
28830 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
28831 + * are atomic on 586 and newer */
28832 + cmpxchg8b (%esi)
28833 + jne 1b
28834 +
28835 + pax_force_retaddr
28836 + ret
28837 + CFI_ENDPROC
28838 +ENDPROC(atomic64_set_unchecked_cx8)
28839 +
28840 ENTRY(atomic64_xchg_cx8)
28841 CFI_STARTPROC
28842
28843 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28844 cmpxchg8b (%esi)
28845 jne 1b
28846
28847 + pax_force_retaddr
28848 ret
28849 CFI_ENDPROC
28850 ENDPROC(atomic64_xchg_cx8)
28851
28852 -.macro addsub_return func ins insc
28853 -ENTRY(atomic64_\func\()_return_cx8)
28854 +.macro addsub_return func ins insc unchecked=""
28855 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28856 CFI_STARTPROC
28857 SAVE ebp
28858 SAVE ebx
28859 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28860 movl %edx, %ecx
28861 \ins\()l %esi, %ebx
28862 \insc\()l %edi, %ecx
28863 +
28864 +.ifb \unchecked
28865 +#ifdef CONFIG_PAX_REFCOUNT
28866 + into
28867 +2:
28868 + _ASM_EXTABLE(2b, 3f)
28869 +#endif
28870 +.endif
28871 +
28872 LOCK_PREFIX
28873 cmpxchg8b (%ebp)
28874 jne 1b
28875 -
28876 -10:
28877 movl %ebx, %eax
28878 movl %ecx, %edx
28879 +
28880 +.ifb \unchecked
28881 +#ifdef CONFIG_PAX_REFCOUNT
28882 +3:
28883 +#endif
28884 +.endif
28885 +
28886 RESTORE edi
28887 RESTORE esi
28888 RESTORE ebx
28889 RESTORE ebp
28890 + pax_force_retaddr
28891 ret
28892 CFI_ENDPROC
28893 -ENDPROC(atomic64_\func\()_return_cx8)
28894 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28895 .endm
28896
28897 addsub_return add add adc
28898 addsub_return sub sub sbb
28899 +addsub_return add add adc _unchecked
28900 +addsub_return sub sub sbb _unchecked
28901
28902 -.macro incdec_return func ins insc
28903 -ENTRY(atomic64_\func\()_return_cx8)
28904 +.macro incdec_return func ins insc unchecked=""
28905 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28906 CFI_STARTPROC
28907 SAVE ebx
28908
28909 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28910 movl %edx, %ecx
28911 \ins\()l $1, %ebx
28912 \insc\()l $0, %ecx
28913 +
28914 +.ifb \unchecked
28915 +#ifdef CONFIG_PAX_REFCOUNT
28916 + into
28917 +2:
28918 + _ASM_EXTABLE(2b, 3f)
28919 +#endif
28920 +.endif
28921 +
28922 LOCK_PREFIX
28923 cmpxchg8b (%esi)
28924 jne 1b
28925
28926 -10:
28927 movl %ebx, %eax
28928 movl %ecx, %edx
28929 +
28930 +.ifb \unchecked
28931 +#ifdef CONFIG_PAX_REFCOUNT
28932 +3:
28933 +#endif
28934 +.endif
28935 +
28936 RESTORE ebx
28937 + pax_force_retaddr
28938 ret
28939 CFI_ENDPROC
28940 -ENDPROC(atomic64_\func\()_return_cx8)
28941 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28942 .endm
28943
28944 incdec_return inc add adc
28945 incdec_return dec sub sbb
28946 +incdec_return inc add adc _unchecked
28947 +incdec_return dec sub sbb _unchecked
28948
28949 ENTRY(atomic64_dec_if_positive_cx8)
28950 CFI_STARTPROC
28951 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28952 movl %edx, %ecx
28953 subl $1, %ebx
28954 sbb $0, %ecx
28955 +
28956 +#ifdef CONFIG_PAX_REFCOUNT
28957 + into
28958 +1234:
28959 + _ASM_EXTABLE(1234b, 2f)
28960 +#endif
28961 +
28962 js 2f
28963 LOCK_PREFIX
28964 cmpxchg8b (%esi)
28965 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28966 movl %ebx, %eax
28967 movl %ecx, %edx
28968 RESTORE ebx
28969 + pax_force_retaddr
28970 ret
28971 CFI_ENDPROC
28972 ENDPROC(atomic64_dec_if_positive_cx8)
28973 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28974 movl %edx, %ecx
28975 addl %ebp, %ebx
28976 adcl %edi, %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 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28988 CFI_ADJUST_CFA_OFFSET -8
28989 RESTORE ebx
28990 RESTORE ebp
28991 + pax_force_retaddr
28992 ret
28993 4:
28994 cmpl %edx, 4(%esp)
28995 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28996 xorl %ecx, %ecx
28997 addl $1, %ebx
28998 adcl %edx, %ecx
28999 +
29000 +#ifdef CONFIG_PAX_REFCOUNT
29001 + into
29002 +1234:
29003 + _ASM_EXTABLE(1234b, 3f)
29004 +#endif
29005 +
29006 LOCK_PREFIX
29007 cmpxchg8b (%esi)
29008 jne 1b
29009 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29010 movl $1, %eax
29011 3:
29012 RESTORE ebx
29013 + pax_force_retaddr
29014 ret
29015 CFI_ENDPROC
29016 ENDPROC(atomic64_inc_not_zero_cx8)
29017 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29018 index e78b8ee..7e173a8 100644
29019 --- a/arch/x86/lib/checksum_32.S
29020 +++ b/arch/x86/lib/checksum_32.S
29021 @@ -29,7 +29,8 @@
29022 #include <asm/dwarf2.h>
29023 #include <asm/errno.h>
29024 #include <asm/asm.h>
29025 -
29026 +#include <asm/segment.h>
29027 +
29028 /*
29029 * computes a partial checksum, e.g. for TCP/UDP fragments
29030 */
29031 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29032
29033 #define ARGBASE 16
29034 #define FP 12
29035 -
29036 -ENTRY(csum_partial_copy_generic)
29037 +
29038 +ENTRY(csum_partial_copy_generic_to_user)
29039 CFI_STARTPROC
29040 +
29041 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29042 + pushl_cfi %gs
29043 + popl_cfi %es
29044 + jmp csum_partial_copy_generic
29045 +#endif
29046 +
29047 +ENTRY(csum_partial_copy_generic_from_user)
29048 +
29049 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29050 + pushl_cfi %gs
29051 + popl_cfi %ds
29052 +#endif
29053 +
29054 +ENTRY(csum_partial_copy_generic)
29055 subl $4,%esp
29056 CFI_ADJUST_CFA_OFFSET 4
29057 pushl_cfi %edi
29058 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29059 jmp 4f
29060 SRC(1: movw (%esi), %bx )
29061 addl $2, %esi
29062 -DST( movw %bx, (%edi) )
29063 +DST( movw %bx, %es:(%edi) )
29064 addl $2, %edi
29065 addw %bx, %ax
29066 adcl $0, %eax
29067 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29068 SRC(1: movl (%esi), %ebx )
29069 SRC( movl 4(%esi), %edx )
29070 adcl %ebx, %eax
29071 -DST( movl %ebx, (%edi) )
29072 +DST( movl %ebx, %es:(%edi) )
29073 adcl %edx, %eax
29074 -DST( movl %edx, 4(%edi) )
29075 +DST( movl %edx, %es:4(%edi) )
29076
29077 SRC( movl 8(%esi), %ebx )
29078 SRC( movl 12(%esi), %edx )
29079 adcl %ebx, %eax
29080 -DST( movl %ebx, 8(%edi) )
29081 +DST( movl %ebx, %es:8(%edi) )
29082 adcl %edx, %eax
29083 -DST( movl %edx, 12(%edi) )
29084 +DST( movl %edx, %es:12(%edi) )
29085
29086 SRC( movl 16(%esi), %ebx )
29087 SRC( movl 20(%esi), %edx )
29088 adcl %ebx, %eax
29089 -DST( movl %ebx, 16(%edi) )
29090 +DST( movl %ebx, %es:16(%edi) )
29091 adcl %edx, %eax
29092 -DST( movl %edx, 20(%edi) )
29093 +DST( movl %edx, %es:20(%edi) )
29094
29095 SRC( movl 24(%esi), %ebx )
29096 SRC( movl 28(%esi), %edx )
29097 adcl %ebx, %eax
29098 -DST( movl %ebx, 24(%edi) )
29099 +DST( movl %ebx, %es:24(%edi) )
29100 adcl %edx, %eax
29101 -DST( movl %edx, 28(%edi) )
29102 +DST( movl %edx, %es:28(%edi) )
29103
29104 lea 32(%esi), %esi
29105 lea 32(%edi), %edi
29106 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29107 shrl $2, %edx # This clears CF
29108 SRC(3: movl (%esi), %ebx )
29109 adcl %ebx, %eax
29110 -DST( movl %ebx, (%edi) )
29111 +DST( movl %ebx, %es:(%edi) )
29112 lea 4(%esi), %esi
29113 lea 4(%edi), %edi
29114 dec %edx
29115 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29116 jb 5f
29117 SRC( movw (%esi), %cx )
29118 leal 2(%esi), %esi
29119 -DST( movw %cx, (%edi) )
29120 +DST( movw %cx, %es:(%edi) )
29121 leal 2(%edi), %edi
29122 je 6f
29123 shll $16,%ecx
29124 SRC(5: movb (%esi), %cl )
29125 -DST( movb %cl, (%edi) )
29126 +DST( movb %cl, %es:(%edi) )
29127 6: addl %ecx, %eax
29128 adcl $0, %eax
29129 7:
29130 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29131
29132 6001:
29133 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29134 - movl $-EFAULT, (%ebx)
29135 + movl $-EFAULT, %ss:(%ebx)
29136
29137 # zero the complete destination - computing the rest
29138 # is too much work
29139 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29140
29141 6002:
29142 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29143 - movl $-EFAULT,(%ebx)
29144 + movl $-EFAULT,%ss:(%ebx)
29145 jmp 5000b
29146
29147 .previous
29148
29149 + pushl_cfi %ss
29150 + popl_cfi %ds
29151 + pushl_cfi %ss
29152 + popl_cfi %es
29153 popl_cfi %ebx
29154 CFI_RESTORE ebx
29155 popl_cfi %esi
29156 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29157 popl_cfi %ecx # equivalent to addl $4,%esp
29158 ret
29159 CFI_ENDPROC
29160 -ENDPROC(csum_partial_copy_generic)
29161 +ENDPROC(csum_partial_copy_generic_to_user)
29162
29163 #else
29164
29165 /* Version for PentiumII/PPro */
29166
29167 #define ROUND1(x) \
29168 + nop; nop; nop; \
29169 SRC(movl x(%esi), %ebx ) ; \
29170 addl %ebx, %eax ; \
29171 - DST(movl %ebx, x(%edi) ) ;
29172 + DST(movl %ebx, %es:x(%edi)) ;
29173
29174 #define ROUND(x) \
29175 + nop; nop; nop; \
29176 SRC(movl x(%esi), %ebx ) ; \
29177 adcl %ebx, %eax ; \
29178 - DST(movl %ebx, x(%edi) ) ;
29179 + DST(movl %ebx, %es:x(%edi)) ;
29180
29181 #define ARGBASE 12
29182 -
29183 -ENTRY(csum_partial_copy_generic)
29184 +
29185 +ENTRY(csum_partial_copy_generic_to_user)
29186 CFI_STARTPROC
29187 +
29188 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29189 + pushl_cfi %gs
29190 + popl_cfi %es
29191 + jmp csum_partial_copy_generic
29192 +#endif
29193 +
29194 +ENTRY(csum_partial_copy_generic_from_user)
29195 +
29196 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29197 + pushl_cfi %gs
29198 + popl_cfi %ds
29199 +#endif
29200 +
29201 +ENTRY(csum_partial_copy_generic)
29202 pushl_cfi %ebx
29203 CFI_REL_OFFSET ebx, 0
29204 pushl_cfi %edi
29205 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29206 subl %ebx, %edi
29207 lea -1(%esi),%edx
29208 andl $-32,%edx
29209 - lea 3f(%ebx,%ebx), %ebx
29210 + lea 3f(%ebx,%ebx,2), %ebx
29211 testl %esi, %esi
29212 jmp *%ebx
29213 1: addl $64,%esi
29214 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29215 jb 5f
29216 SRC( movw (%esi), %dx )
29217 leal 2(%esi), %esi
29218 -DST( movw %dx, (%edi) )
29219 +DST( movw %dx, %es:(%edi) )
29220 leal 2(%edi), %edi
29221 je 6f
29222 shll $16,%edx
29223 5:
29224 SRC( movb (%esi), %dl )
29225 -DST( movb %dl, (%edi) )
29226 +DST( movb %dl, %es:(%edi) )
29227 6: addl %edx, %eax
29228 adcl $0, %eax
29229 7:
29230 .section .fixup, "ax"
29231 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29232 - movl $-EFAULT, (%ebx)
29233 + movl $-EFAULT, %ss:(%ebx)
29234 # zero the complete destination (computing the rest is too much work)
29235 movl ARGBASE+8(%esp),%edi # dst
29236 movl ARGBASE+12(%esp),%ecx # len
29237 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29238 rep; stosb
29239 jmp 7b
29240 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29241 - movl $-EFAULT, (%ebx)
29242 + movl $-EFAULT, %ss:(%ebx)
29243 jmp 7b
29244 .previous
29245
29246 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29247 + pushl_cfi %ss
29248 + popl_cfi %ds
29249 + pushl_cfi %ss
29250 + popl_cfi %es
29251 +#endif
29252 +
29253 popl_cfi %esi
29254 CFI_RESTORE esi
29255 popl_cfi %edi
29256 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29257 CFI_RESTORE ebx
29258 ret
29259 CFI_ENDPROC
29260 -ENDPROC(csum_partial_copy_generic)
29261 +ENDPROC(csum_partial_copy_generic_to_user)
29262
29263 #undef ROUND
29264 #undef ROUND1
29265 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29266 index f2145cf..cea889d 100644
29267 --- a/arch/x86/lib/clear_page_64.S
29268 +++ b/arch/x86/lib/clear_page_64.S
29269 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29270 movl $4096/8,%ecx
29271 xorl %eax,%eax
29272 rep stosq
29273 + pax_force_retaddr
29274 ret
29275 CFI_ENDPROC
29276 ENDPROC(clear_page_c)
29277 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29278 movl $4096,%ecx
29279 xorl %eax,%eax
29280 rep stosb
29281 + pax_force_retaddr
29282 ret
29283 CFI_ENDPROC
29284 ENDPROC(clear_page_c_e)
29285 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29286 leaq 64(%rdi),%rdi
29287 jnz .Lloop
29288 nop
29289 + pax_force_retaddr
29290 ret
29291 CFI_ENDPROC
29292 .Lclear_page_end:
29293 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29294
29295 #include <asm/cpufeature.h>
29296
29297 - .section .altinstr_replacement,"ax"
29298 + .section .altinstr_replacement,"a"
29299 1: .byte 0xeb /* jmp <disp8> */
29300 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29301 2: .byte 0xeb /* jmp <disp8> */
29302 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29303 index 1e572c5..2a162cd 100644
29304 --- a/arch/x86/lib/cmpxchg16b_emu.S
29305 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29306 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29307
29308 popf
29309 mov $1, %al
29310 + pax_force_retaddr
29311 ret
29312
29313 not_same:
29314 popf
29315 xor %al,%al
29316 + pax_force_retaddr
29317 ret
29318
29319 CFI_ENDPROC
29320 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29321 index 176cca6..e0d658e 100644
29322 --- a/arch/x86/lib/copy_page_64.S
29323 +++ b/arch/x86/lib/copy_page_64.S
29324 @@ -9,6 +9,7 @@ copy_page_rep:
29325 CFI_STARTPROC
29326 movl $4096/8, %ecx
29327 rep movsq
29328 + pax_force_retaddr
29329 ret
29330 CFI_ENDPROC
29331 ENDPROC(copy_page_rep)
29332 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29333 CFI_ADJUST_CFA_OFFSET 2*8
29334 movq %rbx, (%rsp)
29335 CFI_REL_OFFSET rbx, 0
29336 - movq %r12, 1*8(%rsp)
29337 - CFI_REL_OFFSET r12, 1*8
29338 + movq %r13, 1*8(%rsp)
29339 + CFI_REL_OFFSET r13, 1*8
29340
29341 movl $(4096/64)-5, %ecx
29342 .p2align 4
29343 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29344 movq 0x8*4(%rsi), %r9
29345 movq 0x8*5(%rsi), %r10
29346 movq 0x8*6(%rsi), %r11
29347 - movq 0x8*7(%rsi), %r12
29348 + movq 0x8*7(%rsi), %r13
29349
29350 prefetcht0 5*64(%rsi)
29351
29352 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29353 movq %r9, 0x8*4(%rdi)
29354 movq %r10, 0x8*5(%rdi)
29355 movq %r11, 0x8*6(%rdi)
29356 - movq %r12, 0x8*7(%rdi)
29357 + movq %r13, 0x8*7(%rdi)
29358
29359 leaq 64 (%rsi), %rsi
29360 leaq 64 (%rdi), %rdi
29361 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29362 movq 0x8*4(%rsi), %r9
29363 movq 0x8*5(%rsi), %r10
29364 movq 0x8*6(%rsi), %r11
29365 - movq 0x8*7(%rsi), %r12
29366 + movq 0x8*7(%rsi), %r13
29367
29368 movq %rax, 0x8*0(%rdi)
29369 movq %rbx, 0x8*1(%rdi)
29370 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29371 movq %r9, 0x8*4(%rdi)
29372 movq %r10, 0x8*5(%rdi)
29373 movq %r11, 0x8*6(%rdi)
29374 - movq %r12, 0x8*7(%rdi)
29375 + movq %r13, 0x8*7(%rdi)
29376
29377 leaq 64(%rdi), %rdi
29378 leaq 64(%rsi), %rsi
29379 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29380
29381 movq (%rsp), %rbx
29382 CFI_RESTORE rbx
29383 - movq 1*8(%rsp), %r12
29384 - CFI_RESTORE r12
29385 + movq 1*8(%rsp), %r13
29386 + CFI_RESTORE r13
29387 addq $2*8, %rsp
29388 CFI_ADJUST_CFA_OFFSET -2*8
29389 + pax_force_retaddr
29390 ret
29391 .Lcopy_page_end:
29392 CFI_ENDPROC
29393 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29394
29395 #include <asm/cpufeature.h>
29396
29397 - .section .altinstr_replacement,"ax"
29398 + .section .altinstr_replacement,"a"
29399 1: .byte 0xeb /* jmp <disp8> */
29400 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29401 2:
29402 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29403 index dee945d..a84067b 100644
29404 --- a/arch/x86/lib/copy_user_64.S
29405 +++ b/arch/x86/lib/copy_user_64.S
29406 @@ -18,31 +18,7 @@
29407 #include <asm/alternative-asm.h>
29408 #include <asm/asm.h>
29409 #include <asm/smap.h>
29410 -
29411 -/*
29412 - * By placing feature2 after feature1 in altinstructions section, we logically
29413 - * implement:
29414 - * If CPU has feature2, jmp to alt2 is used
29415 - * else if CPU has feature1, jmp to alt1 is used
29416 - * else jmp to orig is used.
29417 - */
29418 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29419 -0:
29420 - .byte 0xe9 /* 32bit jump */
29421 - .long \orig-1f /* by default jump to orig */
29422 -1:
29423 - .section .altinstr_replacement,"ax"
29424 -2: .byte 0xe9 /* near jump with 32bit immediate */
29425 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29426 -3: .byte 0xe9 /* near jump with 32bit immediate */
29427 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29428 - .previous
29429 -
29430 - .section .altinstructions,"a"
29431 - altinstruction_entry 0b,2b,\feature1,5,5
29432 - altinstruction_entry 0b,3b,\feature2,5,5
29433 - .previous
29434 - .endm
29435 +#include <asm/pgtable.h>
29436
29437 .macro ALIGN_DESTINATION
29438 #ifdef FIX_ALIGNMENT
29439 @@ -70,52 +46,6 @@
29440 #endif
29441 .endm
29442
29443 -/* Standard copy_to_user with segment limit checking */
29444 -ENTRY(_copy_to_user)
29445 - CFI_STARTPROC
29446 - GET_THREAD_INFO(%rax)
29447 - movq %rdi,%rcx
29448 - addq %rdx,%rcx
29449 - jc bad_to_user
29450 - cmpq TI_addr_limit(%rax),%rcx
29451 - ja bad_to_user
29452 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29453 - copy_user_generic_unrolled,copy_user_generic_string, \
29454 - copy_user_enhanced_fast_string
29455 - CFI_ENDPROC
29456 -ENDPROC(_copy_to_user)
29457 -
29458 -/* Standard copy_from_user with segment limit checking */
29459 -ENTRY(_copy_from_user)
29460 - CFI_STARTPROC
29461 - GET_THREAD_INFO(%rax)
29462 - movq %rsi,%rcx
29463 - addq %rdx,%rcx
29464 - jc bad_from_user
29465 - cmpq TI_addr_limit(%rax),%rcx
29466 - ja bad_from_user
29467 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29468 - copy_user_generic_unrolled,copy_user_generic_string, \
29469 - copy_user_enhanced_fast_string
29470 - CFI_ENDPROC
29471 -ENDPROC(_copy_from_user)
29472 -
29473 - .section .fixup,"ax"
29474 - /* must zero dest */
29475 -ENTRY(bad_from_user)
29476 -bad_from_user:
29477 - CFI_STARTPROC
29478 - movl %edx,%ecx
29479 - xorl %eax,%eax
29480 - rep
29481 - stosb
29482 -bad_to_user:
29483 - movl %edx,%eax
29484 - ret
29485 - CFI_ENDPROC
29486 -ENDPROC(bad_from_user)
29487 - .previous
29488 -
29489 /*
29490 * copy_user_generic_unrolled - memory copy with exception handling.
29491 * This version is for CPUs like P4 that don't have efficient micro
29492 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29493 */
29494 ENTRY(copy_user_generic_unrolled)
29495 CFI_STARTPROC
29496 + ASM_PAX_OPEN_USERLAND
29497 ASM_STAC
29498 cmpl $8,%edx
29499 jb 20f /* less then 8 bytes, go to byte copy loop */
29500 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29501 jnz 21b
29502 23: xor %eax,%eax
29503 ASM_CLAC
29504 + ASM_PAX_CLOSE_USERLAND
29505 + pax_force_retaddr
29506 ret
29507
29508 .section .fixup,"ax"
29509 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29510 */
29511 ENTRY(copy_user_generic_string)
29512 CFI_STARTPROC
29513 + ASM_PAX_OPEN_USERLAND
29514 ASM_STAC
29515 cmpl $8,%edx
29516 jb 2f /* less than 8 bytes, go to byte copy loop */
29517 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29518 movsb
29519 xorl %eax,%eax
29520 ASM_CLAC
29521 + ASM_PAX_CLOSE_USERLAND
29522 + pax_force_retaddr
29523 ret
29524
29525 .section .fixup,"ax"
29526 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29527 */
29528 ENTRY(copy_user_enhanced_fast_string)
29529 CFI_STARTPROC
29530 + ASM_PAX_OPEN_USERLAND
29531 ASM_STAC
29532 movl %edx,%ecx
29533 1: rep
29534 movsb
29535 xorl %eax,%eax
29536 ASM_CLAC
29537 + ASM_PAX_CLOSE_USERLAND
29538 + pax_force_retaddr
29539 ret
29540
29541 .section .fixup,"ax"
29542 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29543 index 6a4f43c..c70fb52 100644
29544 --- a/arch/x86/lib/copy_user_nocache_64.S
29545 +++ b/arch/x86/lib/copy_user_nocache_64.S
29546 @@ -8,6 +8,7 @@
29547
29548 #include <linux/linkage.h>
29549 #include <asm/dwarf2.h>
29550 +#include <asm/alternative-asm.h>
29551
29552 #define FIX_ALIGNMENT 1
29553
29554 @@ -16,6 +17,7 @@
29555 #include <asm/thread_info.h>
29556 #include <asm/asm.h>
29557 #include <asm/smap.h>
29558 +#include <asm/pgtable.h>
29559
29560 .macro ALIGN_DESTINATION
29561 #ifdef FIX_ALIGNMENT
29562 @@ -49,6 +51,16 @@
29563 */
29564 ENTRY(__copy_user_nocache)
29565 CFI_STARTPROC
29566 +
29567 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29568 + mov pax_user_shadow_base,%rcx
29569 + cmp %rcx,%rsi
29570 + jae 1f
29571 + add %rcx,%rsi
29572 +1:
29573 +#endif
29574 +
29575 + ASM_PAX_OPEN_USERLAND
29576 ASM_STAC
29577 cmpl $8,%edx
29578 jb 20f /* less then 8 bytes, go to byte copy loop */
29579 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29580 jnz 21b
29581 23: xorl %eax,%eax
29582 ASM_CLAC
29583 + ASM_PAX_CLOSE_USERLAND
29584 sfence
29585 + pax_force_retaddr
29586 ret
29587
29588 .section .fixup,"ax"
29589 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29590 index 2419d5f..fe52d0e 100644
29591 --- a/arch/x86/lib/csum-copy_64.S
29592 +++ b/arch/x86/lib/csum-copy_64.S
29593 @@ -9,6 +9,7 @@
29594 #include <asm/dwarf2.h>
29595 #include <asm/errno.h>
29596 #include <asm/asm.h>
29597 +#include <asm/alternative-asm.h>
29598
29599 /*
29600 * Checksum copy with exception handling.
29601 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29602 CFI_ADJUST_CFA_OFFSET 7*8
29603 movq %rbx, 2*8(%rsp)
29604 CFI_REL_OFFSET rbx, 2*8
29605 - movq %r12, 3*8(%rsp)
29606 - CFI_REL_OFFSET r12, 3*8
29607 + movq %r15, 3*8(%rsp)
29608 + CFI_REL_OFFSET r15, 3*8
29609 movq %r14, 4*8(%rsp)
29610 CFI_REL_OFFSET r14, 4*8
29611 movq %r13, 5*8(%rsp)
29612 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29613 movl %edx, %ecx
29614
29615 xorl %r9d, %r9d
29616 - movq %rcx, %r12
29617 + movq %rcx, %r15
29618
29619 - shrq $6, %r12
29620 + shrq $6, %r15
29621 jz .Lhandle_tail /* < 64 */
29622
29623 clc
29624
29625 /* main loop. clear in 64 byte blocks */
29626 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29627 - /* r11: temp3, rdx: temp4, r12 loopcnt */
29628 + /* r11: temp3, rdx: temp4, r15 loopcnt */
29629 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29630 .p2align 4
29631 .Lloop:
29632 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29633 adcq %r14, %rax
29634 adcq %r13, %rax
29635
29636 - decl %r12d
29637 + decl %r15d
29638
29639 dest
29640 movq %rbx, (%rsi)
29641 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29642 .Lende:
29643 movq 2*8(%rsp), %rbx
29644 CFI_RESTORE rbx
29645 - movq 3*8(%rsp), %r12
29646 - CFI_RESTORE r12
29647 + movq 3*8(%rsp), %r15
29648 + CFI_RESTORE r15
29649 movq 4*8(%rsp), %r14
29650 CFI_RESTORE r14
29651 movq 5*8(%rsp), %r13
29652 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29653 CFI_RESTORE rbp
29654 addq $7*8, %rsp
29655 CFI_ADJUST_CFA_OFFSET -7*8
29656 + pax_force_retaddr
29657 ret
29658 CFI_RESTORE_STATE
29659
29660 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29661 index 7609e0e..b449b98 100644
29662 --- a/arch/x86/lib/csum-wrappers_64.c
29663 +++ b/arch/x86/lib/csum-wrappers_64.c
29664 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29665 len -= 2;
29666 }
29667 }
29668 + pax_open_userland();
29669 stac();
29670 - isum = csum_partial_copy_generic((__force const void *)src,
29671 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29672 dst, len, isum, errp, NULL);
29673 clac();
29674 + pax_close_userland();
29675 if (unlikely(*errp))
29676 goto out_err;
29677
29678 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29679 }
29680
29681 *errp = 0;
29682 + pax_open_userland();
29683 stac();
29684 - ret = csum_partial_copy_generic(src, (void __force *)dst,
29685 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29686 len, isum, NULL, errp);
29687 clac();
29688 + pax_close_userland();
29689 return ret;
29690 }
29691 EXPORT_SYMBOL(csum_partial_copy_to_user);
29692 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29693 index a451235..1daa956 100644
29694 --- a/arch/x86/lib/getuser.S
29695 +++ b/arch/x86/lib/getuser.S
29696 @@ -33,17 +33,40 @@
29697 #include <asm/thread_info.h>
29698 #include <asm/asm.h>
29699 #include <asm/smap.h>
29700 +#include <asm/segment.h>
29701 +#include <asm/pgtable.h>
29702 +#include <asm/alternative-asm.h>
29703 +
29704 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29705 +#define __copyuser_seg gs;
29706 +#else
29707 +#define __copyuser_seg
29708 +#endif
29709
29710 .text
29711 ENTRY(__get_user_1)
29712 CFI_STARTPROC
29713 +
29714 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29715 GET_THREAD_INFO(%_ASM_DX)
29716 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29717 jae bad_get_user
29718 ASM_STAC
29719 -1: movzbl (%_ASM_AX),%edx
29720 +
29721 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29722 + mov pax_user_shadow_base,%_ASM_DX
29723 + cmp %_ASM_DX,%_ASM_AX
29724 + jae 1234f
29725 + add %_ASM_DX,%_ASM_AX
29726 +1234:
29727 +#endif
29728 +
29729 +#endif
29730 +
29731 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
29732 xor %eax,%eax
29733 ASM_CLAC
29734 + pax_force_retaddr
29735 ret
29736 CFI_ENDPROC
29737 ENDPROC(__get_user_1)
29738 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29739 ENTRY(__get_user_2)
29740 CFI_STARTPROC
29741 add $1,%_ASM_AX
29742 +
29743 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29744 jc bad_get_user
29745 GET_THREAD_INFO(%_ASM_DX)
29746 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29747 jae bad_get_user
29748 ASM_STAC
29749 -2: movzwl -1(%_ASM_AX),%edx
29750 +
29751 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29752 + mov pax_user_shadow_base,%_ASM_DX
29753 + cmp %_ASM_DX,%_ASM_AX
29754 + jae 1234f
29755 + add %_ASM_DX,%_ASM_AX
29756 +1234:
29757 +#endif
29758 +
29759 +#endif
29760 +
29761 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29762 xor %eax,%eax
29763 ASM_CLAC
29764 + pax_force_retaddr
29765 ret
29766 CFI_ENDPROC
29767 ENDPROC(__get_user_2)
29768 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29769 ENTRY(__get_user_4)
29770 CFI_STARTPROC
29771 add $3,%_ASM_AX
29772 +
29773 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29774 jc bad_get_user
29775 GET_THREAD_INFO(%_ASM_DX)
29776 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29777 jae bad_get_user
29778 ASM_STAC
29779 -3: movl -3(%_ASM_AX),%edx
29780 +
29781 +#if defined(CONFIG_X86_64) && defined(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 +#endif
29790 +
29791 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
29792 xor %eax,%eax
29793 ASM_CLAC
29794 + pax_force_retaddr
29795 ret
29796 CFI_ENDPROC
29797 ENDPROC(__get_user_4)
29798 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29799 GET_THREAD_INFO(%_ASM_DX)
29800 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29801 jae bad_get_user
29802 +
29803 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29804 + mov pax_user_shadow_base,%_ASM_DX
29805 + cmp %_ASM_DX,%_ASM_AX
29806 + jae 1234f
29807 + add %_ASM_DX,%_ASM_AX
29808 +1234:
29809 +#endif
29810 +
29811 ASM_STAC
29812 4: movq -7(%_ASM_AX),%rdx
29813 xor %eax,%eax
29814 ASM_CLAC
29815 + pax_force_retaddr
29816 ret
29817 #else
29818 add $7,%_ASM_AX
29819 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29820 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29821 jae bad_get_user_8
29822 ASM_STAC
29823 -4: movl -7(%_ASM_AX),%edx
29824 -5: movl -3(%_ASM_AX),%ecx
29825 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
29826 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29827 xor %eax,%eax
29828 ASM_CLAC
29829 + pax_force_retaddr
29830 ret
29831 #endif
29832 CFI_ENDPROC
29833 @@ -113,6 +175,7 @@ bad_get_user:
29834 xor %edx,%edx
29835 mov $(-EFAULT),%_ASM_AX
29836 ASM_CLAC
29837 + pax_force_retaddr
29838 ret
29839 CFI_ENDPROC
29840 END(bad_get_user)
29841 @@ -124,6 +187,7 @@ bad_get_user_8:
29842 xor %ecx,%ecx
29843 mov $(-EFAULT),%_ASM_AX
29844 ASM_CLAC
29845 + pax_force_retaddr
29846 ret
29847 CFI_ENDPROC
29848 END(bad_get_user_8)
29849 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29850 index 54fcffe..7be149e 100644
29851 --- a/arch/x86/lib/insn.c
29852 +++ b/arch/x86/lib/insn.c
29853 @@ -20,8 +20,10 @@
29854
29855 #ifdef __KERNEL__
29856 #include <linux/string.h>
29857 +#include <asm/pgtable_types.h>
29858 #else
29859 #include <string.h>
29860 +#define ktla_ktva(addr) addr
29861 #endif
29862 #include <asm/inat.h>
29863 #include <asm/insn.h>
29864 @@ -53,8 +55,8 @@
29865 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29866 {
29867 memset(insn, 0, sizeof(*insn));
29868 - insn->kaddr = kaddr;
29869 - insn->next_byte = kaddr;
29870 + insn->kaddr = ktla_ktva(kaddr);
29871 + insn->next_byte = ktla_ktva(kaddr);
29872 insn->x86_64 = x86_64 ? 1 : 0;
29873 insn->opnd_bytes = 4;
29874 if (x86_64)
29875 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29876 index 05a95e7..326f2fa 100644
29877 --- a/arch/x86/lib/iomap_copy_64.S
29878 +++ b/arch/x86/lib/iomap_copy_64.S
29879 @@ -17,6 +17,7 @@
29880
29881 #include <linux/linkage.h>
29882 #include <asm/dwarf2.h>
29883 +#include <asm/alternative-asm.h>
29884
29885 /*
29886 * override generic version in lib/iomap_copy.c
29887 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29888 CFI_STARTPROC
29889 movl %edx,%ecx
29890 rep movsd
29891 + pax_force_retaddr
29892 ret
29893 CFI_ENDPROC
29894 ENDPROC(__iowrite32_copy)
29895 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29896 index 56313a3..0db417e 100644
29897 --- a/arch/x86/lib/memcpy_64.S
29898 +++ b/arch/x86/lib/memcpy_64.S
29899 @@ -24,7 +24,7 @@
29900 * This gets patched over the unrolled variant (below) via the
29901 * alternative instructions framework:
29902 */
29903 - .section .altinstr_replacement, "ax", @progbits
29904 + .section .altinstr_replacement, "a", @progbits
29905 .Lmemcpy_c:
29906 movq %rdi, %rax
29907 movq %rdx, %rcx
29908 @@ -33,6 +33,7 @@
29909 rep movsq
29910 movl %edx, %ecx
29911 rep movsb
29912 + pax_force_retaddr
29913 ret
29914 .Lmemcpy_e:
29915 .previous
29916 @@ -44,11 +45,12 @@
29917 * This gets patched over the unrolled variant (below) via the
29918 * alternative instructions framework:
29919 */
29920 - .section .altinstr_replacement, "ax", @progbits
29921 + .section .altinstr_replacement, "a", @progbits
29922 .Lmemcpy_c_e:
29923 movq %rdi, %rax
29924 movq %rdx, %rcx
29925 rep movsb
29926 + pax_force_retaddr
29927 ret
29928 .Lmemcpy_e_e:
29929 .previous
29930 @@ -136,6 +138,7 @@ ENTRY(memcpy)
29931 movq %r9, 1*8(%rdi)
29932 movq %r10, -2*8(%rdi, %rdx)
29933 movq %r11, -1*8(%rdi, %rdx)
29934 + pax_force_retaddr
29935 retq
29936 .p2align 4
29937 .Lless_16bytes:
29938 @@ -148,6 +151,7 @@ ENTRY(memcpy)
29939 movq -1*8(%rsi, %rdx), %r9
29940 movq %r8, 0*8(%rdi)
29941 movq %r9, -1*8(%rdi, %rdx)
29942 + pax_force_retaddr
29943 retq
29944 .p2align 4
29945 .Lless_8bytes:
29946 @@ -161,6 +165,7 @@ ENTRY(memcpy)
29947 movl -4(%rsi, %rdx), %r8d
29948 movl %ecx, (%rdi)
29949 movl %r8d, -4(%rdi, %rdx)
29950 + pax_force_retaddr
29951 retq
29952 .p2align 4
29953 .Lless_3bytes:
29954 @@ -179,6 +184,7 @@ ENTRY(memcpy)
29955 movb %cl, (%rdi)
29956
29957 .Lend:
29958 + pax_force_retaddr
29959 retq
29960 CFI_ENDPROC
29961 ENDPROC(memcpy)
29962 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29963 index 65268a6..dd1de11 100644
29964 --- a/arch/x86/lib/memmove_64.S
29965 +++ b/arch/x86/lib/memmove_64.S
29966 @@ -202,14 +202,16 @@ ENTRY(memmove)
29967 movb (%rsi), %r11b
29968 movb %r11b, (%rdi)
29969 13:
29970 + pax_force_retaddr
29971 retq
29972 CFI_ENDPROC
29973
29974 - .section .altinstr_replacement,"ax"
29975 + .section .altinstr_replacement,"a"
29976 .Lmemmove_begin_forward_efs:
29977 /* Forward moving data. */
29978 movq %rdx, %rcx
29979 rep movsb
29980 + pax_force_retaddr
29981 retq
29982 .Lmemmove_end_forward_efs:
29983 .previous
29984 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29985 index 2dcb380..2eb79fe 100644
29986 --- a/arch/x86/lib/memset_64.S
29987 +++ b/arch/x86/lib/memset_64.S
29988 @@ -16,7 +16,7 @@
29989 *
29990 * rax original destination
29991 */
29992 - .section .altinstr_replacement, "ax", @progbits
29993 + .section .altinstr_replacement, "a", @progbits
29994 .Lmemset_c:
29995 movq %rdi,%r9
29996 movq %rdx,%rcx
29997 @@ -30,6 +30,7 @@
29998 movl %edx,%ecx
29999 rep stosb
30000 movq %r9,%rax
30001 + pax_force_retaddr
30002 ret
30003 .Lmemset_e:
30004 .previous
30005 @@ -45,13 +46,14 @@
30006 *
30007 * rax original destination
30008 */
30009 - .section .altinstr_replacement, "ax", @progbits
30010 + .section .altinstr_replacement, "a", @progbits
30011 .Lmemset_c_e:
30012 movq %rdi,%r9
30013 movb %sil,%al
30014 movq %rdx,%rcx
30015 rep stosb
30016 movq %r9,%rax
30017 + pax_force_retaddr
30018 ret
30019 .Lmemset_e_e:
30020 .previous
30021 @@ -118,6 +120,7 @@ ENTRY(__memset)
30022
30023 .Lende:
30024 movq %r10,%rax
30025 + pax_force_retaddr
30026 ret
30027
30028 CFI_RESTORE_STATE
30029 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30030 index c9f2d9b..e7fd2c0 100644
30031 --- a/arch/x86/lib/mmx_32.c
30032 +++ b/arch/x86/lib/mmx_32.c
30033 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30034 {
30035 void *p;
30036 int i;
30037 + unsigned long cr0;
30038
30039 if (unlikely(in_interrupt()))
30040 return __memcpy(to, from, len);
30041 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30042 kernel_fpu_begin();
30043
30044 __asm__ __volatile__ (
30045 - "1: prefetch (%0)\n" /* This set is 28 bytes */
30046 - " prefetch 64(%0)\n"
30047 - " prefetch 128(%0)\n"
30048 - " prefetch 192(%0)\n"
30049 - " prefetch 256(%0)\n"
30050 + "1: prefetch (%1)\n" /* This set is 28 bytes */
30051 + " prefetch 64(%1)\n"
30052 + " prefetch 128(%1)\n"
30053 + " prefetch 192(%1)\n"
30054 + " prefetch 256(%1)\n"
30055 "2: \n"
30056 ".section .fixup, \"ax\"\n"
30057 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30058 + "3: \n"
30059 +
30060 +#ifdef CONFIG_PAX_KERNEXEC
30061 + " movl %%cr0, %0\n"
30062 + " movl %0, %%eax\n"
30063 + " andl $0xFFFEFFFF, %%eax\n"
30064 + " movl %%eax, %%cr0\n"
30065 +#endif
30066 +
30067 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30068 +
30069 +#ifdef CONFIG_PAX_KERNEXEC
30070 + " movl %0, %%cr0\n"
30071 +#endif
30072 +
30073 " jmp 2b\n"
30074 ".previous\n"
30075 _ASM_EXTABLE(1b, 3b)
30076 - : : "r" (from));
30077 + : "=&r" (cr0) : "r" (from) : "ax");
30078
30079 for ( ; i > 5; i--) {
30080 __asm__ __volatile__ (
30081 - "1: prefetch 320(%0)\n"
30082 - "2: movq (%0), %%mm0\n"
30083 - " movq 8(%0), %%mm1\n"
30084 - " movq 16(%0), %%mm2\n"
30085 - " movq 24(%0), %%mm3\n"
30086 - " movq %%mm0, (%1)\n"
30087 - " movq %%mm1, 8(%1)\n"
30088 - " movq %%mm2, 16(%1)\n"
30089 - " movq %%mm3, 24(%1)\n"
30090 - " movq 32(%0), %%mm0\n"
30091 - " movq 40(%0), %%mm1\n"
30092 - " movq 48(%0), %%mm2\n"
30093 - " movq 56(%0), %%mm3\n"
30094 - " movq %%mm0, 32(%1)\n"
30095 - " movq %%mm1, 40(%1)\n"
30096 - " movq %%mm2, 48(%1)\n"
30097 - " movq %%mm3, 56(%1)\n"
30098 + "1: prefetch 320(%1)\n"
30099 + "2: movq (%1), %%mm0\n"
30100 + " movq 8(%1), %%mm1\n"
30101 + " movq 16(%1), %%mm2\n"
30102 + " movq 24(%1), %%mm3\n"
30103 + " movq %%mm0, (%2)\n"
30104 + " movq %%mm1, 8(%2)\n"
30105 + " movq %%mm2, 16(%2)\n"
30106 + " movq %%mm3, 24(%2)\n"
30107 + " movq 32(%1), %%mm0\n"
30108 + " movq 40(%1), %%mm1\n"
30109 + " movq 48(%1), %%mm2\n"
30110 + " movq 56(%1), %%mm3\n"
30111 + " movq %%mm0, 32(%2)\n"
30112 + " movq %%mm1, 40(%2)\n"
30113 + " movq %%mm2, 48(%2)\n"
30114 + " movq %%mm3, 56(%2)\n"
30115 ".section .fixup, \"ax\"\n"
30116 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30117 + "3:\n"
30118 +
30119 +#ifdef CONFIG_PAX_KERNEXEC
30120 + " movl %%cr0, %0\n"
30121 + " movl %0, %%eax\n"
30122 + " andl $0xFFFEFFFF, %%eax\n"
30123 + " movl %%eax, %%cr0\n"
30124 +#endif
30125 +
30126 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30127 +
30128 +#ifdef CONFIG_PAX_KERNEXEC
30129 + " movl %0, %%cr0\n"
30130 +#endif
30131 +
30132 " jmp 2b\n"
30133 ".previous\n"
30134 _ASM_EXTABLE(1b, 3b)
30135 - : : "r" (from), "r" (to) : "memory");
30136 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30137
30138 from += 64;
30139 to += 64;
30140 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30141 static void fast_copy_page(void *to, void *from)
30142 {
30143 int i;
30144 + unsigned long cr0;
30145
30146 kernel_fpu_begin();
30147
30148 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30149 * but that is for later. -AV
30150 */
30151 __asm__ __volatile__(
30152 - "1: prefetch (%0)\n"
30153 - " prefetch 64(%0)\n"
30154 - " prefetch 128(%0)\n"
30155 - " prefetch 192(%0)\n"
30156 - " prefetch 256(%0)\n"
30157 + "1: prefetch (%1)\n"
30158 + " prefetch 64(%1)\n"
30159 + " prefetch 128(%1)\n"
30160 + " prefetch 192(%1)\n"
30161 + " prefetch 256(%1)\n"
30162 "2: \n"
30163 ".section .fixup, \"ax\"\n"
30164 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30165 + "3: \n"
30166 +
30167 +#ifdef CONFIG_PAX_KERNEXEC
30168 + " movl %%cr0, %0\n"
30169 + " movl %0, %%eax\n"
30170 + " andl $0xFFFEFFFF, %%eax\n"
30171 + " movl %%eax, %%cr0\n"
30172 +#endif
30173 +
30174 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30175 +
30176 +#ifdef CONFIG_PAX_KERNEXEC
30177 + " movl %0, %%cr0\n"
30178 +#endif
30179 +
30180 " jmp 2b\n"
30181 ".previous\n"
30182 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30183 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30184
30185 for (i = 0; i < (4096-320)/64; i++) {
30186 __asm__ __volatile__ (
30187 - "1: prefetch 320(%0)\n"
30188 - "2: movq (%0), %%mm0\n"
30189 - " movntq %%mm0, (%1)\n"
30190 - " movq 8(%0), %%mm1\n"
30191 - " movntq %%mm1, 8(%1)\n"
30192 - " movq 16(%0), %%mm2\n"
30193 - " movntq %%mm2, 16(%1)\n"
30194 - " movq 24(%0), %%mm3\n"
30195 - " movntq %%mm3, 24(%1)\n"
30196 - " movq 32(%0), %%mm4\n"
30197 - " movntq %%mm4, 32(%1)\n"
30198 - " movq 40(%0), %%mm5\n"
30199 - " movntq %%mm5, 40(%1)\n"
30200 - " movq 48(%0), %%mm6\n"
30201 - " movntq %%mm6, 48(%1)\n"
30202 - " movq 56(%0), %%mm7\n"
30203 - " movntq %%mm7, 56(%1)\n"
30204 + "1: prefetch 320(%1)\n"
30205 + "2: movq (%1), %%mm0\n"
30206 + " movntq %%mm0, (%2)\n"
30207 + " movq 8(%1), %%mm1\n"
30208 + " movntq %%mm1, 8(%2)\n"
30209 + " movq 16(%1), %%mm2\n"
30210 + " movntq %%mm2, 16(%2)\n"
30211 + " movq 24(%1), %%mm3\n"
30212 + " movntq %%mm3, 24(%2)\n"
30213 + " movq 32(%1), %%mm4\n"
30214 + " movntq %%mm4, 32(%2)\n"
30215 + " movq 40(%1), %%mm5\n"
30216 + " movntq %%mm5, 40(%2)\n"
30217 + " movq 48(%1), %%mm6\n"
30218 + " movntq %%mm6, 48(%2)\n"
30219 + " movq 56(%1), %%mm7\n"
30220 + " movntq %%mm7, 56(%2)\n"
30221 ".section .fixup, \"ax\"\n"
30222 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30223 + "3:\n"
30224 +
30225 +#ifdef CONFIG_PAX_KERNEXEC
30226 + " movl %%cr0, %0\n"
30227 + " movl %0, %%eax\n"
30228 + " andl $0xFFFEFFFF, %%eax\n"
30229 + " movl %%eax, %%cr0\n"
30230 +#endif
30231 +
30232 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30233 +
30234 +#ifdef CONFIG_PAX_KERNEXEC
30235 + " movl %0, %%cr0\n"
30236 +#endif
30237 +
30238 " jmp 2b\n"
30239 ".previous\n"
30240 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30241 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30242
30243 from += 64;
30244 to += 64;
30245 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30246 static void fast_copy_page(void *to, void *from)
30247 {
30248 int i;
30249 + unsigned long cr0;
30250
30251 kernel_fpu_begin();
30252
30253 __asm__ __volatile__ (
30254 - "1: prefetch (%0)\n"
30255 - " prefetch 64(%0)\n"
30256 - " prefetch 128(%0)\n"
30257 - " prefetch 192(%0)\n"
30258 - " prefetch 256(%0)\n"
30259 + "1: prefetch (%1)\n"
30260 + " prefetch 64(%1)\n"
30261 + " prefetch 128(%1)\n"
30262 + " prefetch 192(%1)\n"
30263 + " prefetch 256(%1)\n"
30264 "2: \n"
30265 ".section .fixup, \"ax\"\n"
30266 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30267 + "3: \n"
30268 +
30269 +#ifdef CONFIG_PAX_KERNEXEC
30270 + " movl %%cr0, %0\n"
30271 + " movl %0, %%eax\n"
30272 + " andl $0xFFFEFFFF, %%eax\n"
30273 + " movl %%eax, %%cr0\n"
30274 +#endif
30275 +
30276 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30277 +
30278 +#ifdef CONFIG_PAX_KERNEXEC
30279 + " movl %0, %%cr0\n"
30280 +#endif
30281 +
30282 " jmp 2b\n"
30283 ".previous\n"
30284 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30285 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30286
30287 for (i = 0; i < 4096/64; i++) {
30288 __asm__ __volatile__ (
30289 - "1: prefetch 320(%0)\n"
30290 - "2: movq (%0), %%mm0\n"
30291 - " movq 8(%0), %%mm1\n"
30292 - " movq 16(%0), %%mm2\n"
30293 - " movq 24(%0), %%mm3\n"
30294 - " movq %%mm0, (%1)\n"
30295 - " movq %%mm1, 8(%1)\n"
30296 - " movq %%mm2, 16(%1)\n"
30297 - " movq %%mm3, 24(%1)\n"
30298 - " movq 32(%0), %%mm0\n"
30299 - " movq 40(%0), %%mm1\n"
30300 - " movq 48(%0), %%mm2\n"
30301 - " movq 56(%0), %%mm3\n"
30302 - " movq %%mm0, 32(%1)\n"
30303 - " movq %%mm1, 40(%1)\n"
30304 - " movq %%mm2, 48(%1)\n"
30305 - " movq %%mm3, 56(%1)\n"
30306 + "1: prefetch 320(%1)\n"
30307 + "2: movq (%1), %%mm0\n"
30308 + " movq 8(%1), %%mm1\n"
30309 + " movq 16(%1), %%mm2\n"
30310 + " movq 24(%1), %%mm3\n"
30311 + " movq %%mm0, (%2)\n"
30312 + " movq %%mm1, 8(%2)\n"
30313 + " movq %%mm2, 16(%2)\n"
30314 + " movq %%mm3, 24(%2)\n"
30315 + " movq 32(%1), %%mm0\n"
30316 + " movq 40(%1), %%mm1\n"
30317 + " movq 48(%1), %%mm2\n"
30318 + " movq 56(%1), %%mm3\n"
30319 + " movq %%mm0, 32(%2)\n"
30320 + " movq %%mm1, 40(%2)\n"
30321 + " movq %%mm2, 48(%2)\n"
30322 + " movq %%mm3, 56(%2)\n"
30323 ".section .fixup, \"ax\"\n"
30324 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30325 + "3:\n"
30326 +
30327 +#ifdef CONFIG_PAX_KERNEXEC
30328 + " movl %%cr0, %0\n"
30329 + " movl %0, %%eax\n"
30330 + " andl $0xFFFEFFFF, %%eax\n"
30331 + " movl %%eax, %%cr0\n"
30332 +#endif
30333 +
30334 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30335 +
30336 +#ifdef CONFIG_PAX_KERNEXEC
30337 + " movl %0, %%cr0\n"
30338 +#endif
30339 +
30340 " jmp 2b\n"
30341 ".previous\n"
30342 _ASM_EXTABLE(1b, 3b)
30343 - : : "r" (from), "r" (to) : "memory");
30344 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30345
30346 from += 64;
30347 to += 64;
30348 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30349 index f6d13ee..d789440 100644
30350 --- a/arch/x86/lib/msr-reg.S
30351 +++ b/arch/x86/lib/msr-reg.S
30352 @@ -3,6 +3,7 @@
30353 #include <asm/dwarf2.h>
30354 #include <asm/asm.h>
30355 #include <asm/msr.h>
30356 +#include <asm/alternative-asm.h>
30357
30358 #ifdef CONFIG_X86_64
30359 /*
30360 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30361 movl %edi, 28(%r10)
30362 popq_cfi %rbp
30363 popq_cfi %rbx
30364 + pax_force_retaddr
30365 ret
30366 3:
30367 CFI_RESTORE_STATE
30368 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30369 index fc6ba17..d4d989d 100644
30370 --- a/arch/x86/lib/putuser.S
30371 +++ b/arch/x86/lib/putuser.S
30372 @@ -16,7 +16,9 @@
30373 #include <asm/errno.h>
30374 #include <asm/asm.h>
30375 #include <asm/smap.h>
30376 -
30377 +#include <asm/segment.h>
30378 +#include <asm/pgtable.h>
30379 +#include <asm/alternative-asm.h>
30380
30381 /*
30382 * __put_user_X
30383 @@ -30,57 +32,125 @@
30384 * as they get called from within inline assembly.
30385 */
30386
30387 -#define ENTER CFI_STARTPROC ; \
30388 - GET_THREAD_INFO(%_ASM_BX)
30389 -#define EXIT ASM_CLAC ; \
30390 - ret ; \
30391 +#define ENTER CFI_STARTPROC
30392 +#define EXIT ASM_CLAC ; \
30393 + pax_force_retaddr ; \
30394 + ret ; \
30395 CFI_ENDPROC
30396
30397 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30398 +#define _DEST %_ASM_CX,%_ASM_BX
30399 +#else
30400 +#define _DEST %_ASM_CX
30401 +#endif
30402 +
30403 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30404 +#define __copyuser_seg gs;
30405 +#else
30406 +#define __copyuser_seg
30407 +#endif
30408 +
30409 .text
30410 ENTRY(__put_user_1)
30411 ENTER
30412 +
30413 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30414 + GET_THREAD_INFO(%_ASM_BX)
30415 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30416 jae bad_put_user
30417 ASM_STAC
30418 -1: movb %al,(%_ASM_CX)
30419 +
30420 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30421 + mov pax_user_shadow_base,%_ASM_BX
30422 + cmp %_ASM_BX,%_ASM_CX
30423 + jb 1234f
30424 + xor %ebx,%ebx
30425 +1234:
30426 +#endif
30427 +
30428 +#endif
30429 +
30430 +1: __copyuser_seg movb %al,(_DEST)
30431 xor %eax,%eax
30432 EXIT
30433 ENDPROC(__put_user_1)
30434
30435 ENTRY(__put_user_2)
30436 ENTER
30437 +
30438 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30439 + GET_THREAD_INFO(%_ASM_BX)
30440 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30441 sub $1,%_ASM_BX
30442 cmp %_ASM_BX,%_ASM_CX
30443 jae bad_put_user
30444 ASM_STAC
30445 -2: movw %ax,(%_ASM_CX)
30446 +
30447 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30448 + mov pax_user_shadow_base,%_ASM_BX
30449 + cmp %_ASM_BX,%_ASM_CX
30450 + jb 1234f
30451 + xor %ebx,%ebx
30452 +1234:
30453 +#endif
30454 +
30455 +#endif
30456 +
30457 +2: __copyuser_seg movw %ax,(_DEST)
30458 xor %eax,%eax
30459 EXIT
30460 ENDPROC(__put_user_2)
30461
30462 ENTRY(__put_user_4)
30463 ENTER
30464 +
30465 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30466 + GET_THREAD_INFO(%_ASM_BX)
30467 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30468 sub $3,%_ASM_BX
30469 cmp %_ASM_BX,%_ASM_CX
30470 jae bad_put_user
30471 ASM_STAC
30472 -3: movl %eax,(%_ASM_CX)
30473 +
30474 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30475 + mov pax_user_shadow_base,%_ASM_BX
30476 + cmp %_ASM_BX,%_ASM_CX
30477 + jb 1234f
30478 + xor %ebx,%ebx
30479 +1234:
30480 +#endif
30481 +
30482 +#endif
30483 +
30484 +3: __copyuser_seg movl %eax,(_DEST)
30485 xor %eax,%eax
30486 EXIT
30487 ENDPROC(__put_user_4)
30488
30489 ENTRY(__put_user_8)
30490 ENTER
30491 +
30492 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30493 + GET_THREAD_INFO(%_ASM_BX)
30494 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30495 sub $7,%_ASM_BX
30496 cmp %_ASM_BX,%_ASM_CX
30497 jae bad_put_user
30498 ASM_STAC
30499 -4: mov %_ASM_AX,(%_ASM_CX)
30500 +
30501 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30502 + mov pax_user_shadow_base,%_ASM_BX
30503 + cmp %_ASM_BX,%_ASM_CX
30504 + jb 1234f
30505 + xor %ebx,%ebx
30506 +1234:
30507 +#endif
30508 +
30509 +#endif
30510 +
30511 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30512 #ifdef CONFIG_X86_32
30513 -5: movl %edx,4(%_ASM_CX)
30514 +5: __copyuser_seg movl %edx,4(_DEST)
30515 #endif
30516 xor %eax,%eax
30517 EXIT
30518 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30519 index 1cad221..de671ee 100644
30520 --- a/arch/x86/lib/rwlock.S
30521 +++ b/arch/x86/lib/rwlock.S
30522 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30523 FRAME
30524 0: LOCK_PREFIX
30525 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30526 +
30527 +#ifdef CONFIG_PAX_REFCOUNT
30528 + jno 1234f
30529 + LOCK_PREFIX
30530 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30531 + int $4
30532 +1234:
30533 + _ASM_EXTABLE(1234b, 1234b)
30534 +#endif
30535 +
30536 1: rep; nop
30537 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30538 jne 1b
30539 LOCK_PREFIX
30540 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30541 +
30542 +#ifdef CONFIG_PAX_REFCOUNT
30543 + jno 1234f
30544 + LOCK_PREFIX
30545 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30546 + int $4
30547 +1234:
30548 + _ASM_EXTABLE(1234b, 1234b)
30549 +#endif
30550 +
30551 jnz 0b
30552 ENDFRAME
30553 + pax_force_retaddr
30554 ret
30555 CFI_ENDPROC
30556 END(__write_lock_failed)
30557 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30558 FRAME
30559 0: LOCK_PREFIX
30560 READ_LOCK_SIZE(inc) (%__lock_ptr)
30561 +
30562 +#ifdef CONFIG_PAX_REFCOUNT
30563 + jno 1234f
30564 + LOCK_PREFIX
30565 + READ_LOCK_SIZE(dec) (%__lock_ptr)
30566 + int $4
30567 +1234:
30568 + _ASM_EXTABLE(1234b, 1234b)
30569 +#endif
30570 +
30571 1: rep; nop
30572 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30573 js 1b
30574 LOCK_PREFIX
30575 READ_LOCK_SIZE(dec) (%__lock_ptr)
30576 +
30577 +#ifdef CONFIG_PAX_REFCOUNT
30578 + jno 1234f
30579 + LOCK_PREFIX
30580 + READ_LOCK_SIZE(inc) (%__lock_ptr)
30581 + int $4
30582 +1234:
30583 + _ASM_EXTABLE(1234b, 1234b)
30584 +#endif
30585 +
30586 js 0b
30587 ENDFRAME
30588 + pax_force_retaddr
30589 ret
30590 CFI_ENDPROC
30591 END(__read_lock_failed)
30592 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30593 index 5dff5f0..cadebf4 100644
30594 --- a/arch/x86/lib/rwsem.S
30595 +++ b/arch/x86/lib/rwsem.S
30596 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30597 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30598 CFI_RESTORE __ASM_REG(dx)
30599 restore_common_regs
30600 + pax_force_retaddr
30601 ret
30602 CFI_ENDPROC
30603 ENDPROC(call_rwsem_down_read_failed)
30604 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30605 movq %rax,%rdi
30606 call rwsem_down_write_failed
30607 restore_common_regs
30608 + pax_force_retaddr
30609 ret
30610 CFI_ENDPROC
30611 ENDPROC(call_rwsem_down_write_failed)
30612 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30613 movq %rax,%rdi
30614 call rwsem_wake
30615 restore_common_regs
30616 -1: ret
30617 +1: pax_force_retaddr
30618 + ret
30619 CFI_ENDPROC
30620 ENDPROC(call_rwsem_wake)
30621
30622 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30623 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30624 CFI_RESTORE __ASM_REG(dx)
30625 restore_common_regs
30626 + pax_force_retaddr
30627 ret
30628 CFI_ENDPROC
30629 ENDPROC(call_rwsem_downgrade_wake)
30630 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30631 index a63efd6..8149fbe 100644
30632 --- a/arch/x86/lib/thunk_64.S
30633 +++ b/arch/x86/lib/thunk_64.S
30634 @@ -8,6 +8,7 @@
30635 #include <linux/linkage.h>
30636 #include <asm/dwarf2.h>
30637 #include <asm/calling.h>
30638 +#include <asm/alternative-asm.h>
30639
30640 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30641 .macro THUNK name, func, put_ret_addr_in_rdi=0
30642 @@ -15,11 +16,11 @@
30643 \name:
30644 CFI_STARTPROC
30645
30646 - /* this one pushes 9 elems, the next one would be %rIP */
30647 - SAVE_ARGS
30648 + /* this one pushes 15+1 elems, the next one would be %rIP */
30649 + SAVE_ARGS 8
30650
30651 .if \put_ret_addr_in_rdi
30652 - movq_cfi_restore 9*8, rdi
30653 + movq_cfi_restore RIP, rdi
30654 .endif
30655
30656 call \func
30657 @@ -38,8 +39,9 @@
30658
30659 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30660 CFI_STARTPROC
30661 - SAVE_ARGS
30662 + SAVE_ARGS 8
30663 restore:
30664 - RESTORE_ARGS
30665 + RESTORE_ARGS 1,8
30666 + pax_force_retaddr
30667 ret
30668 CFI_ENDPROC
30669 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30670 index e2f5e21..4b22130 100644
30671 --- a/arch/x86/lib/usercopy_32.c
30672 +++ b/arch/x86/lib/usercopy_32.c
30673 @@ -42,11 +42,13 @@ do { \
30674 int __d0; \
30675 might_fault(); \
30676 __asm__ __volatile__( \
30677 + __COPYUSER_SET_ES \
30678 ASM_STAC "\n" \
30679 "0: rep; stosl\n" \
30680 " movl %2,%0\n" \
30681 "1: rep; stosb\n" \
30682 "2: " ASM_CLAC "\n" \
30683 + __COPYUSER_RESTORE_ES \
30684 ".section .fixup,\"ax\"\n" \
30685 "3: lea 0(%2,%0,4),%0\n" \
30686 " jmp 2b\n" \
30687 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30688
30689 #ifdef CONFIG_X86_INTEL_USERCOPY
30690 static unsigned long
30691 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
30692 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30693 {
30694 int d0, d1;
30695 __asm__ __volatile__(
30696 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30697 " .align 2,0x90\n"
30698 "3: movl 0(%4), %%eax\n"
30699 "4: movl 4(%4), %%edx\n"
30700 - "5: movl %%eax, 0(%3)\n"
30701 - "6: movl %%edx, 4(%3)\n"
30702 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30703 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30704 "7: movl 8(%4), %%eax\n"
30705 "8: movl 12(%4),%%edx\n"
30706 - "9: movl %%eax, 8(%3)\n"
30707 - "10: movl %%edx, 12(%3)\n"
30708 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30709 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30710 "11: movl 16(%4), %%eax\n"
30711 "12: movl 20(%4), %%edx\n"
30712 - "13: movl %%eax, 16(%3)\n"
30713 - "14: movl %%edx, 20(%3)\n"
30714 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30715 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30716 "15: movl 24(%4), %%eax\n"
30717 "16: movl 28(%4), %%edx\n"
30718 - "17: movl %%eax, 24(%3)\n"
30719 - "18: movl %%edx, 28(%3)\n"
30720 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30721 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30722 "19: movl 32(%4), %%eax\n"
30723 "20: movl 36(%4), %%edx\n"
30724 - "21: movl %%eax, 32(%3)\n"
30725 - "22: movl %%edx, 36(%3)\n"
30726 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30727 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30728 "23: movl 40(%4), %%eax\n"
30729 "24: movl 44(%4), %%edx\n"
30730 - "25: movl %%eax, 40(%3)\n"
30731 - "26: movl %%edx, 44(%3)\n"
30732 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30733 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30734 "27: movl 48(%4), %%eax\n"
30735 "28: movl 52(%4), %%edx\n"
30736 - "29: movl %%eax, 48(%3)\n"
30737 - "30: movl %%edx, 52(%3)\n"
30738 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30739 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30740 "31: movl 56(%4), %%eax\n"
30741 "32: movl 60(%4), %%edx\n"
30742 - "33: movl %%eax, 56(%3)\n"
30743 - "34: movl %%edx, 60(%3)\n"
30744 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30745 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30746 " addl $-64, %0\n"
30747 " addl $64, %4\n"
30748 " addl $64, %3\n"
30749 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30750 " shrl $2, %0\n"
30751 " andl $3, %%eax\n"
30752 " cld\n"
30753 + __COPYUSER_SET_ES
30754 "99: rep; movsl\n"
30755 "36: movl %%eax, %0\n"
30756 "37: rep; movsb\n"
30757 "100:\n"
30758 + __COPYUSER_RESTORE_ES
30759 + ".section .fixup,\"ax\"\n"
30760 + "101: lea 0(%%eax,%0,4),%0\n"
30761 + " jmp 100b\n"
30762 + ".previous\n"
30763 + _ASM_EXTABLE(1b,100b)
30764 + _ASM_EXTABLE(2b,100b)
30765 + _ASM_EXTABLE(3b,100b)
30766 + _ASM_EXTABLE(4b,100b)
30767 + _ASM_EXTABLE(5b,100b)
30768 + _ASM_EXTABLE(6b,100b)
30769 + _ASM_EXTABLE(7b,100b)
30770 + _ASM_EXTABLE(8b,100b)
30771 + _ASM_EXTABLE(9b,100b)
30772 + _ASM_EXTABLE(10b,100b)
30773 + _ASM_EXTABLE(11b,100b)
30774 + _ASM_EXTABLE(12b,100b)
30775 + _ASM_EXTABLE(13b,100b)
30776 + _ASM_EXTABLE(14b,100b)
30777 + _ASM_EXTABLE(15b,100b)
30778 + _ASM_EXTABLE(16b,100b)
30779 + _ASM_EXTABLE(17b,100b)
30780 + _ASM_EXTABLE(18b,100b)
30781 + _ASM_EXTABLE(19b,100b)
30782 + _ASM_EXTABLE(20b,100b)
30783 + _ASM_EXTABLE(21b,100b)
30784 + _ASM_EXTABLE(22b,100b)
30785 + _ASM_EXTABLE(23b,100b)
30786 + _ASM_EXTABLE(24b,100b)
30787 + _ASM_EXTABLE(25b,100b)
30788 + _ASM_EXTABLE(26b,100b)
30789 + _ASM_EXTABLE(27b,100b)
30790 + _ASM_EXTABLE(28b,100b)
30791 + _ASM_EXTABLE(29b,100b)
30792 + _ASM_EXTABLE(30b,100b)
30793 + _ASM_EXTABLE(31b,100b)
30794 + _ASM_EXTABLE(32b,100b)
30795 + _ASM_EXTABLE(33b,100b)
30796 + _ASM_EXTABLE(34b,100b)
30797 + _ASM_EXTABLE(35b,100b)
30798 + _ASM_EXTABLE(36b,100b)
30799 + _ASM_EXTABLE(37b,100b)
30800 + _ASM_EXTABLE(99b,101b)
30801 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
30802 + : "1"(to), "2"(from), "0"(size)
30803 + : "eax", "edx", "memory");
30804 + return size;
30805 +}
30806 +
30807 +static unsigned long
30808 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30809 +{
30810 + int d0, d1;
30811 + __asm__ __volatile__(
30812 + " .align 2,0x90\n"
30813 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30814 + " cmpl $67, %0\n"
30815 + " jbe 3f\n"
30816 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30817 + " .align 2,0x90\n"
30818 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30819 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30820 + "5: movl %%eax, 0(%3)\n"
30821 + "6: movl %%edx, 4(%3)\n"
30822 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30823 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30824 + "9: movl %%eax, 8(%3)\n"
30825 + "10: movl %%edx, 12(%3)\n"
30826 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30827 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30828 + "13: movl %%eax, 16(%3)\n"
30829 + "14: movl %%edx, 20(%3)\n"
30830 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30831 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30832 + "17: movl %%eax, 24(%3)\n"
30833 + "18: movl %%edx, 28(%3)\n"
30834 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30835 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30836 + "21: movl %%eax, 32(%3)\n"
30837 + "22: movl %%edx, 36(%3)\n"
30838 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30839 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30840 + "25: movl %%eax, 40(%3)\n"
30841 + "26: movl %%edx, 44(%3)\n"
30842 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30843 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30844 + "29: movl %%eax, 48(%3)\n"
30845 + "30: movl %%edx, 52(%3)\n"
30846 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30847 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30848 + "33: movl %%eax, 56(%3)\n"
30849 + "34: movl %%edx, 60(%3)\n"
30850 + " addl $-64, %0\n"
30851 + " addl $64, %4\n"
30852 + " addl $64, %3\n"
30853 + " cmpl $63, %0\n"
30854 + " ja 1b\n"
30855 + "35: movl %0, %%eax\n"
30856 + " shrl $2, %0\n"
30857 + " andl $3, %%eax\n"
30858 + " cld\n"
30859 + "99: rep; "__copyuser_seg" movsl\n"
30860 + "36: movl %%eax, %0\n"
30861 + "37: rep; "__copyuser_seg" movsb\n"
30862 + "100:\n"
30863 ".section .fixup,\"ax\"\n"
30864 "101: lea 0(%%eax,%0,4),%0\n"
30865 " jmp 100b\n"
30866 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30867 int d0, d1;
30868 __asm__ __volatile__(
30869 " .align 2,0x90\n"
30870 - "0: movl 32(%4), %%eax\n"
30871 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30872 " cmpl $67, %0\n"
30873 " jbe 2f\n"
30874 - "1: movl 64(%4), %%eax\n"
30875 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30876 " .align 2,0x90\n"
30877 - "2: movl 0(%4), %%eax\n"
30878 - "21: movl 4(%4), %%edx\n"
30879 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30880 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30881 " movl %%eax, 0(%3)\n"
30882 " movl %%edx, 4(%3)\n"
30883 - "3: movl 8(%4), %%eax\n"
30884 - "31: movl 12(%4),%%edx\n"
30885 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30886 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30887 " movl %%eax, 8(%3)\n"
30888 " movl %%edx, 12(%3)\n"
30889 - "4: movl 16(%4), %%eax\n"
30890 - "41: movl 20(%4), %%edx\n"
30891 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30892 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30893 " movl %%eax, 16(%3)\n"
30894 " movl %%edx, 20(%3)\n"
30895 - "10: movl 24(%4), %%eax\n"
30896 - "51: movl 28(%4), %%edx\n"
30897 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30898 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30899 " movl %%eax, 24(%3)\n"
30900 " movl %%edx, 28(%3)\n"
30901 - "11: movl 32(%4), %%eax\n"
30902 - "61: movl 36(%4), %%edx\n"
30903 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30904 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30905 " movl %%eax, 32(%3)\n"
30906 " movl %%edx, 36(%3)\n"
30907 - "12: movl 40(%4), %%eax\n"
30908 - "71: movl 44(%4), %%edx\n"
30909 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30910 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30911 " movl %%eax, 40(%3)\n"
30912 " movl %%edx, 44(%3)\n"
30913 - "13: movl 48(%4), %%eax\n"
30914 - "81: movl 52(%4), %%edx\n"
30915 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30916 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30917 " movl %%eax, 48(%3)\n"
30918 " movl %%edx, 52(%3)\n"
30919 - "14: movl 56(%4), %%eax\n"
30920 - "91: movl 60(%4), %%edx\n"
30921 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30922 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30923 " movl %%eax, 56(%3)\n"
30924 " movl %%edx, 60(%3)\n"
30925 " addl $-64, %0\n"
30926 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30927 " shrl $2, %0\n"
30928 " andl $3, %%eax\n"
30929 " cld\n"
30930 - "6: rep; movsl\n"
30931 + "6: rep; "__copyuser_seg" movsl\n"
30932 " movl %%eax,%0\n"
30933 - "7: rep; movsb\n"
30934 + "7: rep; "__copyuser_seg" movsb\n"
30935 "8:\n"
30936 ".section .fixup,\"ax\"\n"
30937 "9: lea 0(%%eax,%0,4),%0\n"
30938 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30939
30940 __asm__ __volatile__(
30941 " .align 2,0x90\n"
30942 - "0: movl 32(%4), %%eax\n"
30943 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30944 " cmpl $67, %0\n"
30945 " jbe 2f\n"
30946 - "1: movl 64(%4), %%eax\n"
30947 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30948 " .align 2,0x90\n"
30949 - "2: movl 0(%4), %%eax\n"
30950 - "21: movl 4(%4), %%edx\n"
30951 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30952 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30953 " movnti %%eax, 0(%3)\n"
30954 " movnti %%edx, 4(%3)\n"
30955 - "3: movl 8(%4), %%eax\n"
30956 - "31: movl 12(%4),%%edx\n"
30957 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30958 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30959 " movnti %%eax, 8(%3)\n"
30960 " movnti %%edx, 12(%3)\n"
30961 - "4: movl 16(%4), %%eax\n"
30962 - "41: movl 20(%4), %%edx\n"
30963 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30964 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30965 " movnti %%eax, 16(%3)\n"
30966 " movnti %%edx, 20(%3)\n"
30967 - "10: movl 24(%4), %%eax\n"
30968 - "51: movl 28(%4), %%edx\n"
30969 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30970 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30971 " movnti %%eax, 24(%3)\n"
30972 " movnti %%edx, 28(%3)\n"
30973 - "11: movl 32(%4), %%eax\n"
30974 - "61: movl 36(%4), %%edx\n"
30975 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30976 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30977 " movnti %%eax, 32(%3)\n"
30978 " movnti %%edx, 36(%3)\n"
30979 - "12: movl 40(%4), %%eax\n"
30980 - "71: movl 44(%4), %%edx\n"
30981 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30982 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30983 " movnti %%eax, 40(%3)\n"
30984 " movnti %%edx, 44(%3)\n"
30985 - "13: movl 48(%4), %%eax\n"
30986 - "81: movl 52(%4), %%edx\n"
30987 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30988 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30989 " movnti %%eax, 48(%3)\n"
30990 " movnti %%edx, 52(%3)\n"
30991 - "14: movl 56(%4), %%eax\n"
30992 - "91: movl 60(%4), %%edx\n"
30993 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30994 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30995 " movnti %%eax, 56(%3)\n"
30996 " movnti %%edx, 60(%3)\n"
30997 " addl $-64, %0\n"
30998 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30999 " shrl $2, %0\n"
31000 " andl $3, %%eax\n"
31001 " cld\n"
31002 - "6: rep; movsl\n"
31003 + "6: rep; "__copyuser_seg" movsl\n"
31004 " movl %%eax,%0\n"
31005 - "7: rep; movsb\n"
31006 + "7: rep; "__copyuser_seg" movsb\n"
31007 "8:\n"
31008 ".section .fixup,\"ax\"\n"
31009 "9: lea 0(%%eax,%0,4),%0\n"
31010 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31011
31012 __asm__ __volatile__(
31013 " .align 2,0x90\n"
31014 - "0: movl 32(%4), %%eax\n"
31015 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31016 " cmpl $67, %0\n"
31017 " jbe 2f\n"
31018 - "1: movl 64(%4), %%eax\n"
31019 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31020 " .align 2,0x90\n"
31021 - "2: movl 0(%4), %%eax\n"
31022 - "21: movl 4(%4), %%edx\n"
31023 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31024 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31025 " movnti %%eax, 0(%3)\n"
31026 " movnti %%edx, 4(%3)\n"
31027 - "3: movl 8(%4), %%eax\n"
31028 - "31: movl 12(%4),%%edx\n"
31029 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31030 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31031 " movnti %%eax, 8(%3)\n"
31032 " movnti %%edx, 12(%3)\n"
31033 - "4: movl 16(%4), %%eax\n"
31034 - "41: movl 20(%4), %%edx\n"
31035 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31036 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31037 " movnti %%eax, 16(%3)\n"
31038 " movnti %%edx, 20(%3)\n"
31039 - "10: movl 24(%4), %%eax\n"
31040 - "51: movl 28(%4), %%edx\n"
31041 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31042 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31043 " movnti %%eax, 24(%3)\n"
31044 " movnti %%edx, 28(%3)\n"
31045 - "11: movl 32(%4), %%eax\n"
31046 - "61: movl 36(%4), %%edx\n"
31047 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31048 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31049 " movnti %%eax, 32(%3)\n"
31050 " movnti %%edx, 36(%3)\n"
31051 - "12: movl 40(%4), %%eax\n"
31052 - "71: movl 44(%4), %%edx\n"
31053 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31054 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31055 " movnti %%eax, 40(%3)\n"
31056 " movnti %%edx, 44(%3)\n"
31057 - "13: movl 48(%4), %%eax\n"
31058 - "81: movl 52(%4), %%edx\n"
31059 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31060 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31061 " movnti %%eax, 48(%3)\n"
31062 " movnti %%edx, 52(%3)\n"
31063 - "14: movl 56(%4), %%eax\n"
31064 - "91: movl 60(%4), %%edx\n"
31065 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31066 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31067 " movnti %%eax, 56(%3)\n"
31068 " movnti %%edx, 60(%3)\n"
31069 " addl $-64, %0\n"
31070 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31071 " shrl $2, %0\n"
31072 " andl $3, %%eax\n"
31073 " cld\n"
31074 - "6: rep; movsl\n"
31075 + "6: rep; "__copyuser_seg" movsl\n"
31076 " movl %%eax,%0\n"
31077 - "7: rep; movsb\n"
31078 + "7: rep; "__copyuser_seg" movsb\n"
31079 "8:\n"
31080 ".section .fixup,\"ax\"\n"
31081 "9: lea 0(%%eax,%0,4),%0\n"
31082 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31083 */
31084 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31085 unsigned long size);
31086 -unsigned long __copy_user_intel(void __user *to, const void *from,
31087 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31088 + unsigned long size);
31089 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31090 unsigned long size);
31091 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31092 const void __user *from, unsigned long size);
31093 #endif /* CONFIG_X86_INTEL_USERCOPY */
31094
31095 /* Generic arbitrary sized copy. */
31096 -#define __copy_user(to, from, size) \
31097 +#define __copy_user(to, from, size, prefix, set, restore) \
31098 do { \
31099 int __d0, __d1, __d2; \
31100 __asm__ __volatile__( \
31101 + set \
31102 " cmp $7,%0\n" \
31103 " jbe 1f\n" \
31104 " movl %1,%0\n" \
31105 " negl %0\n" \
31106 " andl $7,%0\n" \
31107 " subl %0,%3\n" \
31108 - "4: rep; movsb\n" \
31109 + "4: rep; "prefix"movsb\n" \
31110 " movl %3,%0\n" \
31111 " shrl $2,%0\n" \
31112 " andl $3,%3\n" \
31113 " .align 2,0x90\n" \
31114 - "0: rep; movsl\n" \
31115 + "0: rep; "prefix"movsl\n" \
31116 " movl %3,%0\n" \
31117 - "1: rep; movsb\n" \
31118 + "1: rep; "prefix"movsb\n" \
31119 "2:\n" \
31120 + restore \
31121 ".section .fixup,\"ax\"\n" \
31122 "5: addl %3,%0\n" \
31123 " jmp 2b\n" \
31124 @@ -538,14 +650,14 @@ do { \
31125 " negl %0\n" \
31126 " andl $7,%0\n" \
31127 " subl %0,%3\n" \
31128 - "4: rep; movsb\n" \
31129 + "4: rep; "__copyuser_seg"movsb\n" \
31130 " movl %3,%0\n" \
31131 " shrl $2,%0\n" \
31132 " andl $3,%3\n" \
31133 " .align 2,0x90\n" \
31134 - "0: rep; movsl\n" \
31135 + "0: rep; "__copyuser_seg"movsl\n" \
31136 " movl %3,%0\n" \
31137 - "1: rep; movsb\n" \
31138 + "1: rep; "__copyuser_seg"movsb\n" \
31139 "2:\n" \
31140 ".section .fixup,\"ax\"\n" \
31141 "5: addl %3,%0\n" \
31142 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31143 {
31144 stac();
31145 if (movsl_is_ok(to, from, n))
31146 - __copy_user(to, from, n);
31147 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31148 else
31149 - n = __copy_user_intel(to, from, n);
31150 + n = __generic_copy_to_user_intel(to, from, n);
31151 clac();
31152 return n;
31153 }
31154 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31155 {
31156 stac();
31157 if (movsl_is_ok(to, from, n))
31158 - __copy_user(to, from, n);
31159 + __copy_user(to, from, n, __copyuser_seg, "", "");
31160 else
31161 - n = __copy_user_intel((void __user *)to,
31162 - (const void *)from, n);
31163 + n = __generic_copy_from_user_intel(to, from, n);
31164 clac();
31165 return n;
31166 }
31167 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31168 if (n > 64 && cpu_has_xmm2)
31169 n = __copy_user_intel_nocache(to, from, n);
31170 else
31171 - __copy_user(to, from, n);
31172 + __copy_user(to, from, n, __copyuser_seg, "", "");
31173 #else
31174 - __copy_user(to, from, n);
31175 + __copy_user(to, from, n, __copyuser_seg, "", "");
31176 #endif
31177 clac();
31178 return n;
31179 }
31180 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31181
31182 -/**
31183 - * copy_to_user: - Copy a block of data into user space.
31184 - * @to: Destination address, in user space.
31185 - * @from: Source address, in kernel space.
31186 - * @n: Number of bytes to copy.
31187 - *
31188 - * Context: User context only. This function may sleep.
31189 - *
31190 - * Copy data from kernel space to user space.
31191 - *
31192 - * Returns number of bytes that could not be copied.
31193 - * On success, this will be zero.
31194 - */
31195 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31196 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31197 +void __set_fs(mm_segment_t x)
31198 {
31199 - if (access_ok(VERIFY_WRITE, to, n))
31200 - n = __copy_to_user(to, from, n);
31201 - return n;
31202 + switch (x.seg) {
31203 + case 0:
31204 + loadsegment(gs, 0);
31205 + break;
31206 + case TASK_SIZE_MAX:
31207 + loadsegment(gs, __USER_DS);
31208 + break;
31209 + case -1UL:
31210 + loadsegment(gs, __KERNEL_DS);
31211 + break;
31212 + default:
31213 + BUG();
31214 + }
31215 }
31216 -EXPORT_SYMBOL(_copy_to_user);
31217 +EXPORT_SYMBOL(__set_fs);
31218
31219 -/**
31220 - * copy_from_user: - Copy a block of data from user space.
31221 - * @to: Destination address, in kernel space.
31222 - * @from: Source address, in user space.
31223 - * @n: Number of bytes to copy.
31224 - *
31225 - * Context: User context only. This function may sleep.
31226 - *
31227 - * Copy data from user space to kernel space.
31228 - *
31229 - * Returns number of bytes that could not be copied.
31230 - * On success, this will be zero.
31231 - *
31232 - * If some data could not be copied, this function will pad the copied
31233 - * data to the requested size using zero bytes.
31234 - */
31235 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31236 +void set_fs(mm_segment_t x)
31237 {
31238 - if (access_ok(VERIFY_READ, from, n))
31239 - n = __copy_from_user(to, from, n);
31240 - else
31241 - memset(to, 0, n);
31242 - return n;
31243 + current_thread_info()->addr_limit = x;
31244 + __set_fs(x);
31245 }
31246 -EXPORT_SYMBOL(_copy_from_user);
31247 +EXPORT_SYMBOL(set_fs);
31248 +#endif
31249 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31250 index c905e89..01ab928 100644
31251 --- a/arch/x86/lib/usercopy_64.c
31252 +++ b/arch/x86/lib/usercopy_64.c
31253 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31254 might_fault();
31255 /* no memory constraint because it doesn't change any memory gcc knows
31256 about */
31257 + pax_open_userland();
31258 stac();
31259 asm volatile(
31260 " testq %[size8],%[size8]\n"
31261 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31262 _ASM_EXTABLE(0b,3b)
31263 _ASM_EXTABLE(1b,2b)
31264 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31265 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31266 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31267 [zero] "r" (0UL), [eight] "r" (8UL));
31268 clac();
31269 + pax_close_userland();
31270 return size;
31271 }
31272 EXPORT_SYMBOL(__clear_user);
31273 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31274 }
31275 EXPORT_SYMBOL(clear_user);
31276
31277 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31278 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31279 {
31280 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31281 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31282 - }
31283 - return len;
31284 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31285 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31286 + return len;
31287 }
31288 EXPORT_SYMBOL(copy_in_user);
31289
31290 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31291 * it is not necessary to optimize tail handling.
31292 */
31293 __visible unsigned long
31294 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31295 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31296 {
31297 char c;
31298 unsigned zero_len;
31299
31300 + clac();
31301 + pax_close_userland();
31302 for (; len; --len, to++) {
31303 if (__get_user_nocheck(c, from++, sizeof(char)))
31304 break;
31305 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31306 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31307 if (__put_user_nocheck(c, to++, sizeof(char)))
31308 break;
31309 - clac();
31310 return len;
31311 }
31312 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31313 index 6a19ad9..1c48f9a 100644
31314 --- a/arch/x86/mm/Makefile
31315 +++ b/arch/x86/mm/Makefile
31316 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31317 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31318
31319 obj-$(CONFIG_MEMTEST) += memtest.o
31320 +
31321 +quote:="
31322 +obj-$(CONFIG_X86_64) += uderef_64.o
31323 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31324 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31325 index 903ec1e..c4166b2 100644
31326 --- a/arch/x86/mm/extable.c
31327 +++ b/arch/x86/mm/extable.c
31328 @@ -6,12 +6,24 @@
31329 static inline unsigned long
31330 ex_insn_addr(const struct exception_table_entry *x)
31331 {
31332 - return (unsigned long)&x->insn + x->insn;
31333 + unsigned long reloc = 0;
31334 +
31335 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31336 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31337 +#endif
31338 +
31339 + return (unsigned long)&x->insn + x->insn + reloc;
31340 }
31341 static inline unsigned long
31342 ex_fixup_addr(const struct exception_table_entry *x)
31343 {
31344 - return (unsigned long)&x->fixup + x->fixup;
31345 + unsigned long reloc = 0;
31346 +
31347 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31348 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31349 +#endif
31350 +
31351 + return (unsigned long)&x->fixup + x->fixup + reloc;
31352 }
31353
31354 int fixup_exception(struct pt_regs *regs)
31355 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31356 unsigned long new_ip;
31357
31358 #ifdef CONFIG_PNPBIOS
31359 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31360 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31361 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31362 extern u32 pnp_bios_is_utter_crap;
31363 pnp_bios_is_utter_crap = 1;
31364 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31365 i += 4;
31366 p->fixup -= i;
31367 i += 4;
31368 +
31369 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31370 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31371 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31372 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31373 +#endif
31374 +
31375 }
31376 }
31377
31378 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31379 index 8e57229..31cce89 100644
31380 --- a/arch/x86/mm/fault.c
31381 +++ b/arch/x86/mm/fault.c
31382 @@ -14,11 +14,18 @@
31383 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31384 #include <linux/prefetch.h> /* prefetchw */
31385 #include <linux/context_tracking.h> /* exception_enter(), ... */
31386 +#include <linux/unistd.h>
31387 +#include <linux/compiler.h>
31388
31389 #include <asm/traps.h> /* dotraplinkage, ... */
31390 #include <asm/pgalloc.h> /* pgd_*(), ... */
31391 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31392 #include <asm/fixmap.h> /* VSYSCALL_START */
31393 +#include <asm/tlbflush.h>
31394 +
31395 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31396 +#include <asm/stacktrace.h>
31397 +#endif
31398
31399 #define CREATE_TRACE_POINTS
31400 #include <asm/trace/exceptions.h>
31401 @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31402 int ret = 0;
31403
31404 /* kprobe_running() needs smp_processor_id() */
31405 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31406 + if (kprobes_built_in() && !user_mode(regs)) {
31407 preempt_disable();
31408 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31409 ret = 1;
31410 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31411 return !instr_lo || (instr_lo>>1) == 1;
31412 case 0x00:
31413 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31414 - if (probe_kernel_address(instr, opcode))
31415 + if (user_mode(regs)) {
31416 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31417 + return 0;
31418 + } else if (probe_kernel_address(instr, opcode))
31419 return 0;
31420
31421 *prefetch = (instr_lo == 0xF) &&
31422 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31423 while (instr < max_instr) {
31424 unsigned char opcode;
31425
31426 - if (probe_kernel_address(instr, opcode))
31427 + if (user_mode(regs)) {
31428 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31429 + break;
31430 + } else if (probe_kernel_address(instr, opcode))
31431 break;
31432
31433 instr++;
31434 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31435 force_sig_info(si_signo, &info, tsk);
31436 }
31437
31438 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31439 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31440 +#endif
31441 +
31442 +#ifdef CONFIG_PAX_EMUTRAMP
31443 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31444 +#endif
31445 +
31446 +#ifdef CONFIG_PAX_PAGEEXEC
31447 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31448 +{
31449 + pgd_t *pgd;
31450 + pud_t *pud;
31451 + pmd_t *pmd;
31452 +
31453 + pgd = pgd_offset(mm, address);
31454 + if (!pgd_present(*pgd))
31455 + return NULL;
31456 + pud = pud_offset(pgd, address);
31457 + if (!pud_present(*pud))
31458 + return NULL;
31459 + pmd = pmd_offset(pud, address);
31460 + if (!pmd_present(*pmd))
31461 + return NULL;
31462 + return pmd;
31463 +}
31464 +#endif
31465 +
31466 DEFINE_SPINLOCK(pgd_lock);
31467 LIST_HEAD(pgd_list);
31468
31469 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31470 for (address = VMALLOC_START & PMD_MASK;
31471 address >= TASK_SIZE && address < FIXADDR_TOP;
31472 address += PMD_SIZE) {
31473 +
31474 +#ifdef CONFIG_PAX_PER_CPU_PGD
31475 + unsigned long cpu;
31476 +#else
31477 struct page *page;
31478 +#endif
31479
31480 spin_lock(&pgd_lock);
31481 +
31482 +#ifdef CONFIG_PAX_PER_CPU_PGD
31483 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31484 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31485 + pmd_t *ret;
31486 +
31487 + ret = vmalloc_sync_one(pgd, address);
31488 + if (!ret)
31489 + break;
31490 + pgd = get_cpu_pgd(cpu, kernel);
31491 +#else
31492 list_for_each_entry(page, &pgd_list, lru) {
31493 + pgd_t *pgd;
31494 spinlock_t *pgt_lock;
31495 pmd_t *ret;
31496
31497 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31498 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31499
31500 spin_lock(pgt_lock);
31501 - ret = vmalloc_sync_one(page_address(page), address);
31502 + pgd = page_address(page);
31503 +#endif
31504 +
31505 + ret = vmalloc_sync_one(pgd, address);
31506 +
31507 +#ifndef CONFIG_PAX_PER_CPU_PGD
31508 spin_unlock(pgt_lock);
31509 +#endif
31510
31511 if (!ret)
31512 break;
31513 @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31514 * an interrupt in the middle of a task switch..
31515 */
31516 pgd_paddr = read_cr3();
31517 +
31518 +#ifdef CONFIG_PAX_PER_CPU_PGD
31519 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31520 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31521 +#endif
31522 +
31523 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31524 if (!pmd_k)
31525 return -1;
31526 @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31527 * happen within a race in page table update. In the later
31528 * case just flush:
31529 */
31530 - pgd = pgd_offset(current->active_mm, address);
31531 +
31532 pgd_ref = pgd_offset_k(address);
31533 if (pgd_none(*pgd_ref))
31534 return -1;
31535
31536 +#ifdef CONFIG_PAX_PER_CPU_PGD
31537 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31538 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31539 + if (pgd_none(*pgd)) {
31540 + set_pgd(pgd, *pgd_ref);
31541 + arch_flush_lazy_mmu_mode();
31542 + } else {
31543 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31544 + }
31545 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31546 +#else
31547 + pgd = pgd_offset(current->active_mm, address);
31548 +#endif
31549 +
31550 if (pgd_none(*pgd)) {
31551 set_pgd(pgd, *pgd_ref);
31552 arch_flush_lazy_mmu_mode();
31553 @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31554 static int is_errata100(struct pt_regs *regs, unsigned long address)
31555 {
31556 #ifdef CONFIG_X86_64
31557 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31558 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31559 return 1;
31560 #endif
31561 return 0;
31562 @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31563 }
31564
31565 static const char nx_warning[] = KERN_CRIT
31566 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31567 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31568
31569 static void
31570 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31571 @@ -582,7 +666,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31572 if (!oops_may_print())
31573 return;
31574
31575 - if (error_code & PF_INSTR) {
31576 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31577 unsigned int level;
31578 pgd_t *pgd;
31579 pte_t *pte;
31580 @@ -593,9 +677,21 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31581 pte = lookup_address_in_pgd(pgd, address, &level);
31582
31583 if (pte && pte_present(*pte) && !pte_exec(*pte))
31584 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31585 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31586 }
31587
31588 +#ifdef CONFIG_PAX_KERNEXEC
31589 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31590 + if (current->signal->curr_ip)
31591 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31592 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31593 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31594 + else
31595 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31596 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31597 + }
31598 +#endif
31599 +
31600 printk(KERN_ALERT "BUG: unable to handle kernel ");
31601 if (address < PAGE_SIZE)
31602 printk(KERN_CONT "NULL pointer dereference");
31603 @@ -776,6 +872,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31604 return;
31605 }
31606 #endif
31607 +
31608 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31609 + if (pax_is_fetch_fault(regs, error_code, address)) {
31610 +
31611 +#ifdef CONFIG_PAX_EMUTRAMP
31612 + switch (pax_handle_fetch_fault(regs)) {
31613 + case 2:
31614 + return;
31615 + }
31616 +#endif
31617 +
31618 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31619 + do_group_exit(SIGKILL);
31620 + }
31621 +#endif
31622 +
31623 /* Kernel addresses are always protection faults: */
31624 if (address >= TASK_SIZE)
31625 error_code |= PF_PROT;
31626 @@ -861,7 +973,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31627 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31628 printk(KERN_ERR
31629 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31630 - tsk->comm, tsk->pid, address);
31631 + tsk->comm, task_pid_nr(tsk), address);
31632 code = BUS_MCEERR_AR;
31633 }
31634 #endif
31635 @@ -915,6 +1027,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31636 return 1;
31637 }
31638
31639 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31640 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31641 +{
31642 + pte_t *pte;
31643 + pmd_t *pmd;
31644 + spinlock_t *ptl;
31645 + unsigned char pte_mask;
31646 +
31647 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31648 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
31649 + return 0;
31650 +
31651 + /* PaX: it's our fault, let's handle it if we can */
31652 +
31653 + /* PaX: take a look at read faults before acquiring any locks */
31654 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31655 + /* instruction fetch attempt from a protected page in user mode */
31656 + up_read(&mm->mmap_sem);
31657 +
31658 +#ifdef CONFIG_PAX_EMUTRAMP
31659 + switch (pax_handle_fetch_fault(regs)) {
31660 + case 2:
31661 + return 1;
31662 + }
31663 +#endif
31664 +
31665 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31666 + do_group_exit(SIGKILL);
31667 + }
31668 +
31669 + pmd = pax_get_pmd(mm, address);
31670 + if (unlikely(!pmd))
31671 + return 0;
31672 +
31673 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31674 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31675 + pte_unmap_unlock(pte, ptl);
31676 + return 0;
31677 + }
31678 +
31679 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31680 + /* write attempt to a protected page in user mode */
31681 + pte_unmap_unlock(pte, ptl);
31682 + return 0;
31683 + }
31684 +
31685 +#ifdef CONFIG_SMP
31686 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31687 +#else
31688 + if (likely(address > get_limit(regs->cs)))
31689 +#endif
31690 + {
31691 + set_pte(pte, pte_mkread(*pte));
31692 + __flush_tlb_one(address);
31693 + pte_unmap_unlock(pte, ptl);
31694 + up_read(&mm->mmap_sem);
31695 + return 1;
31696 + }
31697 +
31698 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31699 +
31700 + /*
31701 + * PaX: fill DTLB with user rights and retry
31702 + */
31703 + __asm__ __volatile__ (
31704 + "orb %2,(%1)\n"
31705 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31706 +/*
31707 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31708 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31709 + * page fault when examined during a TLB load attempt. this is true not only
31710 + * for PTEs holding a non-present entry but also present entries that will
31711 + * raise a page fault (such as those set up by PaX, or the copy-on-write
31712 + * mechanism). in effect it means that we do *not* need to flush the TLBs
31713 + * for our target pages since their PTEs are simply not in the TLBs at all.
31714 +
31715 + * the best thing in omitting it is that we gain around 15-20% speed in the
31716 + * fast path of the page fault handler and can get rid of tracing since we
31717 + * can no longer flush unintended entries.
31718 + */
31719 + "invlpg (%0)\n"
31720 +#endif
31721 + __copyuser_seg"testb $0,(%0)\n"
31722 + "xorb %3,(%1)\n"
31723 + :
31724 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31725 + : "memory", "cc");
31726 + pte_unmap_unlock(pte, ptl);
31727 + up_read(&mm->mmap_sem);
31728 + return 1;
31729 +}
31730 +#endif
31731 +
31732 /*
31733 * Handle a spurious fault caused by a stale TLB entry.
31734 *
31735 @@ -981,6 +1186,9 @@ int show_unhandled_signals = 1;
31736 static inline int
31737 access_error(unsigned long error_code, struct vm_area_struct *vma)
31738 {
31739 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31740 + return 1;
31741 +
31742 if (error_code & PF_WRITE) {
31743 /* write, present and write, not present: */
31744 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31745 @@ -1015,7 +1223,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31746 if (error_code & PF_USER)
31747 return false;
31748
31749 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31750 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31751 return false;
31752
31753 return true;
31754 @@ -1043,6 +1251,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31755 tsk = current;
31756 mm = tsk->mm;
31757
31758 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31759 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31760 + if (!search_exception_tables(regs->ip)) {
31761 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31762 + bad_area_nosemaphore(regs, error_code, address);
31763 + return;
31764 + }
31765 + if (address < pax_user_shadow_base) {
31766 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31767 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31768 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31769 + } else
31770 + address -= pax_user_shadow_base;
31771 + }
31772 +#endif
31773 +
31774 /*
31775 * Detect and handle instructions that would cause a page fault for
31776 * both a tracked kernel page and a userspace page.
31777 @@ -1120,7 +1344,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31778 * User-mode registers count as a user access even for any
31779 * potential system fault or CPU buglet:
31780 */
31781 - if (user_mode_vm(regs)) {
31782 + if (user_mode(regs)) {
31783 local_irq_enable();
31784 error_code |= PF_USER;
31785 flags |= FAULT_FLAG_USER;
31786 @@ -1167,6 +1391,11 @@ retry:
31787 might_sleep();
31788 }
31789
31790 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31791 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31792 + return;
31793 +#endif
31794 +
31795 vma = find_vma(mm, address);
31796 if (unlikely(!vma)) {
31797 bad_area(regs, error_code, address);
31798 @@ -1178,18 +1407,24 @@ retry:
31799 bad_area(regs, error_code, address);
31800 return;
31801 }
31802 - if (error_code & PF_USER) {
31803 - /*
31804 - * Accessing the stack below %sp is always a bug.
31805 - * The large cushion allows instructions like enter
31806 - * and pusha to work. ("enter $65535, $31" pushes
31807 - * 32 pointers and then decrements %sp by 65535.)
31808 - */
31809 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31810 - bad_area(regs, error_code, address);
31811 - return;
31812 - }
31813 + /*
31814 + * Accessing the stack below %sp is always a bug.
31815 + * The large cushion allows instructions like enter
31816 + * and pusha to work. ("enter $65535, $31" pushes
31817 + * 32 pointers and then decrements %sp by 65535.)
31818 + */
31819 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31820 + bad_area(regs, error_code, address);
31821 + return;
31822 }
31823 +
31824 +#ifdef CONFIG_PAX_SEGMEXEC
31825 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31826 + bad_area(regs, error_code, address);
31827 + return;
31828 + }
31829 +#endif
31830 +
31831 if (unlikely(expand_stack(vma, address))) {
31832 bad_area(regs, error_code, address);
31833 return;
31834 @@ -1301,3 +1536,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31835 exception_exit(prev_state);
31836 }
31837 #endif /* CONFIG_TRACING */
31838 +
31839 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31840 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31841 +{
31842 + struct mm_struct *mm = current->mm;
31843 + unsigned long ip = regs->ip;
31844 +
31845 + if (v8086_mode(regs))
31846 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31847 +
31848 +#ifdef CONFIG_PAX_PAGEEXEC
31849 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31850 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31851 + return true;
31852 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31853 + return true;
31854 + return false;
31855 + }
31856 +#endif
31857 +
31858 +#ifdef CONFIG_PAX_SEGMEXEC
31859 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31860 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31861 + return true;
31862 + return false;
31863 + }
31864 +#endif
31865 +
31866 + return false;
31867 +}
31868 +#endif
31869 +
31870 +#ifdef CONFIG_PAX_EMUTRAMP
31871 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31872 +{
31873 + int err;
31874 +
31875 + do { /* PaX: libffi trampoline emulation */
31876 + unsigned char mov, jmp;
31877 + unsigned int addr1, addr2;
31878 +
31879 +#ifdef CONFIG_X86_64
31880 + if ((regs->ip + 9) >> 32)
31881 + break;
31882 +#endif
31883 +
31884 + err = get_user(mov, (unsigned char __user *)regs->ip);
31885 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31886 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31887 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31888 +
31889 + if (err)
31890 + break;
31891 +
31892 + if (mov == 0xB8 && jmp == 0xE9) {
31893 + regs->ax = addr1;
31894 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31895 + return 2;
31896 + }
31897 + } while (0);
31898 +
31899 + do { /* PaX: gcc trampoline emulation #1 */
31900 + unsigned char mov1, mov2;
31901 + unsigned short jmp;
31902 + unsigned int addr1, addr2;
31903 +
31904 +#ifdef CONFIG_X86_64
31905 + if ((regs->ip + 11) >> 32)
31906 + break;
31907 +#endif
31908 +
31909 + err = get_user(mov1, (unsigned char __user *)regs->ip);
31910 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31911 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31912 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31913 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31914 +
31915 + if (err)
31916 + break;
31917 +
31918 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31919 + regs->cx = addr1;
31920 + regs->ax = addr2;
31921 + regs->ip = addr2;
31922 + return 2;
31923 + }
31924 + } while (0);
31925 +
31926 + do { /* PaX: gcc trampoline emulation #2 */
31927 + unsigned char mov, jmp;
31928 + unsigned int addr1, addr2;
31929 +
31930 +#ifdef CONFIG_X86_64
31931 + if ((regs->ip + 9) >> 32)
31932 + break;
31933 +#endif
31934 +
31935 + err = get_user(mov, (unsigned char __user *)regs->ip);
31936 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31937 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31938 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31939 +
31940 + if (err)
31941 + break;
31942 +
31943 + if (mov == 0xB9 && jmp == 0xE9) {
31944 + regs->cx = addr1;
31945 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31946 + return 2;
31947 + }
31948 + } while (0);
31949 +
31950 + return 1; /* PaX in action */
31951 +}
31952 +
31953 +#ifdef CONFIG_X86_64
31954 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31955 +{
31956 + int err;
31957 +
31958 + do { /* PaX: libffi trampoline emulation */
31959 + unsigned short mov1, mov2, jmp1;
31960 + unsigned char stcclc, jmp2;
31961 + unsigned long addr1, addr2;
31962 +
31963 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31964 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31965 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31966 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31967 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31968 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31969 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31970 +
31971 + if (err)
31972 + break;
31973 +
31974 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31975 + regs->r11 = addr1;
31976 + regs->r10 = addr2;
31977 + if (stcclc == 0xF8)
31978 + regs->flags &= ~X86_EFLAGS_CF;
31979 + else
31980 + regs->flags |= X86_EFLAGS_CF;
31981 + regs->ip = addr1;
31982 + return 2;
31983 + }
31984 + } while (0);
31985 +
31986 + do { /* PaX: gcc trampoline emulation #1 */
31987 + unsigned short mov1, mov2, jmp1;
31988 + unsigned char jmp2;
31989 + unsigned int addr1;
31990 + unsigned long addr2;
31991 +
31992 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31993 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31994 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31995 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31996 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31997 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31998 +
31999 + if (err)
32000 + break;
32001 +
32002 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32003 + regs->r11 = addr1;
32004 + regs->r10 = addr2;
32005 + regs->ip = addr1;
32006 + return 2;
32007 + }
32008 + } while (0);
32009 +
32010 + do { /* PaX: gcc trampoline emulation #2 */
32011 + unsigned short mov1, mov2, jmp1;
32012 + unsigned char jmp2;
32013 + unsigned long addr1, addr2;
32014 +
32015 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32016 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32017 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32018 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32019 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32020 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32021 +
32022 + if (err)
32023 + break;
32024 +
32025 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32026 + regs->r11 = addr1;
32027 + regs->r10 = addr2;
32028 + regs->ip = addr1;
32029 + return 2;
32030 + }
32031 + } while (0);
32032 +
32033 + return 1; /* PaX in action */
32034 +}
32035 +#endif
32036 +
32037 +/*
32038 + * PaX: decide what to do with offenders (regs->ip = fault address)
32039 + *
32040 + * returns 1 when task should be killed
32041 + * 2 when gcc trampoline was detected
32042 + */
32043 +static int pax_handle_fetch_fault(struct pt_regs *regs)
32044 +{
32045 + if (v8086_mode(regs))
32046 + return 1;
32047 +
32048 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32049 + return 1;
32050 +
32051 +#ifdef CONFIG_X86_32
32052 + return pax_handle_fetch_fault_32(regs);
32053 +#else
32054 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32055 + return pax_handle_fetch_fault_32(regs);
32056 + else
32057 + return pax_handle_fetch_fault_64(regs);
32058 +#endif
32059 +}
32060 +#endif
32061 +
32062 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32063 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32064 +{
32065 + long i;
32066 +
32067 + printk(KERN_ERR "PAX: bytes at PC: ");
32068 + for (i = 0; i < 20; i++) {
32069 + unsigned char c;
32070 + if (get_user(c, (unsigned char __force_user *)pc+i))
32071 + printk(KERN_CONT "?? ");
32072 + else
32073 + printk(KERN_CONT "%02x ", c);
32074 + }
32075 + printk("\n");
32076 +
32077 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32078 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
32079 + unsigned long c;
32080 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
32081 +#ifdef CONFIG_X86_32
32082 + printk(KERN_CONT "???????? ");
32083 +#else
32084 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32085 + printk(KERN_CONT "???????? ???????? ");
32086 + else
32087 + printk(KERN_CONT "???????????????? ");
32088 +#endif
32089 + } else {
32090 +#ifdef CONFIG_X86_64
32091 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32092 + printk(KERN_CONT "%08x ", (unsigned int)c);
32093 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32094 + } else
32095 +#endif
32096 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32097 + }
32098 + }
32099 + printk("\n");
32100 +}
32101 +#endif
32102 +
32103 +/**
32104 + * probe_kernel_write(): safely attempt to write to a location
32105 + * @dst: address to write to
32106 + * @src: pointer to the data that shall be written
32107 + * @size: size of the data chunk
32108 + *
32109 + * Safely write to address @dst from the buffer at @src. If a kernel fault
32110 + * happens, handle that and return -EFAULT.
32111 + */
32112 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32113 +{
32114 + long ret;
32115 + mm_segment_t old_fs = get_fs();
32116 +
32117 + set_fs(KERNEL_DS);
32118 + pagefault_disable();
32119 + pax_open_kernel();
32120 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32121 + pax_close_kernel();
32122 + pagefault_enable();
32123 + set_fs(old_fs);
32124 +
32125 + return ret ? -EFAULT : 0;
32126 +}
32127 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32128 index 207d9aef..69030980 100644
32129 --- a/arch/x86/mm/gup.c
32130 +++ b/arch/x86/mm/gup.c
32131 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32132 addr = start;
32133 len = (unsigned long) nr_pages << PAGE_SHIFT;
32134 end = start + len;
32135 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32136 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32137 (void __user *)start, len)))
32138 return 0;
32139
32140 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32141 goto slow_irqon;
32142 #endif
32143
32144 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32145 + (void __user *)start, len)))
32146 + return 0;
32147 +
32148 /*
32149 * XXX: batch / limit 'nr', to avoid large irq off latency
32150 * needs some instrumenting to determine the common sizes used by
32151 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32152 index 4500142..53a363c 100644
32153 --- a/arch/x86/mm/highmem_32.c
32154 +++ b/arch/x86/mm/highmem_32.c
32155 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32156 idx = type + KM_TYPE_NR*smp_processor_id();
32157 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32158 BUG_ON(!pte_none(*(kmap_pte-idx)));
32159 +
32160 + pax_open_kernel();
32161 set_pte(kmap_pte-idx, mk_pte(page, prot));
32162 + pax_close_kernel();
32163 +
32164 arch_flush_lazy_mmu_mode();
32165
32166 return (void *)vaddr;
32167 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32168 index 8b977eb..4732c33 100644
32169 --- a/arch/x86/mm/hugetlbpage.c
32170 +++ b/arch/x86/mm/hugetlbpage.c
32171 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32172 #ifdef CONFIG_HUGETLB_PAGE
32173 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32174 unsigned long addr, unsigned long len,
32175 - unsigned long pgoff, unsigned long flags)
32176 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32177 {
32178 struct hstate *h = hstate_file(file);
32179 struct vm_unmapped_area_info info;
32180 -
32181 +
32182 info.flags = 0;
32183 info.length = len;
32184 info.low_limit = current->mm->mmap_legacy_base;
32185 info.high_limit = TASK_SIZE;
32186 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32187 info.align_offset = 0;
32188 + info.threadstack_offset = offset;
32189 return vm_unmapped_area(&info);
32190 }
32191
32192 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32193 unsigned long addr0, unsigned long len,
32194 - unsigned long pgoff, unsigned long flags)
32195 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32196 {
32197 struct hstate *h = hstate_file(file);
32198 struct vm_unmapped_area_info info;
32199 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32200 info.high_limit = current->mm->mmap_base;
32201 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32202 info.align_offset = 0;
32203 + info.threadstack_offset = offset;
32204 addr = vm_unmapped_area(&info);
32205
32206 /*
32207 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32208 VM_BUG_ON(addr != -ENOMEM);
32209 info.flags = 0;
32210 info.low_limit = TASK_UNMAPPED_BASE;
32211 +
32212 +#ifdef CONFIG_PAX_RANDMMAP
32213 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32214 + info.low_limit += current->mm->delta_mmap;
32215 +#endif
32216 +
32217 info.high_limit = TASK_SIZE;
32218 addr = vm_unmapped_area(&info);
32219 }
32220 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32221 struct hstate *h = hstate_file(file);
32222 struct mm_struct *mm = current->mm;
32223 struct vm_area_struct *vma;
32224 + unsigned long pax_task_size = TASK_SIZE;
32225 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32226
32227 if (len & ~huge_page_mask(h))
32228 return -EINVAL;
32229 - if (len > TASK_SIZE)
32230 +
32231 +#ifdef CONFIG_PAX_SEGMEXEC
32232 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32233 + pax_task_size = SEGMEXEC_TASK_SIZE;
32234 +#endif
32235 +
32236 + pax_task_size -= PAGE_SIZE;
32237 +
32238 + if (len > pax_task_size)
32239 return -ENOMEM;
32240
32241 if (flags & MAP_FIXED) {
32242 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32243 return addr;
32244 }
32245
32246 +#ifdef CONFIG_PAX_RANDMMAP
32247 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32248 +#endif
32249 +
32250 if (addr) {
32251 addr = ALIGN(addr, huge_page_size(h));
32252 vma = find_vma(mm, addr);
32253 - if (TASK_SIZE - len >= addr &&
32254 - (!vma || addr + len <= vma->vm_start))
32255 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32256 return addr;
32257 }
32258 if (mm->get_unmapped_area == arch_get_unmapped_area)
32259 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32260 - pgoff, flags);
32261 + pgoff, flags, offset);
32262 else
32263 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32264 - pgoff, flags);
32265 + pgoff, flags, offset);
32266 }
32267 #endif /* CONFIG_HUGETLB_PAGE */
32268
32269 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32270 index f971306..e83e0f6 100644
32271 --- a/arch/x86/mm/init.c
32272 +++ b/arch/x86/mm/init.c
32273 @@ -4,6 +4,7 @@
32274 #include <linux/swap.h>
32275 #include <linux/memblock.h>
32276 #include <linux/bootmem.h> /* for max_low_pfn */
32277 +#include <linux/tboot.h>
32278
32279 #include <asm/cacheflush.h>
32280 #include <asm/e820.h>
32281 @@ -17,6 +18,8 @@
32282 #include <asm/proto.h>
32283 #include <asm/dma.h> /* for MAX_DMA_PFN */
32284 #include <asm/microcode.h>
32285 +#include <asm/desc.h>
32286 +#include <asm/bios_ebda.h>
32287
32288 #include "mm_internal.h"
32289
32290 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32291 early_ioremap_page_table_range_init();
32292 #endif
32293
32294 +#ifdef CONFIG_PAX_PER_CPU_PGD
32295 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32296 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32297 + KERNEL_PGD_PTRS);
32298 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32299 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32300 + KERNEL_PGD_PTRS);
32301 + load_cr3(get_cpu_pgd(0, kernel));
32302 +#else
32303 load_cr3(swapper_pg_dir);
32304 +#endif
32305 +
32306 __flush_tlb_all();
32307
32308 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32309 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32310 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32311 * mmio resources as well as potential bios/acpi data regions.
32312 */
32313 +
32314 +#ifdef CONFIG_GRKERNSEC_KMEM
32315 +static unsigned int ebda_start __read_only;
32316 +static unsigned int ebda_end __read_only;
32317 +#endif
32318 +
32319 int devmem_is_allowed(unsigned long pagenr)
32320 {
32321 - if (pagenr < 256)
32322 +#ifdef CONFIG_GRKERNSEC_KMEM
32323 + /* allow BDA */
32324 + if (!pagenr)
32325 return 1;
32326 + /* allow EBDA */
32327 + if (pagenr >= ebda_start && pagenr < ebda_end)
32328 + return 1;
32329 + /* if tboot is in use, allow access to its hardcoded serial log range */
32330 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32331 + return 1;
32332 +#else
32333 + if (!pagenr)
32334 + return 1;
32335 +#ifdef CONFIG_VM86
32336 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32337 + return 1;
32338 +#endif
32339 +#endif
32340 +
32341 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32342 + return 1;
32343 +#ifdef CONFIG_GRKERNSEC_KMEM
32344 + /* throw out everything else below 1MB */
32345 + if (pagenr <= 256)
32346 + return 0;
32347 +#endif
32348 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32349 return 0;
32350 if (!page_is_ram(pagenr))
32351 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32352 #endif
32353 }
32354
32355 +#ifdef CONFIG_GRKERNSEC_KMEM
32356 +static inline void gr_init_ebda(void)
32357 +{
32358 + unsigned int ebda_addr;
32359 + unsigned int ebda_size = 0;
32360 +
32361 + ebda_addr = get_bios_ebda();
32362 + if (ebda_addr) {
32363 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32364 + ebda_size <<= 10;
32365 + }
32366 + if (ebda_addr && ebda_size) {
32367 + ebda_start = ebda_addr >> PAGE_SHIFT;
32368 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32369 + } else {
32370 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32371 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32372 + }
32373 +}
32374 +#else
32375 +static inline void gr_init_ebda(void) { }
32376 +#endif
32377 +
32378 void free_initmem(void)
32379 {
32380 +#ifdef CONFIG_PAX_KERNEXEC
32381 +#ifdef CONFIG_X86_32
32382 + /* PaX: limit KERNEL_CS to actual size */
32383 + unsigned long addr, limit;
32384 + struct desc_struct d;
32385 + int cpu;
32386 +#else
32387 + pgd_t *pgd;
32388 + pud_t *pud;
32389 + pmd_t *pmd;
32390 + unsigned long addr, end;
32391 +#endif
32392 +#endif
32393 +
32394 + gr_init_ebda();
32395 +
32396 +#ifdef CONFIG_PAX_KERNEXEC
32397 +#ifdef CONFIG_X86_32
32398 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32399 + limit = (limit - 1UL) >> PAGE_SHIFT;
32400 +
32401 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32402 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32403 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32404 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32405 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32406 + }
32407 +
32408 + /* PaX: make KERNEL_CS read-only */
32409 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32410 + if (!paravirt_enabled())
32411 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32412 +/*
32413 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32414 + pgd = pgd_offset_k(addr);
32415 + pud = pud_offset(pgd, addr);
32416 + pmd = pmd_offset(pud, addr);
32417 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32418 + }
32419 +*/
32420 +#ifdef CONFIG_X86_PAE
32421 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32422 +/*
32423 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32424 + pgd = pgd_offset_k(addr);
32425 + pud = pud_offset(pgd, addr);
32426 + pmd = pmd_offset(pud, addr);
32427 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32428 + }
32429 +*/
32430 +#endif
32431 +
32432 +#ifdef CONFIG_MODULES
32433 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32434 +#endif
32435 +
32436 +#else
32437 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32438 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32439 + pgd = pgd_offset_k(addr);
32440 + pud = pud_offset(pgd, addr);
32441 + pmd = pmd_offset(pud, addr);
32442 + if (!pmd_present(*pmd))
32443 + continue;
32444 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32445 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32446 + else
32447 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32448 + }
32449 +
32450 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32451 + end = addr + KERNEL_IMAGE_SIZE;
32452 + for (; addr < end; addr += PMD_SIZE) {
32453 + pgd = pgd_offset_k(addr);
32454 + pud = pud_offset(pgd, addr);
32455 + pmd = pmd_offset(pud, addr);
32456 + if (!pmd_present(*pmd))
32457 + continue;
32458 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32459 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32460 + }
32461 +#endif
32462 +
32463 + flush_tlb_all();
32464 +#endif
32465 +
32466 free_init_pages("unused kernel",
32467 (unsigned long)(&__init_begin),
32468 (unsigned long)(&__init_end));
32469 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32470 index e395048..cd38278 100644
32471 --- a/arch/x86/mm/init_32.c
32472 +++ b/arch/x86/mm/init_32.c
32473 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32474 bool __read_mostly __vmalloc_start_set = false;
32475
32476 /*
32477 - * Creates a middle page table and puts a pointer to it in the
32478 - * given global directory entry. This only returns the gd entry
32479 - * in non-PAE compilation mode, since the middle layer is folded.
32480 - */
32481 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32482 -{
32483 - pud_t *pud;
32484 - pmd_t *pmd_table;
32485 -
32486 -#ifdef CONFIG_X86_PAE
32487 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32488 - pmd_table = (pmd_t *)alloc_low_page();
32489 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32490 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32491 - pud = pud_offset(pgd, 0);
32492 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32493 -
32494 - return pmd_table;
32495 - }
32496 -#endif
32497 - pud = pud_offset(pgd, 0);
32498 - pmd_table = pmd_offset(pud, 0);
32499 -
32500 - return pmd_table;
32501 -}
32502 -
32503 -/*
32504 * Create a page table and place a pointer to it in a middle page
32505 * directory entry:
32506 */
32507 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32508 pte_t *page_table = (pte_t *)alloc_low_page();
32509
32510 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32511 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32512 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32513 +#else
32514 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32515 +#endif
32516 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32517 }
32518
32519 return pte_offset_kernel(pmd, 0);
32520 }
32521
32522 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32523 +{
32524 + pud_t *pud;
32525 + pmd_t *pmd_table;
32526 +
32527 + pud = pud_offset(pgd, 0);
32528 + pmd_table = pmd_offset(pud, 0);
32529 +
32530 + return pmd_table;
32531 +}
32532 +
32533 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32534 {
32535 int pgd_idx = pgd_index(vaddr);
32536 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32537 int pgd_idx, pmd_idx;
32538 unsigned long vaddr;
32539 pgd_t *pgd;
32540 + pud_t *pud;
32541 pmd_t *pmd;
32542 pte_t *pte = NULL;
32543 unsigned long count = page_table_range_init_count(start, end);
32544 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32545 pgd = pgd_base + pgd_idx;
32546
32547 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32548 - pmd = one_md_table_init(pgd);
32549 - pmd = pmd + pmd_index(vaddr);
32550 + pud = pud_offset(pgd, vaddr);
32551 + pmd = pmd_offset(pud, vaddr);
32552 +
32553 +#ifdef CONFIG_X86_PAE
32554 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32555 +#endif
32556 +
32557 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32558 pmd++, pmd_idx++) {
32559 pte = page_table_kmap_check(one_page_table_init(pmd),
32560 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32561 }
32562 }
32563
32564 -static inline int is_kernel_text(unsigned long addr)
32565 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32566 {
32567 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32568 - return 1;
32569 - return 0;
32570 + if ((start >= ktla_ktva((unsigned long)_etext) ||
32571 + end <= ktla_ktva((unsigned long)_stext)) &&
32572 + (start >= ktla_ktva((unsigned long)_einittext) ||
32573 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32574 +
32575 +#ifdef CONFIG_ACPI_SLEEP
32576 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32577 +#endif
32578 +
32579 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32580 + return 0;
32581 + return 1;
32582 }
32583
32584 /*
32585 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32586 unsigned long last_map_addr = end;
32587 unsigned long start_pfn, end_pfn;
32588 pgd_t *pgd_base = swapper_pg_dir;
32589 - int pgd_idx, pmd_idx, pte_ofs;
32590 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32591 unsigned long pfn;
32592 pgd_t *pgd;
32593 + pud_t *pud;
32594 pmd_t *pmd;
32595 pte_t *pte;
32596 unsigned pages_2m, pages_4k;
32597 @@ -291,8 +295,13 @@ repeat:
32598 pfn = start_pfn;
32599 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32600 pgd = pgd_base + pgd_idx;
32601 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32602 - pmd = one_md_table_init(pgd);
32603 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32604 + pud = pud_offset(pgd, 0);
32605 + pmd = pmd_offset(pud, 0);
32606 +
32607 +#ifdef CONFIG_X86_PAE
32608 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32609 +#endif
32610
32611 if (pfn >= end_pfn)
32612 continue;
32613 @@ -304,14 +313,13 @@ repeat:
32614 #endif
32615 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32616 pmd++, pmd_idx++) {
32617 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32618 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32619
32620 /*
32621 * Map with big pages if possible, otherwise
32622 * create normal page tables:
32623 */
32624 if (use_pse) {
32625 - unsigned int addr2;
32626 pgprot_t prot = PAGE_KERNEL_LARGE;
32627 /*
32628 * first pass will use the same initial
32629 @@ -322,11 +330,7 @@ repeat:
32630 _PAGE_PSE);
32631
32632 pfn &= PMD_MASK >> PAGE_SHIFT;
32633 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32634 - PAGE_OFFSET + PAGE_SIZE-1;
32635 -
32636 - if (is_kernel_text(addr) ||
32637 - is_kernel_text(addr2))
32638 + if (is_kernel_text(address, address + PMD_SIZE))
32639 prot = PAGE_KERNEL_LARGE_EXEC;
32640
32641 pages_2m++;
32642 @@ -343,7 +347,7 @@ repeat:
32643 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32644 pte += pte_ofs;
32645 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32646 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32647 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32648 pgprot_t prot = PAGE_KERNEL;
32649 /*
32650 * first pass will use the same initial
32651 @@ -351,7 +355,7 @@ repeat:
32652 */
32653 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32654
32655 - if (is_kernel_text(addr))
32656 + if (is_kernel_text(address, address + PAGE_SIZE))
32657 prot = PAGE_KERNEL_EXEC;
32658
32659 pages_4k++;
32660 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32661
32662 pud = pud_offset(pgd, va);
32663 pmd = pmd_offset(pud, va);
32664 - if (!pmd_present(*pmd))
32665 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32666 break;
32667
32668 /* should not be large page here */
32669 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32670
32671 static void __init pagetable_init(void)
32672 {
32673 - pgd_t *pgd_base = swapper_pg_dir;
32674 -
32675 - permanent_kmaps_init(pgd_base);
32676 + permanent_kmaps_init(swapper_pg_dir);
32677 }
32678
32679 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32680 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32681 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32682
32683 /* user-defined highmem size */
32684 @@ -787,10 +789,10 @@ void __init mem_init(void)
32685 ((unsigned long)&__init_end -
32686 (unsigned long)&__init_begin) >> 10,
32687
32688 - (unsigned long)&_etext, (unsigned long)&_edata,
32689 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32690 + (unsigned long)&_sdata, (unsigned long)&_edata,
32691 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32692
32693 - (unsigned long)&_text, (unsigned long)&_etext,
32694 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32695 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32696
32697 /*
32698 @@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32699 if (!kernel_set_to_readonly)
32700 return;
32701
32702 + start = ktla_ktva(start);
32703 pr_debug("Set kernel text: %lx - %lx for read write\n",
32704 start, start+size);
32705
32706 @@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32707 if (!kernel_set_to_readonly)
32708 return;
32709
32710 + start = ktla_ktva(start);
32711 pr_debug("Set kernel text: %lx - %lx for read only\n",
32712 start, start+size);
32713
32714 @@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32715 unsigned long start = PFN_ALIGN(_text);
32716 unsigned long size = PFN_ALIGN(_etext) - start;
32717
32718 + start = ktla_ktva(start);
32719 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32720 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32721 size >> 10);
32722 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32723 index f35c66c..84b95ef 100644
32724 --- a/arch/x86/mm/init_64.c
32725 +++ b/arch/x86/mm/init_64.c
32726 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32727 * around without checking the pgd every time.
32728 */
32729
32730 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32731 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32732 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32733
32734 int force_personality32;
32735 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32736
32737 for (address = start; address <= end; address += PGDIR_SIZE) {
32738 const pgd_t *pgd_ref = pgd_offset_k(address);
32739 +
32740 +#ifdef CONFIG_PAX_PER_CPU_PGD
32741 + unsigned long cpu;
32742 +#else
32743 struct page *page;
32744 +#endif
32745
32746 if (pgd_none(*pgd_ref))
32747 continue;
32748
32749 spin_lock(&pgd_lock);
32750 +
32751 +#ifdef CONFIG_PAX_PER_CPU_PGD
32752 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32753 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32754 +
32755 + if (pgd_none(*pgd))
32756 + set_pgd(pgd, *pgd_ref);
32757 + else
32758 + BUG_ON(pgd_page_vaddr(*pgd)
32759 + != pgd_page_vaddr(*pgd_ref));
32760 + pgd = pgd_offset_cpu(cpu, kernel, address);
32761 +#else
32762 list_for_each_entry(page, &pgd_list, lru) {
32763 pgd_t *pgd;
32764 spinlock_t *pgt_lock;
32765 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32766 /* the pgt_lock only for Xen */
32767 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32768 spin_lock(pgt_lock);
32769 +#endif
32770
32771 if (pgd_none(*pgd))
32772 set_pgd(pgd, *pgd_ref);
32773 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32774 BUG_ON(pgd_page_vaddr(*pgd)
32775 != pgd_page_vaddr(*pgd_ref));
32776
32777 +#ifndef CONFIG_PAX_PER_CPU_PGD
32778 spin_unlock(pgt_lock);
32779 +#endif
32780 +
32781 }
32782 spin_unlock(&pgd_lock);
32783 }
32784 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32785 {
32786 if (pgd_none(*pgd)) {
32787 pud_t *pud = (pud_t *)spp_getpage();
32788 - pgd_populate(&init_mm, pgd, pud);
32789 + pgd_populate_kernel(&init_mm, pgd, pud);
32790 if (pud != pud_offset(pgd, 0))
32791 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32792 pud, pud_offset(pgd, 0));
32793 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32794 {
32795 if (pud_none(*pud)) {
32796 pmd_t *pmd = (pmd_t *) spp_getpage();
32797 - pud_populate(&init_mm, pud, pmd);
32798 + pud_populate_kernel(&init_mm, pud, pmd);
32799 if (pmd != pmd_offset(pud, 0))
32800 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32801 pmd, pmd_offset(pud, 0));
32802 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32803 pmd = fill_pmd(pud, vaddr);
32804 pte = fill_pte(pmd, vaddr);
32805
32806 + pax_open_kernel();
32807 set_pte(pte, new_pte);
32808 + pax_close_kernel();
32809
32810 /*
32811 * It's enough to flush this one mapping.
32812 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32813 pgd = pgd_offset_k((unsigned long)__va(phys));
32814 if (pgd_none(*pgd)) {
32815 pud = (pud_t *) spp_getpage();
32816 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32817 - _PAGE_USER));
32818 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32819 }
32820 pud = pud_offset(pgd, (unsigned long)__va(phys));
32821 if (pud_none(*pud)) {
32822 pmd = (pmd_t *) spp_getpage();
32823 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32824 - _PAGE_USER));
32825 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32826 }
32827 pmd = pmd_offset(pud, phys);
32828 BUG_ON(!pmd_none(*pmd));
32829 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32830 prot);
32831
32832 spin_lock(&init_mm.page_table_lock);
32833 - pud_populate(&init_mm, pud, pmd);
32834 + pud_populate_kernel(&init_mm, pud, pmd);
32835 spin_unlock(&init_mm.page_table_lock);
32836 }
32837 __flush_tlb_all();
32838 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32839 page_size_mask);
32840
32841 spin_lock(&init_mm.page_table_lock);
32842 - pgd_populate(&init_mm, pgd, pud);
32843 + pgd_populate_kernel(&init_mm, pgd, pud);
32844 spin_unlock(&init_mm.page_table_lock);
32845 pgd_changed = true;
32846 }
32847 @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32848 static struct vm_area_struct gate_vma = {
32849 .vm_start = VSYSCALL_START,
32850 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32851 - .vm_page_prot = PAGE_READONLY_EXEC,
32852 - .vm_flags = VM_READ | VM_EXEC
32853 + .vm_page_prot = PAGE_READONLY,
32854 + .vm_flags = VM_READ
32855 };
32856
32857 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32858 @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32859
32860 const char *arch_vma_name(struct vm_area_struct *vma)
32861 {
32862 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32863 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32864 return "[vdso]";
32865 if (vma == &gate_vma)
32866 return "[vsyscall]";
32867 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32868 index 7b179b4..6bd17777 100644
32869 --- a/arch/x86/mm/iomap_32.c
32870 +++ b/arch/x86/mm/iomap_32.c
32871 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32872 type = kmap_atomic_idx_push();
32873 idx = type + KM_TYPE_NR * smp_processor_id();
32874 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32875 +
32876 + pax_open_kernel();
32877 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32878 + pax_close_kernel();
32879 +
32880 arch_flush_lazy_mmu_mode();
32881
32882 return (void *)vaddr;
32883 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32884 index bc7527e..5e2c495 100644
32885 --- a/arch/x86/mm/ioremap.c
32886 +++ b/arch/x86/mm/ioremap.c
32887 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
32888 unsigned long i;
32889
32890 for (i = 0; i < nr_pages; ++i)
32891 - if (pfn_valid(start_pfn + i) &&
32892 - !PageReserved(pfn_to_page(start_pfn + i)))
32893 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
32894 + !PageReserved(pfn_to_page(start_pfn + i))))
32895 return 1;
32896
32897 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
32898 @@ -268,7 +268,7 @@ EXPORT_SYMBOL(ioremap_prot);
32899 *
32900 * Caller must ensure there is only one unmapping for the same pointer.
32901 */
32902 -void iounmap(volatile void __iomem *addr)
32903 +void iounmap(const volatile void __iomem *addr)
32904 {
32905 struct vm_struct *p, *o;
32906
32907 @@ -322,6 +322,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32908
32909 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32910 if (page_is_ram(start >> PAGE_SHIFT))
32911 +#ifdef CONFIG_HIGHMEM
32912 + if ((start >> PAGE_SHIFT) < max_low_pfn)
32913 +#endif
32914 return __va(phys);
32915
32916 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32917 @@ -334,13 +337,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32918 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32919 {
32920 if (page_is_ram(phys >> PAGE_SHIFT))
32921 +#ifdef CONFIG_HIGHMEM
32922 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
32923 +#endif
32924 return;
32925
32926 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32927 return;
32928 }
32929
32930 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32931 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32932
32933 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32934 {
32935 @@ -370,8 +376,7 @@ void __init early_ioremap_init(void)
32936 early_ioremap_setup();
32937
32938 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32939 - memset(bm_pte, 0, sizeof(bm_pte));
32940 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
32941 + pmd_populate_user(&init_mm, pmd, bm_pte);
32942
32943 /*
32944 * The boot-ioremap range spans multiple pmds, for which
32945 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32946 index dd89a13..d77bdcc 100644
32947 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
32948 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32949 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32950 * memory (e.g. tracked pages)? For now, we need this to avoid
32951 * invoking kmemcheck for PnP BIOS calls.
32952 */
32953 - if (regs->flags & X86_VM_MASK)
32954 + if (v8086_mode(regs))
32955 return false;
32956 - if (regs->cs != __KERNEL_CS)
32957 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32958 return false;
32959
32960 pte = kmemcheck_pte_lookup(address);
32961 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32962 index 25e7e13..1964579 100644
32963 --- a/arch/x86/mm/mmap.c
32964 +++ b/arch/x86/mm/mmap.c
32965 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32966 * Leave an at least ~128 MB hole with possible stack randomization.
32967 */
32968 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32969 -#define MAX_GAP (TASK_SIZE/6*5)
32970 +#define MAX_GAP (pax_task_size/6*5)
32971
32972 static int mmap_is_legacy(void)
32973 {
32974 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32975 return rnd << PAGE_SHIFT;
32976 }
32977
32978 -static unsigned long mmap_base(void)
32979 +static unsigned long mmap_base(struct mm_struct *mm)
32980 {
32981 unsigned long gap = rlimit(RLIMIT_STACK);
32982 + unsigned long pax_task_size = TASK_SIZE;
32983 +
32984 +#ifdef CONFIG_PAX_SEGMEXEC
32985 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32986 + pax_task_size = SEGMEXEC_TASK_SIZE;
32987 +#endif
32988
32989 if (gap < MIN_GAP)
32990 gap = MIN_GAP;
32991 else if (gap > MAX_GAP)
32992 gap = MAX_GAP;
32993
32994 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32995 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32996 }
32997
32998 /*
32999 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33000 * does, but not when emulating X86_32
33001 */
33002 -static unsigned long mmap_legacy_base(void)
33003 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
33004 {
33005 - if (mmap_is_ia32())
33006 + if (mmap_is_ia32()) {
33007 +
33008 +#ifdef CONFIG_PAX_SEGMEXEC
33009 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33010 + return SEGMEXEC_TASK_UNMAPPED_BASE;
33011 + else
33012 +#endif
33013 +
33014 return TASK_UNMAPPED_BASE;
33015 - else
33016 + } else
33017 return TASK_UNMAPPED_BASE + mmap_rnd();
33018 }
33019
33020 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33021 */
33022 void arch_pick_mmap_layout(struct mm_struct *mm)
33023 {
33024 - mm->mmap_legacy_base = mmap_legacy_base();
33025 - mm->mmap_base = mmap_base();
33026 + mm->mmap_legacy_base = mmap_legacy_base(mm);
33027 + mm->mmap_base = mmap_base(mm);
33028 +
33029 +#ifdef CONFIG_PAX_RANDMMAP
33030 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
33031 + mm->mmap_legacy_base += mm->delta_mmap;
33032 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33033 + }
33034 +#endif
33035
33036 if (mmap_is_legacy()) {
33037 mm->mmap_base = mm->mmap_legacy_base;
33038 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33039 index 0057a7a..95c7edd 100644
33040 --- a/arch/x86/mm/mmio-mod.c
33041 +++ b/arch/x86/mm/mmio-mod.c
33042 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33043 break;
33044 default:
33045 {
33046 - unsigned char *ip = (unsigned char *)instptr;
33047 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33048 my_trace->opcode = MMIO_UNKNOWN_OP;
33049 my_trace->width = 0;
33050 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33051 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33052 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33053 void __iomem *addr)
33054 {
33055 - static atomic_t next_id;
33056 + static atomic_unchecked_t next_id;
33057 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33058 /* These are page-unaligned. */
33059 struct mmiotrace_map map = {
33060 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33061 .private = trace
33062 },
33063 .phys = offset,
33064 - .id = atomic_inc_return(&next_id)
33065 + .id = atomic_inc_return_unchecked(&next_id)
33066 };
33067 map.map_id = trace->id;
33068
33069 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33070 ioremap_trace_core(offset, size, addr);
33071 }
33072
33073 -static void iounmap_trace_core(volatile void __iomem *addr)
33074 +static void iounmap_trace_core(const volatile void __iomem *addr)
33075 {
33076 struct mmiotrace_map map = {
33077 .phys = 0,
33078 @@ -328,7 +328,7 @@ not_enabled:
33079 }
33080 }
33081
33082 -void mmiotrace_iounmap(volatile void __iomem *addr)
33083 +void mmiotrace_iounmap(const volatile void __iomem *addr)
33084 {
33085 might_sleep();
33086 if (is_enabled()) /* recheck and proper locking in *_core() */
33087 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33088 index 1d045f9..3a00249 100644
33089 --- a/arch/x86/mm/numa.c
33090 +++ b/arch/x86/mm/numa.c
33091 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33092 return true;
33093 }
33094
33095 -static int __init numa_register_memblks(struct numa_meminfo *mi)
33096 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33097 {
33098 unsigned long uninitialized_var(pfn_align);
33099 int i, nid;
33100 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
33101 index 461bc82..4e091a3 100644
33102 --- a/arch/x86/mm/pageattr-test.c
33103 +++ b/arch/x86/mm/pageattr-test.c
33104 @@ -35,7 +35,7 @@ enum {
33105
33106 static int pte_testbit(pte_t pte)
33107 {
33108 - return pte_flags(pte) & _PAGE_UNUSED1;
33109 + return pte_flags(pte) & _PAGE_CPA_TEST;
33110 }
33111
33112 struct split_state {
33113 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33114 index ae242a7..1c7998f 100644
33115 --- a/arch/x86/mm/pageattr.c
33116 +++ b/arch/x86/mm/pageattr.c
33117 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33118 */
33119 #ifdef CONFIG_PCI_BIOS
33120 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33121 - pgprot_val(forbidden) |= _PAGE_NX;
33122 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33123 #endif
33124
33125 /*
33126 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33127 * Does not cover __inittext since that is gone later on. On
33128 * 64bit we do not enforce !NX on the low mapping
33129 */
33130 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
33131 - pgprot_val(forbidden) |= _PAGE_NX;
33132 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33133 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33134
33135 +#ifdef CONFIG_DEBUG_RODATA
33136 /*
33137 * The .rodata section needs to be read-only. Using the pfn
33138 * catches all aliases.
33139 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33140 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33141 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33142 pgprot_val(forbidden) |= _PAGE_RW;
33143 +#endif
33144
33145 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33146 /*
33147 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33148 }
33149 #endif
33150
33151 +#ifdef CONFIG_PAX_KERNEXEC
33152 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33153 + pgprot_val(forbidden) |= _PAGE_RW;
33154 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33155 + }
33156 +#endif
33157 +
33158 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33159
33160 return prot;
33161 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33162 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33163 {
33164 /* change init_mm */
33165 + pax_open_kernel();
33166 set_pte_atomic(kpte, pte);
33167 +
33168 #ifdef CONFIG_X86_32
33169 if (!SHARED_KERNEL_PMD) {
33170 +
33171 +#ifdef CONFIG_PAX_PER_CPU_PGD
33172 + unsigned long cpu;
33173 +#else
33174 struct page *page;
33175 +#endif
33176
33177 +#ifdef CONFIG_PAX_PER_CPU_PGD
33178 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33179 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33180 +#else
33181 list_for_each_entry(page, &pgd_list, lru) {
33182 - pgd_t *pgd;
33183 + pgd_t *pgd = (pgd_t *)page_address(page);
33184 +#endif
33185 +
33186 pud_t *pud;
33187 pmd_t *pmd;
33188
33189 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33190 + pgd += pgd_index(address);
33191 pud = pud_offset(pgd, address);
33192 pmd = pmd_offset(pud, address);
33193 set_pte_atomic((pte_t *)pmd, pte);
33194 }
33195 }
33196 #endif
33197 + pax_close_kernel();
33198 }
33199
33200 static int
33201 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33202 index 6574388..87e9bef 100644
33203 --- a/arch/x86/mm/pat.c
33204 +++ b/arch/x86/mm/pat.c
33205 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33206
33207 if (!entry) {
33208 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33209 - current->comm, current->pid, start, end - 1);
33210 + current->comm, task_pid_nr(current), start, end - 1);
33211 return -EINVAL;
33212 }
33213
33214 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33215
33216 while (cursor < to) {
33217 if (!devmem_is_allowed(pfn)) {
33218 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33219 - current->comm, from, to - 1);
33220 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33221 + current->comm, from, to - 1, cursor);
33222 return 0;
33223 }
33224 cursor += PAGE_SIZE;
33225 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33226 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33227 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33228 "for [mem %#010Lx-%#010Lx]\n",
33229 - current->comm, current->pid,
33230 + current->comm, task_pid_nr(current),
33231 cattr_name(flags),
33232 base, (unsigned long long)(base + size-1));
33233 return -EINVAL;
33234 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33235 flags = lookup_memtype(paddr);
33236 if (want_flags != flags) {
33237 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33238 - current->comm, current->pid,
33239 + current->comm, task_pid_nr(current),
33240 cattr_name(want_flags),
33241 (unsigned long long)paddr,
33242 (unsigned long long)(paddr + size - 1),
33243 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33244 free_memtype(paddr, paddr + size);
33245 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33246 " for [mem %#010Lx-%#010Lx], got %s\n",
33247 - current->comm, current->pid,
33248 + current->comm, task_pid_nr(current),
33249 cattr_name(want_flags),
33250 (unsigned long long)paddr,
33251 (unsigned long long)(paddr + size - 1),
33252 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33253 index 415f6c4..d319983 100644
33254 --- a/arch/x86/mm/pat_rbtree.c
33255 +++ b/arch/x86/mm/pat_rbtree.c
33256 @@ -160,7 +160,7 @@ success:
33257
33258 failure:
33259 printk(KERN_INFO "%s:%d conflicting memory types "
33260 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33261 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33262 end, cattr_name(found_type), cattr_name(match->type));
33263 return -EBUSY;
33264 }
33265 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33266 index 9f0614d..92ae64a 100644
33267 --- a/arch/x86/mm/pf_in.c
33268 +++ b/arch/x86/mm/pf_in.c
33269 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33270 int i;
33271 enum reason_type rv = OTHERS;
33272
33273 - p = (unsigned char *)ins_addr;
33274 + p = (unsigned char *)ktla_ktva(ins_addr);
33275 p += skip_prefix(p, &prf);
33276 p += get_opcode(p, &opcode);
33277
33278 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33279 struct prefix_bits prf;
33280 int i;
33281
33282 - p = (unsigned char *)ins_addr;
33283 + p = (unsigned char *)ktla_ktva(ins_addr);
33284 p += skip_prefix(p, &prf);
33285 p += get_opcode(p, &opcode);
33286
33287 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33288 struct prefix_bits prf;
33289 int i;
33290
33291 - p = (unsigned char *)ins_addr;
33292 + p = (unsigned char *)ktla_ktva(ins_addr);
33293 p += skip_prefix(p, &prf);
33294 p += get_opcode(p, &opcode);
33295
33296 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33297 struct prefix_bits prf;
33298 int i;
33299
33300 - p = (unsigned char *)ins_addr;
33301 + p = (unsigned char *)ktla_ktva(ins_addr);
33302 p += skip_prefix(p, &prf);
33303 p += get_opcode(p, &opcode);
33304 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33305 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33306 struct prefix_bits prf;
33307 int i;
33308
33309 - p = (unsigned char *)ins_addr;
33310 + p = (unsigned char *)ktla_ktva(ins_addr);
33311 p += skip_prefix(p, &prf);
33312 p += get_opcode(p, &opcode);
33313 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33314 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33315 index c96314a..433b127 100644
33316 --- a/arch/x86/mm/pgtable.c
33317 +++ b/arch/x86/mm/pgtable.c
33318 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33319 list_del(&page->lru);
33320 }
33321
33322 -#define UNSHARED_PTRS_PER_PGD \
33323 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33324 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33325 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33326
33327 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33328 +{
33329 + unsigned int count = USER_PGD_PTRS;
33330
33331 + if (!pax_user_shadow_base)
33332 + return;
33333 +
33334 + while (count--)
33335 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33336 +}
33337 +#endif
33338 +
33339 +#ifdef CONFIG_PAX_PER_CPU_PGD
33340 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33341 +{
33342 + unsigned int count = USER_PGD_PTRS;
33343 +
33344 + while (count--) {
33345 + pgd_t pgd;
33346 +
33347 +#ifdef CONFIG_X86_64
33348 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33349 +#else
33350 + pgd = *src++;
33351 +#endif
33352 +
33353 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33354 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33355 +#endif
33356 +
33357 + *dst++ = pgd;
33358 + }
33359 +
33360 +}
33361 +#endif
33362 +
33363 +#ifdef CONFIG_X86_64
33364 +#define pxd_t pud_t
33365 +#define pyd_t pgd_t
33366 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33367 +#define pgtable_pxd_page_ctor(page) true
33368 +#define pgtable_pxd_page_dtor(page)
33369 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33370 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33371 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33372 +#define PYD_SIZE PGDIR_SIZE
33373 +#else
33374 +#define pxd_t pmd_t
33375 +#define pyd_t pud_t
33376 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33377 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33378 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33379 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33380 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33381 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33382 +#define PYD_SIZE PUD_SIZE
33383 +#endif
33384 +
33385 +#ifdef CONFIG_PAX_PER_CPU_PGD
33386 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33387 +static inline void pgd_dtor(pgd_t *pgd) {}
33388 +#else
33389 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33390 {
33391 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33392 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33393 pgd_list_del(pgd);
33394 spin_unlock(&pgd_lock);
33395 }
33396 +#endif
33397
33398 /*
33399 * List of all pgd's needed for non-PAE so it can invalidate entries
33400 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33401 * -- nyc
33402 */
33403
33404 -#ifdef CONFIG_X86_PAE
33405 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33406 /*
33407 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33408 * updating the top-level pagetable entries to guarantee the
33409 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33410 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33411 * and initialize the kernel pmds here.
33412 */
33413 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33414 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33415
33416 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33417 {
33418 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33419 */
33420 flush_tlb_mm(mm);
33421 }
33422 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33423 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33424 #else /* !CONFIG_X86_PAE */
33425
33426 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33427 -#define PREALLOCATED_PMDS 0
33428 +#define PREALLOCATED_PXDS 0
33429
33430 #endif /* CONFIG_X86_PAE */
33431
33432 -static void free_pmds(pmd_t *pmds[])
33433 +static void free_pxds(pxd_t *pxds[])
33434 {
33435 int i;
33436
33437 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33438 - if (pmds[i]) {
33439 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33440 - free_page((unsigned long)pmds[i]);
33441 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33442 + if (pxds[i]) {
33443 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33444 + free_page((unsigned long)pxds[i]);
33445 }
33446 }
33447
33448 -static int preallocate_pmds(pmd_t *pmds[])
33449 +static int preallocate_pxds(pxd_t *pxds[])
33450 {
33451 int i;
33452 bool failed = false;
33453
33454 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33455 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33456 - if (!pmd)
33457 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33458 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33459 + if (!pxd)
33460 failed = true;
33461 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33462 - free_page((unsigned long)pmd);
33463 - pmd = NULL;
33464 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33465 + free_page((unsigned long)pxd);
33466 + pxd = NULL;
33467 failed = true;
33468 }
33469 - pmds[i] = pmd;
33470 + pxds[i] = pxd;
33471 }
33472
33473 if (failed) {
33474 - free_pmds(pmds);
33475 + free_pxds(pxds);
33476 return -ENOMEM;
33477 }
33478
33479 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33480 * preallocate which never got a corresponding vma will need to be
33481 * freed manually.
33482 */
33483 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33484 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33485 {
33486 int i;
33487
33488 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33489 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33490 pgd_t pgd = pgdp[i];
33491
33492 if (pgd_val(pgd) != 0) {
33493 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33494 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33495
33496 - pgdp[i] = native_make_pgd(0);
33497 + set_pgd(pgdp + i, native_make_pgd(0));
33498
33499 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33500 - pmd_free(mm, pmd);
33501 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33502 + pxd_free(mm, pxd);
33503 }
33504 }
33505 }
33506
33507 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33508 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33509 {
33510 - pud_t *pud;
33511 + pyd_t *pyd;
33512 int i;
33513
33514 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33515 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33516 return;
33517
33518 - pud = pud_offset(pgd, 0);
33519 -
33520 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33521 - pmd_t *pmd = pmds[i];
33522 +#ifdef CONFIG_X86_64
33523 + pyd = pyd_offset(mm, 0L);
33524 +#else
33525 + pyd = pyd_offset(pgd, 0L);
33526 +#endif
33527
33528 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33529 + pxd_t *pxd = pxds[i];
33530 if (i >= KERNEL_PGD_BOUNDARY)
33531 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33532 - sizeof(pmd_t) * PTRS_PER_PMD);
33533 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33534 + sizeof(pxd_t) * PTRS_PER_PMD);
33535
33536 - pud_populate(mm, pud, pmd);
33537 + pyd_populate(mm, pyd, pxd);
33538 }
33539 }
33540
33541 pgd_t *pgd_alloc(struct mm_struct *mm)
33542 {
33543 pgd_t *pgd;
33544 - pmd_t *pmds[PREALLOCATED_PMDS];
33545 + pxd_t *pxds[PREALLOCATED_PXDS];
33546
33547 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33548
33549 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33550
33551 mm->pgd = pgd;
33552
33553 - if (preallocate_pmds(pmds) != 0)
33554 + if (preallocate_pxds(pxds) != 0)
33555 goto out_free_pgd;
33556
33557 if (paravirt_pgd_alloc(mm) != 0)
33558 - goto out_free_pmds;
33559 + goto out_free_pxds;
33560
33561 /*
33562 * Make sure that pre-populating the pmds is atomic with
33563 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33564 spin_lock(&pgd_lock);
33565
33566 pgd_ctor(mm, pgd);
33567 - pgd_prepopulate_pmd(mm, pgd, pmds);
33568 + pgd_prepopulate_pxd(mm, pgd, pxds);
33569
33570 spin_unlock(&pgd_lock);
33571
33572 return pgd;
33573
33574 -out_free_pmds:
33575 - free_pmds(pmds);
33576 +out_free_pxds:
33577 + free_pxds(pxds);
33578 out_free_pgd:
33579 free_page((unsigned long)pgd);
33580 out:
33581 @@ -313,7 +380,7 @@ out:
33582
33583 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33584 {
33585 - pgd_mop_up_pmds(mm, pgd);
33586 + pgd_mop_up_pxds(mm, pgd);
33587 pgd_dtor(pgd);
33588 paravirt_pgd_free(mm, pgd);
33589 free_page((unsigned long)pgd);
33590 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33591 index 4dd8cf6..f9d143e 100644
33592 --- a/arch/x86/mm/pgtable_32.c
33593 +++ b/arch/x86/mm/pgtable_32.c
33594 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33595 return;
33596 }
33597 pte = pte_offset_kernel(pmd, vaddr);
33598 +
33599 + pax_open_kernel();
33600 if (pte_val(pteval))
33601 set_pte_at(&init_mm, vaddr, pte, pteval);
33602 else
33603 pte_clear(&init_mm, vaddr, pte);
33604 + pax_close_kernel();
33605
33606 /*
33607 * It's enough to flush this one mapping.
33608 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33609 index e666cbb..61788c45 100644
33610 --- a/arch/x86/mm/physaddr.c
33611 +++ b/arch/x86/mm/physaddr.c
33612 @@ -10,7 +10,7 @@
33613 #ifdef CONFIG_X86_64
33614
33615 #ifdef CONFIG_DEBUG_VIRTUAL
33616 -unsigned long __phys_addr(unsigned long x)
33617 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33618 {
33619 unsigned long y = x - __START_KERNEL_map;
33620
33621 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33622 #else
33623
33624 #ifdef CONFIG_DEBUG_VIRTUAL
33625 -unsigned long __phys_addr(unsigned long x)
33626 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33627 {
33628 unsigned long phys_addr = x - PAGE_OFFSET;
33629 /* VMALLOC_* aren't constants */
33630 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33631 index 90555bf..f5f1828 100644
33632 --- a/arch/x86/mm/setup_nx.c
33633 +++ b/arch/x86/mm/setup_nx.c
33634 @@ -5,8 +5,10 @@
33635 #include <asm/pgtable.h>
33636 #include <asm/proto.h>
33637
33638 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33639 static int disable_nx;
33640
33641 +#ifndef CONFIG_PAX_PAGEEXEC
33642 /*
33643 * noexec = on|off
33644 *
33645 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33646 return 0;
33647 }
33648 early_param("noexec", noexec_setup);
33649 +#endif
33650 +
33651 +#endif
33652
33653 void x86_configure_nx(void)
33654 {
33655 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33656 if (cpu_has_nx && !disable_nx)
33657 __supported_pte_mask |= _PAGE_NX;
33658 else
33659 +#endif
33660 __supported_pte_mask &= ~_PAGE_NX;
33661 }
33662
33663 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33664 index dd8dda1..9e9b0f6 100644
33665 --- a/arch/x86/mm/tlb.c
33666 +++ b/arch/x86/mm/tlb.c
33667 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
33668 BUG();
33669 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33670 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33671 +
33672 +#ifndef CONFIG_PAX_PER_CPU_PGD
33673 load_cr3(swapper_pg_dir);
33674 +#endif
33675 +
33676 }
33677 }
33678 EXPORT_SYMBOL_GPL(leave_mm);
33679 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33680 new file mode 100644
33681 index 0000000..dace51c
33682 --- /dev/null
33683 +++ b/arch/x86/mm/uderef_64.c
33684 @@ -0,0 +1,37 @@
33685 +#include <linux/mm.h>
33686 +#include <asm/pgtable.h>
33687 +#include <asm/uaccess.h>
33688 +
33689 +#ifdef CONFIG_PAX_MEMORY_UDEREF
33690 +/* PaX: due to the special call convention these functions must
33691 + * - remain leaf functions under all configurations,
33692 + * - never be called directly, only dereferenced from the wrappers.
33693 + */
33694 +void __pax_open_userland(void)
33695 +{
33696 + unsigned int cpu;
33697 +
33698 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33699 + return;
33700 +
33701 + cpu = raw_get_cpu();
33702 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33703 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33704 + raw_put_cpu_no_resched();
33705 +}
33706 +EXPORT_SYMBOL(__pax_open_userland);
33707 +
33708 +void __pax_close_userland(void)
33709 +{
33710 + unsigned int cpu;
33711 +
33712 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33713 + return;
33714 +
33715 + cpu = raw_get_cpu();
33716 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33717 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33718 + raw_put_cpu_no_resched();
33719 +}
33720 +EXPORT_SYMBOL(__pax_close_userland);
33721 +#endif
33722 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33723 index 0149575..f746de8 100644
33724 --- a/arch/x86/net/bpf_jit.S
33725 +++ b/arch/x86/net/bpf_jit.S
33726 @@ -9,6 +9,7 @@
33727 */
33728 #include <linux/linkage.h>
33729 #include <asm/dwarf2.h>
33730 +#include <asm/alternative-asm.h>
33731
33732 /*
33733 * Calling convention :
33734 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33735 jle bpf_slow_path_word
33736 mov (SKBDATA,%rsi),%eax
33737 bswap %eax /* ntohl() */
33738 + pax_force_retaddr
33739 ret
33740
33741 sk_load_half:
33742 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33743 jle bpf_slow_path_half
33744 movzwl (SKBDATA,%rsi),%eax
33745 rol $8,%ax # ntohs()
33746 + pax_force_retaddr
33747 ret
33748
33749 sk_load_byte:
33750 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33751 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33752 jle bpf_slow_path_byte
33753 movzbl (SKBDATA,%rsi),%eax
33754 + pax_force_retaddr
33755 ret
33756
33757 /**
33758 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33759 movzbl (SKBDATA,%rsi),%ebx
33760 and $15,%bl
33761 shl $2,%bl
33762 + pax_force_retaddr
33763 ret
33764
33765 /* rsi contains offset and can be scratched */
33766 @@ -109,6 +114,7 @@ bpf_slow_path_word:
33767 js bpf_error
33768 mov -12(%rbp),%eax
33769 bswap %eax
33770 + pax_force_retaddr
33771 ret
33772
33773 bpf_slow_path_half:
33774 @@ -117,12 +123,14 @@ bpf_slow_path_half:
33775 mov -12(%rbp),%ax
33776 rol $8,%ax
33777 movzwl %ax,%eax
33778 + pax_force_retaddr
33779 ret
33780
33781 bpf_slow_path_byte:
33782 bpf_slow_path_common(1)
33783 js bpf_error
33784 movzbl -12(%rbp),%eax
33785 + pax_force_retaddr
33786 ret
33787
33788 bpf_slow_path_byte_msh:
33789 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33790 and $15,%al
33791 shl $2,%al
33792 xchg %eax,%ebx
33793 + pax_force_retaddr
33794 ret
33795
33796 #define sk_negative_common(SIZE) \
33797 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33798 sk_negative_common(4)
33799 mov (%rax), %eax
33800 bswap %eax
33801 + pax_force_retaddr
33802 ret
33803
33804 bpf_slow_path_half_neg:
33805 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33806 mov (%rax),%ax
33807 rol $8,%ax
33808 movzwl %ax,%eax
33809 + pax_force_retaddr
33810 ret
33811
33812 bpf_slow_path_byte_neg:
33813 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33814 .globl sk_load_byte_negative_offset
33815 sk_negative_common(1)
33816 movzbl (%rax), %eax
33817 + pax_force_retaddr
33818 ret
33819
33820 bpf_slow_path_byte_msh_neg:
33821 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33822 and $15,%al
33823 shl $2,%al
33824 xchg %eax,%ebx
33825 + pax_force_retaddr
33826 ret
33827
33828 bpf_error:
33829 @@ -197,4 +210,5 @@ bpf_error:
33830 xor %eax,%eax
33831 mov -8(%rbp),%rbx
33832 leaveq
33833 + pax_force_retaddr
33834 ret
33835 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33836 index 6d5663a..f1ec380 100644
33837 --- a/arch/x86/net/bpf_jit_comp.c
33838 +++ b/arch/x86/net/bpf_jit_comp.c
33839 @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33840 return ptr + len;
33841 }
33842
33843 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33844 +#define MAX_INSTR_CODE_SIZE 96
33845 +#else
33846 +#define MAX_INSTR_CODE_SIZE 64
33847 +#endif
33848 +
33849 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33850
33851 #define EMIT1(b1) EMIT(b1, 1)
33852 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33853 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33854 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33855 +
33856 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33857 +/* original constant will appear in ecx */
33858 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
33859 +do { \
33860 + /* mov ecx, randkey */ \
33861 + EMIT1(0xb9); \
33862 + EMIT(_key, 4); \
33863 + /* xor ecx, randkey ^ off */ \
33864 + EMIT2(0x81, 0xf1); \
33865 + EMIT((_key) ^ (_off), 4); \
33866 +} while (0)
33867 +
33868 +#define EMIT1_off32(b1, _off) \
33869 +do { \
33870 + switch (b1) { \
33871 + case 0x05: /* add eax, imm32 */ \
33872 + case 0x2d: /* sub eax, imm32 */ \
33873 + case 0x25: /* and eax, imm32 */ \
33874 + case 0x0d: /* or eax, imm32 */ \
33875 + case 0xb8: /* mov eax, imm32 */ \
33876 + case 0x35: /* xor eax, imm32 */ \
33877 + case 0x3d: /* cmp eax, imm32 */ \
33878 + case 0xa9: /* test eax, imm32 */ \
33879 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33880 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33881 + break; \
33882 + case 0xbb: /* mov ebx, imm32 */ \
33883 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33884 + /* mov ebx, ecx */ \
33885 + EMIT2(0x89, 0xcb); \
33886 + break; \
33887 + case 0xbe: /* mov esi, imm32 */ \
33888 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33889 + /* mov esi, ecx */ \
33890 + EMIT2(0x89, 0xce); \
33891 + break; \
33892 + case 0xe8: /* call rel imm32, always to known funcs */ \
33893 + EMIT1(b1); \
33894 + EMIT(_off, 4); \
33895 + break; \
33896 + case 0xe9: /* jmp rel imm32 */ \
33897 + EMIT1(b1); \
33898 + EMIT(_off, 4); \
33899 + /* prevent fall-through, we're not called if off = 0 */ \
33900 + EMIT(0xcccccccc, 4); \
33901 + EMIT(0xcccccccc, 4); \
33902 + break; \
33903 + default: \
33904 + BUILD_BUG(); \
33905 + } \
33906 +} while (0)
33907 +
33908 +#define EMIT2_off32(b1, b2, _off) \
33909 +do { \
33910 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33911 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33912 + EMIT(randkey, 4); \
33913 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33914 + EMIT((_off) - randkey, 4); \
33915 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33916 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33917 + /* imul eax, ecx */ \
33918 + EMIT3(0x0f, 0xaf, 0xc1); \
33919 + } else { \
33920 + BUILD_BUG(); \
33921 + } \
33922 +} while (0)
33923 +#else
33924 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33925 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33926 +#endif
33927
33928 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33929 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33930 @@ -91,6 +168,24 @@ do { \
33931 #define X86_JBE 0x76
33932 #define X86_JA 0x77
33933
33934 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33935 +#define APPEND_FLOW_VERIFY() \
33936 +do { \
33937 + /* mov ecx, randkey */ \
33938 + EMIT1(0xb9); \
33939 + EMIT(randkey, 4); \
33940 + /* cmp ecx, randkey */ \
33941 + EMIT2(0x81, 0xf9); \
33942 + EMIT(randkey, 4); \
33943 + /* jz after 8 int 3s */ \
33944 + EMIT2(0x74, 0x08); \
33945 + EMIT(0xcccccccc, 4); \
33946 + EMIT(0xcccccccc, 4); \
33947 +} while (0)
33948 +#else
33949 +#define APPEND_FLOW_VERIFY() do { } while (0)
33950 +#endif
33951 +
33952 #define EMIT_COND_JMP(op, offset) \
33953 do { \
33954 if (is_near(offset)) \
33955 @@ -98,6 +193,7 @@ do { \
33956 else { \
33957 EMIT2(0x0f, op + 0x10); \
33958 EMIT(offset, 4); /* jxx .+off32 */ \
33959 + APPEND_FLOW_VERIFY(); \
33960 } \
33961 } while (0)
33962
33963 @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33964 return -1;
33965 }
33966
33967 -struct bpf_binary_header {
33968 - unsigned int pages;
33969 - /* Note : for security reasons, bpf code will follow a randomly
33970 - * sized amount of int3 instructions
33971 - */
33972 - u8 image[];
33973 -};
33974 -
33975 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33976 +/* Note : for security reasons, bpf code will follow a randomly
33977 + * sized amount of int3 instructions
33978 + */
33979 +static u8 *bpf_alloc_binary(unsigned int proglen,
33980 u8 **image_ptr)
33981 {
33982 unsigned int sz, hole;
33983 - struct bpf_binary_header *header;
33984 + u8 *header;
33985
33986 /* Most of BPF filters are really small,
33987 * but if some of them fill a page, allow at least
33988 * 128 extra bytes to insert a random section of int3
33989 */
33990 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33991 - header = module_alloc(sz);
33992 + sz = round_up(proglen + 128, PAGE_SIZE);
33993 + header = module_alloc_exec(sz);
33994 if (!header)
33995 return NULL;
33996
33997 + pax_open_kernel();
33998 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33999 + pax_close_kernel();
34000
34001 - header->pages = sz / PAGE_SIZE;
34002 - hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34003 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34004
34005 /* insert a random number of int3 instructions before BPF code */
34006 - *image_ptr = &header->image[prandom_u32() % hole];
34007 + *image_ptr = &header[prandom_u32() % hole];
34008 return header;
34009 }
34010
34011 void bpf_jit_compile(struct sk_filter *fp)
34012 {
34013 - u8 temp[64];
34014 + u8 temp[MAX_INSTR_CODE_SIZE];
34015 u8 *prog;
34016 unsigned int proglen, oldproglen = 0;
34017 int ilen, i;
34018 int t_offset, f_offset;
34019 u8 t_op, f_op, seen = 0, pass;
34020 u8 *image = NULL;
34021 - struct bpf_binary_header *header = NULL;
34022 + u8 *header = NULL;
34023 u8 *func;
34024 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
34025 unsigned int cleanup_addr; /* epilogue code offset */
34026 unsigned int *addrs;
34027 const struct sock_filter *filter = fp->insns;
34028 int flen = fp->len;
34029 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34030 + unsigned int randkey;
34031 +#endif
34032
34033 if (!bpf_jit_enable)
34034 return;
34035 @@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34036 return;
34037
34038 /* Before first pass, make a rough estimation of addrs[]
34039 - * each bpf instruction is translated to less than 64 bytes
34040 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
34041 */
34042 for (proglen = 0, i = 0; i < flen; i++) {
34043 - proglen += 64;
34044 + proglen += MAX_INSTR_CODE_SIZE;
34045 addrs[i] = proglen;
34046 }
34047 cleanup_addr = proglen; /* epilogue address */
34048 @@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34049 for (i = 0; i < flen; i++) {
34050 unsigned int K = filter[i].k;
34051
34052 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34053 + randkey = prandom_u32();
34054 +#endif
34055 +
34056 switch (filter[i].code) {
34057 case BPF_S_ALU_ADD_X: /* A += X; */
34058 seen |= SEEN_XREG;
34059 @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
34060 case BPF_S_ALU_MUL_K: /* A *= K */
34061 if (is_imm8(K))
34062 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
34063 - else {
34064 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
34065 - EMIT(K, 4);
34066 - }
34067 + else
34068 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
34069 break;
34070 case BPF_S_ALU_DIV_X: /* A /= X; */
34071 seen |= SEEN_XREG;
34072 @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34073 break;
34074 }
34075 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34076 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34077 + DILUTE_CONST_SEQUENCE(K, randkey);
34078 +#else
34079 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34080 +#endif
34081 EMIT2(0xf7, 0xf1); /* div %ecx */
34082 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
34083 break;
34084 @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34085 if (K == 1)
34086 break;
34087 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34088 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34089 + DILUTE_CONST_SEQUENCE(K, randkey);
34090 +#else
34091 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34092 +#endif
34093 EMIT2(0xf7, 0xf1); /* div %ecx */
34094 break;
34095 case BPF_S_ALU_AND_X:
34096 @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
34097 if (is_imm8(K)) {
34098 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
34099 } else {
34100 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
34101 - EMIT(K, 4);
34102 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
34103 }
34104 } else {
34105 EMIT2(0x89,0xde); /* mov %ebx,%esi */
34106 @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34107 if (unlikely(proglen + ilen > oldproglen)) {
34108 pr_err("bpb_jit_compile fatal error\n");
34109 kfree(addrs);
34110 - module_free(NULL, header);
34111 + module_free_exec(NULL, image);
34112 return;
34113 }
34114 + pax_open_kernel();
34115 memcpy(image + proglen, temp, ilen);
34116 + pax_close_kernel();
34117 }
34118 proglen += ilen;
34119 addrs[i] = proglen;
34120 @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34121
34122 if (image) {
34123 bpf_flush_icache(header, image + proglen);
34124 - set_memory_ro((unsigned long)header, header->pages);
34125 fp->bpf_func = (void *)image;
34126 fp->jited = 1;
34127 }
34128 @@ -783,10 +888,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34129 {
34130 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34131 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34132 - struct bpf_binary_header *header = (void *)addr;
34133
34134 - set_memory_rw(addr, header->pages);
34135 - module_free(NULL, header);
34136 + set_memory_rw(addr, 1);
34137 + module_free_exec(NULL, (void *)addr);
34138 kfree(fp);
34139 }
34140
34141 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34142 index 5d04be5..2beeaa2 100644
34143 --- a/arch/x86/oprofile/backtrace.c
34144 +++ b/arch/x86/oprofile/backtrace.c
34145 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34146 struct stack_frame_ia32 *fp;
34147 unsigned long bytes;
34148
34149 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34150 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34151 if (bytes != 0)
34152 return NULL;
34153
34154 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34155 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34156
34157 oprofile_add_trace(bufhead[0].return_address);
34158
34159 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34160 struct stack_frame bufhead[2];
34161 unsigned long bytes;
34162
34163 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34164 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34165 if (bytes != 0)
34166 return NULL;
34167
34168 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34169 {
34170 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34171
34172 - if (!user_mode_vm(regs)) {
34173 + if (!user_mode(regs)) {
34174 unsigned long stack = kernel_stack_pointer(regs);
34175 if (depth)
34176 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34177 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34178 index 379e8bd..6386e09 100644
34179 --- a/arch/x86/oprofile/nmi_int.c
34180 +++ b/arch/x86/oprofile/nmi_int.c
34181 @@ -23,6 +23,7 @@
34182 #include <asm/nmi.h>
34183 #include <asm/msr.h>
34184 #include <asm/apic.h>
34185 +#include <asm/pgtable.h>
34186
34187 #include "op_counter.h"
34188 #include "op_x86_model.h"
34189 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34190 if (ret)
34191 return ret;
34192
34193 - if (!model->num_virt_counters)
34194 - model->num_virt_counters = model->num_counters;
34195 + if (!model->num_virt_counters) {
34196 + pax_open_kernel();
34197 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
34198 + pax_close_kernel();
34199 + }
34200
34201 mux_init(ops);
34202
34203 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34204 index 50d86c0..7985318 100644
34205 --- a/arch/x86/oprofile/op_model_amd.c
34206 +++ b/arch/x86/oprofile/op_model_amd.c
34207 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34208 num_counters = AMD64_NUM_COUNTERS;
34209 }
34210
34211 - op_amd_spec.num_counters = num_counters;
34212 - op_amd_spec.num_controls = num_counters;
34213 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34214 + pax_open_kernel();
34215 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34216 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34217 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34218 + pax_close_kernel();
34219
34220 return 0;
34221 }
34222 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34223 index d90528e..0127e2b 100644
34224 --- a/arch/x86/oprofile/op_model_ppro.c
34225 +++ b/arch/x86/oprofile/op_model_ppro.c
34226 @@ -19,6 +19,7 @@
34227 #include <asm/msr.h>
34228 #include <asm/apic.h>
34229 #include <asm/nmi.h>
34230 +#include <asm/pgtable.h>
34231
34232 #include "op_x86_model.h"
34233 #include "op_counter.h"
34234 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34235
34236 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34237
34238 - op_arch_perfmon_spec.num_counters = num_counters;
34239 - op_arch_perfmon_spec.num_controls = num_counters;
34240 + pax_open_kernel();
34241 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34242 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34243 + pax_close_kernel();
34244 }
34245
34246 static int arch_perfmon_init(struct oprofile_operations *ignore)
34247 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34248 index 71e8a67..6a313bb 100644
34249 --- a/arch/x86/oprofile/op_x86_model.h
34250 +++ b/arch/x86/oprofile/op_x86_model.h
34251 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34252 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34253 struct op_msrs const * const msrs);
34254 #endif
34255 -};
34256 +} __do_const;
34257
34258 struct op_counter_config;
34259
34260 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34261 index 84b9d67..260e5ff 100644
34262 --- a/arch/x86/pci/intel_mid_pci.c
34263 +++ b/arch/x86/pci/intel_mid_pci.c
34264 @@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34265 pr_info("Intel MID platform detected, using MID PCI ops\n");
34266 pci_mmcfg_late_init();
34267 pcibios_enable_irq = intel_mid_pci_irq_enable;
34268 - pci_root_ops = intel_mid_pci_ops;
34269 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34270 pci_soc_mode = 1;
34271 /* Continue with standard init */
34272 return 1;
34273 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34274 index 84112f5..6334d60 100644
34275 --- a/arch/x86/pci/irq.c
34276 +++ b/arch/x86/pci/irq.c
34277 @@ -50,7 +50,7 @@ struct irq_router {
34278 struct irq_router_handler {
34279 u16 vendor;
34280 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34281 -};
34282 +} __do_const;
34283
34284 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34285 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34286 @@ -790,7 +790,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34287 return 0;
34288 }
34289
34290 -static __initdata struct irq_router_handler pirq_routers[] = {
34291 +static __initconst const struct irq_router_handler pirq_routers[] = {
34292 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34293 { PCI_VENDOR_ID_AL, ali_router_probe },
34294 { PCI_VENDOR_ID_ITE, ite_router_probe },
34295 @@ -817,7 +817,7 @@ static struct pci_dev *pirq_router_dev;
34296 static void __init pirq_find_router(struct irq_router *r)
34297 {
34298 struct irq_routing_table *rt = pirq_table;
34299 - struct irq_router_handler *h;
34300 + const struct irq_router_handler *h;
34301
34302 #ifdef CONFIG_PCI_BIOS
34303 if (!rt->signature) {
34304 @@ -1090,7 +1090,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34305 return 0;
34306 }
34307
34308 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34309 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34310 {
34311 .callback = fix_broken_hp_bios_irq9,
34312 .ident = "HP Pavilion N5400 Series Laptop",
34313 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34314 index c77b24a..c979855 100644
34315 --- a/arch/x86/pci/pcbios.c
34316 +++ b/arch/x86/pci/pcbios.c
34317 @@ -79,7 +79,7 @@ union bios32 {
34318 static struct {
34319 unsigned long address;
34320 unsigned short segment;
34321 -} bios32_indirect = { 0, __KERNEL_CS };
34322 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34323
34324 /*
34325 * Returns the entry point for the given service, NULL on error
34326 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34327 unsigned long length; /* %ecx */
34328 unsigned long entry; /* %edx */
34329 unsigned long flags;
34330 + struct desc_struct d, *gdt;
34331
34332 local_irq_save(flags);
34333 - __asm__("lcall *(%%edi); cld"
34334 +
34335 + gdt = get_cpu_gdt_table(smp_processor_id());
34336 +
34337 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34338 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34339 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34340 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34341 +
34342 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34343 : "=a" (return_code),
34344 "=b" (address),
34345 "=c" (length),
34346 "=d" (entry)
34347 : "0" (service),
34348 "1" (0),
34349 - "D" (&bios32_indirect));
34350 + "D" (&bios32_indirect),
34351 + "r"(__PCIBIOS_DS)
34352 + : "memory");
34353 +
34354 + pax_open_kernel();
34355 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34356 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34357 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34358 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34359 + pax_close_kernel();
34360 +
34361 local_irq_restore(flags);
34362
34363 switch (return_code) {
34364 - case 0:
34365 - return address + entry;
34366 - case 0x80: /* Not present */
34367 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34368 - return 0;
34369 - default: /* Shouldn't happen */
34370 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34371 - service, return_code);
34372 + case 0: {
34373 + int cpu;
34374 + unsigned char flags;
34375 +
34376 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34377 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34378 + printk(KERN_WARNING "bios32_service: not valid\n");
34379 return 0;
34380 + }
34381 + address = address + PAGE_OFFSET;
34382 + length += 16UL; /* some BIOSs underreport this... */
34383 + flags = 4;
34384 + if (length >= 64*1024*1024) {
34385 + length >>= PAGE_SHIFT;
34386 + flags |= 8;
34387 + }
34388 +
34389 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34390 + gdt = get_cpu_gdt_table(cpu);
34391 + pack_descriptor(&d, address, length, 0x9b, flags);
34392 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34393 + pack_descriptor(&d, address, length, 0x93, flags);
34394 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34395 + }
34396 + return entry;
34397 + }
34398 + case 0x80: /* Not present */
34399 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34400 + return 0;
34401 + default: /* Shouldn't happen */
34402 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34403 + service, return_code);
34404 + return 0;
34405 }
34406 }
34407
34408 static struct {
34409 unsigned long address;
34410 unsigned short segment;
34411 -} pci_indirect = { 0, __KERNEL_CS };
34412 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34413
34414 -static int pci_bios_present;
34415 +static int pci_bios_present __read_only;
34416
34417 static int check_pcibios(void)
34418 {
34419 @@ -131,11 +174,13 @@ static int check_pcibios(void)
34420 unsigned long flags, pcibios_entry;
34421
34422 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34423 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34424 + pci_indirect.address = pcibios_entry;
34425
34426 local_irq_save(flags);
34427 - __asm__(
34428 - "lcall *(%%edi); cld\n\t"
34429 + __asm__("movw %w6, %%ds\n\t"
34430 + "lcall *%%ss:(%%edi); cld\n\t"
34431 + "push %%ss\n\t"
34432 + "pop %%ds\n\t"
34433 "jc 1f\n\t"
34434 "xor %%ah, %%ah\n"
34435 "1:"
34436 @@ -144,7 +189,8 @@ static int check_pcibios(void)
34437 "=b" (ebx),
34438 "=c" (ecx)
34439 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34440 - "D" (&pci_indirect)
34441 + "D" (&pci_indirect),
34442 + "r" (__PCIBIOS_DS)
34443 : "memory");
34444 local_irq_restore(flags);
34445
34446 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34447
34448 switch (len) {
34449 case 1:
34450 - __asm__("lcall *(%%esi); cld\n\t"
34451 + __asm__("movw %w6, %%ds\n\t"
34452 + "lcall *%%ss:(%%esi); cld\n\t"
34453 + "push %%ss\n\t"
34454 + "pop %%ds\n\t"
34455 "jc 1f\n\t"
34456 "xor %%ah, %%ah\n"
34457 "1:"
34458 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34459 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34460 "b" (bx),
34461 "D" ((long)reg),
34462 - "S" (&pci_indirect));
34463 + "S" (&pci_indirect),
34464 + "r" (__PCIBIOS_DS));
34465 /*
34466 * Zero-extend the result beyond 8 bits, do not trust the
34467 * BIOS having done it:
34468 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34469 *value &= 0xff;
34470 break;
34471 case 2:
34472 - __asm__("lcall *(%%esi); cld\n\t"
34473 + __asm__("movw %w6, %%ds\n\t"
34474 + "lcall *%%ss:(%%esi); cld\n\t"
34475 + "push %%ss\n\t"
34476 + "pop %%ds\n\t"
34477 "jc 1f\n\t"
34478 "xor %%ah, %%ah\n"
34479 "1:"
34480 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34481 : "1" (PCIBIOS_READ_CONFIG_WORD),
34482 "b" (bx),
34483 "D" ((long)reg),
34484 - "S" (&pci_indirect));
34485 + "S" (&pci_indirect),
34486 + "r" (__PCIBIOS_DS));
34487 /*
34488 * Zero-extend the result beyond 16 bits, do not trust the
34489 * BIOS having done it:
34490 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34491 *value &= 0xffff;
34492 break;
34493 case 4:
34494 - __asm__("lcall *(%%esi); cld\n\t"
34495 + __asm__("movw %w6, %%ds\n\t"
34496 + "lcall *%%ss:(%%esi); cld\n\t"
34497 + "push %%ss\n\t"
34498 + "pop %%ds\n\t"
34499 "jc 1f\n\t"
34500 "xor %%ah, %%ah\n"
34501 "1:"
34502 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34503 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34504 "b" (bx),
34505 "D" ((long)reg),
34506 - "S" (&pci_indirect));
34507 + "S" (&pci_indirect),
34508 + "r" (__PCIBIOS_DS));
34509 break;
34510 }
34511
34512 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34513
34514 switch (len) {
34515 case 1:
34516 - __asm__("lcall *(%%esi); cld\n\t"
34517 + __asm__("movw %w6, %%ds\n\t"
34518 + "lcall *%%ss:(%%esi); cld\n\t"
34519 + "push %%ss\n\t"
34520 + "pop %%ds\n\t"
34521 "jc 1f\n\t"
34522 "xor %%ah, %%ah\n"
34523 "1:"
34524 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34525 "c" (value),
34526 "b" (bx),
34527 "D" ((long)reg),
34528 - "S" (&pci_indirect));
34529 + "S" (&pci_indirect),
34530 + "r" (__PCIBIOS_DS));
34531 break;
34532 case 2:
34533 - __asm__("lcall *(%%esi); cld\n\t"
34534 + __asm__("movw %w6, %%ds\n\t"
34535 + "lcall *%%ss:(%%esi); cld\n\t"
34536 + "push %%ss\n\t"
34537 + "pop %%ds\n\t"
34538 "jc 1f\n\t"
34539 "xor %%ah, %%ah\n"
34540 "1:"
34541 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34542 "c" (value),
34543 "b" (bx),
34544 "D" ((long)reg),
34545 - "S" (&pci_indirect));
34546 + "S" (&pci_indirect),
34547 + "r" (__PCIBIOS_DS));
34548 break;
34549 case 4:
34550 - __asm__("lcall *(%%esi); cld\n\t"
34551 + __asm__("movw %w6, %%ds\n\t"
34552 + "lcall *%%ss:(%%esi); cld\n\t"
34553 + "push %%ss\n\t"
34554 + "pop %%ds\n\t"
34555 "jc 1f\n\t"
34556 "xor %%ah, %%ah\n"
34557 "1:"
34558 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34559 "c" (value),
34560 "b" (bx),
34561 "D" ((long)reg),
34562 - "S" (&pci_indirect));
34563 + "S" (&pci_indirect),
34564 + "r" (__PCIBIOS_DS));
34565 break;
34566 }
34567
34568 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34569
34570 DBG("PCI: Fetching IRQ routing table... ");
34571 __asm__("push %%es\n\t"
34572 + "movw %w8, %%ds\n\t"
34573 "push %%ds\n\t"
34574 "pop %%es\n\t"
34575 - "lcall *(%%esi); cld\n\t"
34576 + "lcall *%%ss:(%%esi); cld\n\t"
34577 "pop %%es\n\t"
34578 + "push %%ss\n\t"
34579 + "pop %%ds\n"
34580 "jc 1f\n\t"
34581 "xor %%ah, %%ah\n"
34582 "1:"
34583 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34584 "1" (0),
34585 "D" ((long) &opt),
34586 "S" (&pci_indirect),
34587 - "m" (opt)
34588 + "m" (opt),
34589 + "r" (__PCIBIOS_DS)
34590 : "memory");
34591 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34592 if (ret & 0xff00)
34593 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34594 {
34595 int ret;
34596
34597 - __asm__("lcall *(%%esi); cld\n\t"
34598 + __asm__("movw %w5, %%ds\n\t"
34599 + "lcall *%%ss:(%%esi); cld\n\t"
34600 + "push %%ss\n\t"
34601 + "pop %%ds\n"
34602 "jc 1f\n\t"
34603 "xor %%ah, %%ah\n"
34604 "1:"
34605 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34606 : "0" (PCIBIOS_SET_PCI_HW_INT),
34607 "b" ((dev->bus->number << 8) | dev->devfn),
34608 "c" ((irq << 8) | (pin + 10)),
34609 - "S" (&pci_indirect));
34610 + "S" (&pci_indirect),
34611 + "r" (__PCIBIOS_DS));
34612 return !(ret & 0xff00);
34613 }
34614 EXPORT_SYMBOL(pcibios_set_irq_routing);
34615 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34616 index 9ee3491..872192f 100644
34617 --- a/arch/x86/platform/efi/efi_32.c
34618 +++ b/arch/x86/platform/efi/efi_32.c
34619 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34620 {
34621 struct desc_ptr gdt_descr;
34622
34623 +#ifdef CONFIG_PAX_KERNEXEC
34624 + struct desc_struct d;
34625 +#endif
34626 +
34627 local_irq_save(efi_rt_eflags);
34628
34629 load_cr3(initial_page_table);
34630 __flush_tlb_all();
34631
34632 +#ifdef CONFIG_PAX_KERNEXEC
34633 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34634 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34635 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34636 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34637 +#endif
34638 +
34639 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34640 gdt_descr.size = GDT_SIZE - 1;
34641 load_gdt(&gdt_descr);
34642 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34643 {
34644 struct desc_ptr gdt_descr;
34645
34646 +#ifdef CONFIG_PAX_KERNEXEC
34647 + struct desc_struct d;
34648 +
34649 + memset(&d, 0, sizeof d);
34650 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34651 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34652 +#endif
34653 +
34654 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34655 gdt_descr.size = GDT_SIZE - 1;
34656 load_gdt(&gdt_descr);
34657
34658 +#ifdef CONFIG_PAX_PER_CPU_PGD
34659 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34660 +#else
34661 load_cr3(swapper_pg_dir);
34662 +#endif
34663 +
34664 __flush_tlb_all();
34665
34666 local_irq_restore(efi_rt_eflags);
34667 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34668 index 290d397..3906bcd 100644
34669 --- a/arch/x86/platform/efi/efi_64.c
34670 +++ b/arch/x86/platform/efi/efi_64.c
34671 @@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
34672 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34673 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34674 }
34675 +
34676 +#ifdef CONFIG_PAX_PER_CPU_PGD
34677 + load_cr3(swapper_pg_dir);
34678 +#endif
34679 +
34680 __flush_tlb_all();
34681 }
34682
34683 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34684 for (pgd = 0; pgd < n_pgds; pgd++)
34685 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34686 kfree(save_pgd);
34687 +
34688 +#ifdef CONFIG_PAX_PER_CPU_PGD
34689 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34690 +#endif
34691 +
34692 __flush_tlb_all();
34693 local_irq_restore(efi_flags);
34694 early_code_mapping_set_exec(0);
34695 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34696 index fbe66e6..eae5e38 100644
34697 --- a/arch/x86/platform/efi/efi_stub_32.S
34698 +++ b/arch/x86/platform/efi/efi_stub_32.S
34699 @@ -6,7 +6,9 @@
34700 */
34701
34702 #include <linux/linkage.h>
34703 +#include <linux/init.h>
34704 #include <asm/page_types.h>
34705 +#include <asm/segment.h>
34706
34707 /*
34708 * efi_call_phys(void *, ...) is a function with variable parameters.
34709 @@ -20,7 +22,7 @@
34710 * service functions will comply with gcc calling convention, too.
34711 */
34712
34713 -.text
34714 +__INIT
34715 ENTRY(efi_call_phys)
34716 /*
34717 * 0. The function can only be called in Linux kernel. So CS has been
34718 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34719 * The mapping of lower virtual memory has been created in prelog and
34720 * epilog.
34721 */
34722 - movl $1f, %edx
34723 - subl $__PAGE_OFFSET, %edx
34724 - jmp *%edx
34725 +#ifdef CONFIG_PAX_KERNEXEC
34726 + movl $(__KERNEXEC_EFI_DS), %edx
34727 + mov %edx, %ds
34728 + mov %edx, %es
34729 + mov %edx, %ss
34730 + addl $2f,(1f)
34731 + ljmp *(1f)
34732 +
34733 +__INITDATA
34734 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34735 +.previous
34736 +
34737 +2:
34738 + subl $2b,(1b)
34739 +#else
34740 + jmp 1f-__PAGE_OFFSET
34741 1:
34742 +#endif
34743
34744 /*
34745 * 2. Now on the top of stack is the return
34746 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34747 * parameter 2, ..., param n. To make things easy, we save the return
34748 * address of efi_call_phys in a global variable.
34749 */
34750 - popl %edx
34751 - movl %edx, saved_return_addr
34752 - /* get the function pointer into ECX*/
34753 - popl %ecx
34754 - movl %ecx, efi_rt_function_ptr
34755 - movl $2f, %edx
34756 - subl $__PAGE_OFFSET, %edx
34757 - pushl %edx
34758 + popl (saved_return_addr)
34759 + popl (efi_rt_function_ptr)
34760
34761 /*
34762 * 3. Clear PG bit in %CR0.
34763 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34764 /*
34765 * 5. Call the physical function.
34766 */
34767 - jmp *%ecx
34768 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34769
34770 -2:
34771 /*
34772 * 6. After EFI runtime service returns, control will return to
34773 * following instruction. We'd better readjust stack pointer first.
34774 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34775 movl %cr0, %edx
34776 orl $0x80000000, %edx
34777 movl %edx, %cr0
34778 - jmp 1f
34779 -1:
34780 +
34781 /*
34782 * 8. Now restore the virtual mode from flat mode by
34783 * adding EIP with PAGE_OFFSET.
34784 */
34785 - movl $1f, %edx
34786 - jmp *%edx
34787 +#ifdef CONFIG_PAX_KERNEXEC
34788 + movl $(__KERNEL_DS), %edx
34789 + mov %edx, %ds
34790 + mov %edx, %es
34791 + mov %edx, %ss
34792 + ljmp $(__KERNEL_CS),$1f
34793 +#else
34794 + jmp 1f+__PAGE_OFFSET
34795 +#endif
34796 1:
34797
34798 /*
34799 * 9. Balance the stack. And because EAX contain the return value,
34800 * we'd better not clobber it.
34801 */
34802 - leal efi_rt_function_ptr, %edx
34803 - movl (%edx), %ecx
34804 - pushl %ecx
34805 + pushl (efi_rt_function_ptr)
34806
34807 /*
34808 - * 10. Push the saved return address onto the stack and return.
34809 + * 10. Return to the saved return address.
34810 */
34811 - leal saved_return_addr, %edx
34812 - movl (%edx), %ecx
34813 - pushl %ecx
34814 - ret
34815 + jmpl *(saved_return_addr)
34816 ENDPROC(efi_call_phys)
34817 .previous
34818
34819 -.data
34820 +__INITDATA
34821 saved_return_addr:
34822 .long 0
34823 efi_rt_function_ptr:
34824 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34825 index e0984ef..a062dac 100644
34826 --- a/arch/x86/platform/efi/efi_stub_64.S
34827 +++ b/arch/x86/platform/efi/efi_stub_64.S
34828 @@ -11,6 +11,7 @@
34829 #include <asm/msr.h>
34830 #include <asm/processor-flags.h>
34831 #include <asm/page_types.h>
34832 +#include <asm/alternative-asm.h>
34833
34834 #define SAVE_XMM \
34835 mov %rsp, %rax; \
34836 @@ -81,6 +82,7 @@ ENTRY(efi_call0)
34837 RESTORE_PGT
34838 addq $32, %rsp
34839 RESTORE_XMM
34840 + pax_force_retaddr 0, 1
34841 ret
34842 ENDPROC(efi_call0)
34843
34844 @@ -93,6 +95,7 @@ ENTRY(efi_call1)
34845 RESTORE_PGT
34846 addq $32, %rsp
34847 RESTORE_XMM
34848 + pax_force_retaddr 0, 1
34849 ret
34850 ENDPROC(efi_call1)
34851
34852 @@ -105,6 +108,7 @@ ENTRY(efi_call2)
34853 RESTORE_PGT
34854 addq $32, %rsp
34855 RESTORE_XMM
34856 + pax_force_retaddr 0, 1
34857 ret
34858 ENDPROC(efi_call2)
34859
34860 @@ -118,6 +122,7 @@ ENTRY(efi_call3)
34861 RESTORE_PGT
34862 addq $32, %rsp
34863 RESTORE_XMM
34864 + pax_force_retaddr 0, 1
34865 ret
34866 ENDPROC(efi_call3)
34867
34868 @@ -132,6 +137,7 @@ ENTRY(efi_call4)
34869 RESTORE_PGT
34870 addq $32, %rsp
34871 RESTORE_XMM
34872 + pax_force_retaddr 0, 1
34873 ret
34874 ENDPROC(efi_call4)
34875
34876 @@ -147,6 +153,7 @@ ENTRY(efi_call5)
34877 RESTORE_PGT
34878 addq $48, %rsp
34879 RESTORE_XMM
34880 + pax_force_retaddr 0, 1
34881 ret
34882 ENDPROC(efi_call5)
34883
34884 @@ -165,6 +172,7 @@ ENTRY(efi_call6)
34885 RESTORE_PGT
34886 addq $48, %rsp
34887 RESTORE_XMM
34888 + pax_force_retaddr 0, 1
34889 ret
34890 ENDPROC(efi_call6)
34891
34892 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34893 index 1bbedc4..eb795b5 100644
34894 --- a/arch/x86/platform/intel-mid/intel-mid.c
34895 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34896 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34897 {
34898 };
34899
34900 -static void intel_mid_reboot(void)
34901 +static void __noreturn intel_mid_reboot(void)
34902 {
34903 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34904 + BUG();
34905 }
34906
34907 static unsigned long __init intel_mid_calibrate_tsc(void)
34908 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34909 index d6ee929..3637cb5 100644
34910 --- a/arch/x86/platform/olpc/olpc_dt.c
34911 +++ b/arch/x86/platform/olpc/olpc_dt.c
34912 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34913 return res;
34914 }
34915
34916 -static struct of_pdt_ops prom_olpc_ops __initdata = {
34917 +static struct of_pdt_ops prom_olpc_ops __initconst = {
34918 .nextprop = olpc_dt_nextprop,
34919 .getproplen = olpc_dt_getproplen,
34920 .getproperty = olpc_dt_getproperty,
34921 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34922 index 424f4c9..f2a2988 100644
34923 --- a/arch/x86/power/cpu.c
34924 +++ b/arch/x86/power/cpu.c
34925 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
34926 static void fix_processor_context(void)
34927 {
34928 int cpu = smp_processor_id();
34929 - struct tss_struct *t = &per_cpu(init_tss, cpu);
34930 -#ifdef CONFIG_X86_64
34931 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
34932 - tss_desc tss;
34933 -#endif
34934 + struct tss_struct *t = init_tss + cpu;
34935 +
34936 set_tss_desc(cpu, t); /*
34937 * This just modifies memory; should not be
34938 * necessary. But... This is necessary, because
34939 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
34940 */
34941
34942 #ifdef CONFIG_X86_64
34943 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34944 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34945 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34946 -
34947 syscall_init(); /* This sets MSR_*STAR and related */
34948 #endif
34949 load_TR_desc(); /* This does ltr */
34950 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34951 index bad628a..a102610 100644
34952 --- a/arch/x86/realmode/init.c
34953 +++ b/arch/x86/realmode/init.c
34954 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
34955 __va(real_mode_header->trampoline_header);
34956
34957 #ifdef CONFIG_X86_32
34958 - trampoline_header->start = __pa_symbol(startup_32_smp);
34959 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34960 +
34961 +#ifdef CONFIG_PAX_KERNEXEC
34962 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34963 +#endif
34964 +
34965 + trampoline_header->boot_cs = __BOOT_CS;
34966 trampoline_header->gdt_limit = __BOOT_DS + 7;
34967 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34968 #else
34969 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
34970 *trampoline_cr4_features = read_cr4();
34971
34972 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34973 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34974 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34975 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34976 #endif
34977 }
34978 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34979 index 3497f14..cc73b92 100644
34980 --- a/arch/x86/realmode/rm/Makefile
34981 +++ b/arch/x86/realmode/rm/Makefile
34982 @@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
34983
34984 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
34985 -I$(srctree)/arch/x86/boot
34986 +ifdef CONSTIFY_PLUGIN
34987 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34988 +endif
34989 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34990 GCOV_PROFILE := n
34991 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34992 index a28221d..93c40f1 100644
34993 --- a/arch/x86/realmode/rm/header.S
34994 +++ b/arch/x86/realmode/rm/header.S
34995 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34996 #endif
34997 /* APM/BIOS reboot */
34998 .long pa_machine_real_restart_asm
34999 -#ifdef CONFIG_X86_64
35000 +#ifdef CONFIG_X86_32
35001 + .long __KERNEL_CS
35002 +#else
35003 .long __KERNEL32_CS
35004 #endif
35005 END(real_mode_header)
35006 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35007 index 48ddd76..c26749f 100644
35008 --- a/arch/x86/realmode/rm/trampoline_32.S
35009 +++ b/arch/x86/realmode/rm/trampoline_32.S
35010 @@ -24,6 +24,12 @@
35011 #include <asm/page_types.h>
35012 #include "realmode.h"
35013
35014 +#ifdef CONFIG_PAX_KERNEXEC
35015 +#define ta(X) (X)
35016 +#else
35017 +#define ta(X) (pa_ ## X)
35018 +#endif
35019 +
35020 .text
35021 .code16
35022
35023 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35024
35025 cli # We should be safe anyway
35026
35027 - movl tr_start, %eax # where we need to go
35028 -
35029 movl $0xA5A5A5A5, trampoline_status
35030 # write marker for master knows we're running
35031
35032 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35033 movw $1, %dx # protected mode (PE) bit
35034 lmsw %dx # into protected mode
35035
35036 - ljmpl $__BOOT_CS, $pa_startup_32
35037 + ljmpl *(trampoline_header)
35038
35039 .section ".text32","ax"
35040 .code32
35041 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35042 .balign 8
35043 GLOBAL(trampoline_header)
35044 tr_start: .space 4
35045 - tr_gdt_pad: .space 2
35046 + tr_boot_cs: .space 2
35047 tr_gdt: .space 6
35048 END(trampoline_header)
35049
35050 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35051 index dac7b20..72dbaca 100644
35052 --- a/arch/x86/realmode/rm/trampoline_64.S
35053 +++ b/arch/x86/realmode/rm/trampoline_64.S
35054 @@ -93,6 +93,7 @@ ENTRY(startup_32)
35055 movl %edx, %gs
35056
35057 movl pa_tr_cr4, %eax
35058 + andl $~X86_CR4_PCIDE, %eax
35059 movl %eax, %cr4 # Enable PAE mode
35060
35061 # Setup trampoline 4 level pagetables
35062 @@ -106,7 +107,7 @@ ENTRY(startup_32)
35063 wrmsr
35064
35065 # Enable paging and in turn activate Long Mode
35066 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35067 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
35068 movl %eax, %cr0
35069
35070 /*
35071 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35072 index 9e7e147..25a4158 100644
35073 --- a/arch/x86/realmode/rm/wakeup_asm.S
35074 +++ b/arch/x86/realmode/rm/wakeup_asm.S
35075 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35076 lgdtl pmode_gdt
35077
35078 /* This really couldn't... */
35079 - movl pmode_entry, %eax
35080 movl pmode_cr0, %ecx
35081 movl %ecx, %cr0
35082 - ljmpl $__KERNEL_CS, $pa_startup_32
35083 - /* -> jmp *%eax in trampoline_32.S */
35084 +
35085 + ljmpl *pmode_entry
35086 #else
35087 jmp trampoline_start
35088 #endif
35089 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35090 index 604a37e..e49702a 100644
35091 --- a/arch/x86/tools/Makefile
35092 +++ b/arch/x86/tools/Makefile
35093 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35094
35095 $(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
35096
35097 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35098 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35099 hostprogs-y += relocs
35100 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35101 PHONY += relocs
35102 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35103 index bbb1d22..e505211 100644
35104 --- a/arch/x86/tools/relocs.c
35105 +++ b/arch/x86/tools/relocs.c
35106 @@ -1,5 +1,7 @@
35107 /* This is included from relocs_32/64.c */
35108
35109 +#include "../../../include/generated/autoconf.h"
35110 +
35111 #define ElfW(type) _ElfW(ELF_BITS, type)
35112 #define _ElfW(bits, type) __ElfW(bits, type)
35113 #define __ElfW(bits, type) Elf##bits##_##type
35114 @@ -11,6 +13,7 @@
35115 #define Elf_Sym ElfW(Sym)
35116
35117 static Elf_Ehdr ehdr;
35118 +static Elf_Phdr *phdr;
35119
35120 struct relocs {
35121 uint32_t *offset;
35122 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35123 }
35124 }
35125
35126 +static void read_phdrs(FILE *fp)
35127 +{
35128 + unsigned int i;
35129 +
35130 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35131 + if (!phdr) {
35132 + die("Unable to allocate %d program headers\n",
35133 + ehdr.e_phnum);
35134 + }
35135 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35136 + die("Seek to %d failed: %s\n",
35137 + ehdr.e_phoff, strerror(errno));
35138 + }
35139 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35140 + die("Cannot read ELF program headers: %s\n",
35141 + strerror(errno));
35142 + }
35143 + for(i = 0; i < ehdr.e_phnum; i++) {
35144 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35145 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35146 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35147 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35148 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35149 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35150 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35151 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35152 + }
35153 +
35154 +}
35155 +
35156 static void read_shdrs(FILE *fp)
35157 {
35158 - int i;
35159 + unsigned int i;
35160 Elf_Shdr shdr;
35161
35162 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35163 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35164
35165 static void read_strtabs(FILE *fp)
35166 {
35167 - int i;
35168 + unsigned int i;
35169 for (i = 0; i < ehdr.e_shnum; i++) {
35170 struct section *sec = &secs[i];
35171 if (sec->shdr.sh_type != SHT_STRTAB) {
35172 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35173
35174 static void read_symtabs(FILE *fp)
35175 {
35176 - int i,j;
35177 + unsigned int i,j;
35178 for (i = 0; i < ehdr.e_shnum; i++) {
35179 struct section *sec = &secs[i];
35180 if (sec->shdr.sh_type != SHT_SYMTAB) {
35181 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35182 }
35183
35184
35185 -static void read_relocs(FILE *fp)
35186 +static void read_relocs(FILE *fp, int use_real_mode)
35187 {
35188 - int i,j;
35189 + unsigned int i,j;
35190 + uint32_t base;
35191 +
35192 for (i = 0; i < ehdr.e_shnum; i++) {
35193 struct section *sec = &secs[i];
35194 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35195 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35196 die("Cannot read symbol table: %s\n",
35197 strerror(errno));
35198 }
35199 + base = 0;
35200 +
35201 +#ifdef CONFIG_X86_32
35202 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35203 + if (phdr[j].p_type != PT_LOAD )
35204 + continue;
35205 + 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)
35206 + continue;
35207 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35208 + break;
35209 + }
35210 +#endif
35211 +
35212 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35213 Elf_Rel *rel = &sec->reltab[j];
35214 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35215 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35216 rel->r_info = elf_xword_to_cpu(rel->r_info);
35217 #if (SHT_REL_TYPE == SHT_RELA)
35218 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35219 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35220
35221 static void print_absolute_symbols(void)
35222 {
35223 - int i;
35224 + unsigned int i;
35225 const char *format;
35226
35227 if (ELF_BITS == 64)
35228 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35229 for (i = 0; i < ehdr.e_shnum; i++) {
35230 struct section *sec = &secs[i];
35231 char *sym_strtab;
35232 - int j;
35233 + unsigned int j;
35234
35235 if (sec->shdr.sh_type != SHT_SYMTAB) {
35236 continue;
35237 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35238
35239 static void print_absolute_relocs(void)
35240 {
35241 - int i, printed = 0;
35242 + unsigned int i, printed = 0;
35243 const char *format;
35244
35245 if (ELF_BITS == 64)
35246 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35247 struct section *sec_applies, *sec_symtab;
35248 char *sym_strtab;
35249 Elf_Sym *sh_symtab;
35250 - int j;
35251 + unsigned int j;
35252 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35253 continue;
35254 }
35255 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35256 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35257 Elf_Sym *sym, const char *symname))
35258 {
35259 - int i;
35260 + unsigned int i;
35261 /* Walk through the relocations */
35262 for (i = 0; i < ehdr.e_shnum; i++) {
35263 char *sym_strtab;
35264 Elf_Sym *sh_symtab;
35265 struct section *sec_applies, *sec_symtab;
35266 - int j;
35267 + unsigned int j;
35268 struct section *sec = &secs[i];
35269
35270 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35271 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35272 {
35273 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35274 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35275 + char *sym_strtab = sec->link->link->strtab;
35276 +
35277 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35278 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35279 + return 0;
35280 +
35281 +#ifdef CONFIG_PAX_KERNEXEC
35282 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35283 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35284 + return 0;
35285 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35286 + return 0;
35287 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35288 + return 0;
35289 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35290 + return 0;
35291 +#endif
35292
35293 switch (r_type) {
35294 case R_386_NONE:
35295 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35296
35297 static void emit_relocs(int as_text, int use_real_mode)
35298 {
35299 - int i;
35300 + unsigned int i;
35301 int (*write_reloc)(uint32_t, FILE *) = write32;
35302 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35303 const char *symname);
35304 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35305 {
35306 regex_init(use_real_mode);
35307 read_ehdr(fp);
35308 + read_phdrs(fp);
35309 read_shdrs(fp);
35310 read_strtabs(fp);
35311 read_symtabs(fp);
35312 - read_relocs(fp);
35313 + read_relocs(fp, use_real_mode);
35314 if (ELF_BITS == 64)
35315 percpu_init();
35316 if (show_absolute_syms) {
35317 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35318 index f40281e..92728c9 100644
35319 --- a/arch/x86/um/mem_32.c
35320 +++ b/arch/x86/um/mem_32.c
35321 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35322 gate_vma.vm_start = FIXADDR_USER_START;
35323 gate_vma.vm_end = FIXADDR_USER_END;
35324 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35325 - gate_vma.vm_page_prot = __P101;
35326 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35327
35328 return 0;
35329 }
35330 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35331 index 80ffa5b..a33bd15 100644
35332 --- a/arch/x86/um/tls_32.c
35333 +++ b/arch/x86/um/tls_32.c
35334 @@ -260,7 +260,7 @@ out:
35335 if (unlikely(task == current &&
35336 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35337 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35338 - "without flushed TLS.", current->pid);
35339 + "without flushed TLS.", task_pid_nr(current));
35340 }
35341
35342 return 0;
35343 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35344 index c580d12..0a0ba35 100644
35345 --- a/arch/x86/vdso/Makefile
35346 +++ b/arch/x86/vdso/Makefile
35347 @@ -196,7 +196,7 @@ quiet_cmd_vdso = VDSO $@
35348 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35349 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35350
35351 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35352 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35353 $(LTO_CFLAGS)
35354 GCOV_PROFILE := n
35355
35356 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35357 index 310c5f0..766d0a7 100644
35358 --- a/arch/x86/vdso/vdso32-setup.c
35359 +++ b/arch/x86/vdso/vdso32-setup.c
35360 @@ -29,6 +29,7 @@
35361 #include <asm/fixmap.h>
35362 #include <asm/hpet.h>
35363 #include <asm/vvar.h>
35364 +#include <asm/mman.h>
35365
35366 #ifdef CONFIG_COMPAT_VDSO
35367 #define VDSO_DEFAULT 0
35368 @@ -99,7 +100,7 @@ void syscall32_cpu_init(void)
35369 void enable_sep_cpu(void)
35370 {
35371 int cpu = get_cpu();
35372 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
35373 + struct tss_struct *tss = init_tss + cpu;
35374
35375 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35376 put_cpu();
35377 @@ -167,7 +168,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35378
35379 down_write(&mm->mmap_sem);
35380
35381 - addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, 0);
35382 + addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, MAP_EXECUTABLE);
35383 if (IS_ERR_VALUE(addr)) {
35384 ret = addr;
35385 goto up_fail;
35386 @@ -175,7 +176,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35387
35388 addr += VDSO_OFFSET(VDSO_PREV_PAGES);
35389
35390 - current->mm->context.vdso = (void *)addr;
35391 + current->mm->context.vdso = addr;
35392
35393 /*
35394 * MAYWRITE to allow gdb to COW and set breakpoints
35395 @@ -224,11 +225,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35396 #endif
35397
35398 current_thread_info()->sysenter_return =
35399 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35400 + (void __force_user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35401
35402 up_fail:
35403 if (ret)
35404 - current->mm->context.vdso = NULL;
35405 + current->mm->context.vdso = 0;
35406
35407 up_write(&mm->mmap_sem);
35408
35409 @@ -282,8 +283,14 @@ __initcall(ia32_binfmt_init);
35410
35411 const char *arch_vma_name(struct vm_area_struct *vma)
35412 {
35413 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35414 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35415 return "[vdso]";
35416 +
35417 +#ifdef CONFIG_PAX_SEGMEXEC
35418 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35419 + return "[vdso]";
35420 +#endif
35421 +
35422 return NULL;
35423 }
35424
35425 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35426 index 1ad1026..1a08abe 100644
35427 --- a/arch/x86/vdso/vma.c
35428 +++ b/arch/x86/vdso/vma.c
35429 @@ -17,8 +17,6 @@
35430 #include <asm/page.h>
35431
35432 #if defined(CONFIG_X86_64)
35433 -unsigned int __read_mostly vdso_enabled = 1;
35434 -
35435 DECLARE_VDSO_IMAGE(vdso);
35436 extern unsigned short vdso_sync_cpuid;
35437 static unsigned vdso_size;
35438 @@ -144,7 +142,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35439 * unaligned here as a result of stack start randomization.
35440 */
35441 addr = PAGE_ALIGN(addr);
35442 - addr = align_vdso_addr(addr);
35443
35444 return addr;
35445 }
35446 @@ -157,30 +154,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35447 unsigned size)
35448 {
35449 struct mm_struct *mm = current->mm;
35450 - unsigned long addr;
35451 + unsigned long addr = 0;
35452 int ret;
35453
35454 - if (!vdso_enabled)
35455 - return 0;
35456 -
35457 down_write(&mm->mmap_sem);
35458 +
35459 +#ifdef CONFIG_PAX_RANDMMAP
35460 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35461 +#endif
35462 +
35463 addr = vdso_addr(mm->start_stack, size);
35464 + addr = align_vdso_addr(addr);
35465 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35466 if (IS_ERR_VALUE(addr)) {
35467 ret = addr;
35468 goto up_fail;
35469 }
35470
35471 - current->mm->context.vdso = (void *)addr;
35472 + mm->context.vdso = addr;
35473
35474 ret = install_special_mapping(mm, addr, size,
35475 VM_READ|VM_EXEC|
35476 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35477 pages);
35478 - if (ret) {
35479 - current->mm->context.vdso = NULL;
35480 - goto up_fail;
35481 - }
35482 + if (ret)
35483 + mm->context.vdso = 0;
35484
35485 up_fail:
35486 up_write(&mm->mmap_sem);
35487 @@ -200,11 +198,4 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35488 vdsox32_size);
35489 }
35490 #endif
35491 -
35492 -static __init int vdso_setup(char *s)
35493 -{
35494 - vdso_enabled = simple_strtoul(s, NULL, 0);
35495 - return 0;
35496 -}
35497 -__setup("vdso=", vdso_setup);
35498 #endif
35499 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35500 index e88fda8..76ce7ce 100644
35501 --- a/arch/x86/xen/Kconfig
35502 +++ b/arch/x86/xen/Kconfig
35503 @@ -9,6 +9,7 @@ config XEN
35504 select XEN_HAVE_PVMMU
35505 depends on X86_64 || (X86_32 && X86_PAE)
35506 depends on X86_TSC
35507 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35508 help
35509 This is the Linux Xen port. Enabling this will allow the
35510 kernel to boot in a paravirtualized environment under the
35511 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35512 index c34bfc4..e599673 100644
35513 --- a/arch/x86/xen/enlighten.c
35514 +++ b/arch/x86/xen/enlighten.c
35515 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35516
35517 struct shared_info xen_dummy_shared_info;
35518
35519 -void *xen_initial_gdt;
35520 -
35521 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35522 __read_mostly int xen_have_vector_callback;
35523 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35524 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35525 {
35526 unsigned long va = dtr->address;
35527 unsigned int size = dtr->size + 1;
35528 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35529 - unsigned long frames[pages];
35530 + unsigned long frames[65536 / PAGE_SIZE];
35531 int f;
35532
35533 /*
35534 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35535 {
35536 unsigned long va = dtr->address;
35537 unsigned int size = dtr->size + 1;
35538 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35539 - unsigned long frames[pages];
35540 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35541 int f;
35542
35543 /*
35544 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35545 * 8-byte entries, or 16 4k pages..
35546 */
35547
35548 - BUG_ON(size > 65536);
35549 + BUG_ON(size > GDT_SIZE);
35550 BUG_ON(va & ~PAGE_MASK);
35551
35552 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35553 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35554 return 0;
35555 }
35556
35557 -static void set_xen_basic_apic_ops(void)
35558 +static void __init set_xen_basic_apic_ops(void)
35559 {
35560 apic->read = xen_apic_read;
35561 apic->write = xen_apic_write;
35562 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35563 #endif
35564 };
35565
35566 -static void xen_reboot(int reason)
35567 +static __noreturn void xen_reboot(int reason)
35568 {
35569 struct sched_shutdown r = { .reason = reason };
35570
35571 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35572 - BUG();
35573 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35574 + BUG();
35575 }
35576
35577 -static void xen_restart(char *msg)
35578 +static __noreturn void xen_restart(char *msg)
35579 {
35580 xen_reboot(SHUTDOWN_reboot);
35581 }
35582
35583 -static void xen_emergency_restart(void)
35584 +static __noreturn void xen_emergency_restart(void)
35585 {
35586 xen_reboot(SHUTDOWN_reboot);
35587 }
35588
35589 -static void xen_machine_halt(void)
35590 +static __noreturn void xen_machine_halt(void)
35591 {
35592 xen_reboot(SHUTDOWN_poweroff);
35593 }
35594
35595 -static void xen_machine_power_off(void)
35596 +static __noreturn void xen_machine_power_off(void)
35597 {
35598 if (pm_power_off)
35599 pm_power_off();
35600 @@ -1564,7 +1560,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35601 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35602
35603 /* Work out if we support NX */
35604 - x86_configure_nx();
35605 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35606 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35607 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35608 + unsigned l, h;
35609 +
35610 + __supported_pte_mask |= _PAGE_NX;
35611 + rdmsr(MSR_EFER, l, h);
35612 + l |= EFER_NX;
35613 + wrmsr(MSR_EFER, l, h);
35614 + }
35615 +#endif
35616
35617 /* Get mfn list */
35618 xen_build_dynamic_phys_to_machine();
35619 @@ -1592,13 +1598,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35620
35621 machine_ops = xen_machine_ops;
35622
35623 - /*
35624 - * The only reliable way to retain the initial address of the
35625 - * percpu gdt_page is to remember it here, so we can go and
35626 - * mark it RW later, when the initial percpu area is freed.
35627 - */
35628 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35629 -
35630 xen_smp_init();
35631
35632 #ifdef CONFIG_ACPI_NUMA
35633 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35634 index 86e02ea..e3705ca 100644
35635 --- a/arch/x86/xen/mmu.c
35636 +++ b/arch/x86/xen/mmu.c
35637 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35638 return val;
35639 }
35640
35641 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35642 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35643 {
35644 if (val & _PAGE_PRESENT) {
35645 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35646 @@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35647 /* L3_k[510] -> level2_kernel_pgt
35648 * L3_i[511] -> level2_fixmap_pgt */
35649 convert_pfn_mfn(level3_kernel_pgt);
35650 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35651 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35652 + convert_pfn_mfn(level3_vmemmap_pgt);
35653 }
35654 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35655 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35656 @@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35657 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35658 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35659 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35660 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35661 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35662 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35663 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35664 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35665 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35666 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35667 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35668
35669 @@ -2122,6 +2129,7 @@ static void __init xen_post_allocator_init(void)
35670 pv_mmu_ops.set_pud = xen_set_pud;
35671 #if PAGETABLE_LEVELS == 4
35672 pv_mmu_ops.set_pgd = xen_set_pgd;
35673 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35674 #endif
35675
35676 /* This will work as long as patching hasn't happened yet
35677 @@ -2200,6 +2208,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35678 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35679 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35680 .set_pgd = xen_set_pgd_hyper,
35681 + .set_pgd_batched = xen_set_pgd_hyper,
35682
35683 .alloc_pud = xen_alloc_pmd_init,
35684 .release_pud = xen_release_pmd_init,
35685 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35686 index 7005974..54fb05f 100644
35687 --- a/arch/x86/xen/smp.c
35688 +++ b/arch/x86/xen/smp.c
35689 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35690
35691 if (xen_pv_domain()) {
35692 if (!xen_feature(XENFEAT_writable_page_tables))
35693 - /* We've switched to the "real" per-cpu gdt, so make
35694 - * sure the old memory can be recycled. */
35695 - make_lowmem_page_readwrite(xen_initial_gdt);
35696 -
35697 #ifdef CONFIG_X86_32
35698 /*
35699 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35700 * expects __USER_DS
35701 */
35702 - loadsegment(ds, __USER_DS);
35703 - loadsegment(es, __USER_DS);
35704 + loadsegment(ds, __KERNEL_DS);
35705 + loadsegment(es, __KERNEL_DS);
35706 #endif
35707
35708 xen_filter_cpu_maps();
35709 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35710 #ifdef CONFIG_X86_32
35711 /* Note: PVH is not yet supported on x86_32. */
35712 ctxt->user_regs.fs = __KERNEL_PERCPU;
35713 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35714 + savesegment(gs, ctxt->user_regs.gs);
35715 #endif
35716 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35717
35718 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35719 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35720 ctxt->flags = VGCF_IN_KERNEL;
35721 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35722 - ctxt->user_regs.ds = __USER_DS;
35723 - ctxt->user_regs.es = __USER_DS;
35724 + ctxt->user_regs.ds = __KERNEL_DS;
35725 + ctxt->user_regs.es = __KERNEL_DS;
35726 ctxt->user_regs.ss = __KERNEL_DS;
35727
35728 xen_copy_trap_info(ctxt->trap_ctxt);
35729 @@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35730 int rc;
35731
35732 per_cpu(current_task, cpu) = idle;
35733 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35734 #ifdef CONFIG_X86_32
35735 irq_ctx_init(cpu);
35736 #else
35737 clear_tsk_thread_flag(idle, TIF_FORK);
35738 #endif
35739 - per_cpu(kernel_stack, cpu) =
35740 - (unsigned long)task_stack_page(idle) -
35741 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35742 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35743
35744 xen_setup_runstate_info(cpu);
35745 xen_setup_timer(cpu);
35746 @@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35747
35748 void __init xen_smp_init(void)
35749 {
35750 - smp_ops = xen_smp_ops;
35751 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35752 xen_fill_possible_map();
35753 }
35754
35755 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35756 index fd92a64..1f72641 100644
35757 --- a/arch/x86/xen/xen-asm_32.S
35758 +++ b/arch/x86/xen/xen-asm_32.S
35759 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
35760 pushw %fs
35761 movl $(__KERNEL_PERCPU), %eax
35762 movl %eax, %fs
35763 - movl %fs:xen_vcpu, %eax
35764 + mov PER_CPU_VAR(xen_vcpu), %eax
35765 POP_FS
35766 #else
35767 movl %ss:xen_vcpu, %eax
35768 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35769 index 485b695..fda3e7c 100644
35770 --- a/arch/x86/xen/xen-head.S
35771 +++ b/arch/x86/xen/xen-head.S
35772 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
35773 #ifdef CONFIG_X86_32
35774 mov %esi,xen_start_info
35775 mov $init_thread_union+THREAD_SIZE,%esp
35776 +#ifdef CONFIG_SMP
35777 + movl $cpu_gdt_table,%edi
35778 + movl $__per_cpu_load,%eax
35779 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35780 + rorl $16,%eax
35781 + movb %al,__KERNEL_PERCPU + 4(%edi)
35782 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35783 + movl $__per_cpu_end - 1,%eax
35784 + subl $__per_cpu_start,%eax
35785 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35786 +#endif
35787 #else
35788 mov %rsi,xen_start_info
35789 mov $init_thread_union+THREAD_SIZE,%rsp
35790 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35791 index 1cb6f4c..9981524 100644
35792 --- a/arch/x86/xen/xen-ops.h
35793 +++ b/arch/x86/xen/xen-ops.h
35794 @@ -10,8 +10,6 @@
35795 extern const char xen_hypervisor_callback[];
35796 extern const char xen_failsafe_callback[];
35797
35798 -extern void *xen_initial_gdt;
35799 -
35800 struct trap_info;
35801 void xen_copy_trap_info(struct trap_info *traps);
35802
35803 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35804 index 525bd3d..ef888b1 100644
35805 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35806 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35807 @@ -119,9 +119,9 @@
35808 ----------------------------------------------------------------------*/
35809
35810 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35811 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35812 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35813 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35814 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35815
35816 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35817 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35818 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35819 index 2f33760..835e50a 100644
35820 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35821 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35822 @@ -11,6 +11,7 @@
35823 #ifndef _XTENSA_CORE_H
35824 #define _XTENSA_CORE_H
35825
35826 +#include <linux/const.h>
35827
35828 /****************************************************************************
35829 Parameters Useful for Any Code, USER or PRIVILEGED
35830 @@ -112,9 +113,9 @@
35831 ----------------------------------------------------------------------*/
35832
35833 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35834 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35835 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35836 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35837 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35838
35839 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35840 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35841 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35842 index af00795..2bb8105 100644
35843 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35844 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35845 @@ -11,6 +11,7 @@
35846 #ifndef _XTENSA_CORE_CONFIGURATION_H
35847 #define _XTENSA_CORE_CONFIGURATION_H
35848
35849 +#include <linux/const.h>
35850
35851 /****************************************************************************
35852 Parameters Useful for Any Code, USER or PRIVILEGED
35853 @@ -118,9 +119,9 @@
35854 ----------------------------------------------------------------------*/
35855
35856 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35857 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35858 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35859 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35860 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35861
35862 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35863 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35864 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35865 index 95ee425..c9c7237 100644
35866 --- a/block/blk-cgroup.c
35867 +++ b/block/blk-cgroup.c
35868 @@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35869 static struct cgroup_subsys_state *
35870 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35871 {
35872 - static atomic64_t id_seq = ATOMIC64_INIT(0);
35873 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35874 struct blkcg *blkcg;
35875
35876 if (!parent_css) {
35877 @@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35878
35879 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35880 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35881 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35882 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35883 done:
35884 spin_lock_init(&blkcg->lock);
35885 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35886 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35887 index c11d24e..e915d24 100644
35888 --- a/block/blk-iopoll.c
35889 +++ b/block/blk-iopoll.c
35890 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35891 }
35892 EXPORT_SYMBOL(blk_iopoll_complete);
35893
35894 -static void blk_iopoll_softirq(struct softirq_action *h)
35895 +static __latent_entropy void blk_iopoll_softirq(void)
35896 {
35897 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35898 int rearm = 0, budget = blk_iopoll_budget;
35899 diff --git a/block/blk-map.c b/block/blk-map.c
35900 index f7b22bc..ec2ddf4 100644
35901 --- a/block/blk-map.c
35902 +++ b/block/blk-map.c
35903 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35904 if (!len || !kbuf)
35905 return -EINVAL;
35906
35907 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35908 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35909 if (do_copy)
35910 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35911 else
35912 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35913 index 53b1737..08177d2e 100644
35914 --- a/block/blk-softirq.c
35915 +++ b/block/blk-softirq.c
35916 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35917 * Softirq action handler - move entries to local list and loop over them
35918 * while passing them to the queue registered handler.
35919 */
35920 -static void blk_done_softirq(struct softirq_action *h)
35921 +static __latent_entropy void blk_done_softirq(void)
35922 {
35923 struct list_head *cpu_list, local_list;
35924
35925 diff --git a/block/bsg.c b/block/bsg.c
35926 index 420a5a9..23834aa 100644
35927 --- a/block/bsg.c
35928 +++ b/block/bsg.c
35929 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35930 struct sg_io_v4 *hdr, struct bsg_device *bd,
35931 fmode_t has_write_perm)
35932 {
35933 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35934 + unsigned char *cmdptr;
35935 +
35936 if (hdr->request_len > BLK_MAX_CDB) {
35937 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35938 if (!rq->cmd)
35939 return -ENOMEM;
35940 - }
35941 + cmdptr = rq->cmd;
35942 + } else
35943 + cmdptr = tmpcmd;
35944
35945 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35946 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35947 hdr->request_len))
35948 return -EFAULT;
35949
35950 + if (cmdptr != rq->cmd)
35951 + memcpy(rq->cmd, cmdptr, hdr->request_len);
35952 +
35953 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35954 if (blk_verify_command(rq->cmd, has_write_perm))
35955 return -EPERM;
35956 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35957 index fbd5a67..f24fd95 100644
35958 --- a/block/compat_ioctl.c
35959 +++ b/block/compat_ioctl.c
35960 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35961 cgc = compat_alloc_user_space(sizeof(*cgc));
35962 cgc32 = compat_ptr(arg);
35963
35964 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35965 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35966 get_user(data, &cgc32->buffer) ||
35967 put_user(compat_ptr(data), &cgc->buffer) ||
35968 copy_in_user(&cgc->buflen, &cgc32->buflen,
35969 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35970 err |= __get_user(f->spec1, &uf->spec1);
35971 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35972 err |= __get_user(name, &uf->name);
35973 - f->name = compat_ptr(name);
35974 + f->name = (void __force_kernel *)compat_ptr(name);
35975 if (err) {
35976 err = -EFAULT;
35977 goto out;
35978 diff --git a/block/genhd.c b/block/genhd.c
35979 index 791f419..89f21c4 100644
35980 --- a/block/genhd.c
35981 +++ b/block/genhd.c
35982 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35983
35984 /*
35985 * Register device numbers dev..(dev+range-1)
35986 - * range must be nonzero
35987 + * Noop if @range is zero.
35988 * The hash chain is sorted on range, so that subranges can override.
35989 */
35990 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35991 struct kobject *(*probe)(dev_t, int *, void *),
35992 int (*lock)(dev_t, void *), void *data)
35993 {
35994 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
35995 + if (range)
35996 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
35997 }
35998
35999 EXPORT_SYMBOL(blk_register_region);
36000
36001 +/* undo blk_register_region(), noop if @range is zero */
36002 void blk_unregister_region(dev_t devt, unsigned long range)
36003 {
36004 - kobj_unmap(bdev_map, devt, range);
36005 + if (range)
36006 + kobj_unmap(bdev_map, devt, range);
36007 }
36008
36009 EXPORT_SYMBOL(blk_unregister_region);
36010 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36011 index dc51f46..d5446a8 100644
36012 --- a/block/partitions/efi.c
36013 +++ b/block/partitions/efi.c
36014 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36015 if (!gpt)
36016 return NULL;
36017
36018 + if (!le32_to_cpu(gpt->num_partition_entries))
36019 + return NULL;
36020 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36021 + if (!pte)
36022 + return NULL;
36023 +
36024 count = le32_to_cpu(gpt->num_partition_entries) *
36025 le32_to_cpu(gpt->sizeof_partition_entry);
36026 - if (!count)
36027 - return NULL;
36028 - pte = kmalloc(count, GFP_KERNEL);
36029 - if (!pte)
36030 - return NULL;
36031 -
36032 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36033 (u8 *) pte, count) < count) {
36034 kfree(pte);
36035 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36036 index 2648797..92ed21f 100644
36037 --- a/block/scsi_ioctl.c
36038 +++ b/block/scsi_ioctl.c
36039 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36040 return put_user(0, p);
36041 }
36042
36043 -static int sg_get_timeout(struct request_queue *q)
36044 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36045 {
36046 return jiffies_to_clock_t(q->sg_timeout);
36047 }
36048 @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
36049 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36050 struct sg_io_hdr *hdr, fmode_t mode)
36051 {
36052 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36053 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36054 + unsigned char *cmdptr;
36055 +
36056 + if (rq->cmd != rq->__cmd)
36057 + cmdptr = rq->cmd;
36058 + else
36059 + cmdptr = tmpcmd;
36060 +
36061 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36062 return -EFAULT;
36063 +
36064 + if (cmdptr != rq->cmd)
36065 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36066 +
36067 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36068 return -EPERM;
36069
36070 @@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36071 int err;
36072 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36073 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36074 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36075 + unsigned char *cmdptr;
36076
36077 if (!sic)
36078 return -EINVAL;
36079 @@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36080 */
36081 err = -EFAULT;
36082 rq->cmd_len = cmdlen;
36083 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
36084 +
36085 + if (rq->cmd != rq->__cmd)
36086 + cmdptr = rq->cmd;
36087 + else
36088 + cmdptr = tmpcmd;
36089 +
36090 + if (copy_from_user(cmdptr, sic->data, cmdlen))
36091 goto error;
36092
36093 + if (rq->cmd != cmdptr)
36094 + memcpy(rq->cmd, cmdptr, cmdlen);
36095 +
36096 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36097 goto error;
36098
36099 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36100 index 7bdd61b..afec999 100644
36101 --- a/crypto/cryptd.c
36102 +++ b/crypto/cryptd.c
36103 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36104
36105 struct cryptd_blkcipher_request_ctx {
36106 crypto_completion_t complete;
36107 -};
36108 +} __no_const;
36109
36110 struct cryptd_hash_ctx {
36111 struct crypto_shash *child;
36112 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36113
36114 struct cryptd_aead_request_ctx {
36115 crypto_completion_t complete;
36116 -};
36117 +} __no_const;
36118
36119 static void cryptd_queue_worker(struct work_struct *work);
36120
36121 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36122 index 309d345..1632720 100644
36123 --- a/crypto/pcrypt.c
36124 +++ b/crypto/pcrypt.c
36125 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36126 int ret;
36127
36128 pinst->kobj.kset = pcrypt_kset;
36129 - ret = kobject_add(&pinst->kobj, NULL, name);
36130 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36131 if (!ret)
36132 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36133
36134 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36135 index 6921c7f..78e1af7 100644
36136 --- a/drivers/acpi/acpica/hwxfsleep.c
36137 +++ b/drivers/acpi/acpica/hwxfsleep.c
36138 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36139 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36140
36141 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36142 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36143 - acpi_hw_extended_sleep},
36144 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36145 - acpi_hw_extended_wake_prep},
36146 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36147 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36148 + .extended_function = acpi_hw_extended_sleep},
36149 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36150 + .extended_function = acpi_hw_extended_wake_prep},
36151 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36152 + .extended_function = acpi_hw_extended_wake}
36153 };
36154
36155 /*
36156 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36157 index e5bcd91..74f050d 100644
36158 --- a/drivers/acpi/apei/apei-internal.h
36159 +++ b/drivers/acpi/apei/apei-internal.h
36160 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36161 struct apei_exec_ins_type {
36162 u32 flags;
36163 apei_exec_ins_func_t run;
36164 -};
36165 +} __do_const;
36166
36167 struct apei_exec_context {
36168 u32 ip;
36169 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36170 index dab7cb7..f0d2994 100644
36171 --- a/drivers/acpi/apei/ghes.c
36172 +++ b/drivers/acpi/apei/ghes.c
36173 @@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36174 const struct acpi_hest_generic *generic,
36175 const struct acpi_generic_status *estatus)
36176 {
36177 - static atomic_t seqno;
36178 + static atomic_unchecked_t seqno;
36179 unsigned int curr_seqno;
36180 char pfx_seq[64];
36181
36182 @@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36183 else
36184 pfx = KERN_ERR;
36185 }
36186 - curr_seqno = atomic_inc_return(&seqno);
36187 + curr_seqno = atomic_inc_return_unchecked(&seqno);
36188 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36189 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36190 pfx_seq, generic->header.source_id);
36191 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36192 index a83e3c6..c3d617f 100644
36193 --- a/drivers/acpi/bgrt.c
36194 +++ b/drivers/acpi/bgrt.c
36195 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36196 if (!bgrt_image)
36197 return -ENODEV;
36198
36199 - bin_attr_image.private = bgrt_image;
36200 - bin_attr_image.size = bgrt_image_size;
36201 + pax_open_kernel();
36202 + *(void **)&bin_attr_image.private = bgrt_image;
36203 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36204 + pax_close_kernel();
36205
36206 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36207 if (!bgrt_kobj)
36208 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36209 index 3d8413d..95f638c 100644
36210 --- a/drivers/acpi/blacklist.c
36211 +++ b/drivers/acpi/blacklist.c
36212 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36213 u32 is_critical_error;
36214 };
36215
36216 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36217 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36218
36219 /*
36220 * POLICY: If *anything* doesn't work, put it on the blacklist.
36221 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36222 return 0;
36223 }
36224
36225 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36226 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36227 {
36228 .callback = dmi_disable_osi_vista,
36229 .ident = "Fujitsu Siemens",
36230 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36231 index c68e724..e863008 100644
36232 --- a/drivers/acpi/custom_method.c
36233 +++ b/drivers/acpi/custom_method.c
36234 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36235 struct acpi_table_header table;
36236 acpi_status status;
36237
36238 +#ifdef CONFIG_GRKERNSEC_KMEM
36239 + return -EPERM;
36240 +#endif
36241 +
36242 if (!(*ppos)) {
36243 /* parse the table header to get the table length */
36244 if (count <= sizeof(struct acpi_table_header))
36245 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36246 index 3dca36d..abaf070 100644
36247 --- a/drivers/acpi/processor_idle.c
36248 +++ b/drivers/acpi/processor_idle.c
36249 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36250 {
36251 int i, count = CPUIDLE_DRIVER_STATE_START;
36252 struct acpi_processor_cx *cx;
36253 - struct cpuidle_state *state;
36254 + cpuidle_state_no_const *state;
36255 struct cpuidle_driver *drv = &acpi_idle_driver;
36256
36257 if (!pr->flags.power_setup_done)
36258 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36259 index 38cb978..352c761 100644
36260 --- a/drivers/acpi/sysfs.c
36261 +++ b/drivers/acpi/sysfs.c
36262 @@ -423,11 +423,11 @@ static u32 num_counters;
36263 static struct attribute **all_attrs;
36264 static u32 acpi_gpe_count;
36265
36266 -static struct attribute_group interrupt_stats_attr_group = {
36267 +static attribute_group_no_const interrupt_stats_attr_group = {
36268 .name = "interrupts",
36269 };
36270
36271 -static struct kobj_attribute *counter_attrs;
36272 +static kobj_attribute_no_const *counter_attrs;
36273
36274 static void delete_gpe_attr_array(void)
36275 {
36276 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36277 index b986145..82bddb8 100644
36278 --- a/drivers/ata/libahci.c
36279 +++ b/drivers/ata/libahci.c
36280 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36281 }
36282 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36283
36284 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36285 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36286 struct ata_taskfile *tf, int is_cmd, u16 flags,
36287 unsigned long timeout_msec)
36288 {
36289 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36290 index 18d97d5..be690af 100644
36291 --- a/drivers/ata/libata-core.c
36292 +++ b/drivers/ata/libata-core.c
36293 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36294 static void ata_dev_xfermask(struct ata_device *dev);
36295 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36296
36297 -atomic_t ata_print_id = ATOMIC_INIT(0);
36298 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36299
36300 struct ata_force_param {
36301 const char *name;
36302 @@ -4858,7 +4858,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36303 struct ata_port *ap;
36304 unsigned int tag;
36305
36306 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36307 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36308 ap = qc->ap;
36309
36310 qc->flags = 0;
36311 @@ -4874,7 +4874,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36312 struct ata_port *ap;
36313 struct ata_link *link;
36314
36315 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36316 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36317 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36318 ap = qc->ap;
36319 link = qc->dev->link;
36320 @@ -5978,6 +5978,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36321 return;
36322
36323 spin_lock(&lock);
36324 + pax_open_kernel();
36325
36326 for (cur = ops->inherits; cur; cur = cur->inherits) {
36327 void **inherit = (void **)cur;
36328 @@ -5991,8 +5992,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36329 if (IS_ERR(*pp))
36330 *pp = NULL;
36331
36332 - ops->inherits = NULL;
36333 + *(struct ata_port_operations **)&ops->inherits = NULL;
36334
36335 + pax_close_kernel();
36336 spin_unlock(&lock);
36337 }
36338
36339 @@ -6185,7 +6187,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36340
36341 /* give ports names and add SCSI hosts */
36342 for (i = 0; i < host->n_ports; i++) {
36343 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36344 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36345 host->ports[i]->local_port_no = i + 1;
36346 }
36347
36348 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36349 index ef8567d..8bdbd03 100644
36350 --- a/drivers/ata/libata-scsi.c
36351 +++ b/drivers/ata/libata-scsi.c
36352 @@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36353
36354 if (rc)
36355 return rc;
36356 - ap->print_id = atomic_inc_return(&ata_print_id);
36357 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36358 return 0;
36359 }
36360 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36361 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36362 index 45b5ab3..98446b8 100644
36363 --- a/drivers/ata/libata.h
36364 +++ b/drivers/ata/libata.h
36365 @@ -53,7 +53,7 @@ enum {
36366 ATA_DNXFER_QUIET = (1 << 31),
36367 };
36368
36369 -extern atomic_t ata_print_id;
36370 +extern atomic_unchecked_t ata_print_id;
36371 extern int atapi_passthru16;
36372 extern int libata_fua;
36373 extern int libata_noacpi;
36374 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36375 index 4edb1a8..84e1658 100644
36376 --- a/drivers/ata/pata_arasan_cf.c
36377 +++ b/drivers/ata/pata_arasan_cf.c
36378 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36379 /* Handle platform specific quirks */
36380 if (quirk) {
36381 if (quirk & CF_BROKEN_PIO) {
36382 - ap->ops->set_piomode = NULL;
36383 + pax_open_kernel();
36384 + *(void **)&ap->ops->set_piomode = NULL;
36385 + pax_close_kernel();
36386 ap->pio_mask = 0;
36387 }
36388 if (quirk & CF_BROKEN_MWDMA)
36389 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36390 index f9b983a..887b9d8 100644
36391 --- a/drivers/atm/adummy.c
36392 +++ b/drivers/atm/adummy.c
36393 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36394 vcc->pop(vcc, skb);
36395 else
36396 dev_kfree_skb_any(skb);
36397 - atomic_inc(&vcc->stats->tx);
36398 + atomic_inc_unchecked(&vcc->stats->tx);
36399
36400 return 0;
36401 }
36402 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36403 index f1a9198..f466a4a 100644
36404 --- a/drivers/atm/ambassador.c
36405 +++ b/drivers/atm/ambassador.c
36406 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36407 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36408
36409 // VC layer stats
36410 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36411 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36412
36413 // free the descriptor
36414 kfree (tx_descr);
36415 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36416 dump_skb ("<<<", vc, skb);
36417
36418 // VC layer stats
36419 - atomic_inc(&atm_vcc->stats->rx);
36420 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36421 __net_timestamp(skb);
36422 // end of our responsibility
36423 atm_vcc->push (atm_vcc, skb);
36424 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36425 } else {
36426 PRINTK (KERN_INFO, "dropped over-size frame");
36427 // should we count this?
36428 - atomic_inc(&atm_vcc->stats->rx_drop);
36429 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36430 }
36431
36432 } else {
36433 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36434 }
36435
36436 if (check_area (skb->data, skb->len)) {
36437 - atomic_inc(&atm_vcc->stats->tx_err);
36438 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36439 return -ENOMEM; // ?
36440 }
36441
36442 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36443 index 0e3f8f9..765a7a5 100644
36444 --- a/drivers/atm/atmtcp.c
36445 +++ b/drivers/atm/atmtcp.c
36446 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36447 if (vcc->pop) vcc->pop(vcc,skb);
36448 else dev_kfree_skb(skb);
36449 if (dev_data) return 0;
36450 - atomic_inc(&vcc->stats->tx_err);
36451 + atomic_inc_unchecked(&vcc->stats->tx_err);
36452 return -ENOLINK;
36453 }
36454 size = skb->len+sizeof(struct atmtcp_hdr);
36455 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36456 if (!new_skb) {
36457 if (vcc->pop) vcc->pop(vcc,skb);
36458 else dev_kfree_skb(skb);
36459 - atomic_inc(&vcc->stats->tx_err);
36460 + atomic_inc_unchecked(&vcc->stats->tx_err);
36461 return -ENOBUFS;
36462 }
36463 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36464 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36465 if (vcc->pop) vcc->pop(vcc,skb);
36466 else dev_kfree_skb(skb);
36467 out_vcc->push(out_vcc,new_skb);
36468 - atomic_inc(&vcc->stats->tx);
36469 - atomic_inc(&out_vcc->stats->rx);
36470 + atomic_inc_unchecked(&vcc->stats->tx);
36471 + atomic_inc_unchecked(&out_vcc->stats->rx);
36472 return 0;
36473 }
36474
36475 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36476 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36477 read_unlock(&vcc_sklist_lock);
36478 if (!out_vcc) {
36479 - atomic_inc(&vcc->stats->tx_err);
36480 + atomic_inc_unchecked(&vcc->stats->tx_err);
36481 goto done;
36482 }
36483 skb_pull(skb,sizeof(struct atmtcp_hdr));
36484 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36485 __net_timestamp(new_skb);
36486 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36487 out_vcc->push(out_vcc,new_skb);
36488 - atomic_inc(&vcc->stats->tx);
36489 - atomic_inc(&out_vcc->stats->rx);
36490 + atomic_inc_unchecked(&vcc->stats->tx);
36491 + atomic_inc_unchecked(&out_vcc->stats->rx);
36492 done:
36493 if (vcc->pop) vcc->pop(vcc,skb);
36494 else dev_kfree_skb(skb);
36495 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36496 index b1955ba..b179940 100644
36497 --- a/drivers/atm/eni.c
36498 +++ b/drivers/atm/eni.c
36499 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36500 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36501 vcc->dev->number);
36502 length = 0;
36503 - atomic_inc(&vcc->stats->rx_err);
36504 + atomic_inc_unchecked(&vcc->stats->rx_err);
36505 }
36506 else {
36507 length = ATM_CELL_SIZE-1; /* no HEC */
36508 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36509 size);
36510 }
36511 eff = length = 0;
36512 - atomic_inc(&vcc->stats->rx_err);
36513 + atomic_inc_unchecked(&vcc->stats->rx_err);
36514 }
36515 else {
36516 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36517 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36518 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36519 vcc->dev->number,vcc->vci,length,size << 2,descr);
36520 length = eff = 0;
36521 - atomic_inc(&vcc->stats->rx_err);
36522 + atomic_inc_unchecked(&vcc->stats->rx_err);
36523 }
36524 }
36525 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36526 @@ -767,7 +767,7 @@ rx_dequeued++;
36527 vcc->push(vcc,skb);
36528 pushed++;
36529 }
36530 - atomic_inc(&vcc->stats->rx);
36531 + atomic_inc_unchecked(&vcc->stats->rx);
36532 }
36533 wake_up(&eni_dev->rx_wait);
36534 }
36535 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36536 PCI_DMA_TODEVICE);
36537 if (vcc->pop) vcc->pop(vcc,skb);
36538 else dev_kfree_skb_irq(skb);
36539 - atomic_inc(&vcc->stats->tx);
36540 + atomic_inc_unchecked(&vcc->stats->tx);
36541 wake_up(&eni_dev->tx_wait);
36542 dma_complete++;
36543 }
36544 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36545 index 82f2ae0..f205c02 100644
36546 --- a/drivers/atm/firestream.c
36547 +++ b/drivers/atm/firestream.c
36548 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36549 }
36550 }
36551
36552 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36553 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36554
36555 fs_dprintk (FS_DEBUG_TXMEM, "i");
36556 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36557 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36558 #endif
36559 skb_put (skb, qe->p1 & 0xffff);
36560 ATM_SKB(skb)->vcc = atm_vcc;
36561 - atomic_inc(&atm_vcc->stats->rx);
36562 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36563 __net_timestamp(skb);
36564 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36565 atm_vcc->push (atm_vcc, skb);
36566 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36567 kfree (pe);
36568 }
36569 if (atm_vcc)
36570 - atomic_inc(&atm_vcc->stats->rx_drop);
36571 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36572 break;
36573 case 0x1f: /* Reassembly abort: no buffers. */
36574 /* Silently increment error counter. */
36575 if (atm_vcc)
36576 - atomic_inc(&atm_vcc->stats->rx_drop);
36577 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36578 break;
36579 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36580 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36581 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36582 index 204814e..cede831 100644
36583 --- a/drivers/atm/fore200e.c
36584 +++ b/drivers/atm/fore200e.c
36585 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36586 #endif
36587 /* check error condition */
36588 if (*entry->status & STATUS_ERROR)
36589 - atomic_inc(&vcc->stats->tx_err);
36590 + atomic_inc_unchecked(&vcc->stats->tx_err);
36591 else
36592 - atomic_inc(&vcc->stats->tx);
36593 + atomic_inc_unchecked(&vcc->stats->tx);
36594 }
36595 }
36596
36597 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36598 if (skb == NULL) {
36599 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36600
36601 - atomic_inc(&vcc->stats->rx_drop);
36602 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36603 return -ENOMEM;
36604 }
36605
36606 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36607
36608 dev_kfree_skb_any(skb);
36609
36610 - atomic_inc(&vcc->stats->rx_drop);
36611 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36612 return -ENOMEM;
36613 }
36614
36615 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36616
36617 vcc->push(vcc, skb);
36618 - atomic_inc(&vcc->stats->rx);
36619 + atomic_inc_unchecked(&vcc->stats->rx);
36620
36621 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36622
36623 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36624 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36625 fore200e->atm_dev->number,
36626 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36627 - atomic_inc(&vcc->stats->rx_err);
36628 + atomic_inc_unchecked(&vcc->stats->rx_err);
36629 }
36630 }
36631
36632 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36633 goto retry_here;
36634 }
36635
36636 - atomic_inc(&vcc->stats->tx_err);
36637 + atomic_inc_unchecked(&vcc->stats->tx_err);
36638
36639 fore200e->tx_sat++;
36640 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36641 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36642 index aa6be26..f70a785 100644
36643 --- a/drivers/atm/he.c
36644 +++ b/drivers/atm/he.c
36645 @@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36646
36647 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36648 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36649 - atomic_inc(&vcc->stats->rx_drop);
36650 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36651 goto return_host_buffers;
36652 }
36653
36654 @@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36655 RBRQ_LEN_ERR(he_dev->rbrq_head)
36656 ? "LEN_ERR" : "",
36657 vcc->vpi, vcc->vci);
36658 - atomic_inc(&vcc->stats->rx_err);
36659 + atomic_inc_unchecked(&vcc->stats->rx_err);
36660 goto return_host_buffers;
36661 }
36662
36663 @@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36664 vcc->push(vcc, skb);
36665 spin_lock(&he_dev->global_lock);
36666
36667 - atomic_inc(&vcc->stats->rx);
36668 + atomic_inc_unchecked(&vcc->stats->rx);
36669
36670 return_host_buffers:
36671 ++pdus_assembled;
36672 @@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36673 tpd->vcc->pop(tpd->vcc, tpd->skb);
36674 else
36675 dev_kfree_skb_any(tpd->skb);
36676 - atomic_inc(&tpd->vcc->stats->tx_err);
36677 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36678 }
36679 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36680 return;
36681 @@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36682 vcc->pop(vcc, skb);
36683 else
36684 dev_kfree_skb_any(skb);
36685 - atomic_inc(&vcc->stats->tx_err);
36686 + atomic_inc_unchecked(&vcc->stats->tx_err);
36687 return -EINVAL;
36688 }
36689
36690 @@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36691 vcc->pop(vcc, skb);
36692 else
36693 dev_kfree_skb_any(skb);
36694 - atomic_inc(&vcc->stats->tx_err);
36695 + atomic_inc_unchecked(&vcc->stats->tx_err);
36696 return -EINVAL;
36697 }
36698 #endif
36699 @@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36700 vcc->pop(vcc, skb);
36701 else
36702 dev_kfree_skb_any(skb);
36703 - atomic_inc(&vcc->stats->tx_err);
36704 + atomic_inc_unchecked(&vcc->stats->tx_err);
36705 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36706 return -ENOMEM;
36707 }
36708 @@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36709 vcc->pop(vcc, skb);
36710 else
36711 dev_kfree_skb_any(skb);
36712 - atomic_inc(&vcc->stats->tx_err);
36713 + atomic_inc_unchecked(&vcc->stats->tx_err);
36714 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36715 return -ENOMEM;
36716 }
36717 @@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36718 __enqueue_tpd(he_dev, tpd, cid);
36719 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36720
36721 - atomic_inc(&vcc->stats->tx);
36722 + atomic_inc_unchecked(&vcc->stats->tx);
36723
36724 return 0;
36725 }
36726 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36727 index 1dc0519..1aadaf7 100644
36728 --- a/drivers/atm/horizon.c
36729 +++ b/drivers/atm/horizon.c
36730 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36731 {
36732 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36733 // VC layer stats
36734 - atomic_inc(&vcc->stats->rx);
36735 + atomic_inc_unchecked(&vcc->stats->rx);
36736 __net_timestamp(skb);
36737 // end of our responsibility
36738 vcc->push (vcc, skb);
36739 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36740 dev->tx_iovec = NULL;
36741
36742 // VC layer stats
36743 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36744 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36745
36746 // free the skb
36747 hrz_kfree_skb (skb);
36748 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36749 index 1bdf104..9dc44b1 100644
36750 --- a/drivers/atm/idt77252.c
36751 +++ b/drivers/atm/idt77252.c
36752 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36753 else
36754 dev_kfree_skb(skb);
36755
36756 - atomic_inc(&vcc->stats->tx);
36757 + atomic_inc_unchecked(&vcc->stats->tx);
36758 }
36759
36760 atomic_dec(&scq->used);
36761 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36762 if ((sb = dev_alloc_skb(64)) == NULL) {
36763 printk("%s: Can't allocate buffers for aal0.\n",
36764 card->name);
36765 - atomic_add(i, &vcc->stats->rx_drop);
36766 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36767 break;
36768 }
36769 if (!atm_charge(vcc, sb->truesize)) {
36770 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36771 card->name);
36772 - atomic_add(i - 1, &vcc->stats->rx_drop);
36773 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36774 dev_kfree_skb(sb);
36775 break;
36776 }
36777 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36778 ATM_SKB(sb)->vcc = vcc;
36779 __net_timestamp(sb);
36780 vcc->push(vcc, sb);
36781 - atomic_inc(&vcc->stats->rx);
36782 + atomic_inc_unchecked(&vcc->stats->rx);
36783
36784 cell += ATM_CELL_PAYLOAD;
36785 }
36786 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36787 "(CDC: %08x)\n",
36788 card->name, len, rpp->len, readl(SAR_REG_CDC));
36789 recycle_rx_pool_skb(card, rpp);
36790 - atomic_inc(&vcc->stats->rx_err);
36791 + atomic_inc_unchecked(&vcc->stats->rx_err);
36792 return;
36793 }
36794 if (stat & SAR_RSQE_CRC) {
36795 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36796 recycle_rx_pool_skb(card, rpp);
36797 - atomic_inc(&vcc->stats->rx_err);
36798 + atomic_inc_unchecked(&vcc->stats->rx_err);
36799 return;
36800 }
36801 if (skb_queue_len(&rpp->queue) > 1) {
36802 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36803 RXPRINTK("%s: Can't alloc RX skb.\n",
36804 card->name);
36805 recycle_rx_pool_skb(card, rpp);
36806 - atomic_inc(&vcc->stats->rx_err);
36807 + atomic_inc_unchecked(&vcc->stats->rx_err);
36808 return;
36809 }
36810 if (!atm_charge(vcc, skb->truesize)) {
36811 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36812 __net_timestamp(skb);
36813
36814 vcc->push(vcc, skb);
36815 - atomic_inc(&vcc->stats->rx);
36816 + atomic_inc_unchecked(&vcc->stats->rx);
36817
36818 return;
36819 }
36820 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36821 __net_timestamp(skb);
36822
36823 vcc->push(vcc, skb);
36824 - atomic_inc(&vcc->stats->rx);
36825 + atomic_inc_unchecked(&vcc->stats->rx);
36826
36827 if (skb->truesize > SAR_FB_SIZE_3)
36828 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36829 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36830 if (vcc->qos.aal != ATM_AAL0) {
36831 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36832 card->name, vpi, vci);
36833 - atomic_inc(&vcc->stats->rx_drop);
36834 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36835 goto drop;
36836 }
36837
36838 if ((sb = dev_alloc_skb(64)) == NULL) {
36839 printk("%s: Can't allocate buffers for AAL0.\n",
36840 card->name);
36841 - atomic_inc(&vcc->stats->rx_err);
36842 + atomic_inc_unchecked(&vcc->stats->rx_err);
36843 goto drop;
36844 }
36845
36846 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36847 ATM_SKB(sb)->vcc = vcc;
36848 __net_timestamp(sb);
36849 vcc->push(vcc, sb);
36850 - atomic_inc(&vcc->stats->rx);
36851 + atomic_inc_unchecked(&vcc->stats->rx);
36852
36853 drop:
36854 skb_pull(queue, 64);
36855 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36856
36857 if (vc == NULL) {
36858 printk("%s: NULL connection in send().\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 if (!test_bit(VCF_TX, &vc->flags)) {
36865 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36866 - atomic_inc(&vcc->stats->tx_err);
36867 + atomic_inc_unchecked(&vcc->stats->tx_err);
36868 dev_kfree_skb(skb);
36869 return -EINVAL;
36870 }
36871 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36872 break;
36873 default:
36874 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36875 - atomic_inc(&vcc->stats->tx_err);
36876 + atomic_inc_unchecked(&vcc->stats->tx_err);
36877 dev_kfree_skb(skb);
36878 return -EINVAL;
36879 }
36880
36881 if (skb_shinfo(skb)->nr_frags != 0) {
36882 printk("%s: No scatter-gather yet.\n", card->name);
36883 - atomic_inc(&vcc->stats->tx_err);
36884 + atomic_inc_unchecked(&vcc->stats->tx_err);
36885 dev_kfree_skb(skb);
36886 return -EINVAL;
36887 }
36888 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36889
36890 err = queue_skb(card, vc, skb, oam);
36891 if (err) {
36892 - atomic_inc(&vcc->stats->tx_err);
36893 + atomic_inc_unchecked(&vcc->stats->tx_err);
36894 dev_kfree_skb(skb);
36895 return err;
36896 }
36897 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36898 skb = dev_alloc_skb(64);
36899 if (!skb) {
36900 printk("%s: Out of memory in send_oam().\n", card->name);
36901 - atomic_inc(&vcc->stats->tx_err);
36902 + atomic_inc_unchecked(&vcc->stats->tx_err);
36903 return -ENOMEM;
36904 }
36905 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36906 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36907 index 4217f29..88f547a 100644
36908 --- a/drivers/atm/iphase.c
36909 +++ b/drivers/atm/iphase.c
36910 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36911 status = (u_short) (buf_desc_ptr->desc_mode);
36912 if (status & (RX_CER | RX_PTE | RX_OFL))
36913 {
36914 - atomic_inc(&vcc->stats->rx_err);
36915 + atomic_inc_unchecked(&vcc->stats->rx_err);
36916 IF_ERR(printk("IA: bad packet, dropping it");)
36917 if (status & RX_CER) {
36918 IF_ERR(printk(" cause: packet CRC error\n");)
36919 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36920 len = dma_addr - buf_addr;
36921 if (len > iadev->rx_buf_sz) {
36922 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36923 - atomic_inc(&vcc->stats->rx_err);
36924 + atomic_inc_unchecked(&vcc->stats->rx_err);
36925 goto out_free_desc;
36926 }
36927
36928 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36929 ia_vcc = INPH_IA_VCC(vcc);
36930 if (ia_vcc == NULL)
36931 {
36932 - atomic_inc(&vcc->stats->rx_err);
36933 + atomic_inc_unchecked(&vcc->stats->rx_err);
36934 atm_return(vcc, skb->truesize);
36935 dev_kfree_skb_any(skb);
36936 goto INCR_DLE;
36937 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36938 if ((length > iadev->rx_buf_sz) || (length >
36939 (skb->len - sizeof(struct cpcs_trailer))))
36940 {
36941 - atomic_inc(&vcc->stats->rx_err);
36942 + atomic_inc_unchecked(&vcc->stats->rx_err);
36943 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36944 length, skb->len);)
36945 atm_return(vcc, skb->truesize);
36946 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36947
36948 IF_RX(printk("rx_dle_intr: skb push");)
36949 vcc->push(vcc,skb);
36950 - atomic_inc(&vcc->stats->rx);
36951 + atomic_inc_unchecked(&vcc->stats->rx);
36952 iadev->rx_pkt_cnt++;
36953 }
36954 INCR_DLE:
36955 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36956 {
36957 struct k_sonet_stats *stats;
36958 stats = &PRIV(_ia_dev[board])->sonet_stats;
36959 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36960 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36961 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36962 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36963 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36964 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36965 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36966 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36967 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36968 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36969 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36970 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36971 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36972 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36973 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36974 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36975 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36976 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36977 }
36978 ia_cmds.status = 0;
36979 break;
36980 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36981 if ((desc == 0) || (desc > iadev->num_tx_desc))
36982 {
36983 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36984 - atomic_inc(&vcc->stats->tx);
36985 + atomic_inc_unchecked(&vcc->stats->tx);
36986 if (vcc->pop)
36987 vcc->pop(vcc, skb);
36988 else
36989 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36990 ATM_DESC(skb) = vcc->vci;
36991 skb_queue_tail(&iadev->tx_dma_q, skb);
36992
36993 - atomic_inc(&vcc->stats->tx);
36994 + atomic_inc_unchecked(&vcc->stats->tx);
36995 iadev->tx_pkt_cnt++;
36996 /* Increment transaction counter */
36997 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36998
36999 #if 0
37000 /* add flow control logic */
37001 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37002 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37003 if (iavcc->vc_desc_cnt > 10) {
37004 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37005 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37006 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37007 index fa7d701..1e404c7 100644
37008 --- a/drivers/atm/lanai.c
37009 +++ b/drivers/atm/lanai.c
37010 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37011 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37012 lanai_endtx(lanai, lvcc);
37013 lanai_free_skb(lvcc->tx.atmvcc, skb);
37014 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37015 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37016 }
37017
37018 /* Try to fill the buffer - don't call unless there is backlog */
37019 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37020 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37021 __net_timestamp(skb);
37022 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37023 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37024 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37025 out:
37026 lvcc->rx.buf.ptr = end;
37027 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37028 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37029 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37030 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37031 lanai->stats.service_rxnotaal5++;
37032 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37033 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37034 return 0;
37035 }
37036 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37037 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37038 int bytes;
37039 read_unlock(&vcc_sklist_lock);
37040 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37041 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37042 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37043 lvcc->stats.x.aal5.service_trash++;
37044 bytes = (SERVICE_GET_END(s) * 16) -
37045 (((unsigned long) lvcc->rx.buf.ptr) -
37046 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37047 }
37048 if (s & SERVICE_STREAM) {
37049 read_unlock(&vcc_sklist_lock);
37050 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37051 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37052 lvcc->stats.x.aal5.service_stream++;
37053 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37054 "PDU on VCI %d!\n", lanai->number, vci);
37055 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37056 return 0;
37057 }
37058 DPRINTK("got rx crc error on vci %d\n", vci);
37059 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37060 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37061 lvcc->stats.x.aal5.service_rxcrc++;
37062 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37063 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37064 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37065 index 9988ac9..7c52585 100644
37066 --- a/drivers/atm/nicstar.c
37067 +++ b/drivers/atm/nicstar.c
37068 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37069 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37070 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37071 card->index);
37072 - atomic_inc(&vcc->stats->tx_err);
37073 + atomic_inc_unchecked(&vcc->stats->tx_err);
37074 dev_kfree_skb_any(skb);
37075 return -EINVAL;
37076 }
37077 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37078 if (!vc->tx) {
37079 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37080 card->index);
37081 - atomic_inc(&vcc->stats->tx_err);
37082 + atomic_inc_unchecked(&vcc->stats->tx_err);
37083 dev_kfree_skb_any(skb);
37084 return -EINVAL;
37085 }
37086 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37087 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37088 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37089 card->index);
37090 - atomic_inc(&vcc->stats->tx_err);
37091 + atomic_inc_unchecked(&vcc->stats->tx_err);
37092 dev_kfree_skb_any(skb);
37093 return -EINVAL;
37094 }
37095
37096 if (skb_shinfo(skb)->nr_frags != 0) {
37097 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37098 - atomic_inc(&vcc->stats->tx_err);
37099 + atomic_inc_unchecked(&vcc->stats->tx_err);
37100 dev_kfree_skb_any(skb);
37101 return -EINVAL;
37102 }
37103 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37104 }
37105
37106 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37107 - atomic_inc(&vcc->stats->tx_err);
37108 + atomic_inc_unchecked(&vcc->stats->tx_err);
37109 dev_kfree_skb_any(skb);
37110 return -EIO;
37111 }
37112 - atomic_inc(&vcc->stats->tx);
37113 + atomic_inc_unchecked(&vcc->stats->tx);
37114
37115 return 0;
37116 }
37117 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37118 printk
37119 ("nicstar%d: Can't allocate buffers for aal0.\n",
37120 card->index);
37121 - atomic_add(i, &vcc->stats->rx_drop);
37122 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37123 break;
37124 }
37125 if (!atm_charge(vcc, sb->truesize)) {
37126 RXPRINTK
37127 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37128 card->index);
37129 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37130 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37131 dev_kfree_skb_any(sb);
37132 break;
37133 }
37134 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37135 ATM_SKB(sb)->vcc = vcc;
37136 __net_timestamp(sb);
37137 vcc->push(vcc, sb);
37138 - atomic_inc(&vcc->stats->rx);
37139 + atomic_inc_unchecked(&vcc->stats->rx);
37140 cell += ATM_CELL_PAYLOAD;
37141 }
37142
37143 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37144 if (iovb == NULL) {
37145 printk("nicstar%d: Out of iovec buffers.\n",
37146 card->index);
37147 - atomic_inc(&vcc->stats->rx_drop);
37148 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37149 recycle_rx_buf(card, skb);
37150 return;
37151 }
37152 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37153 small or large buffer itself. */
37154 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37155 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37156 - atomic_inc(&vcc->stats->rx_err);
37157 + atomic_inc_unchecked(&vcc->stats->rx_err);
37158 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37159 NS_MAX_IOVECS);
37160 NS_PRV_IOVCNT(iovb) = 0;
37161 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37162 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37163 card->index);
37164 which_list(card, skb);
37165 - atomic_inc(&vcc->stats->rx_err);
37166 + atomic_inc_unchecked(&vcc->stats->rx_err);
37167 recycle_rx_buf(card, skb);
37168 vc->rx_iov = NULL;
37169 recycle_iov_buf(card, iovb);
37170 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37171 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37172 card->index);
37173 which_list(card, skb);
37174 - atomic_inc(&vcc->stats->rx_err);
37175 + atomic_inc_unchecked(&vcc->stats->rx_err);
37176 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37177 NS_PRV_IOVCNT(iovb));
37178 vc->rx_iov = NULL;
37179 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37180 printk(" - PDU size mismatch.\n");
37181 else
37182 printk(".\n");
37183 - atomic_inc(&vcc->stats->rx_err);
37184 + atomic_inc_unchecked(&vcc->stats->rx_err);
37185 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37186 NS_PRV_IOVCNT(iovb));
37187 vc->rx_iov = NULL;
37188 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37189 /* skb points to a small buffer */
37190 if (!atm_charge(vcc, skb->truesize)) {
37191 push_rxbufs(card, skb);
37192 - atomic_inc(&vcc->stats->rx_drop);
37193 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37194 } else {
37195 skb_put(skb, len);
37196 dequeue_sm_buf(card, skb);
37197 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37198 ATM_SKB(skb)->vcc = vcc;
37199 __net_timestamp(skb);
37200 vcc->push(vcc, skb);
37201 - atomic_inc(&vcc->stats->rx);
37202 + atomic_inc_unchecked(&vcc->stats->rx);
37203 }
37204 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37205 struct sk_buff *sb;
37206 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37207 if (len <= NS_SMBUFSIZE) {
37208 if (!atm_charge(vcc, sb->truesize)) {
37209 push_rxbufs(card, sb);
37210 - atomic_inc(&vcc->stats->rx_drop);
37211 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37212 } else {
37213 skb_put(sb, len);
37214 dequeue_sm_buf(card, sb);
37215 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37216 ATM_SKB(sb)->vcc = vcc;
37217 __net_timestamp(sb);
37218 vcc->push(vcc, sb);
37219 - atomic_inc(&vcc->stats->rx);
37220 + atomic_inc_unchecked(&vcc->stats->rx);
37221 }
37222
37223 push_rxbufs(card, skb);
37224 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37225
37226 if (!atm_charge(vcc, skb->truesize)) {
37227 push_rxbufs(card, skb);
37228 - atomic_inc(&vcc->stats->rx_drop);
37229 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37230 } else {
37231 dequeue_lg_buf(card, skb);
37232 #ifdef NS_USE_DESTRUCTORS
37233 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37234 ATM_SKB(skb)->vcc = vcc;
37235 __net_timestamp(skb);
37236 vcc->push(vcc, skb);
37237 - atomic_inc(&vcc->stats->rx);
37238 + atomic_inc_unchecked(&vcc->stats->rx);
37239 }
37240
37241 push_rxbufs(card, sb);
37242 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37243 printk
37244 ("nicstar%d: Out of huge buffers.\n",
37245 card->index);
37246 - atomic_inc(&vcc->stats->rx_drop);
37247 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37248 recycle_iovec_rx_bufs(card,
37249 (struct iovec *)
37250 iovb->data,
37251 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37252 card->hbpool.count++;
37253 } else
37254 dev_kfree_skb_any(hb);
37255 - atomic_inc(&vcc->stats->rx_drop);
37256 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37257 } else {
37258 /* Copy the small buffer to the huge buffer */
37259 sb = (struct sk_buff *)iov->iov_base;
37260 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37261 #endif /* NS_USE_DESTRUCTORS */
37262 __net_timestamp(hb);
37263 vcc->push(vcc, hb);
37264 - atomic_inc(&vcc->stats->rx);
37265 + atomic_inc_unchecked(&vcc->stats->rx);
37266 }
37267 }
37268
37269 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37270 index 943cf0d..37d15d5 100644
37271 --- a/drivers/atm/solos-pci.c
37272 +++ b/drivers/atm/solos-pci.c
37273 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37274 }
37275 atm_charge(vcc, skb->truesize);
37276 vcc->push(vcc, skb);
37277 - atomic_inc(&vcc->stats->rx);
37278 + atomic_inc_unchecked(&vcc->stats->rx);
37279 break;
37280
37281 case PKT_STATUS:
37282 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37283 vcc = SKB_CB(oldskb)->vcc;
37284
37285 if (vcc) {
37286 - atomic_inc(&vcc->stats->tx);
37287 + atomic_inc_unchecked(&vcc->stats->tx);
37288 solos_pop(vcc, oldskb);
37289 } else {
37290 dev_kfree_skb_irq(oldskb);
37291 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37292 index 0215934..ce9f5b1 100644
37293 --- a/drivers/atm/suni.c
37294 +++ b/drivers/atm/suni.c
37295 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37296
37297
37298 #define ADD_LIMITED(s,v) \
37299 - atomic_add((v),&stats->s); \
37300 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37301 + atomic_add_unchecked((v),&stats->s); \
37302 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37303
37304
37305 static void suni_hz(unsigned long from_timer)
37306 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37307 index 5120a96..e2572bd 100644
37308 --- a/drivers/atm/uPD98402.c
37309 +++ b/drivers/atm/uPD98402.c
37310 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37311 struct sonet_stats tmp;
37312 int error = 0;
37313
37314 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37315 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37316 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37317 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37318 if (zero && !error) {
37319 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37320
37321
37322 #define ADD_LIMITED(s,v) \
37323 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37324 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37325 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37326 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37327 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37328 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37329
37330
37331 static void stat_event(struct atm_dev *dev)
37332 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37333 if (reason & uPD98402_INT_PFM) stat_event(dev);
37334 if (reason & uPD98402_INT_PCO) {
37335 (void) GET(PCOCR); /* clear interrupt cause */
37336 - atomic_add(GET(HECCT),
37337 + atomic_add_unchecked(GET(HECCT),
37338 &PRIV(dev)->sonet_stats.uncorr_hcs);
37339 }
37340 if ((reason & uPD98402_INT_RFO) &&
37341 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37342 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37343 uPD98402_INT_LOS),PIMR); /* enable them */
37344 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37345 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37346 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37347 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37348 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37349 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37350 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37351 return 0;
37352 }
37353
37354 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37355 index 969c3c2..9b72956 100644
37356 --- a/drivers/atm/zatm.c
37357 +++ b/drivers/atm/zatm.c
37358 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37359 }
37360 if (!size) {
37361 dev_kfree_skb_irq(skb);
37362 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37363 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37364 continue;
37365 }
37366 if (!atm_charge(vcc,skb->truesize)) {
37367 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37368 skb->len = size;
37369 ATM_SKB(skb)->vcc = vcc;
37370 vcc->push(vcc,skb);
37371 - atomic_inc(&vcc->stats->rx);
37372 + atomic_inc_unchecked(&vcc->stats->rx);
37373 }
37374 zout(pos & 0xffff,MTA(mbx));
37375 #if 0 /* probably a stupid idea */
37376 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37377 skb_queue_head(&zatm_vcc->backlog,skb);
37378 break;
37379 }
37380 - atomic_inc(&vcc->stats->tx);
37381 + atomic_inc_unchecked(&vcc->stats->tx);
37382 wake_up(&zatm_vcc->tx_wait);
37383 }
37384
37385 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37386 index 83e910a..b224a73 100644
37387 --- a/drivers/base/bus.c
37388 +++ b/drivers/base/bus.c
37389 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37390 return -EINVAL;
37391
37392 mutex_lock(&subsys->p->mutex);
37393 - list_add_tail(&sif->node, &subsys->p->interfaces);
37394 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37395 if (sif->add_dev) {
37396 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37397 while ((dev = subsys_dev_iter_next(&iter)))
37398 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37399 subsys = sif->subsys;
37400
37401 mutex_lock(&subsys->p->mutex);
37402 - list_del_init(&sif->node);
37403 + pax_list_del_init((struct list_head *)&sif->node);
37404 if (sif->remove_dev) {
37405 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37406 while ((dev = subsys_dev_iter_next(&iter)))
37407 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37408 index 25798db..15f130e 100644
37409 --- a/drivers/base/devtmpfs.c
37410 +++ b/drivers/base/devtmpfs.c
37411 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37412 if (!thread)
37413 return 0;
37414
37415 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37416 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37417 if (err)
37418 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37419 else
37420 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37421 *err = sys_unshare(CLONE_NEWNS);
37422 if (*err)
37423 goto out;
37424 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37425 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37426 if (*err)
37427 goto out;
37428 - sys_chdir("/.."); /* will traverse into overmounted root */
37429 - sys_chroot(".");
37430 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37431 + sys_chroot((char __force_user *)".");
37432 complete(&setup_done);
37433 while (1) {
37434 spin_lock(&req_lock);
37435 diff --git a/drivers/base/node.c b/drivers/base/node.c
37436 index 8f7ed99..700dd0c 100644
37437 --- a/drivers/base/node.c
37438 +++ b/drivers/base/node.c
37439 @@ -624,7 +624,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37440 struct node_attr {
37441 struct device_attribute attr;
37442 enum node_states state;
37443 -};
37444 +} __do_const;
37445
37446 static ssize_t show_node_state(struct device *dev,
37447 struct device_attribute *attr, char *buf)
37448 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37449 index ae098a2..0999830 100644
37450 --- a/drivers/base/power/domain.c
37451 +++ b/drivers/base/power/domain.c
37452 @@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37453
37454 if (dev->power.subsys_data->domain_data) {
37455 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37456 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
37457 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37458 if (clear_td)
37459 - gpd_data->td = (struct gpd_timing_data){ 0 };
37460 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37461
37462 if (--gpd_data->refcount == 0) {
37463 dev->power.subsys_data->domain_data = NULL;
37464 @@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37465 {
37466 struct cpuidle_driver *cpuidle_drv;
37467 struct gpd_cpu_data *cpu_data;
37468 - struct cpuidle_state *idle_state;
37469 + cpuidle_state_no_const *idle_state;
37470 int ret = 0;
37471
37472 if (IS_ERR_OR_NULL(genpd) || state < 0)
37473 @@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37474 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37475 {
37476 struct gpd_cpu_data *cpu_data;
37477 - struct cpuidle_state *idle_state;
37478 + cpuidle_state_no_const *idle_state;
37479 int ret = 0;
37480
37481 if (IS_ERR_OR_NULL(genpd))
37482 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37483 index 95b181d1..c4f0e19 100644
37484 --- a/drivers/base/power/sysfs.c
37485 +++ b/drivers/base/power/sysfs.c
37486 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37487 return -EIO;
37488 }
37489 }
37490 - return sprintf(buf, p);
37491 + return sprintf(buf, "%s", p);
37492 }
37493
37494 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37495 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37496 index 2d56f41..8830f19 100644
37497 --- a/drivers/base/power/wakeup.c
37498 +++ b/drivers/base/power/wakeup.c
37499 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37500 * They need to be modified together atomically, so it's better to use one
37501 * atomic variable to hold them both.
37502 */
37503 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37504 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37505
37506 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37507 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37508
37509 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37510 {
37511 - unsigned int comb = atomic_read(&combined_event_count);
37512 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37513
37514 *cnt = (comb >> IN_PROGRESS_BITS);
37515 *inpr = comb & MAX_IN_PROGRESS;
37516 @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37517 ws->start_prevent_time = ws->last_time;
37518
37519 /* Increment the counter of events in progress. */
37520 - cec = atomic_inc_return(&combined_event_count);
37521 + cec = atomic_inc_return_unchecked(&combined_event_count);
37522
37523 trace_wakeup_source_activate(ws->name, cec);
37524 }
37525 @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37526 * Increment the counter of registered wakeup events and decrement the
37527 * couter of wakeup events in progress simultaneously.
37528 */
37529 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37530 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37531 trace_wakeup_source_deactivate(ws->name, cec);
37532
37533 split_counters(&cnt, &inpr);
37534 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37535 index e8d11b6..7b1b36f 100644
37536 --- a/drivers/base/syscore.c
37537 +++ b/drivers/base/syscore.c
37538 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37539 void register_syscore_ops(struct syscore_ops *ops)
37540 {
37541 mutex_lock(&syscore_ops_lock);
37542 - list_add_tail(&ops->node, &syscore_ops_list);
37543 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37544 mutex_unlock(&syscore_ops_lock);
37545 }
37546 EXPORT_SYMBOL_GPL(register_syscore_ops);
37547 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37548 void unregister_syscore_ops(struct syscore_ops *ops)
37549 {
37550 mutex_lock(&syscore_ops_lock);
37551 - list_del(&ops->node);
37552 + pax_list_del((struct list_head *)&ops->node);
37553 mutex_unlock(&syscore_ops_lock);
37554 }
37555 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37556 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37557 index 73894ca..69f64ef 100644
37558 --- a/drivers/block/cciss.c
37559 +++ b/drivers/block/cciss.c
37560 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37561 while (!list_empty(&h->reqQ)) {
37562 c = list_entry(h->reqQ.next, CommandList_struct, list);
37563 /* can't do anything if fifo is full */
37564 - if ((h->access.fifo_full(h))) {
37565 + if ((h->access->fifo_full(h))) {
37566 dev_warn(&h->pdev->dev, "fifo full\n");
37567 break;
37568 }
37569 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37570 h->Qdepth--;
37571
37572 /* Tell the controller execute command */
37573 - h->access.submit_command(h, c);
37574 + h->access->submit_command(h, c);
37575
37576 /* Put job onto the completed Q */
37577 addQ(&h->cmpQ, c);
37578 @@ -3447,17 +3447,17 @@ startio:
37579
37580 static inline unsigned long get_next_completion(ctlr_info_t *h)
37581 {
37582 - return h->access.command_completed(h);
37583 + return h->access->command_completed(h);
37584 }
37585
37586 static inline int interrupt_pending(ctlr_info_t *h)
37587 {
37588 - return h->access.intr_pending(h);
37589 + return h->access->intr_pending(h);
37590 }
37591
37592 static inline long interrupt_not_for_us(ctlr_info_t *h)
37593 {
37594 - return ((h->access.intr_pending(h) == 0) ||
37595 + return ((h->access->intr_pending(h) == 0) ||
37596 (h->interrupts_enabled == 0));
37597 }
37598
37599 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37600 u32 a;
37601
37602 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37603 - return h->access.command_completed(h);
37604 + return h->access->command_completed(h);
37605
37606 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37607 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37608 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37609 trans_support & CFGTBL_Trans_use_short_tags);
37610
37611 /* Change the access methods to the performant access methods */
37612 - h->access = SA5_performant_access;
37613 + h->access = &SA5_performant_access;
37614 h->transMethod = CFGTBL_Trans_Performant;
37615
37616 return;
37617 @@ -4325,7 +4325,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37618 if (prod_index < 0)
37619 return -ENODEV;
37620 h->product_name = products[prod_index].product_name;
37621 - h->access = *(products[prod_index].access);
37622 + h->access = products[prod_index].access;
37623
37624 if (cciss_board_disabled(h)) {
37625 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37626 @@ -5057,7 +5057,7 @@ reinit_after_soft_reset:
37627 }
37628
37629 /* make sure the board interrupts are off */
37630 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37631 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37632 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37633 if (rc)
37634 goto clean2;
37635 @@ -5107,7 +5107,7 @@ reinit_after_soft_reset:
37636 * fake ones to scoop up any residual completions.
37637 */
37638 spin_lock_irqsave(&h->lock, flags);
37639 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37640 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37641 spin_unlock_irqrestore(&h->lock, flags);
37642 free_irq(h->intr[h->intr_mode], h);
37643 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37644 @@ -5127,9 +5127,9 @@ reinit_after_soft_reset:
37645 dev_info(&h->pdev->dev, "Board READY.\n");
37646 dev_info(&h->pdev->dev,
37647 "Waiting for stale completions to drain.\n");
37648 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37649 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37650 msleep(10000);
37651 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37652 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37653
37654 rc = controller_reset_failed(h->cfgtable);
37655 if (rc)
37656 @@ -5152,7 +5152,7 @@ reinit_after_soft_reset:
37657 cciss_scsi_setup(h);
37658
37659 /* Turn the interrupts on so we can service requests */
37660 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37661 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37662
37663 /* Get the firmware version */
37664 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37665 @@ -5224,7 +5224,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37666 kfree(flush_buf);
37667 if (return_code != IO_OK)
37668 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37669 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37670 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37671 free_irq(h->intr[h->intr_mode], h);
37672 }
37673
37674 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37675 index 7fda30e..2f27946 100644
37676 --- a/drivers/block/cciss.h
37677 +++ b/drivers/block/cciss.h
37678 @@ -101,7 +101,7 @@ struct ctlr_info
37679 /* information about each logical volume */
37680 drive_info_struct *drv[CISS_MAX_LUN];
37681
37682 - struct access_method access;
37683 + struct access_method *access;
37684
37685 /* queue and queue Info */
37686 struct list_head reqQ;
37687 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37688 }
37689
37690 static struct access_method SA5_access = {
37691 - SA5_submit_command,
37692 - SA5_intr_mask,
37693 - SA5_fifo_full,
37694 - SA5_intr_pending,
37695 - SA5_completed,
37696 + .submit_command = SA5_submit_command,
37697 + .set_intr_mask = SA5_intr_mask,
37698 + .fifo_full = SA5_fifo_full,
37699 + .intr_pending = SA5_intr_pending,
37700 + .command_completed = SA5_completed,
37701 };
37702
37703 static struct access_method SA5B_access = {
37704 - SA5_submit_command,
37705 - SA5B_intr_mask,
37706 - SA5_fifo_full,
37707 - SA5B_intr_pending,
37708 - SA5_completed,
37709 + .submit_command = SA5_submit_command,
37710 + .set_intr_mask = SA5B_intr_mask,
37711 + .fifo_full = SA5_fifo_full,
37712 + .intr_pending = SA5B_intr_pending,
37713 + .command_completed = SA5_completed,
37714 };
37715
37716 static struct access_method SA5_performant_access = {
37717 - SA5_submit_command,
37718 - SA5_performant_intr_mask,
37719 - SA5_fifo_full,
37720 - SA5_performant_intr_pending,
37721 - SA5_performant_completed,
37722 + .submit_command = SA5_submit_command,
37723 + .set_intr_mask = SA5_performant_intr_mask,
37724 + .fifo_full = SA5_fifo_full,
37725 + .intr_pending = SA5_performant_intr_pending,
37726 + .command_completed = SA5_performant_completed,
37727 };
37728
37729 struct board_type {
37730 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37731 index 2b94403..fd6ad1f 100644
37732 --- a/drivers/block/cpqarray.c
37733 +++ b/drivers/block/cpqarray.c
37734 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37735 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37736 goto Enomem4;
37737 }
37738 - hba[i]->access.set_intr_mask(hba[i], 0);
37739 + hba[i]->access->set_intr_mask(hba[i], 0);
37740 if (request_irq(hba[i]->intr, do_ida_intr,
37741 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37742 {
37743 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37744 add_timer(&hba[i]->timer);
37745
37746 /* Enable IRQ now that spinlock and rate limit timer are set up */
37747 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37748 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37749
37750 for(j=0; j<NWD; j++) {
37751 struct gendisk *disk = ida_gendisk[i][j];
37752 @@ -694,7 +694,7 @@ DBGINFO(
37753 for(i=0; i<NR_PRODUCTS; i++) {
37754 if (board_id == products[i].board_id) {
37755 c->product_name = products[i].product_name;
37756 - c->access = *(products[i].access);
37757 + c->access = products[i].access;
37758 break;
37759 }
37760 }
37761 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37762 hba[ctlr]->intr = intr;
37763 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37764 hba[ctlr]->product_name = products[j].product_name;
37765 - hba[ctlr]->access = *(products[j].access);
37766 + hba[ctlr]->access = products[j].access;
37767 hba[ctlr]->ctlr = ctlr;
37768 hba[ctlr]->board_id = board_id;
37769 hba[ctlr]->pci_dev = NULL; /* not PCI */
37770 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37771
37772 while((c = h->reqQ) != NULL) {
37773 /* Can't do anything if we're busy */
37774 - if (h->access.fifo_full(h) == 0)
37775 + if (h->access->fifo_full(h) == 0)
37776 return;
37777
37778 /* Get the first entry from the request Q */
37779 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37780 h->Qdepth--;
37781
37782 /* Tell the controller to do our bidding */
37783 - h->access.submit_command(h, c);
37784 + h->access->submit_command(h, c);
37785
37786 /* Get onto the completion Q */
37787 addQ(&h->cmpQ, c);
37788 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37789 unsigned long flags;
37790 __u32 a,a1;
37791
37792 - istat = h->access.intr_pending(h);
37793 + istat = h->access->intr_pending(h);
37794 /* Is this interrupt for us? */
37795 if (istat == 0)
37796 return IRQ_NONE;
37797 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37798 */
37799 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37800 if (istat & FIFO_NOT_EMPTY) {
37801 - while((a = h->access.command_completed(h))) {
37802 + while((a = h->access->command_completed(h))) {
37803 a1 = a; a &= ~3;
37804 if ((c = h->cmpQ) == NULL)
37805 {
37806 @@ -1448,11 +1448,11 @@ static int sendcmd(
37807 /*
37808 * Disable interrupt
37809 */
37810 - info_p->access.set_intr_mask(info_p, 0);
37811 + info_p->access->set_intr_mask(info_p, 0);
37812 /* Make sure there is room in the command FIFO */
37813 /* Actually it should be completely empty at this time. */
37814 for (i = 200000; i > 0; i--) {
37815 - temp = info_p->access.fifo_full(info_p);
37816 + temp = info_p->access->fifo_full(info_p);
37817 if (temp != 0) {
37818 break;
37819 }
37820 @@ -1465,7 +1465,7 @@ DBG(
37821 /*
37822 * Send the cmd
37823 */
37824 - info_p->access.submit_command(info_p, c);
37825 + info_p->access->submit_command(info_p, c);
37826 complete = pollcomplete(ctlr);
37827
37828 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37829 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37830 * we check the new geometry. Then turn interrupts back on when
37831 * we're done.
37832 */
37833 - host->access.set_intr_mask(host, 0);
37834 + host->access->set_intr_mask(host, 0);
37835 getgeometry(ctlr);
37836 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37837 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37838
37839 for(i=0; i<NWD; i++) {
37840 struct gendisk *disk = ida_gendisk[ctlr][i];
37841 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37842 /* Wait (up to 2 seconds) for a command to complete */
37843
37844 for (i = 200000; i > 0; i--) {
37845 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
37846 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
37847 if (done == 0) {
37848 udelay(10); /* a short fixed delay */
37849 } else
37850 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37851 index be73e9d..7fbf140 100644
37852 --- a/drivers/block/cpqarray.h
37853 +++ b/drivers/block/cpqarray.h
37854 @@ -99,7 +99,7 @@ struct ctlr_info {
37855 drv_info_t drv[NWD];
37856 struct proc_dir_entry *proc;
37857
37858 - struct access_method access;
37859 + struct access_method *access;
37860
37861 cmdlist_t *reqQ;
37862 cmdlist_t *cmpQ;
37863 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37864 index e7093d4..b364085 100644
37865 --- a/drivers/block/drbd/drbd_int.h
37866 +++ b/drivers/block/drbd/drbd_int.h
37867 @@ -331,7 +331,7 @@ struct drbd_epoch {
37868 struct drbd_connection *connection;
37869 struct list_head list;
37870 unsigned int barrier_nr;
37871 - atomic_t epoch_size; /* increased on every request added. */
37872 + atomic_unchecked_t epoch_size; /* increased on every request added. */
37873 atomic_t active; /* increased on every req. added, and dec on every finished. */
37874 unsigned long flags;
37875 };
37876 @@ -787,7 +787,7 @@ struct drbd_device {
37877 unsigned int al_tr_number;
37878 int al_tr_cycle;
37879 wait_queue_head_t seq_wait;
37880 - atomic_t packet_seq;
37881 + atomic_unchecked_t packet_seq;
37882 unsigned int peer_seq;
37883 spinlock_t peer_seq_lock;
37884 unsigned int minor;
37885 @@ -1361,7 +1361,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37886 char __user *uoptval;
37887 int err;
37888
37889 - uoptval = (char __user __force *)optval;
37890 + uoptval = (char __force_user *)optval;
37891
37892 set_fs(KERNEL_DS);
37893 if (level == SOL_SOCKET)
37894 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37895 index 89c497c..9c736ae 100644
37896 --- a/drivers/block/drbd/drbd_interval.c
37897 +++ b/drivers/block/drbd/drbd_interval.c
37898 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37899 }
37900
37901 static const struct rb_augment_callbacks augment_callbacks = {
37902 - augment_propagate,
37903 - augment_copy,
37904 - augment_rotate,
37905 + .propagate = augment_propagate,
37906 + .copy = augment_copy,
37907 + .rotate = augment_rotate,
37908 };
37909
37910 /**
37911 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37912 index 331e5cc..6d657bce 100644
37913 --- a/drivers/block/drbd/drbd_main.c
37914 +++ b/drivers/block/drbd/drbd_main.c
37915 @@ -1322,7 +1322,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
37916 p->sector = sector;
37917 p->block_id = block_id;
37918 p->blksize = blksize;
37919 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
37920 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
37921 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
37922 }
37923
37924 @@ -1628,7 +1628,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
37925 return -EIO;
37926 p->sector = cpu_to_be64(req->i.sector);
37927 p->block_id = (unsigned long)req;
37928 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
37929 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
37930 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
37931 if (device->state.conn >= C_SYNC_SOURCE &&
37932 device->state.conn <= C_PAUSED_SYNC_T)
37933 @@ -2658,8 +2658,8 @@ void drbd_destroy_connection(struct kref *kref)
37934 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
37935 struct drbd_resource *resource = connection->resource;
37936
37937 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
37938 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
37939 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
37940 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
37941 kfree(connection->current_epoch);
37942
37943 idr_destroy(&connection->peer_devices);
37944 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37945 index 526414b..4eb8184 100644
37946 --- a/drivers/block/drbd/drbd_nl.c
37947 +++ b/drivers/block/drbd/drbd_nl.c
37948 @@ -3505,7 +3505,7 @@ out:
37949
37950 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
37951 {
37952 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37953 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37954 struct sk_buff *msg;
37955 struct drbd_genlmsghdr *d_out;
37956 unsigned seq;
37957 @@ -3518,7 +3518,7 @@ void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
37958 return;
37959 }
37960
37961 - seq = atomic_inc_return(&drbd_genl_seq);
37962 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37963 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37964 if (!msg)
37965 goto failed;
37966 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37967 index 68e3992..1aca24a 100644
37968 --- a/drivers/block/drbd/drbd_receiver.c
37969 +++ b/drivers/block/drbd/drbd_receiver.c
37970 @@ -826,7 +826,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
37971 struct drbd_device *device = peer_device->device;
37972 int err;
37973
37974 - atomic_set(&device->packet_seq, 0);
37975 + atomic_set_unchecked(&device->packet_seq, 0);
37976 device->peer_seq = 0;
37977
37978 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
37979 @@ -1188,7 +1188,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
37980 do {
37981 next_epoch = NULL;
37982
37983 - epoch_size = atomic_read(&epoch->epoch_size);
37984 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37985
37986 switch (ev & ~EV_CLEANUP) {
37987 case EV_PUT:
37988 @@ -1228,7 +1228,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
37989 rv = FE_DESTROYED;
37990 } else {
37991 epoch->flags = 0;
37992 - atomic_set(&epoch->epoch_size, 0);
37993 + atomic_set_unchecked(&epoch->epoch_size, 0);
37994 /* atomic_set(&epoch->active, 0); is already zero */
37995 if (rv == FE_STILL_LIVE)
37996 rv = FE_RECYCLED;
37997 @@ -1456,7 +1456,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
37998 conn_wait_active_ee_empty(connection);
37999 drbd_flush(connection);
38000
38001 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38002 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38003 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38004 if (epoch)
38005 break;
38006 @@ -1469,11 +1469,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38007 }
38008
38009 epoch->flags = 0;
38010 - atomic_set(&epoch->epoch_size, 0);
38011 + atomic_set_unchecked(&epoch->epoch_size, 0);
38012 atomic_set(&epoch->active, 0);
38013
38014 spin_lock(&connection->epoch_lock);
38015 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38016 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38017 list_add(&epoch->list, &connection->current_epoch->list);
38018 connection->current_epoch = epoch;
38019 connection->epochs++;
38020 @@ -2182,7 +2182,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38021
38022 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38023 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38024 - atomic_inc(&connection->current_epoch->epoch_size);
38025 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38026 err2 = drbd_drain_block(peer_device, pi->size);
38027 if (!err)
38028 err = err2;
38029 @@ -2216,7 +2216,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38030
38031 spin_lock(&connection->epoch_lock);
38032 peer_req->epoch = connection->current_epoch;
38033 - atomic_inc(&peer_req->epoch->epoch_size);
38034 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38035 atomic_inc(&peer_req->epoch->active);
38036 spin_unlock(&connection->epoch_lock);
38037
38038 @@ -4396,7 +4396,7 @@ struct data_cmd {
38039 int expect_payload;
38040 size_t pkt_size;
38041 int (*fn)(struct drbd_connection *, struct packet_info *);
38042 -};
38043 +} __do_const;
38044
38045 static struct data_cmd drbd_cmd_handler[] = {
38046 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38047 @@ -4506,7 +4506,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38048 if (!list_empty(&connection->current_epoch->list))
38049 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38050 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38051 - atomic_set(&connection->current_epoch->epoch_size, 0);
38052 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38053 connection->send.seen_any_write_yet = false;
38054
38055 drbd_info(connection, "Connection closed\n");
38056 @@ -5281,7 +5281,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38057 struct asender_cmd {
38058 size_t pkt_size;
38059 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38060 -};
38061 +} __do_const;
38062
38063 static struct asender_cmd asender_tbl[] = {
38064 [P_PING] = { 0, got_Ping },
38065 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38066 index f70a230..9dc90d5 100644
38067 --- a/drivers/block/loop.c
38068 +++ b/drivers/block/loop.c
38069 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38070
38071 file_start_write(file);
38072 set_fs(get_ds());
38073 - bw = file->f_op->write(file, buf, len, &pos);
38074 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38075 set_fs(old_fs);
38076 file_end_write(file);
38077 if (likely(bw == len))
38078 diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
38079 index 091b9ea..f5428f8 100644
38080 --- a/drivers/block/null_blk.c
38081 +++ b/drivers/block/null_blk.c
38082 @@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
38083 return 0;
38084 }
38085
38086 -static struct blk_mq_ops null_mq_ops = {
38087 - .queue_rq = null_queue_rq,
38088 - .map_queue = blk_mq_map_queue,
38089 +static struct blk_mq_ops null_mq_single_ops = {
38090 + .queue_rq = null_queue_rq,
38091 + .map_queue = blk_mq_map_queue,
38092 .init_hctx = null_init_hctx,
38093 .complete = null_softirq_done_fn,
38094 + .alloc_hctx = blk_mq_alloc_single_hw_queue,
38095 + .free_hctx = blk_mq_free_single_hw_queue,
38096 +};
38097 +
38098 +static struct blk_mq_ops null_mq_per_node_ops = {
38099 + .queue_rq = null_queue_rq,
38100 + .map_queue = blk_mq_map_queue,
38101 + .init_hctx = null_init_hctx,
38102 + .alloc_hctx = null_alloc_hctx,
38103 + .free_hctx = null_free_hctx,
38104 };
38105
38106 static struct blk_mq_reg null_mq_reg = {
38107 - .ops = &null_mq_ops,
38108 + .ops = &null_mq_single_ops,
38109 .queue_depth = 64,
38110 .cmd_size = sizeof(struct nullb_cmd),
38111 .flags = BLK_MQ_F_SHOULD_MERGE,
38112 @@ -521,13 +531,8 @@ static int null_add_dev(void)
38113 null_mq_reg.queue_depth = hw_queue_depth;
38114 null_mq_reg.nr_hw_queues = submit_queues;
38115
38116 - if (use_per_node_hctx) {
38117 - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38118 - null_mq_reg.ops->free_hctx = null_free_hctx;
38119 - } else {
38120 - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38121 - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38122 - }
38123 + if (use_per_node_hctx)
38124 + null_mq_reg.ops = &null_mq_per_node_ops;
38125
38126 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38127 } else if (queue_mode == NULL_Q_BIO) {
38128 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38129 index a2af73d..c0b8f61 100644
38130 --- a/drivers/block/pktcdvd.c
38131 +++ b/drivers/block/pktcdvd.c
38132 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38133
38134 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38135 {
38136 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38137 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38138 }
38139
38140 /*
38141 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38142 return -EROFS;
38143 }
38144 pd->settings.fp = ti.fp;
38145 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38146 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38147
38148 if (ti.nwa_v) {
38149 pd->nwa = be32_to_cpu(ti.next_writable);
38150 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38151 index e5565fb..71be10b4 100644
38152 --- a/drivers/block/smart1,2.h
38153 +++ b/drivers/block/smart1,2.h
38154 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38155 }
38156
38157 static struct access_method smart4_access = {
38158 - smart4_submit_command,
38159 - smart4_intr_mask,
38160 - smart4_fifo_full,
38161 - smart4_intr_pending,
38162 - smart4_completed,
38163 + .submit_command = smart4_submit_command,
38164 + .set_intr_mask = smart4_intr_mask,
38165 + .fifo_full = smart4_fifo_full,
38166 + .intr_pending = smart4_intr_pending,
38167 + .command_completed = smart4_completed,
38168 };
38169
38170 /*
38171 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38172 }
38173
38174 static struct access_method smart2_access = {
38175 - smart2_submit_command,
38176 - smart2_intr_mask,
38177 - smart2_fifo_full,
38178 - smart2_intr_pending,
38179 - smart2_completed,
38180 + .submit_command = smart2_submit_command,
38181 + .set_intr_mask = smart2_intr_mask,
38182 + .fifo_full = smart2_fifo_full,
38183 + .intr_pending = smart2_intr_pending,
38184 + .command_completed = smart2_completed,
38185 };
38186
38187 /*
38188 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38189 }
38190
38191 static struct access_method smart2e_access = {
38192 - smart2e_submit_command,
38193 - smart2e_intr_mask,
38194 - smart2e_fifo_full,
38195 - smart2e_intr_pending,
38196 - smart2e_completed,
38197 + .submit_command = smart2e_submit_command,
38198 + .set_intr_mask = smart2e_intr_mask,
38199 + .fifo_full = smart2e_fifo_full,
38200 + .intr_pending = smart2e_intr_pending,
38201 + .command_completed = smart2e_completed,
38202 };
38203
38204 /*
38205 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38206 }
38207
38208 static struct access_method smart1_access = {
38209 - smart1_submit_command,
38210 - smart1_intr_mask,
38211 - smart1_fifo_full,
38212 - smart1_intr_pending,
38213 - smart1_completed,
38214 + .submit_command = smart1_submit_command,
38215 + .set_intr_mask = smart1_intr_mask,
38216 + .fifo_full = smart1_fifo_full,
38217 + .intr_pending = smart1_intr_pending,
38218 + .command_completed = smart1_completed,
38219 };
38220 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38221 index f038dba..bb74c08 100644
38222 --- a/drivers/bluetooth/btwilink.c
38223 +++ b/drivers/bluetooth/btwilink.c
38224 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38225
38226 static int bt_ti_probe(struct platform_device *pdev)
38227 {
38228 - static struct ti_st *hst;
38229 + struct ti_st *hst;
38230 struct hci_dev *hdev;
38231 int err;
38232
38233 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38234 index 8a3aff7..d7538c2 100644
38235 --- a/drivers/cdrom/cdrom.c
38236 +++ b/drivers/cdrom/cdrom.c
38237 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38238 ENSURE(reset, CDC_RESET);
38239 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38240 cdi->mc_flags = 0;
38241 - cdo->n_minors = 0;
38242 cdi->options = CDO_USE_FFLAGS;
38243
38244 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38245 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38246 else
38247 cdi->cdda_method = CDDA_OLD;
38248
38249 - if (!cdo->generic_packet)
38250 - cdo->generic_packet = cdrom_dummy_generic_packet;
38251 + if (!cdo->generic_packet) {
38252 + pax_open_kernel();
38253 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38254 + pax_close_kernel();
38255 + }
38256
38257 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38258 mutex_lock(&cdrom_mutex);
38259 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38260 if (cdi->exit)
38261 cdi->exit(cdi);
38262
38263 - cdi->ops->n_minors--;
38264 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38265 }
38266
38267 @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38268 */
38269 nr = nframes;
38270 do {
38271 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38272 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38273 if (cgc.buffer)
38274 break;
38275
38276 @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38277 struct cdrom_device_info *cdi;
38278 int ret;
38279
38280 - ret = scnprintf(info + *pos, max_size - *pos, header);
38281 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38282 if (!ret)
38283 return 1;
38284
38285 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38286 index 51e75ad..39c4c76 100644
38287 --- a/drivers/cdrom/gdrom.c
38288 +++ b/drivers/cdrom/gdrom.c
38289 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38290 .audio_ioctl = gdrom_audio_ioctl,
38291 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38292 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38293 - .n_minors = 1,
38294 };
38295
38296 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38297 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38298 index 6e9f74a..50c7cea 100644
38299 --- a/drivers/char/Kconfig
38300 +++ b/drivers/char/Kconfig
38301 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38302
38303 config DEVKMEM
38304 bool "/dev/kmem virtual device support"
38305 - default y
38306 + default n
38307 + depends on !GRKERNSEC_KMEM
38308 help
38309 Say Y here if you want to support the /dev/kmem device. The
38310 /dev/kmem device is rarely used, but can be used for certain
38311 @@ -577,6 +578,7 @@ config DEVPORT
38312 bool
38313 depends on !M68K
38314 depends on ISA || PCI
38315 + depends on !GRKERNSEC_KMEM
38316 default y
38317
38318 source "drivers/s390/char/Kconfig"
38319 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38320 index a48e05b..6bac831 100644
38321 --- a/drivers/char/agp/compat_ioctl.c
38322 +++ b/drivers/char/agp/compat_ioctl.c
38323 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38324 return -ENOMEM;
38325 }
38326
38327 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38328 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38329 sizeof(*usegment) * ureserve.seg_count)) {
38330 kfree(usegment);
38331 kfree(ksegment);
38332 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38333 index b297033..fa217ca 100644
38334 --- a/drivers/char/agp/frontend.c
38335 +++ b/drivers/char/agp/frontend.c
38336 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38337 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38338 return -EFAULT;
38339
38340 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38341 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38342 return -EFAULT;
38343
38344 client = agp_find_client_by_pid(reserve.pid);
38345 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38346 if (segment == NULL)
38347 return -ENOMEM;
38348
38349 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38350 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38351 sizeof(struct agp_segment) * reserve.seg_count)) {
38352 kfree(segment);
38353 return -EFAULT;
38354 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38355 index 4f94375..413694e 100644
38356 --- a/drivers/char/genrtc.c
38357 +++ b/drivers/char/genrtc.c
38358 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38359 switch (cmd) {
38360
38361 case RTC_PLL_GET:
38362 + memset(&pll, 0, sizeof(pll));
38363 if (get_rtc_pll(&pll))
38364 return -EINVAL;
38365 else
38366 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38367 index d5d4cd8..22d561d 100644
38368 --- a/drivers/char/hpet.c
38369 +++ b/drivers/char/hpet.c
38370 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38371 }
38372
38373 static int
38374 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38375 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38376 struct hpet_info *info)
38377 {
38378 struct hpet_timer __iomem *timer;
38379 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38380 index 86fe45c..c0ea948 100644
38381 --- a/drivers/char/hw_random/intel-rng.c
38382 +++ b/drivers/char/hw_random/intel-rng.c
38383 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38384
38385 if (no_fwh_detect)
38386 return -ENODEV;
38387 - printk(warning);
38388 + printk("%s", warning);
38389 return -EBUSY;
38390 }
38391
38392 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38393 index e6db938..835e3a2 100644
38394 --- a/drivers/char/ipmi/ipmi_msghandler.c
38395 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38396 @@ -438,7 +438,7 @@ struct ipmi_smi {
38397 struct proc_dir_entry *proc_dir;
38398 char proc_dir_name[10];
38399
38400 - atomic_t stats[IPMI_NUM_STATS];
38401 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38402
38403 /*
38404 * run_to_completion duplicate of smb_info, smi_info
38405 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38406 static DEFINE_MUTEX(smi_watchers_mutex);
38407
38408 #define ipmi_inc_stat(intf, stat) \
38409 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38410 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38411 #define ipmi_get_stat(intf, stat) \
38412 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38413 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38414
38415 static int is_lan_addr(struct ipmi_addr *addr)
38416 {
38417 @@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38418 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38419 init_waitqueue_head(&intf->waitq);
38420 for (i = 0; i < IPMI_NUM_STATS; i++)
38421 - atomic_set(&intf->stats[i], 0);
38422 + atomic_set_unchecked(&intf->stats[i], 0);
38423
38424 intf->proc_dir = NULL;
38425
38426 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38427 index 1c4bb4f..719e873 100644
38428 --- a/drivers/char/ipmi/ipmi_si_intf.c
38429 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38430 @@ -285,7 +285,7 @@ struct smi_info {
38431 unsigned char slave_addr;
38432
38433 /* Counters and things for the proc filesystem. */
38434 - atomic_t stats[SI_NUM_STATS];
38435 + atomic_unchecked_t stats[SI_NUM_STATS];
38436
38437 struct task_struct *thread;
38438
38439 @@ -294,9 +294,9 @@ struct smi_info {
38440 };
38441
38442 #define smi_inc_stat(smi, stat) \
38443 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38444 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38445 #define smi_get_stat(smi, stat) \
38446 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38447 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38448
38449 #define SI_MAX_PARMS 4
38450
38451 @@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
38452 atomic_set(&new_smi->req_events, 0);
38453 new_smi->run_to_completion = false;
38454 for (i = 0; i < SI_NUM_STATS; i++)
38455 - atomic_set(&new_smi->stats[i], 0);
38456 + atomic_set_unchecked(&new_smi->stats[i], 0);
38457
38458 new_smi->interrupt_disabled = true;
38459 atomic_set(&new_smi->stop_operation, 0);
38460 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38461 index 917403f..dddd899 100644
38462 --- a/drivers/char/mem.c
38463 +++ b/drivers/char/mem.c
38464 @@ -18,6 +18,7 @@
38465 #include <linux/raw.h>
38466 #include <linux/tty.h>
38467 #include <linux/capability.h>
38468 +#include <linux/security.h>
38469 #include <linux/ptrace.h>
38470 #include <linux/device.h>
38471 #include <linux/highmem.h>
38472 @@ -36,6 +37,10 @@
38473
38474 #define DEVPORT_MINOR 4
38475
38476 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38477 +extern const struct file_operations grsec_fops;
38478 +#endif
38479 +
38480 static inline unsigned long size_inside_page(unsigned long start,
38481 unsigned long size)
38482 {
38483 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38484
38485 while (cursor < to) {
38486 if (!devmem_is_allowed(pfn)) {
38487 +#ifdef CONFIG_GRKERNSEC_KMEM
38488 + gr_handle_mem_readwrite(from, to);
38489 +#else
38490 printk(KERN_INFO
38491 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38492 current->comm, from, to);
38493 +#endif
38494 return 0;
38495 }
38496 cursor += PAGE_SIZE;
38497 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38498 }
38499 return 1;
38500 }
38501 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38502 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38503 +{
38504 + return 0;
38505 +}
38506 #else
38507 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38508 {
38509 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38510
38511 while (count > 0) {
38512 unsigned long remaining;
38513 + char *temp;
38514
38515 sz = size_inside_page(p, count);
38516
38517 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38518 if (!ptr)
38519 return -EFAULT;
38520
38521 - remaining = copy_to_user(buf, ptr, sz);
38522 +#ifdef CONFIG_PAX_USERCOPY
38523 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38524 + if (!temp) {
38525 + unxlate_dev_mem_ptr(p, ptr);
38526 + return -ENOMEM;
38527 + }
38528 + memcpy(temp, ptr, sz);
38529 +#else
38530 + temp = ptr;
38531 +#endif
38532 +
38533 + remaining = copy_to_user(buf, temp, sz);
38534 +
38535 +#ifdef CONFIG_PAX_USERCOPY
38536 + kfree(temp);
38537 +#endif
38538 +
38539 unxlate_dev_mem_ptr(p, ptr);
38540 if (remaining)
38541 return -EFAULT;
38542 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38543 size_t count, loff_t *ppos)
38544 {
38545 unsigned long p = *ppos;
38546 - ssize_t low_count, read, sz;
38547 + ssize_t low_count, read, sz, err = 0;
38548 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38549 - int err = 0;
38550
38551 read = 0;
38552 if (p < (unsigned long) high_memory) {
38553 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38554 }
38555 #endif
38556 while (low_count > 0) {
38557 + char *temp;
38558 +
38559 sz = size_inside_page(p, low_count);
38560
38561 /*
38562 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38563 */
38564 kbuf = xlate_dev_kmem_ptr((char *)p);
38565
38566 - if (copy_to_user(buf, kbuf, sz))
38567 +#ifdef CONFIG_PAX_USERCOPY
38568 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38569 + if (!temp)
38570 + return -ENOMEM;
38571 + memcpy(temp, kbuf, sz);
38572 +#else
38573 + temp = kbuf;
38574 +#endif
38575 +
38576 + err = copy_to_user(buf, temp, sz);
38577 +
38578 +#ifdef CONFIG_PAX_USERCOPY
38579 + kfree(temp);
38580 +#endif
38581 +
38582 + if (err)
38583 return -EFAULT;
38584 buf += sz;
38585 p += sz;
38586 @@ -827,6 +874,9 @@ static const struct memdev {
38587 #ifdef CONFIG_PRINTK
38588 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38589 #endif
38590 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38591 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38592 +#endif
38593 };
38594
38595 static int memory_open(struct inode *inode, struct file *filp)
38596 @@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
38597 continue;
38598
38599 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38600 - NULL, devlist[minor].name);
38601 + NULL, "%s", devlist[minor].name);
38602 }
38603
38604 return tty_init();
38605 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38606 index 9df78e2..01ba9ae 100644
38607 --- a/drivers/char/nvram.c
38608 +++ b/drivers/char/nvram.c
38609 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38610
38611 spin_unlock_irq(&rtc_lock);
38612
38613 - if (copy_to_user(buf, contents, tmp - contents))
38614 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38615 return -EFAULT;
38616
38617 *ppos = i;
38618 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38619 index 8320abd..ec48108 100644
38620 --- a/drivers/char/pcmcia/synclink_cs.c
38621 +++ b/drivers/char/pcmcia/synclink_cs.c
38622 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38623
38624 if (debug_level >= DEBUG_LEVEL_INFO)
38625 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38626 - __FILE__, __LINE__, info->device_name, port->count);
38627 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38628
38629 - WARN_ON(!port->count);
38630 + WARN_ON(!atomic_read(&port->count));
38631
38632 if (tty_port_close_start(port, tty, filp) == 0)
38633 goto cleanup;
38634 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38635 cleanup:
38636 if (debug_level >= DEBUG_LEVEL_INFO)
38637 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38638 - tty->driver->name, port->count);
38639 + tty->driver->name, atomic_read(&port->count));
38640 }
38641
38642 /* Wait until the transmitter is empty.
38643 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38644
38645 if (debug_level >= DEBUG_LEVEL_INFO)
38646 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38647 - __FILE__, __LINE__, tty->driver->name, port->count);
38648 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38649
38650 /* If port is closing, signal caller to try again */
38651 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38652 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38653 goto cleanup;
38654 }
38655 spin_lock(&port->lock);
38656 - port->count++;
38657 + atomic_inc(&port->count);
38658 spin_unlock(&port->lock);
38659 spin_unlock_irqrestore(&info->netlock, flags);
38660
38661 - if (port->count == 1) {
38662 + if (atomic_read(&port->count) == 1) {
38663 /* 1st open on this device, init hardware */
38664 retval = startup(info, tty);
38665 if (retval < 0)
38666 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38667 unsigned short new_crctype;
38668
38669 /* return error if TTY interface open */
38670 - if (info->port.count)
38671 + if (atomic_read(&info->port.count))
38672 return -EBUSY;
38673
38674 switch (encoding)
38675 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38676
38677 /* arbitrate between network and tty opens */
38678 spin_lock_irqsave(&info->netlock, flags);
38679 - if (info->port.count != 0 || info->netcount != 0) {
38680 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38681 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38682 spin_unlock_irqrestore(&info->netlock, flags);
38683 return -EBUSY;
38684 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38685 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38686
38687 /* return error if TTY interface open */
38688 - if (info->port.count)
38689 + if (atomic_read(&info->port.count))
38690 return -EBUSY;
38691
38692 if (cmd != SIOCWANDEV)
38693 diff --git a/drivers/char/random.c b/drivers/char/random.c
38694 index 2b6e4cd..32033f3 100644
38695 --- a/drivers/char/random.c
38696 +++ b/drivers/char/random.c
38697 @@ -270,10 +270,17 @@
38698 /*
38699 * Configuration information
38700 */
38701 +#ifdef CONFIG_GRKERNSEC_RANDNET
38702 +#define INPUT_POOL_SHIFT 14
38703 +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38704 +#define OUTPUT_POOL_SHIFT 12
38705 +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38706 +#else
38707 #define INPUT_POOL_SHIFT 12
38708 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38709 #define OUTPUT_POOL_SHIFT 10
38710 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38711 +#endif
38712 #define SEC_XFER_SIZE 512
38713 #define EXTRACT_SIZE 10
38714
38715 @@ -284,9 +291,6 @@
38716 /*
38717 * To allow fractional bits to be tracked, the entropy_count field is
38718 * denominated in units of 1/8th bits.
38719 - *
38720 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38721 - * credit_entropy_bits() needs to be 64 bits wide.
38722 */
38723 #define ENTROPY_SHIFT 3
38724 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38725 @@ -361,12 +365,19 @@ static struct poolinfo {
38726 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38727 int tap1, tap2, tap3, tap4, tap5;
38728 } poolinfo_table[] = {
38729 +#ifdef CONFIG_GRKERNSEC_RANDNET
38730 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38731 + { S(512), 411, 308, 208, 104, 1 },
38732 + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38733 + { S(128), 104, 76, 51, 25, 1 },
38734 +#else
38735 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38736 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38737 { S(128), 104, 76, 51, 25, 1 },
38738 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38739 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38740 { S(32), 26, 19, 14, 7, 1 },
38741 +#endif
38742 #if 0
38743 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38744 { S(2048), 1638, 1231, 819, 411, 1 },
38745 @@ -433,9 +444,9 @@ struct entropy_store {
38746 };
38747
38748 static void push_to_pool(struct work_struct *work);
38749 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38750 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38751 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38752 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38753 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38754 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38755
38756 static struct entropy_store input_pool = {
38757 .poolinfo = &poolinfo_table[0],
38758 @@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38759 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38760 }
38761
38762 - ACCESS_ONCE(r->input_rotate) = input_rotate;
38763 - ACCESS_ONCE(r->add_ptr) = i;
38764 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38765 + ACCESS_ONCE_RW(r->add_ptr) = i;
38766 smp_wmb();
38767
38768 if (out)
38769 @@ -632,7 +643,7 @@ retry:
38770 /* The +2 corresponds to the /4 in the denominator */
38771
38772 do {
38773 - unsigned int anfrac = min(pnfrac, pool_size/2);
38774 + u64 anfrac = min(pnfrac, pool_size/2);
38775 unsigned int add =
38776 ((pool_size - entropy_count)*anfrac*3) >> s;
38777
38778 @@ -641,7 +652,7 @@ retry:
38779 } while (unlikely(entropy_count < pool_size-2 && pnfrac));
38780 }
38781
38782 - if (entropy_count < 0) {
38783 + if (unlikely(entropy_count < 0)) {
38784 pr_warn("random: negative entropy/overflow: pool %s count %d\n",
38785 r->name, entropy_count);
38786 WARN_ON(1);
38787 @@ -980,7 +991,7 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
38788 int reserved)
38789 {
38790 int entropy_count, orig;
38791 - size_t ibytes;
38792 + size_t ibytes, nfrac;
38793
38794 BUG_ON(r->entropy_count > r->poolinfo->poolfracbits);
38795
38796 @@ -998,7 +1009,17 @@ retry:
38797 }
38798 if (ibytes < min)
38799 ibytes = 0;
38800 - if ((entropy_count -= ibytes << (ENTROPY_SHIFT + 3)) < 0)
38801 +
38802 + if (unlikely(entropy_count < 0)) {
38803 + pr_warn("random: negative entropy count: pool %s count %d\n",
38804 + r->name, entropy_count);
38805 + WARN_ON(1);
38806 + entropy_count = 0;
38807 + }
38808 + nfrac = ibytes << (ENTROPY_SHIFT + 3);
38809 + if ((size_t) entropy_count > nfrac)
38810 + entropy_count -= nfrac;
38811 + else
38812 entropy_count = 0;
38813
38814 if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
38815 @@ -1166,7 +1187,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38816
38817 extract_buf(r, tmp);
38818 i = min_t(int, nbytes, EXTRACT_SIZE);
38819 - if (copy_to_user(buf, tmp, i)) {
38820 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38821 ret = -EFAULT;
38822 break;
38823 }
38824 @@ -1375,6 +1396,7 @@ urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
38825 "with %d bits of entropy available\n",
38826 current->comm, nonblocking_pool.entropy_total);
38827
38828 + nbytes = min_t(size_t, nbytes, INT_MAX >> (ENTROPY_SHIFT + 3));
38829 ret = extract_entropy_user(&nonblocking_pool, buf, nbytes);
38830
38831 trace_urandom_read(8 * nbytes, ENTROPY_BITS(&nonblocking_pool),
38832 @@ -1555,7 +1577,7 @@ static char sysctl_bootid[16];
38833 static int proc_do_uuid(struct ctl_table *table, int write,
38834 void __user *buffer, size_t *lenp, loff_t *ppos)
38835 {
38836 - struct ctl_table fake_table;
38837 + ctl_table_no_const fake_table;
38838 unsigned char buf[64], tmp_uuid[16], *uuid;
38839
38840 uuid = table->data;
38841 @@ -1585,7 +1607,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38842 static int proc_do_entropy(ctl_table *table, int write,
38843 void __user *buffer, size_t *lenp, loff_t *ppos)
38844 {
38845 - ctl_table fake_table;
38846 + ctl_table_no_const fake_table;
38847 int entropy_count;
38848
38849 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38850 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38851 index 7cc1fe22..b602d6b 100644
38852 --- a/drivers/char/sonypi.c
38853 +++ b/drivers/char/sonypi.c
38854 @@ -54,6 +54,7 @@
38855
38856 #include <asm/uaccess.h>
38857 #include <asm/io.h>
38858 +#include <asm/local.h>
38859
38860 #include <linux/sonypi.h>
38861
38862 @@ -490,7 +491,7 @@ static struct sonypi_device {
38863 spinlock_t fifo_lock;
38864 wait_queue_head_t fifo_proc_list;
38865 struct fasync_struct *fifo_async;
38866 - int open_count;
38867 + local_t open_count;
38868 int model;
38869 struct input_dev *input_jog_dev;
38870 struct input_dev *input_key_dev;
38871 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38872 static int sonypi_misc_release(struct inode *inode, struct file *file)
38873 {
38874 mutex_lock(&sonypi_device.lock);
38875 - sonypi_device.open_count--;
38876 + local_dec(&sonypi_device.open_count);
38877 mutex_unlock(&sonypi_device.lock);
38878 return 0;
38879 }
38880 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38881 {
38882 mutex_lock(&sonypi_device.lock);
38883 /* Flush input queue on first open */
38884 - if (!sonypi_device.open_count)
38885 + if (!local_read(&sonypi_device.open_count))
38886 kfifo_reset(&sonypi_device.fifo);
38887 - sonypi_device.open_count++;
38888 + local_inc(&sonypi_device.open_count);
38889 mutex_unlock(&sonypi_device.lock);
38890
38891 return 0;
38892 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38893 index b9a57fa..5bb9e38 100644
38894 --- a/drivers/char/tpm/tpm_acpi.c
38895 +++ b/drivers/char/tpm/tpm_acpi.c
38896 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38897 virt = acpi_os_map_memory(start, len);
38898 if (!virt) {
38899 kfree(log->bios_event_log);
38900 + log->bios_event_log = NULL;
38901 printk("%s: ERROR - Unable to map memory\n", __func__);
38902 return -EIO;
38903 }
38904
38905 - memcpy_fromio(log->bios_event_log, virt, len);
38906 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38907
38908 acpi_os_unmap_memory(virt, len);
38909 return 0;
38910 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38911 index 59f7cb2..bac8b6d 100644
38912 --- a/drivers/char/tpm/tpm_eventlog.c
38913 +++ b/drivers/char/tpm/tpm_eventlog.c
38914 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38915 event = addr;
38916
38917 if ((event->event_type == 0 && event->event_size == 0) ||
38918 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38919 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38920 return NULL;
38921
38922 return addr;
38923 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38924 return NULL;
38925
38926 if ((event->event_type == 0 && event->event_size == 0) ||
38927 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38928 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38929 return NULL;
38930
38931 (*pos)++;
38932 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38933 int i;
38934
38935 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38936 - seq_putc(m, data[i]);
38937 + if (!seq_putc(m, data[i]))
38938 + return -EFAULT;
38939
38940 return 0;
38941 }
38942 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38943 index 60aafb8..10c08e0 100644
38944 --- a/drivers/char/virtio_console.c
38945 +++ b/drivers/char/virtio_console.c
38946 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38947 if (to_user) {
38948 ssize_t ret;
38949
38950 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38951 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38952 if (ret)
38953 return -EFAULT;
38954 } else {
38955 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38956 if (!port_has_data(port) && !port->host_connected)
38957 return 0;
38958
38959 - return fill_readbuf(port, ubuf, count, true);
38960 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38961 }
38962
38963 static int wait_port_writable(struct port *port, bool nonblock)
38964 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38965 index 57a078e..c17cde8 100644
38966 --- a/drivers/clk/clk-composite.c
38967 +++ b/drivers/clk/clk-composite.c
38968 @@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38969 struct clk *clk;
38970 struct clk_init_data init;
38971 struct clk_composite *composite;
38972 - struct clk_ops *clk_composite_ops;
38973 + clk_ops_no_const *clk_composite_ops;
38974
38975 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38976 if (!composite) {
38977 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
38978 index 501d513..fb0ecf9 100644
38979 --- a/drivers/clk/socfpga/clk-gate.c
38980 +++ b/drivers/clk/socfpga/clk-gate.c
38981 @@ -22,6 +22,7 @@
38982 #include <linux/mfd/syscon.h>
38983 #include <linux/of.h>
38984 #include <linux/regmap.h>
38985 +#include <asm/pgtable.h>
38986
38987 #include "clk.h"
38988
38989 @@ -175,7 +176,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
38990 return 0;
38991 }
38992
38993 -static struct clk_ops gateclk_ops = {
38994 +static clk_ops_no_const gateclk_ops __read_only = {
38995 .prepare = socfpga_clk_prepare,
38996 .recalc_rate = socfpga_clk_recalc_rate,
38997 .get_parent = socfpga_clk_get_parent,
38998 @@ -209,8 +210,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
38999 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
39000 socfpga_clk->hw.bit_idx = clk_gate[1];
39001
39002 - gateclk_ops.enable = clk_gate_ops.enable;
39003 - gateclk_ops.disable = clk_gate_ops.disable;
39004 + pax_open_kernel();
39005 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
39006 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
39007 + pax_close_kernel();
39008 }
39009
39010 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
39011 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
39012 index de6da95..a2e72c0 100644
39013 --- a/drivers/clk/socfpga/clk-pll.c
39014 +++ b/drivers/clk/socfpga/clk-pll.c
39015 @@ -21,6 +21,7 @@
39016 #include <linux/io.h>
39017 #include <linux/of.h>
39018 #include <linux/of_address.h>
39019 +#include <asm/pgtable.h>
39020
39021 #include "clk.h"
39022
39023 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
39024 CLK_MGR_PLL_CLK_SRC_MASK;
39025 }
39026
39027 -static struct clk_ops clk_pll_ops = {
39028 +static struct clk_ops_no_const clk_pll_ops __read_only = {
39029 .recalc_rate = clk_pll_recalc_rate,
39030 .get_parent = clk_pll_get_parent,
39031 };
39032 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
39033 pll_clk->hw.hw.init = &init;
39034
39035 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39036 - clk_pll_ops.enable = clk_gate_ops.enable;
39037 - clk_pll_ops.disable = clk_gate_ops.disable;
39038 + pax_open_kernel();
39039 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39040 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39041 + pax_close_kernel();
39042
39043 clk = clk_register(NULL, &pll_clk->hw.hw);
39044 if (WARN_ON(IS_ERR(clk))) {
39045 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39046 index 000e4e0..4770351 100644
39047 --- a/drivers/cpufreq/acpi-cpufreq.c
39048 +++ b/drivers/cpufreq/acpi-cpufreq.c
39049 @@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39050 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39051 per_cpu(acfreq_data, cpu) = data;
39052
39053 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39054 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39055 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39056 + pax_open_kernel();
39057 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39058 + pax_close_kernel();
39059 + }
39060
39061 result = acpi_processor_register_performance(data->acpi_data, cpu);
39062 if (result)
39063 @@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39064 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39065 break;
39066 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39067 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39068 + pax_open_kernel();
39069 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39070 + pax_close_kernel();
39071 break;
39072 default:
39073 break;
39074 @@ -904,8 +909,10 @@ static void __init acpi_cpufreq_boost_init(void)
39075 if (!msrs)
39076 return;
39077
39078 - acpi_cpufreq_driver.boost_supported = true;
39079 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
39080 + pax_open_kernel();
39081 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39082 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39083 + pax_close_kernel();
39084
39085 cpu_notifier_register_begin();
39086
39087 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39088 index 558224c..55e3b57 100644
39089 --- a/drivers/cpufreq/cpufreq.c
39090 +++ b/drivers/cpufreq/cpufreq.c
39091 @@ -2022,7 +2022,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39092 }
39093
39094 mutex_lock(&cpufreq_governor_mutex);
39095 - list_del(&governor->governor_list);
39096 + pax_list_del(&governor->governor_list);
39097 mutex_unlock(&cpufreq_governor_mutex);
39098 return;
39099 }
39100 @@ -2238,7 +2238,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39101 return NOTIFY_OK;
39102 }
39103
39104 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
39105 +static struct notifier_block cpufreq_cpu_notifier = {
39106 .notifier_call = cpufreq_cpu_callback,
39107 };
39108
39109 @@ -2278,13 +2278,17 @@ int cpufreq_boost_trigger_state(int state)
39110 return 0;
39111
39112 write_lock_irqsave(&cpufreq_driver_lock, flags);
39113 - cpufreq_driver->boost_enabled = state;
39114 + pax_open_kernel();
39115 + *(bool *)&cpufreq_driver->boost_enabled = state;
39116 + pax_close_kernel();
39117 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39118
39119 ret = cpufreq_driver->set_boost(state);
39120 if (ret) {
39121 write_lock_irqsave(&cpufreq_driver_lock, flags);
39122 - cpufreq_driver->boost_enabled = !state;
39123 + pax_open_kernel();
39124 + *(bool *)&cpufreq_driver->boost_enabled = !state;
39125 + pax_close_kernel();
39126 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39127
39128 pr_err("%s: Cannot %s BOOST\n",
39129 @@ -2340,8 +2344,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39130
39131 pr_debug("trying to register driver %s\n", driver_data->name);
39132
39133 - if (driver_data->setpolicy)
39134 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
39135 + if (driver_data->setpolicy) {
39136 + pax_open_kernel();
39137 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39138 + pax_close_kernel();
39139 + }
39140
39141 write_lock_irqsave(&cpufreq_driver_lock, flags);
39142 if (cpufreq_driver) {
39143 @@ -2356,8 +2363,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39144 * Check if driver provides function to enable boost -
39145 * if not, use cpufreq_boost_set_sw as default
39146 */
39147 - if (!cpufreq_driver->set_boost)
39148 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39149 + if (!cpufreq_driver->set_boost) {
39150 + pax_open_kernel();
39151 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39152 + pax_close_kernel();
39153 + }
39154
39155 ret = cpufreq_sysfs_create_file(&boost.attr);
39156 if (ret) {
39157 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39158 index e1c6433..31203ae 100644
39159 --- a/drivers/cpufreq/cpufreq_governor.c
39160 +++ b/drivers/cpufreq/cpufreq_governor.c
39161 @@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39162 struct dbs_data *dbs_data;
39163 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39164 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39165 - struct od_ops *od_ops = NULL;
39166 + const struct od_ops *od_ops = NULL;
39167 struct od_dbs_tuners *od_tuners = NULL;
39168 struct cs_dbs_tuners *cs_tuners = NULL;
39169 struct cpu_dbs_common_info *cpu_cdbs;
39170 @@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39171
39172 if ((cdata->governor == GOV_CONSERVATIVE) &&
39173 (!policy->governor->initialized)) {
39174 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39175 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39176
39177 cpufreq_register_notifier(cs_ops->notifier_block,
39178 CPUFREQ_TRANSITION_NOTIFIER);
39179 @@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39180
39181 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39182 (policy->governor->initialized == 1)) {
39183 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39184 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39185
39186 cpufreq_unregister_notifier(cs_ops->notifier_block,
39187 CPUFREQ_TRANSITION_NOTIFIER);
39188 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39189 index bfb9ae1..e1d3a7e 100644
39190 --- a/drivers/cpufreq/cpufreq_governor.h
39191 +++ b/drivers/cpufreq/cpufreq_governor.h
39192 @@ -205,7 +205,7 @@ struct common_dbs_data {
39193 void (*exit)(struct dbs_data *dbs_data);
39194
39195 /* Governor specific ops, see below */
39196 - void *gov_ops;
39197 + const void *gov_ops;
39198 };
39199
39200 /* Governor Per policy data */
39201 @@ -225,7 +225,7 @@ struct od_ops {
39202 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39203 unsigned int freq_next, unsigned int relation);
39204 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39205 -};
39206 +} __no_const;
39207
39208 struct cs_ops {
39209 struct notifier_block *notifier_block;
39210 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39211 index 18d4091..434be15 100644
39212 --- a/drivers/cpufreq/cpufreq_ondemand.c
39213 +++ b/drivers/cpufreq/cpufreq_ondemand.c
39214 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39215
39216 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39217
39218 -static struct od_ops od_ops = {
39219 +static struct od_ops od_ops __read_only = {
39220 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39221 .powersave_bias_target = generic_powersave_bias_target,
39222 .freq_increase = dbs_freq_increase,
39223 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39224 (struct cpufreq_policy *, unsigned int, unsigned int),
39225 unsigned int powersave_bias)
39226 {
39227 - od_ops.powersave_bias_target = f;
39228 + pax_open_kernel();
39229 + *(void **)&od_ops.powersave_bias_target = f;
39230 + pax_close_kernel();
39231 od_set_powersave_bias(powersave_bias);
39232 }
39233 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39234
39235 void od_unregister_powersave_bias_handler(void)
39236 {
39237 - od_ops.powersave_bias_target = generic_powersave_bias_target;
39238 + pax_open_kernel();
39239 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39240 + pax_close_kernel();
39241 od_set_powersave_bias(0);
39242 }
39243 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39244 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39245 index 870eecc..787bbca 100644
39246 --- a/drivers/cpufreq/intel_pstate.c
39247 +++ b/drivers/cpufreq/intel_pstate.c
39248 @@ -125,10 +125,10 @@ struct pstate_funcs {
39249 struct cpu_defaults {
39250 struct pstate_adjust_policy pid_policy;
39251 struct pstate_funcs funcs;
39252 -};
39253 +} __do_const;
39254
39255 static struct pstate_adjust_policy pid_params;
39256 -static struct pstate_funcs pstate_funcs;
39257 +static struct pstate_funcs *pstate_funcs;
39258
39259 struct perf_limits {
39260 int no_turbo;
39261 @@ -530,7 +530,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39262
39263 cpu->pstate.current_pstate = pstate;
39264
39265 - pstate_funcs.set(cpu, pstate);
39266 + pstate_funcs->set(cpu, pstate);
39267 }
39268
39269 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39270 @@ -552,12 +552,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39271 {
39272 sprintf(cpu->name, "Intel 2nd generation core");
39273
39274 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39275 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39276 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39277 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39278 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39279 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39280
39281 - if (pstate_funcs.get_vid)
39282 - pstate_funcs.get_vid(cpu);
39283 + if (pstate_funcs->get_vid)
39284 + pstate_funcs->get_vid(cpu);
39285 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39286 }
39287
39288 @@ -847,9 +847,9 @@ static int intel_pstate_msrs_not_valid(void)
39289 rdmsrl(MSR_IA32_APERF, aperf);
39290 rdmsrl(MSR_IA32_MPERF, mperf);
39291
39292 - if (!pstate_funcs.get_max() ||
39293 - !pstate_funcs.get_min() ||
39294 - !pstate_funcs.get_turbo())
39295 + if (!pstate_funcs->get_max() ||
39296 + !pstate_funcs->get_min() ||
39297 + !pstate_funcs->get_turbo())
39298 return -ENODEV;
39299
39300 rdmsrl(MSR_IA32_APERF, tmp);
39301 @@ -863,7 +863,7 @@ static int intel_pstate_msrs_not_valid(void)
39302 return 0;
39303 }
39304
39305 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39306 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39307 {
39308 pid_params.sample_rate_ms = policy->sample_rate_ms;
39309 pid_params.p_gain_pct = policy->p_gain_pct;
39310 @@ -875,11 +875,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39311
39312 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39313 {
39314 - pstate_funcs.get_max = funcs->get_max;
39315 - pstate_funcs.get_min = funcs->get_min;
39316 - pstate_funcs.get_turbo = funcs->get_turbo;
39317 - pstate_funcs.set = funcs->set;
39318 - pstate_funcs.get_vid = funcs->get_vid;
39319 + pstate_funcs = funcs;
39320 }
39321
39322 #if IS_ENABLED(CONFIG_ACPI)
39323 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39324 index 529cfd9..0e28fff 100644
39325 --- a/drivers/cpufreq/p4-clockmod.c
39326 +++ b/drivers/cpufreq/p4-clockmod.c
39327 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39328 case 0x0F: /* Core Duo */
39329 case 0x16: /* Celeron Core */
39330 case 0x1C: /* Atom */
39331 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39332 + pax_open_kernel();
39333 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39334 + pax_close_kernel();
39335 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39336 case 0x0D: /* Pentium M (Dothan) */
39337 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39338 + pax_open_kernel();
39339 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39340 + pax_close_kernel();
39341 /* fall through */
39342 case 0x09: /* Pentium M (Banias) */
39343 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39344 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39345
39346 /* on P-4s, the TSC runs with constant frequency independent whether
39347 * throttling is active or not. */
39348 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39349 + pax_open_kernel();
39350 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39351 + pax_close_kernel();
39352
39353 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39354 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39355 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39356 index 9bb42ba..b01b4a2 100644
39357 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39358 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39359 @@ -18,14 +18,12 @@
39360 #include <asm/head.h>
39361 #include <asm/timer.h>
39362
39363 -static struct cpufreq_driver *cpufreq_us3_driver;
39364 -
39365 struct us3_freq_percpu_info {
39366 struct cpufreq_frequency_table table[4];
39367 };
39368
39369 /* Indexed by cpu number. */
39370 -static struct us3_freq_percpu_info *us3_freq_table;
39371 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39372
39373 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39374 * in the Safari config register.
39375 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39376
39377 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39378 {
39379 - if (cpufreq_us3_driver)
39380 - us3_freq_target(policy, 0);
39381 + us3_freq_target(policy, 0);
39382
39383 return 0;
39384 }
39385
39386 +static int __init us3_freq_init(void);
39387 +static void __exit us3_freq_exit(void);
39388 +
39389 +static struct cpufreq_driver cpufreq_us3_driver = {
39390 + .init = us3_freq_cpu_init,
39391 + .verify = cpufreq_generic_frequency_table_verify,
39392 + .target_index = us3_freq_target,
39393 + .get = us3_freq_get,
39394 + .exit = us3_freq_cpu_exit,
39395 + .name = "UltraSPARC-III",
39396 +
39397 +};
39398 +
39399 static int __init us3_freq_init(void)
39400 {
39401 unsigned long manuf, impl, ver;
39402 - int ret;
39403
39404 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39405 return -ENODEV;
39406 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39407 (impl == CHEETAH_IMPL ||
39408 impl == CHEETAH_PLUS_IMPL ||
39409 impl == JAGUAR_IMPL ||
39410 - impl == PANTHER_IMPL)) {
39411 - struct cpufreq_driver *driver;
39412 -
39413 - ret = -ENOMEM;
39414 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39415 - if (!driver)
39416 - goto err_out;
39417 -
39418 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39419 - GFP_KERNEL);
39420 - if (!us3_freq_table)
39421 - goto err_out;
39422 -
39423 - driver->init = us3_freq_cpu_init;
39424 - driver->verify = cpufreq_generic_frequency_table_verify;
39425 - driver->target_index = us3_freq_target;
39426 - driver->get = us3_freq_get;
39427 - driver->exit = us3_freq_cpu_exit;
39428 - strcpy(driver->name, "UltraSPARC-III");
39429 -
39430 - cpufreq_us3_driver = driver;
39431 - ret = cpufreq_register_driver(driver);
39432 - if (ret)
39433 - goto err_out;
39434 -
39435 - return 0;
39436 -
39437 -err_out:
39438 - if (driver) {
39439 - kfree(driver);
39440 - cpufreq_us3_driver = NULL;
39441 - }
39442 - kfree(us3_freq_table);
39443 - us3_freq_table = NULL;
39444 - return ret;
39445 - }
39446 + impl == PANTHER_IMPL))
39447 + return cpufreq_register_driver(&cpufreq_us3_driver);
39448
39449 return -ENODEV;
39450 }
39451
39452 static void __exit us3_freq_exit(void)
39453 {
39454 - if (cpufreq_us3_driver) {
39455 - cpufreq_unregister_driver(cpufreq_us3_driver);
39456 - kfree(cpufreq_us3_driver);
39457 - cpufreq_us3_driver = NULL;
39458 - kfree(us3_freq_table);
39459 - us3_freq_table = NULL;
39460 - }
39461 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39462 }
39463
39464 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39465 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39466 index 6723f03..3465190 100644
39467 --- a/drivers/cpufreq/speedstep-centrino.c
39468 +++ b/drivers/cpufreq/speedstep-centrino.c
39469 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39470 !cpu_has(cpu, X86_FEATURE_EST))
39471 return -ENODEV;
39472
39473 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39474 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39475 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39476 + pax_open_kernel();
39477 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39478 + pax_close_kernel();
39479 + }
39480
39481 if (policy->cpu != 0)
39482 return -ENODEV;
39483 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39484 index 136d6a2..06e373d 100644
39485 --- a/drivers/cpuidle/driver.c
39486 +++ b/drivers/cpuidle/driver.c
39487 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39488
39489 static void poll_idle_init(struct cpuidle_driver *drv)
39490 {
39491 - struct cpuidle_state *state = &drv->states[0];
39492 + cpuidle_state_no_const *state = &drv->states[0];
39493
39494 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39495 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39496 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39497 index ca89412..a7b9c49 100644
39498 --- a/drivers/cpuidle/governor.c
39499 +++ b/drivers/cpuidle/governor.c
39500 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39501 mutex_lock(&cpuidle_lock);
39502 if (__cpuidle_find_governor(gov->name) == NULL) {
39503 ret = 0;
39504 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39505 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39506 if (!cpuidle_curr_governor ||
39507 cpuidle_curr_governor->rating < gov->rating)
39508 cpuidle_switch_governor(gov);
39509 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39510 index efe2f17..b8124f9 100644
39511 --- a/drivers/cpuidle/sysfs.c
39512 +++ b/drivers/cpuidle/sysfs.c
39513 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39514 NULL
39515 };
39516
39517 -static struct attribute_group cpuidle_attr_group = {
39518 +static attribute_group_no_const cpuidle_attr_group = {
39519 .attrs = cpuidle_default_attrs,
39520 .name = "cpuidle",
39521 };
39522 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39523 index 12fea3e..1e28f47 100644
39524 --- a/drivers/crypto/hifn_795x.c
39525 +++ b/drivers/crypto/hifn_795x.c
39526 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39527 MODULE_PARM_DESC(hifn_pll_ref,
39528 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39529
39530 -static atomic_t hifn_dev_number;
39531 +static atomic_unchecked_t hifn_dev_number;
39532
39533 #define ACRYPTO_OP_DECRYPT 0
39534 #define ACRYPTO_OP_ENCRYPT 1
39535 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39536 goto err_out_disable_pci_device;
39537
39538 snprintf(name, sizeof(name), "hifn%d",
39539 - atomic_inc_return(&hifn_dev_number)-1);
39540 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39541
39542 err = pci_request_regions(pdev, name);
39543 if (err)
39544 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39545 index 2042ec3..a9ce67f 100644
39546 --- a/drivers/devfreq/devfreq.c
39547 +++ b/drivers/devfreq/devfreq.c
39548 @@ -616,7 +616,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39549 goto err_out;
39550 }
39551
39552 - list_add(&governor->node, &devfreq_governor_list);
39553 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39554
39555 list_for_each_entry(devfreq, &devfreq_list, node) {
39556 int ret = 0;
39557 @@ -704,7 +704,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39558 }
39559 }
39560
39561 - list_del(&governor->node);
39562 + pax_list_del((struct list_head *)&governor->node);
39563 err_out:
39564 mutex_unlock(&devfreq_list_lock);
39565
39566 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39567 index 5239677..1cb71a8 100644
39568 --- a/drivers/dma/sh/shdma-base.c
39569 +++ b/drivers/dma/sh/shdma-base.c
39570 @@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39571 schan->slave_id = -EINVAL;
39572 }
39573
39574 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39575 - sdev->desc_size, GFP_KERNEL);
39576 + schan->desc = kcalloc(sdev->desc_size,
39577 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39578 if (!schan->desc) {
39579 ret = -ENOMEM;
39580 goto edescalloc;
39581 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39582 index dda7e75..0a4c867 100644
39583 --- a/drivers/dma/sh/shdmac.c
39584 +++ b/drivers/dma/sh/shdmac.c
39585 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39586 return ret;
39587 }
39588
39589 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39590 +static struct notifier_block sh_dmae_nmi_notifier = {
39591 .notifier_call = sh_dmae_nmi_handler,
39592
39593 /* Run before NMI debug handler and KGDB */
39594 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39595 index 592af5f..bb1d583 100644
39596 --- a/drivers/edac/edac_device.c
39597 +++ b/drivers/edac/edac_device.c
39598 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39599 */
39600 int edac_device_alloc_index(void)
39601 {
39602 - static atomic_t device_indexes = ATOMIC_INIT(0);
39603 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39604
39605 - return atomic_inc_return(&device_indexes) - 1;
39606 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39607 }
39608 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39609
39610 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39611 index 01fae82..1dd8289 100644
39612 --- a/drivers/edac/edac_mc_sysfs.c
39613 +++ b/drivers/edac/edac_mc_sysfs.c
39614 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39615 struct dev_ch_attribute {
39616 struct device_attribute attr;
39617 int channel;
39618 -};
39619 +} __do_const;
39620
39621 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39622 struct dev_ch_attribute dev_attr_legacy_##_name = \
39623 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39624 }
39625
39626 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39627 + pax_open_kernel();
39628 if (mci->get_sdram_scrub_rate) {
39629 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39630 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39631 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39632 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39633 }
39634 if (mci->set_sdram_scrub_rate) {
39635 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39636 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39637 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39638 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39639 }
39640 + pax_close_kernel();
39641 err = device_create_file(&mci->dev,
39642 &dev_attr_sdram_scrub_rate);
39643 if (err) {
39644 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39645 index 2cf44b4d..6dd2dc7 100644
39646 --- a/drivers/edac/edac_pci.c
39647 +++ b/drivers/edac/edac_pci.c
39648 @@ -29,7 +29,7 @@
39649
39650 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39651 static LIST_HEAD(edac_pci_list);
39652 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39653 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39654
39655 /*
39656 * edac_pci_alloc_ctl_info
39657 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39658 */
39659 int edac_pci_alloc_index(void)
39660 {
39661 - return atomic_inc_return(&pci_indexes) - 1;
39662 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39663 }
39664 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39665
39666 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39667 index e8658e4..22746d6 100644
39668 --- a/drivers/edac/edac_pci_sysfs.c
39669 +++ b/drivers/edac/edac_pci_sysfs.c
39670 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39671 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39672 static int edac_pci_poll_msec = 1000; /* one second workq period */
39673
39674 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39675 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39676 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39677 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39678
39679 static struct kobject *edac_pci_top_main_kobj;
39680 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39681 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39682 void *value;
39683 ssize_t(*show) (void *, char *);
39684 ssize_t(*store) (void *, const char *, size_t);
39685 -};
39686 +} __do_const;
39687
39688 /* Set of show/store abstract level functions for PCI Parity object */
39689 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39690 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39691 edac_printk(KERN_CRIT, EDAC_PCI,
39692 "Signaled System Error on %s\n",
39693 pci_name(dev));
39694 - atomic_inc(&pci_nonparity_count);
39695 + atomic_inc_unchecked(&pci_nonparity_count);
39696 }
39697
39698 if (status & (PCI_STATUS_PARITY)) {
39699 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39700 "Master Data Parity Error on %s\n",
39701 pci_name(dev));
39702
39703 - atomic_inc(&pci_parity_count);
39704 + atomic_inc_unchecked(&pci_parity_count);
39705 }
39706
39707 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39708 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39709 "Detected Parity Error on %s\n",
39710 pci_name(dev));
39711
39712 - atomic_inc(&pci_parity_count);
39713 + atomic_inc_unchecked(&pci_parity_count);
39714 }
39715 }
39716
39717 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39718 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39719 "Signaled System Error on %s\n",
39720 pci_name(dev));
39721 - atomic_inc(&pci_nonparity_count);
39722 + atomic_inc_unchecked(&pci_nonparity_count);
39723 }
39724
39725 if (status & (PCI_STATUS_PARITY)) {
39726 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39727 "Master Data Parity Error on "
39728 "%s\n", pci_name(dev));
39729
39730 - atomic_inc(&pci_parity_count);
39731 + atomic_inc_unchecked(&pci_parity_count);
39732 }
39733
39734 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39735 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39736 "Detected Parity Error on %s\n",
39737 pci_name(dev));
39738
39739 - atomic_inc(&pci_parity_count);
39740 + atomic_inc_unchecked(&pci_parity_count);
39741 }
39742 }
39743 }
39744 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39745 if (!check_pci_errors)
39746 return;
39747
39748 - before_count = atomic_read(&pci_parity_count);
39749 + before_count = atomic_read_unchecked(&pci_parity_count);
39750
39751 /* scan all PCI devices looking for a Parity Error on devices and
39752 * bridges.
39753 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39754 /* Only if operator has selected panic on PCI Error */
39755 if (edac_pci_get_panic_on_pe()) {
39756 /* If the count is different 'after' from 'before' */
39757 - if (before_count != atomic_read(&pci_parity_count))
39758 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39759 panic("EDAC: PCI Parity Error");
39760 }
39761 }
39762 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39763 index 51b7e3a..aa8a3e8 100644
39764 --- a/drivers/edac/mce_amd.h
39765 +++ b/drivers/edac/mce_amd.h
39766 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39767 bool (*mc0_mce)(u16, u8);
39768 bool (*mc1_mce)(u16, u8);
39769 bool (*mc2_mce)(u16, u8);
39770 -};
39771 +} __no_const;
39772
39773 void amd_report_gart_errors(bool);
39774 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39775 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39776 index 57ea7f4..af06b76 100644
39777 --- a/drivers/firewire/core-card.c
39778 +++ b/drivers/firewire/core-card.c
39779 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39780 const struct fw_card_driver *driver,
39781 struct device *device)
39782 {
39783 - static atomic_t index = ATOMIC_INIT(-1);
39784 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39785
39786 - card->index = atomic_inc_return(&index);
39787 + card->index = atomic_inc_return_unchecked(&index);
39788 card->driver = driver;
39789 card->device = device;
39790 card->current_tlabel = 0;
39791 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39792
39793 void fw_core_remove_card(struct fw_card *card)
39794 {
39795 - struct fw_card_driver dummy_driver = dummy_driver_template;
39796 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39797
39798 card->driver->update_phy_reg(card, 4,
39799 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39800 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39801 index 2c6d5e1..a2cca6b 100644
39802 --- a/drivers/firewire/core-device.c
39803 +++ b/drivers/firewire/core-device.c
39804 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39805 struct config_rom_attribute {
39806 struct device_attribute attr;
39807 u32 key;
39808 -};
39809 +} __do_const;
39810
39811 static ssize_t show_immediate(struct device *dev,
39812 struct device_attribute *dattr, char *buf)
39813 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39814 index eb6935c..3cc2bfa 100644
39815 --- a/drivers/firewire/core-transaction.c
39816 +++ b/drivers/firewire/core-transaction.c
39817 @@ -38,6 +38,7 @@
39818 #include <linux/timer.h>
39819 #include <linux/types.h>
39820 #include <linux/workqueue.h>
39821 +#include <linux/sched.h>
39822
39823 #include <asm/byteorder.h>
39824
39825 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39826 index f477308..2795f24 100644
39827 --- a/drivers/firewire/core.h
39828 +++ b/drivers/firewire/core.h
39829 @@ -111,6 +111,7 @@ struct fw_card_driver {
39830
39831 int (*stop_iso)(struct fw_iso_context *ctx);
39832 };
39833 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39834
39835 void fw_card_initialize(struct fw_card *card,
39836 const struct fw_card_driver *driver, struct device *device);
39837 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39838 index 586f2f7..3545ad2 100644
39839 --- a/drivers/firewire/ohci.c
39840 +++ b/drivers/firewire/ohci.c
39841 @@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39842 be32_to_cpu(ohci->next_header));
39843 }
39844
39845 +#ifndef CONFIG_GRKERNSEC
39846 if (param_remote_dma) {
39847 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39848 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39849 }
39850 +#endif
39851
39852 spin_unlock_irq(&ohci->lock);
39853
39854 @@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39855 unsigned long flags;
39856 int n, ret = 0;
39857
39858 +#ifndef CONFIG_GRKERNSEC
39859 if (param_remote_dma)
39860 return 0;
39861 +#endif
39862
39863 /*
39864 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39865 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39866 index 94a58a0..f5eba42 100644
39867 --- a/drivers/firmware/dmi-id.c
39868 +++ b/drivers/firmware/dmi-id.c
39869 @@ -16,7 +16,7 @@
39870 struct dmi_device_attribute{
39871 struct device_attribute dev_attr;
39872 int field;
39873 -};
39874 +} __do_const;
39875 #define to_dmi_dev_attr(_dev_attr) \
39876 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39877
39878 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39879 index 17afc51..0ef90cd 100644
39880 --- a/drivers/firmware/dmi_scan.c
39881 +++ b/drivers/firmware/dmi_scan.c
39882 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39883 if (buf == NULL)
39884 return -1;
39885
39886 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39887 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39888
39889 dmi_unmap(buf);
39890 return 0;
39891 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39892 index 1491dd4..aa910db 100644
39893 --- a/drivers/firmware/efi/cper.c
39894 +++ b/drivers/firmware/efi/cper.c
39895 @@ -41,12 +41,12 @@
39896 */
39897 u64 cper_next_record_id(void)
39898 {
39899 - static atomic64_t seq;
39900 + static atomic64_unchecked_t seq;
39901
39902 - if (!atomic64_read(&seq))
39903 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
39904 + if (!atomic64_read_unchecked(&seq))
39905 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39906
39907 - return atomic64_inc_return(&seq);
39908 + return atomic64_inc_return_unchecked(&seq);
39909 }
39910 EXPORT_SYMBOL_GPL(cper_next_record_id);
39911
39912 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39913 index af20f17..4e4e545 100644
39914 --- a/drivers/firmware/efi/efi.c
39915 +++ b/drivers/firmware/efi/efi.c
39916 @@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39917 };
39918
39919 static struct efivars generic_efivars;
39920 -static struct efivar_operations generic_ops;
39921 +static efivar_operations_no_const generic_ops __read_only;
39922
39923 static int generic_ops_register(void)
39924 {
39925 - generic_ops.get_variable = efi.get_variable;
39926 - generic_ops.set_variable = efi.set_variable;
39927 - generic_ops.get_next_variable = efi.get_next_variable;
39928 - generic_ops.query_variable_store = efi_query_variable_store;
39929 + pax_open_kernel();
39930 + *(void **)&generic_ops.get_variable = efi.get_variable;
39931 + *(void **)&generic_ops.set_variable = efi.set_variable;
39932 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39933 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39934 + pax_close_kernel();
39935
39936 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39937 }
39938 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39939 index 50ea412..caccd6e9 100644
39940 --- a/drivers/firmware/efi/efivars.c
39941 +++ b/drivers/firmware/efi/efivars.c
39942 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39943 static int
39944 create_efivars_bin_attributes(void)
39945 {
39946 - struct bin_attribute *attr;
39947 + bin_attribute_no_const *attr;
39948 int error;
39949
39950 /* new_var */
39951 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39952 index 2f569aa..c95f4fb 100644
39953 --- a/drivers/firmware/google/memconsole.c
39954 +++ b/drivers/firmware/google/memconsole.c
39955 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
39956 if (!found_memconsole())
39957 return -ENODEV;
39958
39959 - memconsole_bin_attr.size = memconsole_length;
39960 + pax_open_kernel();
39961 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39962 + pax_close_kernel();
39963 +
39964 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39965 }
39966
39967 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39968 index 8765bd6..2e5b147 100644
39969 --- a/drivers/gpio/gpio-em.c
39970 +++ b/drivers/gpio/gpio-em.c
39971 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39972 struct em_gio_priv *p;
39973 struct resource *io[2], *irq[2];
39974 struct gpio_chip *gpio_chip;
39975 - struct irq_chip *irq_chip;
39976 + irq_chip_no_const *irq_chip;
39977 const char *name = dev_name(&pdev->dev);
39978 int ret;
39979
39980 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39981 index 7030422..42a3fe9 100644
39982 --- a/drivers/gpio/gpio-ich.c
39983 +++ b/drivers/gpio/gpio-ich.c
39984 @@ -94,7 +94,7 @@ struct ichx_desc {
39985 * this option allows driver caching written output values
39986 */
39987 bool use_outlvl_cache;
39988 -};
39989 +} __do_const;
39990
39991 static struct {
39992 spinlock_t lock;
39993 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39994 index 03c9148..c66e753 100644
39995 --- a/drivers/gpio/gpio-rcar.c
39996 +++ b/drivers/gpio/gpio-rcar.c
39997 @@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39998 struct gpio_rcar_priv *p;
39999 struct resource *io, *irq;
40000 struct gpio_chip *gpio_chip;
40001 - struct irq_chip *irq_chip;
40002 + irq_chip_no_const *irq_chip;
40003 struct device *dev = &pdev->dev;
40004 const char *name = dev_name(dev);
40005 int ret;
40006 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40007 index 66cbcc1..0c5e622 100644
40008 --- a/drivers/gpio/gpio-vr41xx.c
40009 +++ b/drivers/gpio/gpio-vr41xx.c
40010 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
40011 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40012 maskl, pendl, maskh, pendh);
40013
40014 - atomic_inc(&irq_err_count);
40015 + atomic_inc_unchecked(&irq_err_count);
40016
40017 return -EINVAL;
40018 }
40019 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40020 index d8b7099..8a314a5 100644
40021 --- a/drivers/gpu/drm/drm_crtc.c
40022 +++ b/drivers/gpu/drm/drm_crtc.c
40023 @@ -3500,7 +3500,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40024 goto done;
40025 }
40026
40027 - if (copy_to_user(&enum_ptr[copied].name,
40028 + if (copy_to_user(enum_ptr[copied].name,
40029 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40030 ret = -EFAULT;
40031 goto done;
40032 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40033 old mode 100644
40034 new mode 100755
40035 index 8218078..9960928a
40036 --- a/drivers/gpu/drm/drm_drv.c
40037 +++ b/drivers/gpu/drm/drm_drv.c
40038 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
40039 /**
40040 * Copy and IOCTL return string to user space
40041 */
40042 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
40043 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
40044 {
40045 int len;
40046
40047 @@ -342,7 +342,7 @@ long drm_ioctl(struct file *filp,
40048 struct drm_file *file_priv = filp->private_data;
40049 struct drm_device *dev;
40050 const struct drm_ioctl_desc *ioctl = NULL;
40051 - drm_ioctl_t *func;
40052 + drm_ioctl_no_const_t func;
40053 unsigned int nr = DRM_IOCTL_NR(cmd);
40054 int retcode = -EINVAL;
40055 char stack_kdata[128];
40056 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40057 index e1eba0b..98f69f9 100644
40058 --- a/drivers/gpu/drm/drm_fops.c
40059 +++ b/drivers/gpu/drm/drm_fops.c
40060 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40061 return PTR_ERR(minor);
40062
40063 dev = minor->dev;
40064 - if (!dev->open_count++)
40065 + if (local_inc_return(&dev->open_count) == 1)
40066 need_setup = 1;
40067
40068 /* share address_space across all char-devs of a single device */
40069 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40070 return 0;
40071
40072 err_undo:
40073 - dev->open_count--;
40074 + local_dec(&dev->open_count);
40075 drm_minor_release(minor);
40076 return retcode;
40077 }
40078 @@ -430,7 +430,7 @@ int drm_release(struct inode *inode, struct file *filp)
40079
40080 mutex_lock(&drm_global_mutex);
40081
40082 - DRM_DEBUG("open_count = %d\n", dev->open_count);
40083 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40084
40085 if (dev->driver->preclose)
40086 dev->driver->preclose(dev, file_priv);
40087 @@ -439,10 +439,10 @@ int drm_release(struct inode *inode, struct file *filp)
40088 * Begin inline drm_release
40089 */
40090
40091 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40092 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40093 task_pid_nr(current),
40094 (long)old_encode_dev(file_priv->minor->kdev->devt),
40095 - dev->open_count);
40096 + local_read(&dev->open_count));
40097
40098 /* Release any auth tokens that might point to this file_priv,
40099 (do that under the drm_global_mutex) */
40100 @@ -543,7 +543,7 @@ int drm_release(struct inode *inode, struct file *filp)
40101 * End inline drm_release
40102 */
40103
40104 - if (!--dev->open_count) {
40105 + if (local_dec_and_test(&dev->open_count)) {
40106 retcode = drm_lastclose(dev);
40107 if (drm_device_is_unplugged(dev))
40108 drm_put_dev(dev);
40109 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40110 index 3d2e91c..d31c4c9 100644
40111 --- a/drivers/gpu/drm/drm_global.c
40112 +++ b/drivers/gpu/drm/drm_global.c
40113 @@ -36,7 +36,7 @@
40114 struct drm_global_item {
40115 struct mutex mutex;
40116 void *object;
40117 - int refcount;
40118 + atomic_t refcount;
40119 };
40120
40121 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40122 @@ -49,7 +49,7 @@ void drm_global_init(void)
40123 struct drm_global_item *item = &glob[i];
40124 mutex_init(&item->mutex);
40125 item->object = NULL;
40126 - item->refcount = 0;
40127 + atomic_set(&item->refcount, 0);
40128 }
40129 }
40130
40131 @@ -59,7 +59,7 @@ void drm_global_release(void)
40132 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40133 struct drm_global_item *item = &glob[i];
40134 BUG_ON(item->object != NULL);
40135 - BUG_ON(item->refcount != 0);
40136 + BUG_ON(atomic_read(&item->refcount) != 0);
40137 }
40138 }
40139
40140 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40141 struct drm_global_item *item = &glob[ref->global_type];
40142
40143 mutex_lock(&item->mutex);
40144 - if (item->refcount == 0) {
40145 + if (atomic_read(&item->refcount) == 0) {
40146 item->object = kzalloc(ref->size, GFP_KERNEL);
40147 if (unlikely(item->object == NULL)) {
40148 ret = -ENOMEM;
40149 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40150 goto out_err;
40151
40152 }
40153 - ++item->refcount;
40154 + atomic_inc(&item->refcount);
40155 ref->object = item->object;
40156 mutex_unlock(&item->mutex);
40157 return 0;
40158 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40159 struct drm_global_item *item = &glob[ref->global_type];
40160
40161 mutex_lock(&item->mutex);
40162 - BUG_ON(item->refcount == 0);
40163 + BUG_ON(atomic_read(&item->refcount) == 0);
40164 BUG_ON(ref->object != item->object);
40165 - if (--item->refcount == 0) {
40166 + if (atomic_dec_and_test(&item->refcount)) {
40167 ref->release(ref);
40168 item->object = NULL;
40169 }
40170 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40171 index 7473035..a48b9c5 100644
40172 --- a/drivers/gpu/drm/drm_info.c
40173 +++ b/drivers/gpu/drm/drm_info.c
40174 @@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40175 struct drm_local_map *map;
40176 struct drm_map_list *r_list;
40177
40178 - /* Hardcoded from _DRM_FRAME_BUFFER,
40179 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40180 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40181 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40182 + static const char * const types[] = {
40183 + [_DRM_FRAME_BUFFER] = "FB",
40184 + [_DRM_REGISTERS] = "REG",
40185 + [_DRM_SHM] = "SHM",
40186 + [_DRM_AGP] = "AGP",
40187 + [_DRM_SCATTER_GATHER] = "SG",
40188 + [_DRM_CONSISTENT] = "PCI"};
40189 const char *type;
40190 int i;
40191
40192 @@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40193 map = r_list->map;
40194 if (!map)
40195 continue;
40196 - if (map->type < 0 || map->type > 5)
40197 + if (map->type >= ARRAY_SIZE(types))
40198 type = "??";
40199 else
40200 type = types[map->type];
40201 @@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40202 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40203 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40204 vma->vm_flags & VM_IO ? 'i' : '-',
40205 +#ifdef CONFIG_GRKERNSEC_HIDESYM
40206 + 0);
40207 +#else
40208 vma->vm_pgoff);
40209 +#endif
40210
40211 #if defined(__i386__)
40212 pgprot = pgprot_val(vma->vm_page_prot);
40213 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40214 index 2f4c4343..dd12cd2 100644
40215 --- a/drivers/gpu/drm/drm_ioc32.c
40216 +++ b/drivers/gpu/drm/drm_ioc32.c
40217 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40218 request = compat_alloc_user_space(nbytes);
40219 if (!access_ok(VERIFY_WRITE, request, nbytes))
40220 return -EFAULT;
40221 - list = (struct drm_buf_desc *) (request + 1);
40222 + list = (struct drm_buf_desc __user *) (request + 1);
40223
40224 if (__put_user(count, &request->count)
40225 || __put_user(list, &request->list))
40226 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40227 request = compat_alloc_user_space(nbytes);
40228 if (!access_ok(VERIFY_WRITE, request, nbytes))
40229 return -EFAULT;
40230 - list = (struct drm_buf_pub *) (request + 1);
40231 + list = (struct drm_buf_pub __user *) (request + 1);
40232
40233 if (__put_user(count, &request->count)
40234 || __put_user(list, &request->list))
40235 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40236 return 0;
40237 }
40238
40239 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
40240 +drm_ioctl_compat_t drm_compat_ioctls[] = {
40241 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40242 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40243 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40244 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40245 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40246 {
40247 unsigned int nr = DRM_IOCTL_NR(cmd);
40248 - drm_ioctl_compat_t *fn;
40249 int ret;
40250
40251 /* Assume that ioctls without an explicit compat routine will just
40252 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40253 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40254 return drm_ioctl(filp, cmd, arg);
40255
40256 - fn = drm_compat_ioctls[nr];
40257 -
40258 - if (fn != NULL)
40259 - ret = (*fn) (filp, cmd, arg);
40260 + if (drm_compat_ioctls[nr] != NULL)
40261 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40262 else
40263 ret = drm_ioctl(filp, cmd, arg);
40264
40265 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40266 index 4c24c3a..c903cab 100644
40267 --- a/drivers/gpu/drm/drm_stub.c
40268 +++ b/drivers/gpu/drm/drm_stub.c
40269 @@ -455,7 +455,7 @@ void drm_unplug_dev(struct drm_device *dev)
40270
40271 drm_device_set_unplugged(dev);
40272
40273 - if (dev->open_count == 0) {
40274 + if (local_read(&dev->open_count) == 0) {
40275 drm_put_dev(dev);
40276 }
40277 mutex_unlock(&drm_global_mutex);
40278 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40279 index c22c309..ae758c3 100644
40280 --- a/drivers/gpu/drm/drm_sysfs.c
40281 +++ b/drivers/gpu/drm/drm_sysfs.c
40282 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40283 */
40284 int drm_sysfs_device_add(struct drm_minor *minor)
40285 {
40286 - char *minor_str;
40287 + const char *minor_str;
40288 int r;
40289
40290 if (minor->type == DRM_MINOR_CONTROL)
40291 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40292 index d4d16ed..8fb0b51 100644
40293 --- a/drivers/gpu/drm/i810/i810_drv.h
40294 +++ b/drivers/gpu/drm/i810/i810_drv.h
40295 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40296 int page_flipping;
40297
40298 wait_queue_head_t irq_queue;
40299 - atomic_t irq_received;
40300 - atomic_t irq_emitted;
40301 + atomic_unchecked_t irq_received;
40302 + atomic_unchecked_t irq_emitted;
40303
40304 int front_offset;
40305 } drm_i810_private_t;
40306 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40307 index eedb023..25076a4 100644
40308 --- a/drivers/gpu/drm/i915/i915_dma.c
40309 +++ b/drivers/gpu/drm/i915/i915_dma.c
40310 @@ -1280,7 +1280,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40311 bool can_switch;
40312
40313 spin_lock(&dev->count_lock);
40314 - can_switch = (dev->open_count == 0);
40315 + can_switch = (local_read(&dev->open_count) == 0);
40316 spin_unlock(&dev->count_lock);
40317 return can_switch;
40318 }
40319 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40320 index 20fef6c..76c78fb 100644
40321 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40322 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40323 @@ -886,9 +886,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40324
40325 static int
40326 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40327 - int count)
40328 + unsigned int count)
40329 {
40330 - int i;
40331 + unsigned int i;
40332 unsigned relocs_total = 0;
40333 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40334
40335 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40336 index 3c59584..500f2e9 100644
40337 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40338 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40339 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40340 (unsigned long)request);
40341 }
40342
40343 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40344 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40345 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40346 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40347 [DRM_I915_GETPARAM] = compat_i915_getparam,
40348 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40349 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40350 {
40351 unsigned int nr = DRM_IOCTL_NR(cmd);
40352 - drm_ioctl_compat_t *fn = NULL;
40353 int ret;
40354
40355 if (nr < DRM_COMMAND_BASE)
40356 return drm_compat_ioctl(filp, cmd, arg);
40357
40358 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40359 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40360 -
40361 - if (fn != NULL)
40362 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40363 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40364 ret = (*fn) (filp, cmd, arg);
40365 - else
40366 + } else
40367 ret = drm_ioctl(filp, cmd, arg);
40368
40369 return ret;
40370 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40371 index b91dfbe..b7fb16d 100644
40372 --- a/drivers/gpu/drm/i915/intel_display.c
40373 +++ b/drivers/gpu/drm/i915/intel_display.c
40374 @@ -11179,13 +11179,13 @@ struct intel_quirk {
40375 int subsystem_vendor;
40376 int subsystem_device;
40377 void (*hook)(struct drm_device *dev);
40378 -};
40379 +} __do_const;
40380
40381 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40382 struct intel_dmi_quirk {
40383 void (*hook)(struct drm_device *dev);
40384 const struct dmi_system_id (*dmi_id_list)[];
40385 -};
40386 +} __do_const;
40387
40388 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40389 {
40390 @@ -11193,18 +11193,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40391 return 1;
40392 }
40393
40394 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40395 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40396 {
40397 - .dmi_id_list = &(const struct dmi_system_id[]) {
40398 - {
40399 - .callback = intel_dmi_reverse_brightness,
40400 - .ident = "NCR Corporation",
40401 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40402 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40403 - },
40404 - },
40405 - { } /* terminating entry */
40406 + .callback = intel_dmi_reverse_brightness,
40407 + .ident = "NCR Corporation",
40408 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40409 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40410 },
40411 + },
40412 + { } /* terminating entry */
40413 +};
40414 +
40415 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40416 + {
40417 + .dmi_id_list = &intel_dmi_quirks_table,
40418 .hook = quirk_invert_brightness,
40419 },
40420 };
40421 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40422 index fe45321..836fdca 100644
40423 --- a/drivers/gpu/drm/mga/mga_drv.h
40424 +++ b/drivers/gpu/drm/mga/mga_drv.h
40425 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40426 u32 clear_cmd;
40427 u32 maccess;
40428
40429 - atomic_t vbl_received; /**< Number of vblanks received. */
40430 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40431 wait_queue_head_t fence_queue;
40432 - atomic_t last_fence_retired;
40433 + atomic_unchecked_t last_fence_retired;
40434 u32 next_fence_to_post;
40435
40436 unsigned int fb_cpp;
40437 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40438 index 86b4bb8..ae237ad 100644
40439 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40440 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40441 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40442 return 0;
40443 }
40444
40445 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40446 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40447 [DRM_MGA_INIT] = compat_mga_init,
40448 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40449 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40450 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40451 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40452 {
40453 unsigned int nr = DRM_IOCTL_NR(cmd);
40454 - drm_ioctl_compat_t *fn = NULL;
40455 int ret;
40456
40457 if (nr < DRM_COMMAND_BASE)
40458 return drm_compat_ioctl(filp, cmd, arg);
40459
40460 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40461 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40462 -
40463 - if (fn != NULL)
40464 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40465 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40466 ret = (*fn) (filp, cmd, arg);
40467 - else
40468 + } else
40469 ret = drm_ioctl(filp, cmd, arg);
40470
40471 return ret;
40472 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40473 index 1b071b8..de8601a 100644
40474 --- a/drivers/gpu/drm/mga/mga_irq.c
40475 +++ b/drivers/gpu/drm/mga/mga_irq.c
40476 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40477 if (crtc != 0)
40478 return 0;
40479
40480 - return atomic_read(&dev_priv->vbl_received);
40481 + return atomic_read_unchecked(&dev_priv->vbl_received);
40482 }
40483
40484
40485 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40486 /* VBLANK interrupt */
40487 if (status & MGA_VLINEPEN) {
40488 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40489 - atomic_inc(&dev_priv->vbl_received);
40490 + atomic_inc_unchecked(&dev_priv->vbl_received);
40491 drm_handle_vblank(dev, 0);
40492 handled = 1;
40493 }
40494 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40495 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40496 MGA_WRITE(MGA_PRIMEND, prim_end);
40497
40498 - atomic_inc(&dev_priv->last_fence_retired);
40499 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40500 wake_up(&dev_priv->fence_queue);
40501 handled = 1;
40502 }
40503 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40504 * using fences.
40505 */
40506 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40507 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40508 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40509 - *sequence) <= (1 << 23)));
40510
40511 *sequence = cur_fence;
40512 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40513 index 8268a4c..5105708 100644
40514 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40515 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40516 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40517 struct bit_table {
40518 const char id;
40519 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40520 -};
40521 +} __no_const;
40522
40523 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40524
40525 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40526 index 7efbafa..19f8087 100644
40527 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40528 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40529 @@ -97,7 +97,6 @@ struct nouveau_drm {
40530 struct drm_global_reference mem_global_ref;
40531 struct ttm_bo_global_ref bo_global_ref;
40532 struct ttm_bo_device bdev;
40533 - atomic_t validate_sequence;
40534 int (*move)(struct nouveau_channel *,
40535 struct ttm_buffer_object *,
40536 struct ttm_mem_reg *, struct ttm_mem_reg *);
40537 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40538 index c1a7e5a..38b8539 100644
40539 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40540 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40541 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40542 unsigned long arg)
40543 {
40544 unsigned int nr = DRM_IOCTL_NR(cmd);
40545 - drm_ioctl_compat_t *fn = NULL;
40546 + drm_ioctl_compat_t fn = NULL;
40547 int ret;
40548
40549 if (nr < DRM_COMMAND_BASE)
40550 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40551 index ab0228f..20b756b 100644
40552 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40553 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40554 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40555 }
40556
40557 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40558 - nouveau_vram_manager_init,
40559 - nouveau_vram_manager_fini,
40560 - nouveau_vram_manager_new,
40561 - nouveau_vram_manager_del,
40562 - nouveau_vram_manager_debug
40563 + .init = nouveau_vram_manager_init,
40564 + .takedown = nouveau_vram_manager_fini,
40565 + .get_node = nouveau_vram_manager_new,
40566 + .put_node = nouveau_vram_manager_del,
40567 + .debug = nouveau_vram_manager_debug
40568 };
40569
40570 static int
40571 @@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40572 }
40573
40574 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40575 - nouveau_gart_manager_init,
40576 - nouveau_gart_manager_fini,
40577 - nouveau_gart_manager_new,
40578 - nouveau_gart_manager_del,
40579 - nouveau_gart_manager_debug
40580 + .init = nouveau_gart_manager_init,
40581 + .takedown = nouveau_gart_manager_fini,
40582 + .get_node = nouveau_gart_manager_new,
40583 + .put_node = nouveau_gart_manager_del,
40584 + .debug = nouveau_gart_manager_debug
40585 };
40586
40587 #include <core/subdev/vm/nv04.h>
40588 @@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40589 }
40590
40591 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40592 - nv04_gart_manager_init,
40593 - nv04_gart_manager_fini,
40594 - nv04_gart_manager_new,
40595 - nv04_gart_manager_del,
40596 - nv04_gart_manager_debug
40597 + .init = nv04_gart_manager_init,
40598 + .takedown = nv04_gart_manager_fini,
40599 + .get_node = nv04_gart_manager_new,
40600 + .put_node = nv04_gart_manager_del,
40601 + .debug = nv04_gart_manager_debug
40602 };
40603
40604 int
40605 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40606 index fb84da3..d7ee463 100644
40607 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40608 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40609 @@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40610 bool can_switch;
40611
40612 spin_lock(&dev->count_lock);
40613 - can_switch = (dev->open_count == 0);
40614 + can_switch = (local_read(&dev->open_count) == 0);
40615 spin_unlock(&dev->count_lock);
40616 return can_switch;
40617 }
40618 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40619 index eb89653..613cf71 100644
40620 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40621 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40622 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40623 int ret;
40624
40625 mutex_lock(&qdev->async_io_mutex);
40626 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40627 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40628 if (qdev->last_sent_io_cmd > irq_num) {
40629 if (intr)
40630 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40631 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40632 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40633 else
40634 ret = wait_event_timeout(qdev->io_cmd_event,
40635 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40636 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40637 /* 0 is timeout, just bail the "hw" has gone away */
40638 if (ret <= 0)
40639 goto out;
40640 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40641 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40642 }
40643 outb(val, addr);
40644 qdev->last_sent_io_cmd = irq_num + 1;
40645 if (intr)
40646 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40647 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40648 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40649 else
40650 ret = wait_event_timeout(qdev->io_cmd_event,
40651 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40652 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40653 out:
40654 if (ret > 0)
40655 ret = 0;
40656 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40657 index c3c2bbd..bc3c0fb 100644
40658 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40659 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40660 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40661 struct drm_info_node *node = (struct drm_info_node *) m->private;
40662 struct qxl_device *qdev = node->minor->dev->dev_private;
40663
40664 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40665 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40666 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40667 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40668 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40669 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40670 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40671 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40672 seq_printf(m, "%d\n", qdev->irq_received_error);
40673 return 0;
40674 }
40675 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40676 index 36ed40b..0397633 100644
40677 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40678 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40679 @@ -290,10 +290,10 @@ struct qxl_device {
40680 unsigned int last_sent_io_cmd;
40681
40682 /* interrupt handling */
40683 - atomic_t irq_received;
40684 - atomic_t irq_received_display;
40685 - atomic_t irq_received_cursor;
40686 - atomic_t irq_received_io_cmd;
40687 + atomic_unchecked_t irq_received;
40688 + atomic_unchecked_t irq_received_display;
40689 + atomic_unchecked_t irq_received_cursor;
40690 + atomic_unchecked_t irq_received_io_cmd;
40691 unsigned irq_received_error;
40692 wait_queue_head_t display_event;
40693 wait_queue_head_t cursor_event;
40694 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40695 index 0bb86e6..d41416d 100644
40696 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40697 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40698 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40699
40700 /* TODO copy slow path code from i915 */
40701 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40702 - 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);
40703 + 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);
40704
40705 {
40706 struct qxl_drawable *draw = fb_cmd;
40707 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40708 struct drm_qxl_reloc reloc;
40709
40710 if (copy_from_user(&reloc,
40711 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40712 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40713 sizeof(reloc))) {
40714 ret = -EFAULT;
40715 goto out_free_bos;
40716 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40717
40718 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40719
40720 - struct drm_qxl_command *commands =
40721 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40722 + struct drm_qxl_command __user *commands =
40723 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40724
40725 - if (copy_from_user(&user_cmd, &commands[cmd_num],
40726 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40727 sizeof(user_cmd)))
40728 return -EFAULT;
40729
40730 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40731 index 28f84b4..fb3e224 100644
40732 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40733 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40734 @@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40735
40736 pending = xchg(&qdev->ram_header->int_pending, 0);
40737
40738 - atomic_inc(&qdev->irq_received);
40739 + atomic_inc_unchecked(&qdev->irq_received);
40740
40741 if (pending & QXL_INTERRUPT_DISPLAY) {
40742 - atomic_inc(&qdev->irq_received_display);
40743 + atomic_inc_unchecked(&qdev->irq_received_display);
40744 wake_up_all(&qdev->display_event);
40745 qxl_queue_garbage_collect(qdev, false);
40746 }
40747 if (pending & QXL_INTERRUPT_CURSOR) {
40748 - atomic_inc(&qdev->irq_received_cursor);
40749 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40750 wake_up_all(&qdev->cursor_event);
40751 }
40752 if (pending & QXL_INTERRUPT_IO_CMD) {
40753 - atomic_inc(&qdev->irq_received_io_cmd);
40754 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40755 wake_up_all(&qdev->io_cmd_event);
40756 }
40757 if (pending & QXL_INTERRUPT_ERROR) {
40758 @@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40759 init_waitqueue_head(&qdev->io_cmd_event);
40760 INIT_WORK(&qdev->client_monitors_config_work,
40761 qxl_client_monitors_config_work_func);
40762 - atomic_set(&qdev->irq_received, 0);
40763 - atomic_set(&qdev->irq_received_display, 0);
40764 - atomic_set(&qdev->irq_received_cursor, 0);
40765 - atomic_set(&qdev->irq_received_io_cmd, 0);
40766 + atomic_set_unchecked(&qdev->irq_received, 0);
40767 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40768 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40769 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40770 qdev->irq_received_error = 0;
40771 ret = drm_irq_install(qdev->ddev);
40772 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40773 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40774 index d52c275..4e6b43d 100644
40775 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40776 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40777 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40778 }
40779 }
40780
40781 -static struct vm_operations_struct qxl_ttm_vm_ops;
40782 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40783 static const struct vm_operations_struct *ttm_vm_ops;
40784
40785 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40786 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40787 return r;
40788 if (unlikely(ttm_vm_ops == NULL)) {
40789 ttm_vm_ops = vma->vm_ops;
40790 + pax_open_kernel();
40791 qxl_ttm_vm_ops = *ttm_vm_ops;
40792 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40793 + pax_close_kernel();
40794 }
40795 vma->vm_ops = &qxl_ttm_vm_ops;
40796 return 0;
40797 @@ -561,25 +563,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40798 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40799 {
40800 #if defined(CONFIG_DEBUG_FS)
40801 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40802 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40803 - unsigned i;
40804 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40805 + {
40806 + .name = "qxl_mem_mm",
40807 + .show = &qxl_mm_dump_table,
40808 + },
40809 + {
40810 + .name = "qxl_surf_mm",
40811 + .show = &qxl_mm_dump_table,
40812 + }
40813 + };
40814
40815 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40816 - if (i == 0)
40817 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40818 - else
40819 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40820 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40821 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40822 - qxl_mem_types_list[i].driver_features = 0;
40823 - if (i == 0)
40824 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40825 - else
40826 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40827 + pax_open_kernel();
40828 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40829 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40830 + pax_close_kernel();
40831
40832 - }
40833 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40834 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40835 #else
40836 return 0;
40837 #endif
40838 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40839 index 59459fe..be26b31 100644
40840 --- a/drivers/gpu/drm/r128/r128_cce.c
40841 +++ b/drivers/gpu/drm/r128/r128_cce.c
40842 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40843
40844 /* GH: Simple idle check.
40845 */
40846 - atomic_set(&dev_priv->idle_count, 0);
40847 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40848
40849 /* We don't support anything other than bus-mastering ring mode,
40850 * but the ring can be in either AGP or PCI space for the ring
40851 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40852 index 5bf3f5f..7000661 100644
40853 --- a/drivers/gpu/drm/r128/r128_drv.h
40854 +++ b/drivers/gpu/drm/r128/r128_drv.h
40855 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40856 int is_pci;
40857 unsigned long cce_buffers_offset;
40858
40859 - atomic_t idle_count;
40860 + atomic_unchecked_t idle_count;
40861
40862 int page_flipping;
40863 int current_page;
40864 u32 crtc_offset;
40865 u32 crtc_offset_cntl;
40866
40867 - atomic_t vbl_received;
40868 + atomic_unchecked_t vbl_received;
40869
40870 u32 color_fmt;
40871 unsigned int front_offset;
40872 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40873 index b0d0fd3..a6fbbe4 100644
40874 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40875 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40876 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40877 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40878 }
40879
40880 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
40881 +drm_ioctl_compat_t r128_compat_ioctls[] = {
40882 [DRM_R128_INIT] = compat_r128_init,
40883 [DRM_R128_DEPTH] = compat_r128_depth,
40884 [DRM_R128_STIPPLE] = compat_r128_stipple,
40885 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40886 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40887 {
40888 unsigned int nr = DRM_IOCTL_NR(cmd);
40889 - drm_ioctl_compat_t *fn = NULL;
40890 int ret;
40891
40892 if (nr < DRM_COMMAND_BASE)
40893 return drm_compat_ioctl(filp, cmd, arg);
40894
40895 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40896 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40897 -
40898 - if (fn != NULL)
40899 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40900 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40901 ret = (*fn) (filp, cmd, arg);
40902 - else
40903 + } else
40904 ret = drm_ioctl(filp, cmd, arg);
40905
40906 return ret;
40907 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40908 index c2ae496..30b5993 100644
40909 --- a/drivers/gpu/drm/r128/r128_irq.c
40910 +++ b/drivers/gpu/drm/r128/r128_irq.c
40911 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40912 if (crtc != 0)
40913 return 0;
40914
40915 - return atomic_read(&dev_priv->vbl_received);
40916 + return atomic_read_unchecked(&dev_priv->vbl_received);
40917 }
40918
40919 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40920 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40921 /* VBLANK interrupt */
40922 if (status & R128_CRTC_VBLANK_INT) {
40923 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40924 - atomic_inc(&dev_priv->vbl_received);
40925 + atomic_inc_unchecked(&dev_priv->vbl_received);
40926 drm_handle_vblank(dev, 0);
40927 return IRQ_HANDLED;
40928 }
40929 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40930 index e806dac..f81d32f 100644
40931 --- a/drivers/gpu/drm/r128/r128_state.c
40932 +++ b/drivers/gpu/drm/r128/r128_state.c
40933 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40934
40935 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40936 {
40937 - if (atomic_read(&dev_priv->idle_count) == 0)
40938 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40939 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40940 else
40941 - atomic_set(&dev_priv->idle_count, 0);
40942 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40943 }
40944
40945 #endif
40946 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40947 index 4a85bb6..aaea819 100644
40948 --- a/drivers/gpu/drm/radeon/mkregtable.c
40949 +++ b/drivers/gpu/drm/radeon/mkregtable.c
40950 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40951 regex_t mask_rex;
40952 regmatch_t match[4];
40953 char buf[1024];
40954 - size_t end;
40955 + long end;
40956 int len;
40957 int done = 0;
40958 int r;
40959 unsigned o;
40960 struct offset *offset;
40961 char last_reg_s[10];
40962 - int last_reg;
40963 + unsigned long last_reg;
40964
40965 if (regcomp
40966 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40967 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40968 index 2cd144c..a01c95a 100644
40969 --- a/drivers/gpu/drm/radeon/radeon_device.c
40970 +++ b/drivers/gpu/drm/radeon/radeon_device.c
40971 @@ -1129,7 +1129,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40972 bool can_switch;
40973
40974 spin_lock(&dev->count_lock);
40975 - can_switch = (dev->open_count == 0);
40976 + can_switch = (local_read(&dev->open_count) == 0);
40977 spin_unlock(&dev->count_lock);
40978 return can_switch;
40979 }
40980 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40981 index dafd812..1bf20c7 100644
40982 --- a/drivers/gpu/drm/radeon/radeon_drv.h
40983 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
40984 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40985
40986 /* SW interrupt */
40987 wait_queue_head_t swi_queue;
40988 - atomic_t swi_emitted;
40989 + atomic_unchecked_t swi_emitted;
40990 int vblank_crtc;
40991 uint32_t irq_enable_reg;
40992 uint32_t r500_disp_irq_reg;
40993 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40994 index bdb0f93..5ff558f 100644
40995 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40996 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40997 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40998 request = compat_alloc_user_space(sizeof(*request));
40999 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41000 || __put_user(req32.param, &request->param)
41001 - || __put_user((void __user *)(unsigned long)req32.value,
41002 + || __put_user((unsigned long)req32.value,
41003 &request->value))
41004 return -EFAULT;
41005
41006 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41007 #define compat_radeon_cp_setparam NULL
41008 #endif /* X86_64 || IA64 */
41009
41010 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41011 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41012 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41013 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41014 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41015 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41016 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41017 {
41018 unsigned int nr = DRM_IOCTL_NR(cmd);
41019 - drm_ioctl_compat_t *fn = NULL;
41020 int ret;
41021
41022 if (nr < DRM_COMMAND_BASE)
41023 return drm_compat_ioctl(filp, cmd, arg);
41024
41025 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
41026 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41027 -
41028 - if (fn != NULL)
41029 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
41030 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41031 ret = (*fn) (filp, cmd, arg);
41032 - else
41033 + } else
41034 ret = drm_ioctl(filp, cmd, arg);
41035
41036 return ret;
41037 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41038 index 244b19b..c19226d 100644
41039 --- a/drivers/gpu/drm/radeon/radeon_irq.c
41040 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
41041 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41042 unsigned int ret;
41043 RING_LOCALS;
41044
41045 - atomic_inc(&dev_priv->swi_emitted);
41046 - ret = atomic_read(&dev_priv->swi_emitted);
41047 + atomic_inc_unchecked(&dev_priv->swi_emitted);
41048 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41049
41050 BEGIN_RING(4);
41051 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41052 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41053 drm_radeon_private_t *dev_priv =
41054 (drm_radeon_private_t *) dev->dev_private;
41055
41056 - atomic_set(&dev_priv->swi_emitted, 0);
41057 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41058 init_waitqueue_head(&dev_priv->swi_queue);
41059
41060 dev->max_vblank_count = 0x001fffff;
41061 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41062 index 956ab7f..fbd36d8 100644
41063 --- a/drivers/gpu/drm/radeon/radeon_state.c
41064 +++ b/drivers/gpu/drm/radeon/radeon_state.c
41065 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41066 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41067 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41068
41069 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
41070 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41071 sarea_priv->nbox * sizeof(depth_boxes[0])))
41072 return -EFAULT;
41073
41074 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41075 {
41076 drm_radeon_private_t *dev_priv = dev->dev_private;
41077 drm_radeon_getparam_t *param = data;
41078 - int value;
41079 + int value = 0;
41080
41081 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41082
41083 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41084 index c8a8a51..219dacc 100644
41085 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
41086 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41087 @@ -797,7 +797,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41088 man->size = size >> PAGE_SHIFT;
41089 }
41090
41091 -static struct vm_operations_struct radeon_ttm_vm_ops;
41092 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41093 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41094
41095 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41096 @@ -838,8 +838,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41097 }
41098 if (unlikely(ttm_vm_ops == NULL)) {
41099 ttm_vm_ops = vma->vm_ops;
41100 + pax_open_kernel();
41101 radeon_ttm_vm_ops = *ttm_vm_ops;
41102 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41103 + pax_close_kernel();
41104 }
41105 vma->vm_ops = &radeon_ttm_vm_ops;
41106 return 0;
41107 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41108 index edb871d..a275c6ed 100644
41109 --- a/drivers/gpu/drm/tegra/dc.c
41110 +++ b/drivers/gpu/drm/tegra/dc.c
41111 @@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41112 }
41113
41114 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41115 - dc->debugfs_files[i].data = dc;
41116 + *(void **)&dc->debugfs_files[i].data = dc;
41117
41118 err = drm_debugfs_create_files(dc->debugfs_files,
41119 ARRAY_SIZE(debugfs_files),
41120 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41121 index 0e599f0..c9ea7c7 100644
41122 --- a/drivers/gpu/drm/tegra/dsi.c
41123 +++ b/drivers/gpu/drm/tegra/dsi.c
41124 @@ -39,7 +39,7 @@ struct tegra_dsi {
41125 struct clk *clk_lp;
41126 struct clk *clk;
41127
41128 - struct drm_info_list *debugfs_files;
41129 + drm_info_list_no_const *debugfs_files;
41130 struct drm_minor *minor;
41131 struct dentry *debugfs;
41132
41133 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41134 index 6928015..c9853e7 100644
41135 --- a/drivers/gpu/drm/tegra/hdmi.c
41136 +++ b/drivers/gpu/drm/tegra/hdmi.c
41137 @@ -59,7 +59,7 @@ struct tegra_hdmi {
41138 bool stereo;
41139 bool dvi;
41140
41141 - struct drm_info_list *debugfs_files;
41142 + drm_info_list_no_const *debugfs_files;
41143 struct drm_minor *minor;
41144 struct dentry *debugfs;
41145 };
41146 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41147 index bd850c9..d9f3573 100644
41148 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41149 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41150 @@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41151 }
41152
41153 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41154 - ttm_bo_man_init,
41155 - ttm_bo_man_takedown,
41156 - ttm_bo_man_get_node,
41157 - ttm_bo_man_put_node,
41158 - ttm_bo_man_debug
41159 + .init = ttm_bo_man_init,
41160 + .takedown = ttm_bo_man_takedown,
41161 + .get_node = ttm_bo_man_get_node,
41162 + .put_node = ttm_bo_man_put_node,
41163 + .debug = ttm_bo_man_debug
41164 };
41165 EXPORT_SYMBOL(ttm_bo_manager_func);
41166 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41167 index dbc2def..0a9f710 100644
41168 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41169 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41170 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41171 zone->glob = glob;
41172 glob->zone_kernel = zone;
41173 ret = kobject_init_and_add(
41174 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41175 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41176 if (unlikely(ret != 0)) {
41177 kobject_put(&zone->kobj);
41178 return ret;
41179 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41180 zone->glob = glob;
41181 glob->zone_dma32 = zone;
41182 ret = kobject_init_and_add(
41183 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41184 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41185 if (unlikely(ret != 0)) {
41186 kobject_put(&zone->kobj);
41187 return ret;
41188 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41189 index 863bef9..cba15cf 100644
41190 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41191 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41192 @@ -391,9 +391,9 @@ out:
41193 static unsigned long
41194 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41195 {
41196 - static atomic_t start_pool = ATOMIC_INIT(0);
41197 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41198 unsigned i;
41199 - unsigned pool_offset = atomic_add_return(1, &start_pool);
41200 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41201 struct ttm_page_pool *pool;
41202 int shrink_pages = sc->nr_to_scan;
41203 unsigned long freed = 0;
41204 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41205 index 3771763..883f206 100644
41206 --- a/drivers/gpu/drm/udl/udl_fb.c
41207 +++ b/drivers/gpu/drm/udl/udl_fb.c
41208 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41209 fb_deferred_io_cleanup(info);
41210 kfree(info->fbdefio);
41211 info->fbdefio = NULL;
41212 - info->fbops->fb_mmap = udl_fb_mmap;
41213 }
41214
41215 pr_warn("released /dev/fb%d user=%d count=%d\n",
41216 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41217 index ad02732..144f5ed 100644
41218 --- a/drivers/gpu/drm/via/via_drv.h
41219 +++ b/drivers/gpu/drm/via/via_drv.h
41220 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41221 typedef uint32_t maskarray_t[5];
41222
41223 typedef struct drm_via_irq {
41224 - atomic_t irq_received;
41225 + atomic_unchecked_t irq_received;
41226 uint32_t pending_mask;
41227 uint32_t enable_mask;
41228 wait_queue_head_t irq_queue;
41229 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
41230 struct timeval last_vblank;
41231 int last_vblank_valid;
41232 unsigned usec_per_vblank;
41233 - atomic_t vbl_received;
41234 + atomic_unchecked_t vbl_received;
41235 drm_via_state_t hc_state;
41236 char pci_buf[VIA_PCI_BUF_SIZE];
41237 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41238 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41239 index 1319433..a993b0c 100644
41240 --- a/drivers/gpu/drm/via/via_irq.c
41241 +++ b/drivers/gpu/drm/via/via_irq.c
41242 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41243 if (crtc != 0)
41244 return 0;
41245
41246 - return atomic_read(&dev_priv->vbl_received);
41247 + return atomic_read_unchecked(&dev_priv->vbl_received);
41248 }
41249
41250 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41251 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41252
41253 status = VIA_READ(VIA_REG_INTERRUPT);
41254 if (status & VIA_IRQ_VBLANK_PENDING) {
41255 - atomic_inc(&dev_priv->vbl_received);
41256 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41257 + atomic_inc_unchecked(&dev_priv->vbl_received);
41258 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41259 do_gettimeofday(&cur_vblank);
41260 if (dev_priv->last_vblank_valid) {
41261 dev_priv->usec_per_vblank =
41262 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41263 dev_priv->last_vblank = cur_vblank;
41264 dev_priv->last_vblank_valid = 1;
41265 }
41266 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41267 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41268 DRM_DEBUG("US per vblank is: %u\n",
41269 dev_priv->usec_per_vblank);
41270 }
41271 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41272
41273 for (i = 0; i < dev_priv->num_irqs; ++i) {
41274 if (status & cur_irq->pending_mask) {
41275 - atomic_inc(&cur_irq->irq_received);
41276 + atomic_inc_unchecked(&cur_irq->irq_received);
41277 wake_up(&cur_irq->irq_queue);
41278 handled = 1;
41279 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41280 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41281 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41282 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41283 masks[irq][4]));
41284 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41285 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41286 } else {
41287 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41288 (((cur_irq_sequence =
41289 - atomic_read(&cur_irq->irq_received)) -
41290 + atomic_read_unchecked(&cur_irq->irq_received)) -
41291 *sequence) <= (1 << 23)));
41292 }
41293 *sequence = cur_irq_sequence;
41294 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41295 }
41296
41297 for (i = 0; i < dev_priv->num_irqs; ++i) {
41298 - atomic_set(&cur_irq->irq_received, 0);
41299 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41300 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41301 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41302 init_waitqueue_head(&cur_irq->irq_queue);
41303 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41304 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41305 case VIA_IRQ_RELATIVE:
41306 irqwait->request.sequence +=
41307 - atomic_read(&cur_irq->irq_received);
41308 + atomic_read_unchecked(&cur_irq->irq_received);
41309 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41310 case VIA_IRQ_ABSOLUTE:
41311 break;
41312 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41313 index 6b252a8..5975dfe 100644
41314 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41315 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41316 @@ -437,7 +437,7 @@ struct vmw_private {
41317 * Fencing and IRQs.
41318 */
41319
41320 - atomic_t marker_seq;
41321 + atomic_unchecked_t marker_seq;
41322 wait_queue_head_t fence_queue;
41323 wait_queue_head_t fifo_queue;
41324 int fence_queue_waiters; /* Protected by hw_mutex */
41325 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41326 index 6ccd993..618d592 100644
41327 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41328 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41329 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41330 (unsigned int) min,
41331 (unsigned int) fifo->capabilities);
41332
41333 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41334 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41335 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41336 vmw_marker_queue_init(&fifo->marker_queue);
41337 return vmw_fifo_send_fence(dev_priv, &dummy);
41338 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41339 if (reserveable)
41340 iowrite32(bytes, fifo_mem +
41341 SVGA_FIFO_RESERVED);
41342 - return fifo_mem + (next_cmd >> 2);
41343 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41344 } else {
41345 need_bounce = true;
41346 }
41347 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41348
41349 fm = vmw_fifo_reserve(dev_priv, bytes);
41350 if (unlikely(fm == NULL)) {
41351 - *seqno = atomic_read(&dev_priv->marker_seq);
41352 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41353 ret = -ENOMEM;
41354 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41355 false, 3*HZ);
41356 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41357 }
41358
41359 do {
41360 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41361 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41362 } while (*seqno == 0);
41363
41364 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41365 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41366 index b1273e8..9c274fd 100644
41367 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41368 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41369 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41370 }
41371
41372 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41373 - vmw_gmrid_man_init,
41374 - vmw_gmrid_man_takedown,
41375 - vmw_gmrid_man_get_node,
41376 - vmw_gmrid_man_put_node,
41377 - vmw_gmrid_man_debug
41378 + .init = vmw_gmrid_man_init,
41379 + .takedown = vmw_gmrid_man_takedown,
41380 + .get_node = vmw_gmrid_man_get_node,
41381 + .put_node = vmw_gmrid_man_put_node,
41382 + .debug = vmw_gmrid_man_debug
41383 };
41384 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41385 index 37881ec..319065d 100644
41386 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41387 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41388 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41389 int ret;
41390
41391 num_clips = arg->num_clips;
41392 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41393 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41394
41395 if (unlikely(num_clips == 0))
41396 return 0;
41397 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41398 int ret;
41399
41400 num_clips = arg->num_clips;
41401 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41402 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41403
41404 if (unlikely(num_clips == 0))
41405 return 0;
41406 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41407 index 0c42376..6febe77 100644
41408 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41409 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41410 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41411 * emitted. Then the fence is stale and signaled.
41412 */
41413
41414 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41415 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41416 > VMW_FENCE_WRAP);
41417
41418 return ret;
41419 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41420
41421 if (fifo_idle)
41422 down_read(&fifo_state->rwsem);
41423 - signal_seq = atomic_read(&dev_priv->marker_seq);
41424 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41425 ret = 0;
41426
41427 for (;;) {
41428 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41429 index 8a8725c2..afed796 100644
41430 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41431 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41432 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41433 while (!vmw_lag_lt(queue, us)) {
41434 spin_lock(&queue->lock);
41435 if (list_empty(&queue->head))
41436 - seqno = atomic_read(&dev_priv->marker_seq);
41437 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41438 else {
41439 marker = list_first_entry(&queue->head,
41440 struct vmw_marker, head);
41441 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41442 index 6866448..2ad2b34 100644
41443 --- a/drivers/gpu/vga/vga_switcheroo.c
41444 +++ b/drivers/gpu/vga/vga_switcheroo.c
41445 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41446
41447 /* this version is for the case where the power switch is separate
41448 to the device being powered down. */
41449 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41450 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41451 {
41452 /* copy over all the bus versions */
41453 if (dev->bus && dev->bus->pm) {
41454 @@ -689,7 +689,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41455 return ret;
41456 }
41457
41458 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41459 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41460 {
41461 /* copy over all the bus versions */
41462 if (dev->bus && dev->bus->pm) {
41463 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41464 index a5c7927..025a2b4 100644
41465 --- a/drivers/hid/hid-core.c
41466 +++ b/drivers/hid/hid-core.c
41467 @@ -2476,7 +2476,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41468
41469 int hid_add_device(struct hid_device *hdev)
41470 {
41471 - static atomic_t id = ATOMIC_INIT(0);
41472 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41473 int ret;
41474
41475 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41476 @@ -2518,7 +2518,7 @@ int hid_add_device(struct hid_device *hdev)
41477 /* XXX hack, any other cleaner solution after the driver core
41478 * is converted to allow more than 20 bytes as the device name? */
41479 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41480 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41481 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41482
41483 hid_debug_register(hdev, dev_name(&hdev->dev));
41484 ret = device_add(&hdev->dev);
41485 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41486 index c13fb5b..55a3802 100644
41487 --- a/drivers/hid/hid-wiimote-debug.c
41488 +++ b/drivers/hid/hid-wiimote-debug.c
41489 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41490 else if (size == 0)
41491 return -EIO;
41492
41493 - if (copy_to_user(u, buf, size))
41494 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
41495 return -EFAULT;
41496
41497 *off += size;
41498 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41499 index 0d078c3..cd0962c 100644
41500 --- a/drivers/hid/uhid.c
41501 +++ b/drivers/hid/uhid.c
41502 @@ -47,7 +47,7 @@ struct uhid_device {
41503 struct mutex report_lock;
41504 wait_queue_head_t report_wait;
41505 atomic_t report_done;
41506 - atomic_t report_id;
41507 + atomic_unchecked_t report_id;
41508 struct uhid_event report_buf;
41509 };
41510
41511 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41512
41513 spin_lock_irqsave(&uhid->qlock, flags);
41514 ev->type = UHID_FEATURE;
41515 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41516 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41517 ev->u.feature.rnum = rnum;
41518 ev->u.feature.rtype = report_type;
41519
41520 @@ -539,7 +539,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41521 spin_lock_irqsave(&uhid->qlock, flags);
41522
41523 /* id for old report; drop it silently */
41524 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41525 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41526 goto unlock;
41527 if (atomic_read(&uhid->report_done))
41528 goto unlock;
41529 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41530 index 602ca86..10a6573 100644
41531 --- a/drivers/hv/channel.c
41532 +++ b/drivers/hv/channel.c
41533 @@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41534 int ret = 0;
41535 int t;
41536
41537 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41538 - atomic_inc(&vmbus_connection.next_gpadl_handle);
41539 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41540 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41541
41542 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41543 if (ret)
41544 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41545 index bcb4950..61dba6c 100644
41546 --- a/drivers/hv/hv.c
41547 +++ b/drivers/hv/hv.c
41548 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41549 u64 output_address = (output) ? virt_to_phys(output) : 0;
41550 u32 output_address_hi = output_address >> 32;
41551 u32 output_address_lo = output_address & 0xFFFFFFFF;
41552 - void *hypercall_page = hv_context.hypercall_page;
41553 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41554
41555 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41556 "=a"(hv_status_lo) : "d" (control_hi),
41557 @@ -154,7 +154,7 @@ int hv_init(void)
41558 /* See if the hypercall page is already set */
41559 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41560
41561 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41562 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41563
41564 if (!virtaddr)
41565 goto cleanup;
41566 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41567 index 5e90c5d..d8fcefb 100644
41568 --- a/drivers/hv/hv_balloon.c
41569 +++ b/drivers/hv/hv_balloon.c
41570 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41571
41572 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41573 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41574 -static atomic_t trans_id = ATOMIC_INIT(0);
41575 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41576
41577 static int dm_ring_size = (5 * PAGE_SIZE);
41578
41579 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
41580 pr_info("Memory hot add failed\n");
41581
41582 dm->state = DM_INITIALIZED;
41583 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41584 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41585 vmbus_sendpacket(dm->dev->channel, &resp,
41586 sizeof(struct dm_hot_add_response),
41587 (unsigned long)NULL,
41588 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
41589 memset(&status, 0, sizeof(struct dm_status));
41590 status.hdr.type = DM_STATUS_REPORT;
41591 status.hdr.size = sizeof(struct dm_status);
41592 - status.hdr.trans_id = atomic_inc_return(&trans_id);
41593 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41594
41595 /*
41596 * The host expects the guest to report free memory.
41597 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
41598 * send the status. This can happen if we were interrupted
41599 * after we picked our transaction ID.
41600 */
41601 - if (status.hdr.trans_id != atomic_read(&trans_id))
41602 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41603 return;
41604
41605 /*
41606 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
41607 */
41608
41609 do {
41610 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41611 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41612 ret = vmbus_sendpacket(dm_device.dev->channel,
41613 bl_resp,
41614 bl_resp->hdr.size,
41615 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41616
41617 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41618 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41619 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41620 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41621 resp.hdr.size = sizeof(struct dm_unballoon_response);
41622
41623 vmbus_sendpacket(dm_device.dev->channel, &resp,
41624 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41625 memset(&version_req, 0, sizeof(struct dm_version_request));
41626 version_req.hdr.type = DM_VERSION_REQUEST;
41627 version_req.hdr.size = sizeof(struct dm_version_request);
41628 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41629 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41630 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41631 version_req.is_last_attempt = 1;
41632
41633 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
41634 memset(&version_req, 0, sizeof(struct dm_version_request));
41635 version_req.hdr.type = DM_VERSION_REQUEST;
41636 version_req.hdr.size = sizeof(struct dm_version_request);
41637 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41638 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41639 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41640 version_req.is_last_attempt = 0;
41641
41642 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
41643 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41644 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41645 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41646 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41647 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41648
41649 cap_msg.caps.cap_bits.balloon = 1;
41650 cap_msg.caps.cap_bits.hot_add = 1;
41651 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41652 index 860134d..ea3a79a 100644
41653 --- a/drivers/hv/hyperv_vmbus.h
41654 +++ b/drivers/hv/hyperv_vmbus.h
41655 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
41656 struct vmbus_connection {
41657 enum vmbus_connect_state conn_state;
41658
41659 - atomic_t next_gpadl_handle;
41660 + atomic_unchecked_t next_gpadl_handle;
41661
41662 /*
41663 * Represents channel interrupts. Each bit position represents a
41664 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41665 index 8e53a3c..7a64e44 100644
41666 --- a/drivers/hv/vmbus_drv.c
41667 +++ b/drivers/hv/vmbus_drv.c
41668 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41669 {
41670 int ret = 0;
41671
41672 - static atomic_t device_num = ATOMIC_INIT(0);
41673 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41674
41675 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41676 - atomic_inc_return(&device_num));
41677 + atomic_inc_return_unchecked(&device_num));
41678
41679 child_device_obj->device.bus = &hv_bus;
41680 child_device_obj->device.parent = &hv_acpi_dev->dev;
41681 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41682 index 579bdf9..75118b5 100644
41683 --- a/drivers/hwmon/acpi_power_meter.c
41684 +++ b/drivers/hwmon/acpi_power_meter.c
41685 @@ -116,7 +116,7 @@ struct sensor_template {
41686 struct device_attribute *devattr,
41687 const char *buf, size_t count);
41688 int index;
41689 -};
41690 +} __do_const;
41691
41692 /* Averaging interval */
41693 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41694 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41695 struct sensor_template *attrs)
41696 {
41697 struct device *dev = &resource->acpi_dev->dev;
41698 - struct sensor_device_attribute *sensors =
41699 + sensor_device_attribute_no_const *sensors =
41700 &resource->sensors[resource->num_sensors];
41701 int res = 0;
41702
41703 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41704 index 3288f13..71cfb4e 100644
41705 --- a/drivers/hwmon/applesmc.c
41706 +++ b/drivers/hwmon/applesmc.c
41707 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41708 {
41709 struct applesmc_node_group *grp;
41710 struct applesmc_dev_attr *node;
41711 - struct attribute *attr;
41712 + attribute_no_const *attr;
41713 int ret, i;
41714
41715 for (grp = groups; grp->format; grp++) {
41716 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41717 index ae208f6..48b6c5b 100644
41718 --- a/drivers/hwmon/asus_atk0110.c
41719 +++ b/drivers/hwmon/asus_atk0110.c
41720 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41721 struct atk_sensor_data {
41722 struct list_head list;
41723 struct atk_data *data;
41724 - struct device_attribute label_attr;
41725 - struct device_attribute input_attr;
41726 - struct device_attribute limit1_attr;
41727 - struct device_attribute limit2_attr;
41728 + device_attribute_no_const label_attr;
41729 + device_attribute_no_const input_attr;
41730 + device_attribute_no_const limit1_attr;
41731 + device_attribute_no_const limit2_attr;
41732 char label_attr_name[ATTR_NAME_SIZE];
41733 char input_attr_name[ATTR_NAME_SIZE];
41734 char limit1_attr_name[ATTR_NAME_SIZE];
41735 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41736 static struct device_attribute atk_name_attr =
41737 __ATTR(name, 0444, atk_name_show, NULL);
41738
41739 -static void atk_init_attribute(struct device_attribute *attr, char *name,
41740 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41741 sysfs_show_func show)
41742 {
41743 sysfs_attr_init(&attr->attr);
41744 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41745 index d76f0b7..55ae976 100644
41746 --- a/drivers/hwmon/coretemp.c
41747 +++ b/drivers/hwmon/coretemp.c
41748 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41749 return NOTIFY_OK;
41750 }
41751
41752 -static struct notifier_block coretemp_cpu_notifier __refdata = {
41753 +static struct notifier_block coretemp_cpu_notifier = {
41754 .notifier_call = coretemp_cpu_callback,
41755 };
41756
41757 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41758 index 632f1dc..57e6a58 100644
41759 --- a/drivers/hwmon/ibmaem.c
41760 +++ b/drivers/hwmon/ibmaem.c
41761 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41762 struct aem_rw_sensor_template *rw)
41763 {
41764 struct device *dev = &data->pdev->dev;
41765 - struct sensor_device_attribute *sensors = data->sensors;
41766 + sensor_device_attribute_no_const *sensors = data->sensors;
41767 int err;
41768
41769 /* Set up read-only sensors */
41770 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41771 index 9fbb1b1..efbaa3e 100644
41772 --- a/drivers/hwmon/iio_hwmon.c
41773 +++ b/drivers/hwmon/iio_hwmon.c
41774 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41775 {
41776 struct device *dev = &pdev->dev;
41777 struct iio_hwmon_state *st;
41778 - struct sensor_device_attribute *a;
41779 + sensor_device_attribute_no_const *a;
41780 int ret, i;
41781 int in_i = 1, temp_i = 1, curr_i = 1;
41782 enum iio_chan_type type;
41783 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41784 index 38d5a63..cf2c2ea 100644
41785 --- a/drivers/hwmon/nct6775.c
41786 +++ b/drivers/hwmon/nct6775.c
41787 @@ -944,10 +944,10 @@ static struct attribute_group *
41788 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41789 int repeat)
41790 {
41791 - struct attribute_group *group;
41792 + attribute_group_no_const *group;
41793 struct sensor_device_attr_u *su;
41794 - struct sensor_device_attribute *a;
41795 - struct sensor_device_attribute_2 *a2;
41796 + sensor_device_attribute_no_const *a;
41797 + sensor_device_attribute_2_no_const *a2;
41798 struct attribute **attrs;
41799 struct sensor_device_template **t;
41800 int i, count;
41801 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41802 index 291d11f..3f0dbbd 100644
41803 --- a/drivers/hwmon/pmbus/pmbus_core.c
41804 +++ b/drivers/hwmon/pmbus/pmbus_core.c
41805 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41806 return 0;
41807 }
41808
41809 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41810 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41811 const char *name,
41812 umode_t mode,
41813 ssize_t (*show)(struct device *dev,
41814 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41815 dev_attr->store = store;
41816 }
41817
41818 -static void pmbus_attr_init(struct sensor_device_attribute *a,
41819 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41820 const char *name,
41821 umode_t mode,
41822 ssize_t (*show)(struct device *dev,
41823 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41824 u16 reg, u8 mask)
41825 {
41826 struct pmbus_boolean *boolean;
41827 - struct sensor_device_attribute *a;
41828 + sensor_device_attribute_no_const *a;
41829
41830 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41831 if (!boolean)
41832 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41833 bool update, bool readonly)
41834 {
41835 struct pmbus_sensor *sensor;
41836 - struct device_attribute *a;
41837 + device_attribute_no_const *a;
41838
41839 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41840 if (!sensor)
41841 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41842 const char *lstring, int index)
41843 {
41844 struct pmbus_label *label;
41845 - struct device_attribute *a;
41846 + device_attribute_no_const *a;
41847
41848 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41849 if (!label)
41850 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41851 index 97cd45a..ac54d8b 100644
41852 --- a/drivers/hwmon/sht15.c
41853 +++ b/drivers/hwmon/sht15.c
41854 @@ -169,7 +169,7 @@ struct sht15_data {
41855 int supply_uv;
41856 bool supply_uv_valid;
41857 struct work_struct update_supply_work;
41858 - atomic_t interrupt_handled;
41859 + atomic_unchecked_t interrupt_handled;
41860 };
41861
41862 /**
41863 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41864 ret = gpio_direction_input(data->pdata->gpio_data);
41865 if (ret)
41866 return ret;
41867 - atomic_set(&data->interrupt_handled, 0);
41868 + atomic_set_unchecked(&data->interrupt_handled, 0);
41869
41870 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41871 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41872 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41873 /* Only relevant if the interrupt hasn't occurred. */
41874 - if (!atomic_read(&data->interrupt_handled))
41875 + if (!atomic_read_unchecked(&data->interrupt_handled))
41876 schedule_work(&data->read_work);
41877 }
41878 ret = wait_event_timeout(data->wait_queue,
41879 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41880
41881 /* First disable the interrupt */
41882 disable_irq_nosync(irq);
41883 - atomic_inc(&data->interrupt_handled);
41884 + atomic_inc_unchecked(&data->interrupt_handled);
41885 /* Then schedule a reading work struct */
41886 if (data->state != SHT15_READING_NOTHING)
41887 schedule_work(&data->read_work);
41888 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41889 * If not, then start the interrupt again - care here as could
41890 * have gone low in meantime so verify it hasn't!
41891 */
41892 - atomic_set(&data->interrupt_handled, 0);
41893 + atomic_set_unchecked(&data->interrupt_handled, 0);
41894 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41895 /* If still not occurred or another handler was scheduled */
41896 if (gpio_get_value(data->pdata->gpio_data)
41897 - || atomic_read(&data->interrupt_handled))
41898 + || atomic_read_unchecked(&data->interrupt_handled))
41899 return;
41900 }
41901
41902 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41903 index 8df43c5..b07b91d 100644
41904 --- a/drivers/hwmon/via-cputemp.c
41905 +++ b/drivers/hwmon/via-cputemp.c
41906 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41907 return NOTIFY_OK;
41908 }
41909
41910 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41911 +static struct notifier_block via_cputemp_cpu_notifier = {
41912 .notifier_call = via_cputemp_cpu_callback,
41913 };
41914
41915 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41916 index 41fc683..a39cfea 100644
41917 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
41918 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41919 @@ -43,7 +43,7 @@
41920 extern struct i2c_adapter amd756_smbus;
41921
41922 static struct i2c_adapter *s4882_adapter;
41923 -static struct i2c_algorithm *s4882_algo;
41924 +static i2c_algorithm_no_const *s4882_algo;
41925
41926 /* Wrapper access functions for multiplexed SMBus */
41927 static DEFINE_MUTEX(amd756_lock);
41928 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41929 index 721f7eb..0fd2a09 100644
41930 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
41931 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41932 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41933 /* usb layer */
41934
41935 /* Send command to device, and get response. */
41936 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41937 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41938 {
41939 int ret = 0;
41940 int actual;
41941 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41942 index b170bdf..3c76427 100644
41943 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41944 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41945 @@ -41,7 +41,7 @@
41946 extern struct i2c_adapter *nforce2_smbus;
41947
41948 static struct i2c_adapter *s4985_adapter;
41949 -static struct i2c_algorithm *s4985_algo;
41950 +static i2c_algorithm_no_const *s4985_algo;
41951
41952 /* Wrapper access functions for multiplexed SMBus */
41953 static DEFINE_MUTEX(nforce2_lock);
41954 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41955 index 80b47e8..1a6040d9 100644
41956 --- a/drivers/i2c/i2c-dev.c
41957 +++ b/drivers/i2c/i2c-dev.c
41958 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41959 break;
41960 }
41961
41962 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41963 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41964 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41965 if (IS_ERR(rdwr_pa[i].buf)) {
41966 res = PTR_ERR(rdwr_pa[i].buf);
41967 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41968 index 0b510ba..4fbb5085 100644
41969 --- a/drivers/ide/ide-cd.c
41970 +++ b/drivers/ide/ide-cd.c
41971 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41972 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41973 if ((unsigned long)buf & alignment
41974 || blk_rq_bytes(rq) & q->dma_pad_mask
41975 - || object_is_on_stack(buf))
41976 + || object_starts_on_stack(buf))
41977 drive->dma = 0;
41978 }
41979 }
41980 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41981 index ede16aec..e423e8a 100644
41982 --- a/drivers/iio/industrialio-core.c
41983 +++ b/drivers/iio/industrialio-core.c
41984 @@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41985 }
41986
41987 static
41988 -int __iio_device_attr_init(struct device_attribute *dev_attr,
41989 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41990 const char *postfix,
41991 struct iio_chan_spec const *chan,
41992 ssize_t (*readfunc)(struct device *dev,
41993 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41994 index c323917..6ddea8b 100644
41995 --- a/drivers/infiniband/core/cm.c
41996 +++ b/drivers/infiniband/core/cm.c
41997 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41998
41999 struct cm_counter_group {
42000 struct kobject obj;
42001 - atomic_long_t counter[CM_ATTR_COUNT];
42002 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42003 };
42004
42005 struct cm_counter_attribute {
42006 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42007 struct ib_mad_send_buf *msg = NULL;
42008 int ret;
42009
42010 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42011 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42012 counter[CM_REQ_COUNTER]);
42013
42014 /* Quick state check to discard duplicate REQs. */
42015 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42016 if (!cm_id_priv)
42017 return;
42018
42019 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42020 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42021 counter[CM_REP_COUNTER]);
42022 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42023 if (ret)
42024 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42025 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42026 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42027 spin_unlock_irq(&cm_id_priv->lock);
42028 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42029 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42030 counter[CM_RTU_COUNTER]);
42031 goto out;
42032 }
42033 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42034 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42035 dreq_msg->local_comm_id);
42036 if (!cm_id_priv) {
42037 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42038 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42039 counter[CM_DREQ_COUNTER]);
42040 cm_issue_drep(work->port, work->mad_recv_wc);
42041 return -EINVAL;
42042 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42043 case IB_CM_MRA_REP_RCVD:
42044 break;
42045 case IB_CM_TIMEWAIT:
42046 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42047 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42048 counter[CM_DREQ_COUNTER]);
42049 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42050 goto unlock;
42051 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42052 cm_free_msg(msg);
42053 goto deref;
42054 case IB_CM_DREQ_RCVD:
42055 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42056 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42057 counter[CM_DREQ_COUNTER]);
42058 goto unlock;
42059 default:
42060 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42061 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42062 cm_id_priv->msg, timeout)) {
42063 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42064 - atomic_long_inc(&work->port->
42065 + atomic_long_inc_unchecked(&work->port->
42066 counter_group[CM_RECV_DUPLICATES].
42067 counter[CM_MRA_COUNTER]);
42068 goto out;
42069 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42070 break;
42071 case IB_CM_MRA_REQ_RCVD:
42072 case IB_CM_MRA_REP_RCVD:
42073 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42074 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42075 counter[CM_MRA_COUNTER]);
42076 /* fall through */
42077 default:
42078 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42079 case IB_CM_LAP_IDLE:
42080 break;
42081 case IB_CM_MRA_LAP_SENT:
42082 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42083 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42084 counter[CM_LAP_COUNTER]);
42085 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42086 goto unlock;
42087 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42088 cm_free_msg(msg);
42089 goto deref;
42090 case IB_CM_LAP_RCVD:
42091 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42092 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42093 counter[CM_LAP_COUNTER]);
42094 goto unlock;
42095 default:
42096 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42097 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42098 if (cur_cm_id_priv) {
42099 spin_unlock_irq(&cm.lock);
42100 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42101 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42102 counter[CM_SIDR_REQ_COUNTER]);
42103 goto out; /* Duplicate message. */
42104 }
42105 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42106 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42107 msg->retries = 1;
42108
42109 - atomic_long_add(1 + msg->retries,
42110 + atomic_long_add_unchecked(1 + msg->retries,
42111 &port->counter_group[CM_XMIT].counter[attr_index]);
42112 if (msg->retries)
42113 - atomic_long_add(msg->retries,
42114 + atomic_long_add_unchecked(msg->retries,
42115 &port->counter_group[CM_XMIT_RETRIES].
42116 counter[attr_index]);
42117
42118 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42119 }
42120
42121 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42122 - atomic_long_inc(&port->counter_group[CM_RECV].
42123 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42124 counter[attr_id - CM_ATTR_ID_OFFSET]);
42125
42126 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42127 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42128 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42129
42130 return sprintf(buf, "%ld\n",
42131 - atomic_long_read(&group->counter[cm_attr->index]));
42132 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42133 }
42134
42135 static const struct sysfs_ops cm_counter_ops = {
42136 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42137 index 9f5ad7c..588cd84 100644
42138 --- a/drivers/infiniband/core/fmr_pool.c
42139 +++ b/drivers/infiniband/core/fmr_pool.c
42140 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42141
42142 struct task_struct *thread;
42143
42144 - atomic_t req_ser;
42145 - atomic_t flush_ser;
42146 + atomic_unchecked_t req_ser;
42147 + atomic_unchecked_t flush_ser;
42148
42149 wait_queue_head_t force_wait;
42150 };
42151 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42152 struct ib_fmr_pool *pool = pool_ptr;
42153
42154 do {
42155 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42156 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42157 ib_fmr_batch_release(pool);
42158
42159 - atomic_inc(&pool->flush_ser);
42160 + atomic_inc_unchecked(&pool->flush_ser);
42161 wake_up_interruptible(&pool->force_wait);
42162
42163 if (pool->flush_function)
42164 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42165 }
42166
42167 set_current_state(TASK_INTERRUPTIBLE);
42168 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42169 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42170 !kthread_should_stop())
42171 schedule();
42172 __set_current_state(TASK_RUNNING);
42173 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42174 pool->dirty_watermark = params->dirty_watermark;
42175 pool->dirty_len = 0;
42176 spin_lock_init(&pool->pool_lock);
42177 - atomic_set(&pool->req_ser, 0);
42178 - atomic_set(&pool->flush_ser, 0);
42179 + atomic_set_unchecked(&pool->req_ser, 0);
42180 + atomic_set_unchecked(&pool->flush_ser, 0);
42181 init_waitqueue_head(&pool->force_wait);
42182
42183 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42184 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42185 }
42186 spin_unlock_irq(&pool->pool_lock);
42187
42188 - serial = atomic_inc_return(&pool->req_ser);
42189 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42190 wake_up_process(pool->thread);
42191
42192 if (wait_event_interruptible(pool->force_wait,
42193 - atomic_read(&pool->flush_ser) - serial >= 0))
42194 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42195 return -EINTR;
42196
42197 return 0;
42198 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42199 } else {
42200 list_add_tail(&fmr->list, &pool->dirty_list);
42201 if (++pool->dirty_len >= pool->dirty_watermark) {
42202 - atomic_inc(&pool->req_ser);
42203 + atomic_inc_unchecked(&pool->req_ser);
42204 wake_up_process(pool->thread);
42205 }
42206 }
42207 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42208 index ec7a298..8742e59 100644
42209 --- a/drivers/infiniband/hw/cxgb4/mem.c
42210 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42211 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42212 int err;
42213 struct fw_ri_tpte tpt;
42214 u32 stag_idx;
42215 - static atomic_t key;
42216 + static atomic_unchecked_t key;
42217
42218 if (c4iw_fatal_error(rdev))
42219 return -EIO;
42220 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42221 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42222 rdev->stats.stag.max = rdev->stats.stag.cur;
42223 mutex_unlock(&rdev->stats.lock);
42224 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42225 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42226 }
42227 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42228 __func__, stag_state, type, pdid, stag_idx);
42229 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42230 index 79b3dbc..96e5fcc 100644
42231 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42232 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42233 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42234 struct ib_atomic_eth *ateth;
42235 struct ipath_ack_entry *e;
42236 u64 vaddr;
42237 - atomic64_t *maddr;
42238 + atomic64_unchecked_t *maddr;
42239 u64 sdata;
42240 u32 rkey;
42241 u8 next;
42242 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42243 IB_ACCESS_REMOTE_ATOMIC)))
42244 goto nack_acc_unlck;
42245 /* Perform atomic OP and save result. */
42246 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42247 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42248 sdata = be64_to_cpu(ateth->swap_data);
42249 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42250 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42251 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42252 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42253 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42254 be64_to_cpu(ateth->compare_data),
42255 sdata);
42256 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42257 index 1f95bba..9530f87 100644
42258 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42259 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42260 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42261 unsigned long flags;
42262 struct ib_wc wc;
42263 u64 sdata;
42264 - atomic64_t *maddr;
42265 + atomic64_unchecked_t *maddr;
42266 enum ib_wc_status send_status;
42267
42268 /*
42269 @@ -382,11 +382,11 @@ again:
42270 IB_ACCESS_REMOTE_ATOMIC)))
42271 goto acc_err;
42272 /* Perform atomic OP and save result. */
42273 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42274 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42275 sdata = wqe->wr.wr.atomic.compare_add;
42276 *(u64 *) sqp->s_sge.sge.vaddr =
42277 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42278 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42279 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42280 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42281 sdata, wqe->wr.wr.atomic.swap);
42282 goto send_comp;
42283 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42284 index fd36ec6..a6a082f 100644
42285 --- a/drivers/infiniband/hw/mlx4/mad.c
42286 +++ b/drivers/infiniband/hw/mlx4/mad.c
42287 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42288
42289 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42290 {
42291 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42292 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42293 cpu_to_be64(0xff00000000000000LL);
42294 }
42295
42296 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42297 index ed327e6..ca1739e0 100644
42298 --- a/drivers/infiniband/hw/mlx4/mcg.c
42299 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42300 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42301 {
42302 char name[20];
42303
42304 - atomic_set(&ctx->tid, 0);
42305 + atomic_set_unchecked(&ctx->tid, 0);
42306 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42307 ctx->mcg_wq = create_singlethread_workqueue(name);
42308 if (!ctx->mcg_wq)
42309 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42310 index 66b0b7d..f14836a 100644
42311 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42312 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42313 @@ -425,7 +425,7 @@ struct mlx4_ib_demux_ctx {
42314 struct list_head mcg_mgid0_list;
42315 struct workqueue_struct *mcg_wq;
42316 struct mlx4_ib_demux_pv_ctx **tun;
42317 - atomic_t tid;
42318 + atomic_unchecked_t tid;
42319 int flushing; /* flushing the work queue */
42320 };
42321
42322 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42323 index 9d3e5c1..6f166df 100644
42324 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42325 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42326 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42327 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42328 }
42329
42330 -int mthca_QUERY_FW(struct mthca_dev *dev)
42331 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42332 {
42333 struct mthca_mailbox *mailbox;
42334 u32 *outbox;
42335 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42336 CMD_TIME_CLASS_B);
42337 }
42338
42339 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42340 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42341 int num_mtt)
42342 {
42343 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42344 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42345 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42346 }
42347
42348 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42349 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42350 int eq_num)
42351 {
42352 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42353 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42354 CMD_TIME_CLASS_B);
42355 }
42356
42357 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42358 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42359 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42360 void *in_mad, void *response_mad)
42361 {
42362 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42363 index ded76c1..0cf0a08 100644
42364 --- a/drivers/infiniband/hw/mthca/mthca_main.c
42365 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
42366 @@ -692,7 +692,7 @@ err_close:
42367 return err;
42368 }
42369
42370 -static int mthca_setup_hca(struct mthca_dev *dev)
42371 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42372 {
42373 int err;
42374
42375 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42376 index ed9a989..6aa5dc2 100644
42377 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
42378 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42379 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42380 * through the bitmaps)
42381 */
42382
42383 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42384 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42385 {
42386 int o;
42387 int m;
42388 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42389 return key;
42390 }
42391
42392 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42393 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42394 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42395 {
42396 struct mthca_mailbox *mailbox;
42397 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42398 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42399 }
42400
42401 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42402 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42403 u64 *buffer_list, int buffer_size_shift,
42404 int list_len, u64 iova, u64 total_size,
42405 u32 access, struct mthca_mr *mr)
42406 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42407 index 415f8e1..e34214e 100644
42408 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
42409 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42410 @@ -764,7 +764,7 @@ unlock:
42411 return 0;
42412 }
42413
42414 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42415 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42416 {
42417 struct mthca_dev *dev = to_mdev(ibcq->device);
42418 struct mthca_cq *cq = to_mcq(ibcq);
42419 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42420 index 353c7b0..c6ce921 100644
42421 --- a/drivers/infiniband/hw/nes/nes.c
42422 +++ b/drivers/infiniband/hw/nes/nes.c
42423 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42424 LIST_HEAD(nes_adapter_list);
42425 static LIST_HEAD(nes_dev_list);
42426
42427 -atomic_t qps_destroyed;
42428 +atomic_unchecked_t qps_destroyed;
42429
42430 static unsigned int ee_flsh_adapter;
42431 static unsigned int sysfs_nonidx_addr;
42432 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42433 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42434 struct nes_adapter *nesadapter = nesdev->nesadapter;
42435
42436 - atomic_inc(&qps_destroyed);
42437 + atomic_inc_unchecked(&qps_destroyed);
42438
42439 /* Free the control structures */
42440
42441 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42442 index 33cc589..3bd6538 100644
42443 --- a/drivers/infiniband/hw/nes/nes.h
42444 +++ b/drivers/infiniband/hw/nes/nes.h
42445 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42446 extern unsigned int wqm_quanta;
42447 extern struct list_head nes_adapter_list;
42448
42449 -extern atomic_t cm_connects;
42450 -extern atomic_t cm_accepts;
42451 -extern atomic_t cm_disconnects;
42452 -extern atomic_t cm_closes;
42453 -extern atomic_t cm_connecteds;
42454 -extern atomic_t cm_connect_reqs;
42455 -extern atomic_t cm_rejects;
42456 -extern atomic_t mod_qp_timouts;
42457 -extern atomic_t qps_created;
42458 -extern atomic_t qps_destroyed;
42459 -extern atomic_t sw_qps_destroyed;
42460 +extern atomic_unchecked_t cm_connects;
42461 +extern atomic_unchecked_t cm_accepts;
42462 +extern atomic_unchecked_t cm_disconnects;
42463 +extern atomic_unchecked_t cm_closes;
42464 +extern atomic_unchecked_t cm_connecteds;
42465 +extern atomic_unchecked_t cm_connect_reqs;
42466 +extern atomic_unchecked_t cm_rejects;
42467 +extern atomic_unchecked_t mod_qp_timouts;
42468 +extern atomic_unchecked_t qps_created;
42469 +extern atomic_unchecked_t qps_destroyed;
42470 +extern atomic_unchecked_t sw_qps_destroyed;
42471 extern u32 mh_detected;
42472 extern u32 mh_pauses_sent;
42473 extern u32 cm_packets_sent;
42474 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42475 extern u32 cm_packets_received;
42476 extern u32 cm_packets_dropped;
42477 extern u32 cm_packets_retrans;
42478 -extern atomic_t cm_listens_created;
42479 -extern atomic_t cm_listens_destroyed;
42480 +extern atomic_unchecked_t cm_listens_created;
42481 +extern atomic_unchecked_t cm_listens_destroyed;
42482 extern u32 cm_backlog_drops;
42483 -extern atomic_t cm_loopbacks;
42484 -extern atomic_t cm_nodes_created;
42485 -extern atomic_t cm_nodes_destroyed;
42486 -extern atomic_t cm_accel_dropped_pkts;
42487 -extern atomic_t cm_resets_recvd;
42488 -extern atomic_t pau_qps_created;
42489 -extern atomic_t pau_qps_destroyed;
42490 +extern atomic_unchecked_t cm_loopbacks;
42491 +extern atomic_unchecked_t cm_nodes_created;
42492 +extern atomic_unchecked_t cm_nodes_destroyed;
42493 +extern atomic_unchecked_t cm_accel_dropped_pkts;
42494 +extern atomic_unchecked_t cm_resets_recvd;
42495 +extern atomic_unchecked_t pau_qps_created;
42496 +extern atomic_unchecked_t pau_qps_destroyed;
42497
42498 extern u32 int_mod_timer_init;
42499 extern u32 int_mod_cq_depth_256;
42500 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42501 index dfa9df4..6bf7221 100644
42502 --- a/drivers/infiniband/hw/nes/nes_cm.c
42503 +++ b/drivers/infiniband/hw/nes/nes_cm.c
42504 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42505 u32 cm_packets_retrans;
42506 u32 cm_packets_created;
42507 u32 cm_packets_received;
42508 -atomic_t cm_listens_created;
42509 -atomic_t cm_listens_destroyed;
42510 +atomic_unchecked_t cm_listens_created;
42511 +atomic_unchecked_t cm_listens_destroyed;
42512 u32 cm_backlog_drops;
42513 -atomic_t cm_loopbacks;
42514 -atomic_t cm_nodes_created;
42515 -atomic_t cm_nodes_destroyed;
42516 -atomic_t cm_accel_dropped_pkts;
42517 -atomic_t cm_resets_recvd;
42518 +atomic_unchecked_t cm_loopbacks;
42519 +atomic_unchecked_t cm_nodes_created;
42520 +atomic_unchecked_t cm_nodes_destroyed;
42521 +atomic_unchecked_t cm_accel_dropped_pkts;
42522 +atomic_unchecked_t cm_resets_recvd;
42523
42524 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42525 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42526 @@ -134,28 +134,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
42527 /* instance of function pointers for client API */
42528 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42529 static struct nes_cm_ops nes_cm_api = {
42530 - mini_cm_accelerated,
42531 - mini_cm_listen,
42532 - mini_cm_del_listen,
42533 - mini_cm_connect,
42534 - mini_cm_close,
42535 - mini_cm_accept,
42536 - mini_cm_reject,
42537 - mini_cm_recv_pkt,
42538 - mini_cm_dealloc_core,
42539 - mini_cm_get,
42540 - mini_cm_set
42541 + .accelerated = mini_cm_accelerated,
42542 + .listen = mini_cm_listen,
42543 + .stop_listener = mini_cm_del_listen,
42544 + .connect = mini_cm_connect,
42545 + .close = mini_cm_close,
42546 + .accept = mini_cm_accept,
42547 + .reject = mini_cm_reject,
42548 + .recv_pkt = mini_cm_recv_pkt,
42549 + .destroy_cm_core = mini_cm_dealloc_core,
42550 + .get = mini_cm_get,
42551 + .set = mini_cm_set
42552 };
42553
42554 static struct nes_cm_core *g_cm_core;
42555
42556 -atomic_t cm_connects;
42557 -atomic_t cm_accepts;
42558 -atomic_t cm_disconnects;
42559 -atomic_t cm_closes;
42560 -atomic_t cm_connecteds;
42561 -atomic_t cm_connect_reqs;
42562 -atomic_t cm_rejects;
42563 +atomic_unchecked_t cm_connects;
42564 +atomic_unchecked_t cm_accepts;
42565 +atomic_unchecked_t cm_disconnects;
42566 +atomic_unchecked_t cm_closes;
42567 +atomic_unchecked_t cm_connecteds;
42568 +atomic_unchecked_t cm_connect_reqs;
42569 +atomic_unchecked_t cm_rejects;
42570
42571 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42572 {
42573 @@ -1319,7 +1319,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42574 kfree(listener);
42575 listener = NULL;
42576 ret = 0;
42577 - atomic_inc(&cm_listens_destroyed);
42578 + atomic_inc_unchecked(&cm_listens_destroyed);
42579 } else {
42580 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42581 }
42582 @@ -1513,7 +1513,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42583 cm_node->rem_mac);
42584
42585 add_hte_node(cm_core, cm_node);
42586 - atomic_inc(&cm_nodes_created);
42587 + atomic_inc_unchecked(&cm_nodes_created);
42588
42589 return cm_node;
42590 }
42591 @@ -1571,7 +1571,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42592 }
42593
42594 atomic_dec(&cm_core->node_cnt);
42595 - atomic_inc(&cm_nodes_destroyed);
42596 + atomic_inc_unchecked(&cm_nodes_destroyed);
42597 nesqp = cm_node->nesqp;
42598 if (nesqp) {
42599 nesqp->cm_node = NULL;
42600 @@ -1635,7 +1635,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42601
42602 static void drop_packet(struct sk_buff *skb)
42603 {
42604 - atomic_inc(&cm_accel_dropped_pkts);
42605 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42606 dev_kfree_skb_any(skb);
42607 }
42608
42609 @@ -1698,7 +1698,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42610 {
42611
42612 int reset = 0; /* whether to send reset in case of err.. */
42613 - atomic_inc(&cm_resets_recvd);
42614 + atomic_inc_unchecked(&cm_resets_recvd);
42615 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42616 " refcnt=%d\n", cm_node, cm_node->state,
42617 atomic_read(&cm_node->ref_count));
42618 @@ -2339,7 +2339,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42619 rem_ref_cm_node(cm_node->cm_core, cm_node);
42620 return NULL;
42621 }
42622 - atomic_inc(&cm_loopbacks);
42623 + atomic_inc_unchecked(&cm_loopbacks);
42624 loopbackremotenode->loopbackpartner = cm_node;
42625 loopbackremotenode->tcp_cntxt.rcv_wscale =
42626 NES_CM_DEFAULT_RCV_WND_SCALE;
42627 @@ -2614,7 +2614,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42628 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42629 else {
42630 rem_ref_cm_node(cm_core, cm_node);
42631 - atomic_inc(&cm_accel_dropped_pkts);
42632 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42633 dev_kfree_skb_any(skb);
42634 }
42635 break;
42636 @@ -2922,7 +2922,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42637
42638 if ((cm_id) && (cm_id->event_handler)) {
42639 if (issue_disconn) {
42640 - atomic_inc(&cm_disconnects);
42641 + atomic_inc_unchecked(&cm_disconnects);
42642 cm_event.event = IW_CM_EVENT_DISCONNECT;
42643 cm_event.status = disconn_status;
42644 cm_event.local_addr = cm_id->local_addr;
42645 @@ -2944,7 +2944,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42646 }
42647
42648 if (issue_close) {
42649 - atomic_inc(&cm_closes);
42650 + atomic_inc_unchecked(&cm_closes);
42651 nes_disconnect(nesqp, 1);
42652
42653 cm_id->provider_data = nesqp;
42654 @@ -3082,7 +3082,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42655
42656 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42657 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42658 - atomic_inc(&cm_accepts);
42659 + atomic_inc_unchecked(&cm_accepts);
42660
42661 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42662 netdev_refcnt_read(nesvnic->netdev));
42663 @@ -3278,7 +3278,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42664 struct nes_cm_core *cm_core;
42665 u8 *start_buff;
42666
42667 - atomic_inc(&cm_rejects);
42668 + atomic_inc_unchecked(&cm_rejects);
42669 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42670 loopback = cm_node->loopbackpartner;
42671 cm_core = cm_node->cm_core;
42672 @@ -3340,7 +3340,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42673 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42674 ntohs(laddr->sin_port));
42675
42676 - atomic_inc(&cm_connects);
42677 + atomic_inc_unchecked(&cm_connects);
42678 nesqp->active_conn = 1;
42679
42680 /* cache the cm_id in the qp */
42681 @@ -3451,7 +3451,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42682 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42683 return err;
42684 }
42685 - atomic_inc(&cm_listens_created);
42686 + atomic_inc_unchecked(&cm_listens_created);
42687 }
42688
42689 cm_id->add_ref(cm_id);
42690 @@ -3558,7 +3558,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42691
42692 if (nesqp->destroyed)
42693 return;
42694 - atomic_inc(&cm_connecteds);
42695 + atomic_inc_unchecked(&cm_connecteds);
42696 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42697 " local port 0x%04X. jiffies = %lu.\n",
42698 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42699 @@ -3741,7 +3741,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42700
42701 cm_id->add_ref(cm_id);
42702 ret = cm_id->event_handler(cm_id, &cm_event);
42703 - atomic_inc(&cm_closes);
42704 + atomic_inc_unchecked(&cm_closes);
42705 cm_event.event = IW_CM_EVENT_CLOSE;
42706 cm_event.status = 0;
42707 cm_event.provider_data = cm_id->provider_data;
42708 @@ -3781,7 +3781,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42709 return;
42710 cm_id = cm_node->cm_id;
42711
42712 - atomic_inc(&cm_connect_reqs);
42713 + atomic_inc_unchecked(&cm_connect_reqs);
42714 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42715 cm_node, cm_id, jiffies);
42716
42717 @@ -3830,7 +3830,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42718 return;
42719 cm_id = cm_node->cm_id;
42720
42721 - atomic_inc(&cm_connect_reqs);
42722 + atomic_inc_unchecked(&cm_connect_reqs);
42723 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42724 cm_node, cm_id, jiffies);
42725
42726 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42727 index 4166452..fc952c3 100644
42728 --- a/drivers/infiniband/hw/nes/nes_mgt.c
42729 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
42730 @@ -40,8 +40,8 @@
42731 #include "nes.h"
42732 #include "nes_mgt.h"
42733
42734 -atomic_t pau_qps_created;
42735 -atomic_t pau_qps_destroyed;
42736 +atomic_unchecked_t pau_qps_created;
42737 +atomic_unchecked_t pau_qps_destroyed;
42738
42739 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42740 {
42741 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42742 {
42743 struct sk_buff *skb;
42744 unsigned long flags;
42745 - atomic_inc(&pau_qps_destroyed);
42746 + atomic_inc_unchecked(&pau_qps_destroyed);
42747
42748 /* Free packets that have not yet been forwarded */
42749 /* Lock is acquired by skb_dequeue when removing the skb */
42750 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42751 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42752 skb_queue_head_init(&nesqp->pau_list);
42753 spin_lock_init(&nesqp->pau_lock);
42754 - atomic_inc(&pau_qps_created);
42755 + atomic_inc_unchecked(&pau_qps_created);
42756 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42757 }
42758
42759 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42760 index 49eb511..a774366 100644
42761 --- a/drivers/infiniband/hw/nes/nes_nic.c
42762 +++ b/drivers/infiniband/hw/nes/nes_nic.c
42763 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42764 target_stat_values[++index] = mh_detected;
42765 target_stat_values[++index] = mh_pauses_sent;
42766 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42767 - target_stat_values[++index] = atomic_read(&cm_connects);
42768 - target_stat_values[++index] = atomic_read(&cm_accepts);
42769 - target_stat_values[++index] = atomic_read(&cm_disconnects);
42770 - target_stat_values[++index] = atomic_read(&cm_connecteds);
42771 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42772 - target_stat_values[++index] = atomic_read(&cm_rejects);
42773 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42774 - target_stat_values[++index] = atomic_read(&qps_created);
42775 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42776 - target_stat_values[++index] = atomic_read(&qps_destroyed);
42777 - target_stat_values[++index] = atomic_read(&cm_closes);
42778 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42779 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42780 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42781 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42782 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42783 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42784 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42785 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42786 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42787 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42788 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42789 target_stat_values[++index] = cm_packets_sent;
42790 target_stat_values[++index] = cm_packets_bounced;
42791 target_stat_values[++index] = cm_packets_created;
42792 target_stat_values[++index] = cm_packets_received;
42793 target_stat_values[++index] = cm_packets_dropped;
42794 target_stat_values[++index] = cm_packets_retrans;
42795 - target_stat_values[++index] = atomic_read(&cm_listens_created);
42796 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42797 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42798 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42799 target_stat_values[++index] = cm_backlog_drops;
42800 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
42801 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
42802 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42803 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42804 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42805 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42806 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42807 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42808 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42809 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42810 target_stat_values[++index] = nesadapter->free_4kpbl;
42811 target_stat_values[++index] = nesadapter->free_256pbl;
42812 target_stat_values[++index] = int_mod_timer_init;
42813 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42814 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42815 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42816 - target_stat_values[++index] = atomic_read(&pau_qps_created);
42817 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42818 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42819 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42820 }
42821
42822 /**
42823 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42824 index 218dd35..97ce31d 100644
42825 --- a/drivers/infiniband/hw/nes/nes_verbs.c
42826 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
42827 @@ -46,9 +46,9 @@
42828
42829 #include <rdma/ib_umem.h>
42830
42831 -atomic_t mod_qp_timouts;
42832 -atomic_t qps_created;
42833 -atomic_t sw_qps_destroyed;
42834 +atomic_unchecked_t mod_qp_timouts;
42835 +atomic_unchecked_t qps_created;
42836 +atomic_unchecked_t sw_qps_destroyed;
42837
42838 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42839
42840 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42841 if (init_attr->create_flags)
42842 return ERR_PTR(-EINVAL);
42843
42844 - atomic_inc(&qps_created);
42845 + atomic_inc_unchecked(&qps_created);
42846 switch (init_attr->qp_type) {
42847 case IB_QPT_RC:
42848 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42849 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42850 struct iw_cm_event cm_event;
42851 int ret = 0;
42852
42853 - atomic_inc(&sw_qps_destroyed);
42854 + atomic_inc_unchecked(&sw_qps_destroyed);
42855 nesqp->destroyed = 1;
42856
42857 /* Blow away the connection if it exists. */
42858 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42859 index c00ae09..04e91be 100644
42860 --- a/drivers/infiniband/hw/qib/qib.h
42861 +++ b/drivers/infiniband/hw/qib/qib.h
42862 @@ -52,6 +52,7 @@
42863 #include <linux/kref.h>
42864 #include <linux/sched.h>
42865 #include <linux/kthread.h>
42866 +#include <linux/slab.h>
42867
42868 #include "qib_common.h"
42869 #include "qib_verbs.h"
42870 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42871 index 24c41ba..102d71f 100644
42872 --- a/drivers/input/gameport/gameport.c
42873 +++ b/drivers/input/gameport/gameport.c
42874 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42875 */
42876 static void gameport_init_port(struct gameport *gameport)
42877 {
42878 - static atomic_t gameport_no = ATOMIC_INIT(0);
42879 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42880
42881 __module_get(THIS_MODULE);
42882
42883 mutex_init(&gameport->drv_mutex);
42884 device_initialize(&gameport->dev);
42885 dev_set_name(&gameport->dev, "gameport%lu",
42886 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
42887 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42888 gameport->dev.bus = &gameport_bus;
42889 gameport->dev.release = gameport_release_port;
42890 if (gameport->parent)
42891 diff --git a/drivers/input/input.c b/drivers/input/input.c
42892 index 1c4c0db..6f7abe3 100644
42893 --- a/drivers/input/input.c
42894 +++ b/drivers/input/input.c
42895 @@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
42896 */
42897 struct input_dev *input_allocate_device(void)
42898 {
42899 - static atomic_t input_no = ATOMIC_INIT(0);
42900 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42901 struct input_dev *dev;
42902
42903 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42904 @@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
42905 INIT_LIST_HEAD(&dev->node);
42906
42907 dev_set_name(&dev->dev, "input%ld",
42908 - (unsigned long) atomic_inc_return(&input_no) - 1);
42909 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42910
42911 __module_get(THIS_MODULE);
42912 }
42913 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42914 index 4a95b22..874c182 100644
42915 --- a/drivers/input/joystick/sidewinder.c
42916 +++ b/drivers/input/joystick/sidewinder.c
42917 @@ -30,6 +30,7 @@
42918 #include <linux/kernel.h>
42919 #include <linux/module.h>
42920 #include <linux/slab.h>
42921 +#include <linux/sched.h>
42922 #include <linux/input.h>
42923 #include <linux/gameport.h>
42924 #include <linux/jiffies.h>
42925 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42926 index 603fe0d..f63decc 100644
42927 --- a/drivers/input/joystick/xpad.c
42928 +++ b/drivers/input/joystick/xpad.c
42929 @@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42930
42931 static int xpad_led_probe(struct usb_xpad *xpad)
42932 {
42933 - static atomic_t led_seq = ATOMIC_INIT(0);
42934 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42935 long led_no;
42936 struct xpad_led *led;
42937 struct led_classdev *led_cdev;
42938 @@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42939 if (!led)
42940 return -ENOMEM;
42941
42942 - led_no = (long)atomic_inc_return(&led_seq) - 1;
42943 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42944
42945 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42946 led->xpad = xpad;
42947 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42948 index 5a73639..d586683 100644
42949 --- a/drivers/input/misc/ims-pcu.c
42950 +++ b/drivers/input/misc/ims-pcu.c
42951 @@ -1850,7 +1850,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42952
42953 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42954 {
42955 - static atomic_t device_no = ATOMIC_INIT(0);
42956 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42957
42958 const struct ims_pcu_device_info *info;
42959 int error;
42960 @@ -1881,7 +1881,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42961 }
42962
42963 /* Device appears to be operable, complete initialization */
42964 - pcu->device_no = atomic_inc_return(&device_no) - 1;
42965 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42966
42967 /*
42968 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
42969 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42970 index 2f0b39d..7370f13 100644
42971 --- a/drivers/input/mouse/psmouse.h
42972 +++ b/drivers/input/mouse/psmouse.h
42973 @@ -116,7 +116,7 @@ struct psmouse_attribute {
42974 ssize_t (*set)(struct psmouse *psmouse, void *data,
42975 const char *buf, size_t count);
42976 bool protect;
42977 -};
42978 +} __do_const;
42979 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42980
42981 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42982 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42983 index b604564..3f14ae4 100644
42984 --- a/drivers/input/mousedev.c
42985 +++ b/drivers/input/mousedev.c
42986 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42987
42988 spin_unlock_irq(&client->packet_lock);
42989
42990 - if (copy_to_user(buffer, data, count))
42991 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
42992 return -EFAULT;
42993
42994 return count;
42995 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42996 index b29134d..394deb0 100644
42997 --- a/drivers/input/serio/serio.c
42998 +++ b/drivers/input/serio/serio.c
42999 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43000 */
43001 static void serio_init_port(struct serio *serio)
43002 {
43003 - static atomic_t serio_no = ATOMIC_INIT(0);
43004 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43005
43006 __module_get(THIS_MODULE);
43007
43008 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43009 mutex_init(&serio->drv_mutex);
43010 device_initialize(&serio->dev);
43011 dev_set_name(&serio->dev, "serio%ld",
43012 - (long)atomic_inc_return(&serio_no) - 1);
43013 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
43014 serio->dev.bus = &serio_bus;
43015 serio->dev.release = serio_release_port;
43016 serio->dev.groups = serio_device_attr_groups;
43017 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43018 index c9a02fe..0debc75 100644
43019 --- a/drivers/input/serio/serio_raw.c
43020 +++ b/drivers/input/serio/serio_raw.c
43021 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43022
43023 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43024 {
43025 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
43026 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43027 struct serio_raw *serio_raw;
43028 int err;
43029
43030 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43031 }
43032
43033 snprintf(serio_raw->name, sizeof(serio_raw->name),
43034 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43035 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43036 kref_init(&serio_raw->kref);
43037 INIT_LIST_HEAD(&serio_raw->client_list);
43038 init_waitqueue_head(&serio_raw->wait);
43039 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43040 index e5555fc..937986d 100644
43041 --- a/drivers/iommu/iommu.c
43042 +++ b/drivers/iommu/iommu.c
43043 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43044 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43045 {
43046 bus_register_notifier(bus, &iommu_bus_nb);
43047 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43048 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43049 }
43050
43051 /**
43052 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43053 index 228632c9..edfe331 100644
43054 --- a/drivers/iommu/irq_remapping.c
43055 +++ b/drivers/iommu/irq_remapping.c
43056 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43057 void panic_if_irq_remap(const char *msg)
43058 {
43059 if (irq_remapping_enabled)
43060 - panic(msg);
43061 + panic("%s", msg);
43062 }
43063
43064 static void ir_ack_apic_edge(struct irq_data *data)
43065 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43066
43067 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43068 {
43069 - chip->irq_print_chip = ir_print_prefix;
43070 - chip->irq_ack = ir_ack_apic_edge;
43071 - chip->irq_eoi = ir_ack_apic_level;
43072 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43073 + pax_open_kernel();
43074 + *(void **)&chip->irq_print_chip = ir_print_prefix;
43075 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
43076 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
43077 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43078 + pax_close_kernel();
43079 }
43080
43081 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43082 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43083 index 57d165e..611997e 100644
43084 --- a/drivers/irqchip/irq-gic.c
43085 +++ b/drivers/irqchip/irq-gic.c
43086 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43087 * Supported arch specific GIC irq extension.
43088 * Default make them NULL.
43089 */
43090 -struct irq_chip gic_arch_extn = {
43091 +irq_chip_no_const gic_arch_extn = {
43092 .irq_eoi = NULL,
43093 .irq_mask = NULL,
43094 .irq_unmask = NULL,
43095 @@ -336,7 +336,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43096 chained_irq_exit(chip, desc);
43097 }
43098
43099 -static struct irq_chip gic_chip = {
43100 +static irq_chip_no_const gic_chip __read_only = {
43101 .name = "GIC",
43102 .irq_mask = gic_mask_irq,
43103 .irq_unmask = gic_unmask_irq,
43104 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43105 index 8777065..a4a9967 100644
43106 --- a/drivers/irqchip/irq-renesas-irqc.c
43107 +++ b/drivers/irqchip/irq-renesas-irqc.c
43108 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43109 struct irqc_priv *p;
43110 struct resource *io;
43111 struct resource *irq;
43112 - struct irq_chip *irq_chip;
43113 + irq_chip_no_const *irq_chip;
43114 const char *name = dev_name(&pdev->dev);
43115 int ret;
43116 int k;
43117 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43118 index ac6f72b..81150f2 100644
43119 --- a/drivers/isdn/capi/capi.c
43120 +++ b/drivers/isdn/capi/capi.c
43121 @@ -81,8 +81,8 @@ struct capiminor {
43122
43123 struct capi20_appl *ap;
43124 u32 ncci;
43125 - atomic_t datahandle;
43126 - atomic_t msgid;
43127 + atomic_unchecked_t datahandle;
43128 + atomic_unchecked_t msgid;
43129
43130 struct tty_port port;
43131 int ttyinstop;
43132 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43133 capimsg_setu16(s, 2, mp->ap->applid);
43134 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43135 capimsg_setu8 (s, 5, CAPI_RESP);
43136 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43137 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43138 capimsg_setu32(s, 8, mp->ncci);
43139 capimsg_setu16(s, 12, datahandle);
43140 }
43141 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43142 mp->outbytes -= len;
43143 spin_unlock_bh(&mp->outlock);
43144
43145 - datahandle = atomic_inc_return(&mp->datahandle);
43146 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43147 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43148 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43149 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43150 capimsg_setu16(skb->data, 2, mp->ap->applid);
43151 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43152 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43153 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43154 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43155 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43156 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43157 capimsg_setu16(skb->data, 16, len); /* Data length */
43158 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43159 index c44950d..10ac276 100644
43160 --- a/drivers/isdn/gigaset/bas-gigaset.c
43161 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43162 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43163
43164
43165 static const struct gigaset_ops gigops = {
43166 - gigaset_write_cmd,
43167 - gigaset_write_room,
43168 - gigaset_chars_in_buffer,
43169 - gigaset_brkchars,
43170 - gigaset_init_bchannel,
43171 - gigaset_close_bchannel,
43172 - gigaset_initbcshw,
43173 - gigaset_freebcshw,
43174 - gigaset_reinitbcshw,
43175 - gigaset_initcshw,
43176 - gigaset_freecshw,
43177 - gigaset_set_modem_ctrl,
43178 - gigaset_baud_rate,
43179 - gigaset_set_line_ctrl,
43180 - gigaset_isoc_send_skb,
43181 - gigaset_isoc_input,
43182 + .write_cmd = gigaset_write_cmd,
43183 + .write_room = gigaset_write_room,
43184 + .chars_in_buffer = gigaset_chars_in_buffer,
43185 + .brkchars = gigaset_brkchars,
43186 + .init_bchannel = gigaset_init_bchannel,
43187 + .close_bchannel = gigaset_close_bchannel,
43188 + .initbcshw = gigaset_initbcshw,
43189 + .freebcshw = gigaset_freebcshw,
43190 + .reinitbcshw = gigaset_reinitbcshw,
43191 + .initcshw = gigaset_initcshw,
43192 + .freecshw = gigaset_freecshw,
43193 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43194 + .baud_rate = gigaset_baud_rate,
43195 + .set_line_ctrl = gigaset_set_line_ctrl,
43196 + .send_skb = gigaset_isoc_send_skb,
43197 + .handle_input = gigaset_isoc_input,
43198 };
43199
43200 /* bas_gigaset_init
43201 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43202 index 600c79b..3752bab 100644
43203 --- a/drivers/isdn/gigaset/interface.c
43204 +++ b/drivers/isdn/gigaset/interface.c
43205 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43206 }
43207 tty->driver_data = cs;
43208
43209 - ++cs->port.count;
43210 + atomic_inc(&cs->port.count);
43211
43212 - if (cs->port.count == 1) {
43213 + if (atomic_read(&cs->port.count) == 1) {
43214 tty_port_tty_set(&cs->port, tty);
43215 cs->port.low_latency = 1;
43216 }
43217 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43218
43219 if (!cs->connected)
43220 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43221 - else if (!cs->port.count)
43222 + else if (!atomic_read(&cs->port.count))
43223 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43224 - else if (!--cs->port.count)
43225 + else if (!atomic_dec_return(&cs->port.count))
43226 tty_port_tty_set(&cs->port, NULL);
43227
43228 mutex_unlock(&cs->mutex);
43229 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43230 index 8c91fd5..14f13ce 100644
43231 --- a/drivers/isdn/gigaset/ser-gigaset.c
43232 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43233 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43234 }
43235
43236 static const struct gigaset_ops ops = {
43237 - gigaset_write_cmd,
43238 - gigaset_write_room,
43239 - gigaset_chars_in_buffer,
43240 - gigaset_brkchars,
43241 - gigaset_init_bchannel,
43242 - gigaset_close_bchannel,
43243 - gigaset_initbcshw,
43244 - gigaset_freebcshw,
43245 - gigaset_reinitbcshw,
43246 - gigaset_initcshw,
43247 - gigaset_freecshw,
43248 - gigaset_set_modem_ctrl,
43249 - gigaset_baud_rate,
43250 - gigaset_set_line_ctrl,
43251 - gigaset_m10x_send_skb, /* asyncdata.c */
43252 - gigaset_m10x_input, /* asyncdata.c */
43253 + .write_cmd = gigaset_write_cmd,
43254 + .write_room = gigaset_write_room,
43255 + .chars_in_buffer = gigaset_chars_in_buffer,
43256 + .brkchars = gigaset_brkchars,
43257 + .init_bchannel = gigaset_init_bchannel,
43258 + .close_bchannel = gigaset_close_bchannel,
43259 + .initbcshw = gigaset_initbcshw,
43260 + .freebcshw = gigaset_freebcshw,
43261 + .reinitbcshw = gigaset_reinitbcshw,
43262 + .initcshw = gigaset_initcshw,
43263 + .freecshw = gigaset_freecshw,
43264 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43265 + .baud_rate = gigaset_baud_rate,
43266 + .set_line_ctrl = gigaset_set_line_ctrl,
43267 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43268 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43269 };
43270
43271
43272 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43273 index d0a41cb..b953e50 100644
43274 --- a/drivers/isdn/gigaset/usb-gigaset.c
43275 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43276 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43277 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43278 memcpy(cs->hw.usb->bchars, buf, 6);
43279 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43280 - 0, 0, &buf, 6, 2000);
43281 + 0, 0, buf, 6, 2000);
43282 }
43283
43284 static void gigaset_freebcshw(struct bc_state *bcs)
43285 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43286 }
43287
43288 static const struct gigaset_ops ops = {
43289 - gigaset_write_cmd,
43290 - gigaset_write_room,
43291 - gigaset_chars_in_buffer,
43292 - gigaset_brkchars,
43293 - gigaset_init_bchannel,
43294 - gigaset_close_bchannel,
43295 - gigaset_initbcshw,
43296 - gigaset_freebcshw,
43297 - gigaset_reinitbcshw,
43298 - gigaset_initcshw,
43299 - gigaset_freecshw,
43300 - gigaset_set_modem_ctrl,
43301 - gigaset_baud_rate,
43302 - gigaset_set_line_ctrl,
43303 - gigaset_m10x_send_skb,
43304 - gigaset_m10x_input,
43305 + .write_cmd = gigaset_write_cmd,
43306 + .write_room = gigaset_write_room,
43307 + .chars_in_buffer = gigaset_chars_in_buffer,
43308 + .brkchars = gigaset_brkchars,
43309 + .init_bchannel = gigaset_init_bchannel,
43310 + .close_bchannel = gigaset_close_bchannel,
43311 + .initbcshw = gigaset_initbcshw,
43312 + .freebcshw = gigaset_freebcshw,
43313 + .reinitbcshw = gigaset_reinitbcshw,
43314 + .initcshw = gigaset_initcshw,
43315 + .freecshw = gigaset_freecshw,
43316 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43317 + .baud_rate = gigaset_baud_rate,
43318 + .set_line_ctrl = gigaset_set_line_ctrl,
43319 + .send_skb = gigaset_m10x_send_skb,
43320 + .handle_input = gigaset_m10x_input,
43321 };
43322
43323 /*
43324 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43325 index 4d9b195..455075c 100644
43326 --- a/drivers/isdn/hardware/avm/b1.c
43327 +++ b/drivers/isdn/hardware/avm/b1.c
43328 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43329 }
43330 if (left) {
43331 if (t4file->user) {
43332 - if (copy_from_user(buf, dp, left))
43333 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43334 return -EFAULT;
43335 } else {
43336 memcpy(buf, dp, left);
43337 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43338 }
43339 if (left) {
43340 if (config->user) {
43341 - if (copy_from_user(buf, dp, left))
43342 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43343 return -EFAULT;
43344 } else {
43345 memcpy(buf, dp, left);
43346 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43347 index 9b856e1..fa03c92 100644
43348 --- a/drivers/isdn/i4l/isdn_common.c
43349 +++ b/drivers/isdn/i4l/isdn_common.c
43350 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43351 } else
43352 return -EINVAL;
43353 case IIOCDBGVAR:
43354 + if (!capable(CAP_SYS_RAWIO))
43355 + return -EPERM;
43356 if (arg) {
43357 if (copy_to_user(argp, &dev, sizeof(ulong)))
43358 return -EFAULT;
43359 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43360 index 91d5730..336523e 100644
43361 --- a/drivers/isdn/i4l/isdn_concap.c
43362 +++ b/drivers/isdn/i4l/isdn_concap.c
43363 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43364 }
43365
43366 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43367 - &isdn_concap_dl_data_req,
43368 - &isdn_concap_dl_connect_req,
43369 - &isdn_concap_dl_disconn_req
43370 + .data_req = &isdn_concap_dl_data_req,
43371 + .connect_req = &isdn_concap_dl_connect_req,
43372 + .disconn_req = &isdn_concap_dl_disconn_req
43373 };
43374
43375 /* The following should better go into a dedicated source file such that
43376 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43377 index 3c5f249..5fac4d0 100644
43378 --- a/drivers/isdn/i4l/isdn_tty.c
43379 +++ b/drivers/isdn/i4l/isdn_tty.c
43380 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43381
43382 #ifdef ISDN_DEBUG_MODEM_OPEN
43383 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43384 - port->count);
43385 + atomic_read(&port->count));
43386 #endif
43387 - port->count++;
43388 + atomic_inc(&port->count);
43389 port->tty = tty;
43390 /*
43391 * Start up serial port
43392 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43393 #endif
43394 return;
43395 }
43396 - if ((tty->count == 1) && (port->count != 1)) {
43397 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43398 /*
43399 * Uh, oh. tty->count is 1, which means that the tty
43400 * structure will be freed. Info->count should always
43401 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43402 * serial port won't be shutdown.
43403 */
43404 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43405 - "info->count is %d\n", port->count);
43406 - port->count = 1;
43407 + "info->count is %d\n", atomic_read(&port->count));
43408 + atomic_set(&port->count, 1);
43409 }
43410 - if (--port->count < 0) {
43411 + if (atomic_dec_return(&port->count) < 0) {
43412 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43413 - info->line, port->count);
43414 - port->count = 0;
43415 + info->line, atomic_read(&port->count));
43416 + atomic_set(&port->count, 0);
43417 }
43418 - if (port->count) {
43419 + if (atomic_read(&port->count)) {
43420 #ifdef ISDN_DEBUG_MODEM_OPEN
43421 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43422 #endif
43423 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43424 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43425 return;
43426 isdn_tty_shutdown(info);
43427 - port->count = 0;
43428 + atomic_set(&port->count, 0);
43429 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43430 port->tty = NULL;
43431 wake_up_interruptible(&port->open_wait);
43432 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43433 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43434 modem_info *info = &dev->mdm.info[i];
43435
43436 - if (info->port.count == 0)
43437 + if (atomic_read(&info->port.count) == 0)
43438 continue;
43439 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43440 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43441 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43442 index e2d4e58..40cd045 100644
43443 --- a/drivers/isdn/i4l/isdn_x25iface.c
43444 +++ b/drivers/isdn/i4l/isdn_x25iface.c
43445 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43446
43447
43448 static struct concap_proto_ops ix25_pops = {
43449 - &isdn_x25iface_proto_new,
43450 - &isdn_x25iface_proto_del,
43451 - &isdn_x25iface_proto_restart,
43452 - &isdn_x25iface_proto_close,
43453 - &isdn_x25iface_xmit,
43454 - &isdn_x25iface_receive,
43455 - &isdn_x25iface_connect_ind,
43456 - &isdn_x25iface_disconn_ind
43457 + .proto_new = &isdn_x25iface_proto_new,
43458 + .proto_del = &isdn_x25iface_proto_del,
43459 + .restart = &isdn_x25iface_proto_restart,
43460 + .close = &isdn_x25iface_proto_close,
43461 + .encap_and_xmit = &isdn_x25iface_xmit,
43462 + .data_ind = &isdn_x25iface_receive,
43463 + .connect_ind = &isdn_x25iface_connect_ind,
43464 + .disconn_ind = &isdn_x25iface_disconn_ind
43465 };
43466
43467 /* error message helper function */
43468 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43469 index 6a7447c..cae33fe 100644
43470 --- a/drivers/isdn/icn/icn.c
43471 +++ b/drivers/isdn/icn/icn.c
43472 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43473 if (count > len)
43474 count = len;
43475 if (user) {
43476 - if (copy_from_user(msg, buf, count))
43477 + if (count > sizeof msg || copy_from_user(msg, buf, count))
43478 return -EFAULT;
43479 } else
43480 memcpy(msg, buf, count);
43481 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43482 index a4f05c5..1433bc5 100644
43483 --- a/drivers/isdn/mISDN/dsp_cmx.c
43484 +++ b/drivers/isdn/mISDN/dsp_cmx.c
43485 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43486 static u16 dsp_count; /* last sample count */
43487 static int dsp_count_valid; /* if we have last sample count */
43488
43489 -void
43490 +void __intentional_overflow(-1)
43491 dsp_cmx_send(void *arg)
43492 {
43493 struct dsp_conf *conf;
43494 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43495 index f58a354..fbae176 100644
43496 --- a/drivers/leds/leds-clevo-mail.c
43497 +++ b/drivers/leds/leds-clevo-mail.c
43498 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43499 * detected as working, but in reality it is not) as low as
43500 * possible.
43501 */
43502 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43503 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43504 {
43505 .callback = clevo_mail_led_dmi_callback,
43506 .ident = "Clevo D410J",
43507 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43508 index 2eb3ef6..295891f 100644
43509 --- a/drivers/leds/leds-ss4200.c
43510 +++ b/drivers/leds/leds-ss4200.c
43511 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43512 * detected as working, but in reality it is not) as low as
43513 * possible.
43514 */
43515 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
43516 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
43517 {
43518 .callback = ss4200_led_dmi_callback,
43519 .ident = "Intel SS4200-E",
43520 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43521 index 0bf1e4e..b4bf44e 100644
43522 --- a/drivers/lguest/core.c
43523 +++ b/drivers/lguest/core.c
43524 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
43525 * The end address needs +1 because __get_vm_area allocates an
43526 * extra guard page, so we need space for that.
43527 */
43528 +
43529 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43530 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43531 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43532 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43533 +#else
43534 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43535 VM_ALLOC, switcher_addr, switcher_addr
43536 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43537 +#endif
43538 +
43539 if (!switcher_vma) {
43540 err = -ENOMEM;
43541 printk("lguest: could not map switcher pages high\n");
43542 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
43543 * Now the Switcher is mapped at the right address, we can't fail!
43544 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43545 */
43546 - memcpy(switcher_vma->addr, start_switcher_text,
43547 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43548 end_switcher_text - start_switcher_text);
43549
43550 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43551 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43552 index e8b55c3..3514c37 100644
43553 --- a/drivers/lguest/page_tables.c
43554 +++ b/drivers/lguest/page_tables.c
43555 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43556 /*:*/
43557
43558 #ifdef CONFIG_X86_PAE
43559 -static void release_pmd(pmd_t *spmd)
43560 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43561 {
43562 /* If the entry's not present, there's nothing to release. */
43563 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43564 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43565 index 922a1ac..9dd0c2a 100644
43566 --- a/drivers/lguest/x86/core.c
43567 +++ b/drivers/lguest/x86/core.c
43568 @@ -59,7 +59,7 @@ static struct {
43569 /* Offset from where switcher.S was compiled to where we've copied it */
43570 static unsigned long switcher_offset(void)
43571 {
43572 - return switcher_addr - (unsigned long)start_switcher_text;
43573 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43574 }
43575
43576 /* This cpu's struct lguest_pages (after the Switcher text page) */
43577 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43578 * These copies are pretty cheap, so we do them unconditionally: */
43579 /* Save the current Host top-level page directory.
43580 */
43581 +
43582 +#ifdef CONFIG_PAX_PER_CPU_PGD
43583 + pages->state.host_cr3 = read_cr3();
43584 +#else
43585 pages->state.host_cr3 = __pa(current->mm->pgd);
43586 +#endif
43587 +
43588 /*
43589 * Set up the Guest's page tables to see this CPU's pages (and no
43590 * other CPU's pages).
43591 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43592 * compiled-in switcher code and the high-mapped copy we just made.
43593 */
43594 for (i = 0; i < IDT_ENTRIES; i++)
43595 - default_idt_entries[i] += switcher_offset();
43596 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43597
43598 /*
43599 * Set up the Switcher's per-cpu areas.
43600 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43601 * it will be undisturbed when we switch. To change %cs and jump we
43602 * need this structure to feed to Intel's "lcall" instruction.
43603 */
43604 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43605 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43606 lguest_entry.segment = LGUEST_CS;
43607
43608 /*
43609 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43610 index 40634b0..4f5855e 100644
43611 --- a/drivers/lguest/x86/switcher_32.S
43612 +++ b/drivers/lguest/x86/switcher_32.S
43613 @@ -87,6 +87,7 @@
43614 #include <asm/page.h>
43615 #include <asm/segment.h>
43616 #include <asm/lguest.h>
43617 +#include <asm/processor-flags.h>
43618
43619 // We mark the start of the code to copy
43620 // It's placed in .text tho it's never run here
43621 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43622 // Changes type when we load it: damn Intel!
43623 // For after we switch over our page tables
43624 // That entry will be read-only: we'd crash.
43625 +
43626 +#ifdef CONFIG_PAX_KERNEXEC
43627 + mov %cr0, %edx
43628 + xor $X86_CR0_WP, %edx
43629 + mov %edx, %cr0
43630 +#endif
43631 +
43632 movl $(GDT_ENTRY_TSS*8), %edx
43633 ltr %dx
43634
43635 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43636 // Let's clear it again for our return.
43637 // The GDT descriptor of the Host
43638 // Points to the table after two "size" bytes
43639 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43640 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43641 // Clear "used" from type field (byte 5, bit 2)
43642 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43643 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43644 +
43645 +#ifdef CONFIG_PAX_KERNEXEC
43646 + mov %cr0, %eax
43647 + xor $X86_CR0_WP, %eax
43648 + mov %eax, %cr0
43649 +#endif
43650
43651 // Once our page table's switched, the Guest is live!
43652 // The Host fades as we run this final step.
43653 @@ -295,13 +309,12 @@ deliver_to_host:
43654 // I consulted gcc, and it gave
43655 // These instructions, which I gladly credit:
43656 leal (%edx,%ebx,8), %eax
43657 - movzwl (%eax),%edx
43658 - movl 4(%eax), %eax
43659 - xorw %ax, %ax
43660 - orl %eax, %edx
43661 + movl 4(%eax), %edx
43662 + movw (%eax), %dx
43663 // Now the address of the handler's in %edx
43664 // We call it now: its "iret" drops us home.
43665 - jmp *%edx
43666 + ljmp $__KERNEL_CS, $1f
43667 +1: jmp *%edx
43668
43669 // Every interrupt can come to us here
43670 // But we must truly tell each apart.
43671 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43672 index 7ef7461..5a09dac 100644
43673 --- a/drivers/md/bcache/closure.h
43674 +++ b/drivers/md/bcache/closure.h
43675 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43676 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43677 struct workqueue_struct *wq)
43678 {
43679 - BUG_ON(object_is_on_stack(cl));
43680 + BUG_ON(object_starts_on_stack(cl));
43681 closure_set_ip(cl);
43682 cl->fn = fn;
43683 cl->wq = wq;
43684 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43685 index 9a8e66a..10cc762 100644
43686 --- a/drivers/md/bitmap.c
43687 +++ b/drivers/md/bitmap.c
43688 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43689 chunk_kb ? "KB" : "B");
43690 if (bitmap->storage.file) {
43691 seq_printf(seq, ", file: ");
43692 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43693 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43694 }
43695
43696 seq_printf(seq, "\n");
43697 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43698 index 5152142..623d141 100644
43699 --- a/drivers/md/dm-ioctl.c
43700 +++ b/drivers/md/dm-ioctl.c
43701 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43702 cmd == DM_LIST_VERSIONS_CMD)
43703 return 0;
43704
43705 - if ((cmd == DM_DEV_CREATE_CMD)) {
43706 + if (cmd == DM_DEV_CREATE_CMD) {
43707 if (!*param->name) {
43708 DMWARN("name not supplied when creating device");
43709 return -EINVAL;
43710 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43711 index 7dfdb5c..4caada6 100644
43712 --- a/drivers/md/dm-raid1.c
43713 +++ b/drivers/md/dm-raid1.c
43714 @@ -40,7 +40,7 @@ enum dm_raid1_error {
43715
43716 struct mirror {
43717 struct mirror_set *ms;
43718 - atomic_t error_count;
43719 + atomic_unchecked_t error_count;
43720 unsigned long error_type;
43721 struct dm_dev *dev;
43722 sector_t offset;
43723 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43724 struct mirror *m;
43725
43726 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43727 - if (!atomic_read(&m->error_count))
43728 + if (!atomic_read_unchecked(&m->error_count))
43729 return m;
43730
43731 return NULL;
43732 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43733 * simple way to tell if a device has encountered
43734 * errors.
43735 */
43736 - atomic_inc(&m->error_count);
43737 + atomic_inc_unchecked(&m->error_count);
43738
43739 if (test_and_set_bit(error_type, &m->error_type))
43740 return;
43741 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43742 struct mirror *m = get_default_mirror(ms);
43743
43744 do {
43745 - if (likely(!atomic_read(&m->error_count)))
43746 + if (likely(!atomic_read_unchecked(&m->error_count)))
43747 return m;
43748
43749 if (m-- == ms->mirror)
43750 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43751 {
43752 struct mirror *default_mirror = get_default_mirror(m->ms);
43753
43754 - return !atomic_read(&default_mirror->error_count);
43755 + return !atomic_read_unchecked(&default_mirror->error_count);
43756 }
43757
43758 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43759 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43760 */
43761 if (likely(region_in_sync(ms, region, 1)))
43762 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43763 - else if (m && atomic_read(&m->error_count))
43764 + else if (m && atomic_read_unchecked(&m->error_count))
43765 m = NULL;
43766
43767 if (likely(m))
43768 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43769 }
43770
43771 ms->mirror[mirror].ms = ms;
43772 - atomic_set(&(ms->mirror[mirror].error_count), 0);
43773 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43774 ms->mirror[mirror].error_type = 0;
43775 ms->mirror[mirror].offset = offset;
43776
43777 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43778 */
43779 static char device_status_char(struct mirror *m)
43780 {
43781 - if (!atomic_read(&(m->error_count)))
43782 + if (!atomic_read_unchecked(&(m->error_count)))
43783 return 'A';
43784
43785 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43786 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43787 index 28a9012..9c0f6a5 100644
43788 --- a/drivers/md/dm-stats.c
43789 +++ b/drivers/md/dm-stats.c
43790 @@ -382,7 +382,7 @@ do_sync_free:
43791 synchronize_rcu_expedited();
43792 dm_stat_free(&s->rcu_head);
43793 } else {
43794 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43795 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43796 call_rcu(&s->rcu_head, dm_stat_free);
43797 }
43798 return 0;
43799 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43800 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43801 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43802 ));
43803 - ACCESS_ONCE(last->last_sector) = end_sector;
43804 - ACCESS_ONCE(last->last_rw) = bi_rw;
43805 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
43806 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43807 }
43808
43809 rcu_read_lock();
43810 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43811 index d1600d2..4c3af3a 100644
43812 --- a/drivers/md/dm-stripe.c
43813 +++ b/drivers/md/dm-stripe.c
43814 @@ -21,7 +21,7 @@ struct stripe {
43815 struct dm_dev *dev;
43816 sector_t physical_start;
43817
43818 - atomic_t error_count;
43819 + atomic_unchecked_t error_count;
43820 };
43821
43822 struct stripe_c {
43823 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43824 kfree(sc);
43825 return r;
43826 }
43827 - atomic_set(&(sc->stripe[i].error_count), 0);
43828 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43829 }
43830
43831 ti->private = sc;
43832 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43833 DMEMIT("%d ", sc->stripes);
43834 for (i = 0; i < sc->stripes; i++) {
43835 DMEMIT("%s ", sc->stripe[i].dev->name);
43836 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43837 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43838 'D' : 'A';
43839 }
43840 buffer[i] = '\0';
43841 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43842 */
43843 for (i = 0; i < sc->stripes; i++)
43844 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43845 - atomic_inc(&(sc->stripe[i].error_count));
43846 - if (atomic_read(&(sc->stripe[i].error_count)) <
43847 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
43848 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43849 DM_IO_ERROR_THRESHOLD)
43850 schedule_work(&sc->trigger_event);
43851 }
43852 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43853 index 50601ec..6d3b9dc 100644
43854 --- a/drivers/md/dm-table.c
43855 +++ b/drivers/md/dm-table.c
43856 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43857 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43858 struct mapped_device *md)
43859 {
43860 - static char *_claim_ptr = "I belong to device-mapper";
43861 + static char _claim_ptr[] = "I belong to device-mapper";
43862 struct block_device *bdev;
43863
43864 int r;
43865 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43866 if (!dev_size)
43867 return 0;
43868
43869 - if ((start >= dev_size) || (start + len > dev_size)) {
43870 + if ((start >= dev_size) || (len > dev_size - start)) {
43871 DMWARN("%s: %s too small for target: "
43872 "start=%llu, len=%llu, dev_size=%llu",
43873 dm_device_name(ti->table->md), bdevname(bdev, b),
43874 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43875 index b086a94..74cb67e 100644
43876 --- a/drivers/md/dm-thin-metadata.c
43877 +++ b/drivers/md/dm-thin-metadata.c
43878 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43879 {
43880 pmd->info.tm = pmd->tm;
43881 pmd->info.levels = 2;
43882 - pmd->info.value_type.context = pmd->data_sm;
43883 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43884 pmd->info.value_type.size = sizeof(__le64);
43885 pmd->info.value_type.inc = data_block_inc;
43886 pmd->info.value_type.dec = data_block_dec;
43887 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43888
43889 pmd->bl_info.tm = pmd->tm;
43890 pmd->bl_info.levels = 1;
43891 - pmd->bl_info.value_type.context = pmd->data_sm;
43892 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43893 pmd->bl_info.value_type.size = sizeof(__le64);
43894 pmd->bl_info.value_type.inc = data_block_inc;
43895 pmd->bl_info.value_type.dec = data_block_dec;
43896 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43897 index 490ac23..b9790cd 100644
43898 --- a/drivers/md/dm.c
43899 +++ b/drivers/md/dm.c
43900 @@ -180,9 +180,9 @@ struct mapped_device {
43901 /*
43902 * Event handling.
43903 */
43904 - atomic_t event_nr;
43905 + atomic_unchecked_t event_nr;
43906 wait_queue_head_t eventq;
43907 - atomic_t uevent_seq;
43908 + atomic_unchecked_t uevent_seq;
43909 struct list_head uevent_list;
43910 spinlock_t uevent_lock; /* Protect access to uevent_list */
43911
43912 @@ -1895,8 +1895,8 @@ static struct mapped_device *alloc_dev(int minor)
43913 spin_lock_init(&md->deferred_lock);
43914 atomic_set(&md->holders, 1);
43915 atomic_set(&md->open_count, 0);
43916 - atomic_set(&md->event_nr, 0);
43917 - atomic_set(&md->uevent_seq, 0);
43918 + atomic_set_unchecked(&md->event_nr, 0);
43919 + atomic_set_unchecked(&md->uevent_seq, 0);
43920 INIT_LIST_HEAD(&md->uevent_list);
43921 spin_lock_init(&md->uevent_lock);
43922
43923 @@ -2050,7 +2050,7 @@ static void event_callback(void *context)
43924
43925 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43926
43927 - atomic_inc(&md->event_nr);
43928 + atomic_inc_unchecked(&md->event_nr);
43929 wake_up(&md->eventq);
43930 }
43931
43932 @@ -2743,18 +2743,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43933
43934 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43935 {
43936 - return atomic_add_return(1, &md->uevent_seq);
43937 + return atomic_add_return_unchecked(1, &md->uevent_seq);
43938 }
43939
43940 uint32_t dm_get_event_nr(struct mapped_device *md)
43941 {
43942 - return atomic_read(&md->event_nr);
43943 + return atomic_read_unchecked(&md->event_nr);
43944 }
43945
43946 int dm_wait_event(struct mapped_device *md, int event_nr)
43947 {
43948 return wait_event_interruptible(md->eventq,
43949 - (event_nr != atomic_read(&md->event_nr)));
43950 + (event_nr != atomic_read_unchecked(&md->event_nr)));
43951 }
43952
43953 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43954 diff --git a/drivers/md/md.c b/drivers/md/md.c
43955 index 9a18209..ec4d3ec 100644
43956 --- a/drivers/md/md.c
43957 +++ b/drivers/md/md.c
43958 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43959 * start build, activate spare
43960 */
43961 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43962 -static atomic_t md_event_count;
43963 +static atomic_unchecked_t md_event_count;
43964 void md_new_event(struct mddev *mddev)
43965 {
43966 - atomic_inc(&md_event_count);
43967 + atomic_inc_unchecked(&md_event_count);
43968 wake_up(&md_event_waiters);
43969 }
43970 EXPORT_SYMBOL_GPL(md_new_event);
43971 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43972 */
43973 static void md_new_event_inintr(struct mddev *mddev)
43974 {
43975 - atomic_inc(&md_event_count);
43976 + atomic_inc_unchecked(&md_event_count);
43977 wake_up(&md_event_waiters);
43978 }
43979
43980 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43981 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43982 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43983 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43984 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43985 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43986
43987 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43988 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43989 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43990 else
43991 sb->resync_offset = cpu_to_le64(0);
43992
43993 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43994 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43995
43996 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43997 sb->size = cpu_to_le64(mddev->dev_sectors);
43998 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43999 static ssize_t
44000 errors_show(struct md_rdev *rdev, char *page)
44001 {
44002 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44003 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44004 }
44005
44006 static ssize_t
44007 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44008 char *e;
44009 unsigned long n = simple_strtoul(buf, &e, 10);
44010 if (*buf && (*e == 0 || *e == '\n')) {
44011 - atomic_set(&rdev->corrected_errors, n);
44012 + atomic_set_unchecked(&rdev->corrected_errors, n);
44013 return len;
44014 }
44015 return -EINVAL;
44016 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
44017 rdev->sb_loaded = 0;
44018 rdev->bb_page = NULL;
44019 atomic_set(&rdev->nr_pending, 0);
44020 - atomic_set(&rdev->read_errors, 0);
44021 - atomic_set(&rdev->corrected_errors, 0);
44022 + atomic_set_unchecked(&rdev->read_errors, 0);
44023 + atomic_set_unchecked(&rdev->corrected_errors, 0);
44024
44025 INIT_LIST_HEAD(&rdev->same_set);
44026 init_waitqueue_head(&rdev->blocked_wait);
44027 @@ -7058,7 +7058,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44028
44029 spin_unlock(&pers_lock);
44030 seq_printf(seq, "\n");
44031 - seq->poll_event = atomic_read(&md_event_count);
44032 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44033 return 0;
44034 }
44035 if (v == (void*)2) {
44036 @@ -7161,7 +7161,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44037 return error;
44038
44039 seq = file->private_data;
44040 - seq->poll_event = atomic_read(&md_event_count);
44041 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44042 return error;
44043 }
44044
44045 @@ -7178,7 +7178,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44046 /* always allow read */
44047 mask = POLLIN | POLLRDNORM;
44048
44049 - if (seq->poll_event != atomic_read(&md_event_count))
44050 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44051 mask |= POLLERR | POLLPRI;
44052 return mask;
44053 }
44054 @@ -7222,7 +7222,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44055 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44056 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44057 (int)part_stat_read(&disk->part0, sectors[1]) -
44058 - atomic_read(&disk->sync_io);
44059 + atomic_read_unchecked(&disk->sync_io);
44060 /* sync IO will cause sync_io to increase before the disk_stats
44061 * as sync_io is counted when a request starts, and
44062 * disk_stats is counted when it completes.
44063 diff --git a/drivers/md/md.h b/drivers/md/md.h
44064 index a49d991..3582bb7 100644
44065 --- a/drivers/md/md.h
44066 +++ b/drivers/md/md.h
44067 @@ -94,13 +94,13 @@ struct md_rdev {
44068 * only maintained for arrays that
44069 * support hot removal
44070 */
44071 - atomic_t read_errors; /* number of consecutive read errors that
44072 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
44073 * we have tried to ignore.
44074 */
44075 struct timespec last_read_error; /* monotonic time since our
44076 * last read error
44077 */
44078 - atomic_t corrected_errors; /* number of corrected read errors,
44079 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44080 * for reporting to userspace and storing
44081 * in superblock.
44082 */
44083 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44084
44085 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44086 {
44087 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44088 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44089 }
44090
44091 struct md_personality
44092 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44093 index 786b689..ea8c956 100644
44094 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44095 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44096 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44097 * Flick into a mode where all blocks get allocated in the new area.
44098 */
44099 smm->begin = old_len;
44100 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44101 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44102
44103 /*
44104 * Extend.
44105 @@ -710,7 +710,7 @@ out:
44106 /*
44107 * Switch back to normal behaviour.
44108 */
44109 - memcpy(sm, &ops, sizeof(*sm));
44110 + memcpy((void *)sm, &ops, sizeof(*sm));
44111 return r;
44112 }
44113
44114 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44115 index 3e6d115..ffecdeb 100644
44116 --- a/drivers/md/persistent-data/dm-space-map.h
44117 +++ b/drivers/md/persistent-data/dm-space-map.h
44118 @@ -71,6 +71,7 @@ struct dm_space_map {
44119 dm_sm_threshold_fn fn,
44120 void *context);
44121 };
44122 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44123
44124 /*----------------------------------------------------------------*/
44125
44126 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44127 index 56e24c0..e1c8e1f 100644
44128 --- a/drivers/md/raid1.c
44129 +++ b/drivers/md/raid1.c
44130 @@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44131 if (r1_sync_page_io(rdev, sect, s,
44132 bio->bi_io_vec[idx].bv_page,
44133 READ) != 0)
44134 - atomic_add(s, &rdev->corrected_errors);
44135 + atomic_add_unchecked(s, &rdev->corrected_errors);
44136 }
44137 sectors -= s;
44138 sect += s;
44139 @@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44140 test_bit(In_sync, &rdev->flags)) {
44141 if (r1_sync_page_io(rdev, sect, s,
44142 conf->tmppage, READ)) {
44143 - atomic_add(s, &rdev->corrected_errors);
44144 + atomic_add_unchecked(s, &rdev->corrected_errors);
44145 printk(KERN_INFO
44146 "md/raid1:%s: read error corrected "
44147 "(%d sectors at %llu on %s)\n",
44148 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44149 index cb882aa..9bd076e 100644
44150 --- a/drivers/md/raid10.c
44151 +++ b/drivers/md/raid10.c
44152 @@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
44153 /* The write handler will notice the lack of
44154 * R10BIO_Uptodate and record any errors etc
44155 */
44156 - atomic_add(r10_bio->sectors,
44157 + atomic_add_unchecked(r10_bio->sectors,
44158 &conf->mirrors[d].rdev->corrected_errors);
44159
44160 /* for reconstruct, we always reschedule after a read.
44161 @@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44162 {
44163 struct timespec cur_time_mon;
44164 unsigned long hours_since_last;
44165 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44166 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44167
44168 ktime_get_ts(&cur_time_mon);
44169
44170 @@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44171 * overflowing the shift of read_errors by hours_since_last.
44172 */
44173 if (hours_since_last >= 8 * sizeof(read_errors))
44174 - atomic_set(&rdev->read_errors, 0);
44175 + atomic_set_unchecked(&rdev->read_errors, 0);
44176 else
44177 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44178 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44179 }
44180
44181 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44182 @@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44183 return;
44184
44185 check_decay_read_errors(mddev, rdev);
44186 - atomic_inc(&rdev->read_errors);
44187 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44188 + atomic_inc_unchecked(&rdev->read_errors);
44189 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44190 char b[BDEVNAME_SIZE];
44191 bdevname(rdev->bdev, b);
44192
44193 @@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44194 "md/raid10:%s: %s: Raid device exceeded "
44195 "read_error threshold [cur %d:max %d]\n",
44196 mdname(mddev), b,
44197 - atomic_read(&rdev->read_errors), max_read_errors);
44198 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44199 printk(KERN_NOTICE
44200 "md/raid10:%s: %s: Failing raid device\n",
44201 mdname(mddev), b);
44202 @@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44203 sect +
44204 choose_data_offset(r10_bio, rdev)),
44205 bdevname(rdev->bdev, b));
44206 - atomic_add(s, &rdev->corrected_errors);
44207 + atomic_add_unchecked(s, &rdev->corrected_errors);
44208 }
44209
44210 rdev_dec_pending(rdev, mddev);
44211 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44212 index ad1b9be..b417412 100644
44213 --- a/drivers/md/raid5.c
44214 +++ b/drivers/md/raid5.c
44215 @@ -1702,6 +1702,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44216 return 1;
44217 }
44218
44219 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44220 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44221 +#endif
44222 +
44223 static int grow_stripes(struct r5conf *conf, int num)
44224 {
44225 struct kmem_cache *sc;
44226 @@ -1713,7 +1717,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44227 "raid%d-%s", conf->level, mdname(conf->mddev));
44228 else
44229 sprintf(conf->cache_name[0],
44230 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44231 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44232 +#else
44233 "raid%d-%p", conf->level, conf->mddev);
44234 +#endif
44235 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44236
44237 conf->active_name = 0;
44238 @@ -1986,21 +1994,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44239 mdname(conf->mddev), STRIPE_SECTORS,
44240 (unsigned long long)s,
44241 bdevname(rdev->bdev, b));
44242 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44243 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44244 clear_bit(R5_ReadError, &sh->dev[i].flags);
44245 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44246 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44247 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44248
44249 - if (atomic_read(&rdev->read_errors))
44250 - atomic_set(&rdev->read_errors, 0);
44251 + if (atomic_read_unchecked(&rdev->read_errors))
44252 + atomic_set_unchecked(&rdev->read_errors, 0);
44253 } else {
44254 const char *bdn = bdevname(rdev->bdev, b);
44255 int retry = 0;
44256 int set_bad = 0;
44257
44258 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44259 - atomic_inc(&rdev->read_errors);
44260 + atomic_inc_unchecked(&rdev->read_errors);
44261 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44262 printk_ratelimited(
44263 KERN_WARNING
44264 @@ -2028,7 +2036,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44265 mdname(conf->mddev),
44266 (unsigned long long)s,
44267 bdn);
44268 - } else if (atomic_read(&rdev->read_errors)
44269 + } else if (atomic_read_unchecked(&rdev->read_errors)
44270 > conf->max_nr_stripes)
44271 printk(KERN_WARNING
44272 "md/raid:%s: Too many read errors, failing device %s.\n",
44273 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44274 index 983db75..ef9248c 100644
44275 --- a/drivers/media/dvb-core/dvbdev.c
44276 +++ b/drivers/media/dvb-core/dvbdev.c
44277 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44278 const struct dvb_device *template, void *priv, int type)
44279 {
44280 struct dvb_device *dvbdev;
44281 - struct file_operations *dvbdevfops;
44282 + file_operations_no_const *dvbdevfops;
44283 struct device *clsdev;
44284 int minor;
44285 int id;
44286 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
44287 index 539f4db..cdd403b 100644
44288 --- a/drivers/media/dvb-frontends/af9033.h
44289 +++ b/drivers/media/dvb-frontends/af9033.h
44290 @@ -82,7 +82,7 @@ struct af9033_ops {
44291 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
44292 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
44293 int onoff);
44294 -};
44295 +} __no_const;
44296
44297
44298 #if IS_ENABLED(CONFIG_DVB_AF9033)
44299 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44300 index 9b6c3bb..baeb5c7 100644
44301 --- a/drivers/media/dvb-frontends/dib3000.h
44302 +++ b/drivers/media/dvb-frontends/dib3000.h
44303 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44304 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44305 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44306 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44307 -};
44308 +} __no_const;
44309
44310 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44311 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44312 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44313 index ed8cb90..5ef7f79 100644
44314 --- a/drivers/media/pci/cx88/cx88-video.c
44315 +++ b/drivers/media/pci/cx88/cx88-video.c
44316 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44317
44318 /* ------------------------------------------------------------------ */
44319
44320 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44321 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44322 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44323 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44324 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44325 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44326
44327 module_param_array(video_nr, int, NULL, 0444);
44328 module_param_array(vbi_nr, int, NULL, 0444);
44329 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44330 index 802642d..5534900 100644
44331 --- a/drivers/media/pci/ivtv/ivtv-driver.c
44332 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
44333 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44334 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44335
44336 /* ivtv instance counter */
44337 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
44338 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44339
44340 /* Parameter declarations */
44341 static int cardtype[IVTV_MAX_CARDS];
44342 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44343 index 9a726ea..f5e9b52 100644
44344 --- a/drivers/media/platform/omap/omap_vout.c
44345 +++ b/drivers/media/platform/omap/omap_vout.c
44346 @@ -63,7 +63,6 @@ enum omap_vout_channels {
44347 OMAP_VIDEO2,
44348 };
44349
44350 -static struct videobuf_queue_ops video_vbq_ops;
44351 /* Variables configurable through module params*/
44352 static u32 video1_numbuffers = 3;
44353 static u32 video2_numbuffers = 3;
44354 @@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
44355 {
44356 struct videobuf_queue *q;
44357 struct omap_vout_device *vout = NULL;
44358 + static struct videobuf_queue_ops video_vbq_ops = {
44359 + .buf_setup = omap_vout_buffer_setup,
44360 + .buf_prepare = omap_vout_buffer_prepare,
44361 + .buf_release = omap_vout_buffer_release,
44362 + .buf_queue = omap_vout_buffer_queue,
44363 + };
44364
44365 vout = video_drvdata(file);
44366 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44367 @@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
44368 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44369
44370 q = &vout->vbq;
44371 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44372 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44373 - video_vbq_ops.buf_release = omap_vout_buffer_release;
44374 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44375 spin_lock_init(&vout->vbq_lock);
44376
44377 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44378 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44379 index fb2acc5..a2fcbdc4 100644
44380 --- a/drivers/media/platform/s5p-tv/mixer.h
44381 +++ b/drivers/media/platform/s5p-tv/mixer.h
44382 @@ -156,7 +156,7 @@ struct mxr_layer {
44383 /** layer index (unique identifier) */
44384 int idx;
44385 /** callbacks for layer methods */
44386 - struct mxr_layer_ops ops;
44387 + struct mxr_layer_ops *ops;
44388 /** format array */
44389 const struct mxr_format **fmt_array;
44390 /** size of format array */
44391 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44392 index 74344c7..a39e70e 100644
44393 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44394 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44395 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44396 {
44397 struct mxr_layer *layer;
44398 int ret;
44399 - struct mxr_layer_ops ops = {
44400 + static struct mxr_layer_ops ops = {
44401 .release = mxr_graph_layer_release,
44402 .buffer_set = mxr_graph_buffer_set,
44403 .stream_set = mxr_graph_stream_set,
44404 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44405 index b713403..53cb5ad 100644
44406 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
44407 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44408 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44409 layer->update_buf = next;
44410 }
44411
44412 - layer->ops.buffer_set(layer, layer->update_buf);
44413 + layer->ops->buffer_set(layer, layer->update_buf);
44414
44415 if (done && done != layer->shadow_buf)
44416 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44417 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44418 index a1ce55f..4a3c4d9 100644
44419 --- a/drivers/media/platform/s5p-tv/mixer_video.c
44420 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
44421 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44422 layer->geo.src.height = layer->geo.src.full_height;
44423
44424 mxr_geometry_dump(mdev, &layer->geo);
44425 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44426 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44427 mxr_geometry_dump(mdev, &layer->geo);
44428 }
44429
44430 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44431 layer->geo.dst.full_width = mbus_fmt.width;
44432 layer->geo.dst.full_height = mbus_fmt.height;
44433 layer->geo.dst.field = mbus_fmt.field;
44434 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44435 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44436
44437 mxr_geometry_dump(mdev, &layer->geo);
44438 }
44439 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44440 /* set source size to highest accepted value */
44441 geo->src.full_width = max(geo->dst.full_width, pix->width);
44442 geo->src.full_height = max(geo->dst.full_height, pix->height);
44443 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44444 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44445 mxr_geometry_dump(mdev, &layer->geo);
44446 /* set cropping to total visible screen */
44447 geo->src.width = pix->width;
44448 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44449 geo->src.x_offset = 0;
44450 geo->src.y_offset = 0;
44451 /* assure consistency of geometry */
44452 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44453 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44454 mxr_geometry_dump(mdev, &layer->geo);
44455 /* set full size to lowest possible value */
44456 geo->src.full_width = 0;
44457 geo->src.full_height = 0;
44458 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44459 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44460 mxr_geometry_dump(mdev, &layer->geo);
44461
44462 /* returning results */
44463 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44464 target->width = s->r.width;
44465 target->height = s->r.height;
44466
44467 - layer->ops.fix_geometry(layer, stage, s->flags);
44468 + layer->ops->fix_geometry(layer, stage, s->flags);
44469
44470 /* retrieve update selection rectangle */
44471 res.left = target->x_offset;
44472 @@ -950,13 +950,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44473 mxr_output_get(mdev);
44474
44475 mxr_layer_update_output(layer);
44476 - layer->ops.format_set(layer);
44477 + layer->ops->format_set(layer);
44478 /* enabling layer in hardware */
44479 spin_lock_irqsave(&layer->enq_slock, flags);
44480 layer->state = MXR_LAYER_STREAMING;
44481 spin_unlock_irqrestore(&layer->enq_slock, flags);
44482
44483 - layer->ops.stream_set(layer, MXR_ENABLE);
44484 + layer->ops->stream_set(layer, MXR_ENABLE);
44485 mxr_streamer_get(mdev);
44486
44487 return 0;
44488 @@ -1026,7 +1026,7 @@ static int stop_streaming(struct vb2_queue *vq)
44489 spin_unlock_irqrestore(&layer->enq_slock, flags);
44490
44491 /* disabling layer in hardware */
44492 - layer->ops.stream_set(layer, MXR_DISABLE);
44493 + layer->ops->stream_set(layer, MXR_DISABLE);
44494 /* remove one streamer */
44495 mxr_streamer_put(mdev);
44496 /* allow changes in output configuration */
44497 @@ -1065,8 +1065,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44498
44499 void mxr_layer_release(struct mxr_layer *layer)
44500 {
44501 - if (layer->ops.release)
44502 - layer->ops.release(layer);
44503 + if (layer->ops->release)
44504 + layer->ops->release(layer);
44505 }
44506
44507 void mxr_base_layer_release(struct mxr_layer *layer)
44508 @@ -1092,7 +1092,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44509
44510 layer->mdev = mdev;
44511 layer->idx = idx;
44512 - layer->ops = *ops;
44513 + layer->ops = ops;
44514
44515 spin_lock_init(&layer->enq_slock);
44516 INIT_LIST_HEAD(&layer->enq_list);
44517 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44518 index c9388c4..ce71ece 100644
44519 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44520 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44521 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44522 {
44523 struct mxr_layer *layer;
44524 int ret;
44525 - struct mxr_layer_ops ops = {
44526 + static struct mxr_layer_ops ops = {
44527 .release = mxr_vp_layer_release,
44528 .buffer_set = mxr_vp_buffer_set,
44529 .stream_set = mxr_vp_stream_set,
44530 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44531 index 3890f4f..b5c7511 100644
44532 --- a/drivers/media/platform/vivi.c
44533 +++ b/drivers/media/platform/vivi.c
44534 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44535 MODULE_LICENSE("Dual BSD/GPL");
44536 MODULE_VERSION(VIVI_VERSION);
44537
44538 -static unsigned video_nr = -1;
44539 -module_param(video_nr, uint, 0644);
44540 +static int video_nr = -1;
44541 +module_param(video_nr, int, 0644);
44542 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44543
44544 static unsigned n_devs = 1;
44545 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44546 index d719e59..63f3470 100644
44547 --- a/drivers/media/radio/radio-cadet.c
44548 +++ b/drivers/media/radio/radio-cadet.c
44549 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44550 unsigned char readbuf[RDS_BUFFER];
44551 int i = 0;
44552
44553 + if (count > RDS_BUFFER)
44554 + return -EFAULT;
44555 mutex_lock(&dev->lock);
44556 if (dev->rdsstat == 0)
44557 cadet_start_rds(dev);
44558 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44559 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44560 mutex_unlock(&dev->lock);
44561
44562 - if (i && copy_to_user(data, readbuf, i))
44563 - return -EFAULT;
44564 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
44565 + i = -EFAULT;
44566 +
44567 return i;
44568 }
44569
44570 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44571 index 5236035..c622c74 100644
44572 --- a/drivers/media/radio/radio-maxiradio.c
44573 +++ b/drivers/media/radio/radio-maxiradio.c
44574 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44575 /* TEA5757 pin mappings */
44576 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44577
44578 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44579 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44580
44581 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44582 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44583 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44584 index 050b3bb..79f62b9 100644
44585 --- a/drivers/media/radio/radio-shark.c
44586 +++ b/drivers/media/radio/radio-shark.c
44587 @@ -79,7 +79,7 @@ struct shark_device {
44588 u32 last_val;
44589 };
44590
44591 -static atomic_t shark_instance = ATOMIC_INIT(0);
44592 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44593
44594 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44595 {
44596 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44597 index 8654e0d..0608a64 100644
44598 --- a/drivers/media/radio/radio-shark2.c
44599 +++ b/drivers/media/radio/radio-shark2.c
44600 @@ -74,7 +74,7 @@ struct shark_device {
44601 u8 *transfer_buffer;
44602 };
44603
44604 -static atomic_t shark_instance = ATOMIC_INIT(0);
44605 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44606
44607 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44608 {
44609 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44610 index 2fd9009..278cc1e 100644
44611 --- a/drivers/media/radio/radio-si476x.c
44612 +++ b/drivers/media/radio/radio-si476x.c
44613 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44614 struct si476x_radio *radio;
44615 struct v4l2_ctrl *ctrl;
44616
44617 - static atomic_t instance = ATOMIC_INIT(0);
44618 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
44619
44620 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44621 if (!radio)
44622 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44623 index a1c641e..3007da9 100644
44624 --- a/drivers/media/usb/dvb-usb/cxusb.c
44625 +++ b/drivers/media/usb/dvb-usb/cxusb.c
44626 @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44627
44628 struct dib0700_adapter_state {
44629 int (*set_param_save) (struct dvb_frontend *);
44630 -};
44631 +} __no_const;
44632
44633 static int dib7070_set_param_override(struct dvb_frontend *fe)
44634 {
44635 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44636 index 733a7ff..f8b52e3 100644
44637 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44638 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44639 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
44640
44641 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
44642 {
44643 - struct hexline hx;
44644 - u8 reset;
44645 + struct hexline *hx;
44646 + u8 *reset;
44647 int ret,pos=0;
44648
44649 + reset = kmalloc(1, GFP_KERNEL);
44650 + if (reset == NULL)
44651 + return -ENOMEM;
44652 +
44653 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
44654 + if (hx == NULL) {
44655 + kfree(reset);
44656 + return -ENOMEM;
44657 + }
44658 +
44659 /* stop the CPU */
44660 - reset = 1;
44661 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
44662 + reset[0] = 1;
44663 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
44664 err("could not stop the USB controller CPU.");
44665
44666 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
44667 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
44668 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
44669 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
44670 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
44671 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
44672
44673 - if (ret != hx.len) {
44674 + if (ret != hx->len) {
44675 err("error while transferring firmware "
44676 "(transferred size: %d, block size: %d)",
44677 - ret,hx.len);
44678 + ret,hx->len);
44679 ret = -EINVAL;
44680 break;
44681 }
44682 }
44683 if (ret < 0) {
44684 err("firmware download failed at %d with %d",pos,ret);
44685 + kfree(reset);
44686 + kfree(hx);
44687 return ret;
44688 }
44689
44690 if (ret == 0) {
44691 /* restart the CPU */
44692 - reset = 0;
44693 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
44694 + reset[0] = 0;
44695 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
44696 err("could not restart the USB controller CPU.");
44697 ret = -EINVAL;
44698 }
44699 } else
44700 ret = -EIO;
44701
44702 + kfree(reset);
44703 + kfree(hx);
44704 +
44705 return ret;
44706 }
44707 EXPORT_SYMBOL(usb_cypress_load_firmware);
44708 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44709 index ae0f56a..ec71784 100644
44710 --- a/drivers/media/usb/dvb-usb/dw2102.c
44711 +++ b/drivers/media/usb/dvb-usb/dw2102.c
44712 @@ -118,7 +118,7 @@ struct su3000_state {
44713
44714 struct s6x0_state {
44715 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44716 -};
44717 +} __no_const;
44718
44719 /* debug */
44720 static int dvb_usb_dw2102_debug;
44721 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
44722 index 98d24ae..bc22415 100644
44723 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
44724 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
44725 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
44726 static int technisat_usb2_i2c_access(struct usb_device *udev,
44727 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
44728 {
44729 - u8 b[64];
44730 - int ret, actual_length;
44731 + u8 *b = kmalloc(64, GFP_KERNEL);
44732 + int ret, actual_length, error = 0;
44733 +
44734 + if (b == NULL)
44735 + return -ENOMEM;
44736
44737 deb_i2c("i2c-access: %02x, tx: ", device_addr);
44738 debug_dump(tx, txlen, deb_i2c);
44739 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44740
44741 if (ret < 0) {
44742 err("i2c-error: out failed %02x = %d", device_addr, ret);
44743 - return -ENODEV;
44744 + error = -ENODEV;
44745 + goto out;
44746 }
44747
44748 ret = usb_bulk_msg(udev,
44749 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44750 b, 64, &actual_length, 1000);
44751 if (ret < 0) {
44752 err("i2c-error: in failed %02x = %d", device_addr, ret);
44753 - return -ENODEV;
44754 + error = -ENODEV;
44755 + goto out;
44756 }
44757
44758 if (b[0] != I2C_STATUS_OK) {
44759 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44760 /* handle tuner-i2c-nak */
44761 if (!(b[0] == I2C_STATUS_NAK &&
44762 device_addr == 0x60
44763 - /* && device_is_technisat_usb2 */))
44764 - return -ENODEV;
44765 + /* && device_is_technisat_usb2 */)) {
44766 + error = -ENODEV;
44767 + goto out;
44768 + }
44769 }
44770
44771 deb_i2c("status: %d, ", b[0]);
44772 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44773
44774 deb_i2c("\n");
44775
44776 - return 0;
44777 +out:
44778 + kfree(b);
44779 + return error;
44780 }
44781
44782 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
44783 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
44784 {
44785 int ret;
44786
44787 - u8 led[8] = {
44788 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
44789 - 0
44790 - };
44791 + u8 *led = kzalloc(8, GFP_KERNEL);
44792 +
44793 + if (led == NULL)
44794 + return -ENOMEM;
44795
44796 if (disable_led_control && state != LED_OFF)
44797 return 0;
44798
44799 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
44800 +
44801 switch (state) {
44802 case LED_ON:
44803 led[1] = 0x82;
44804 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
44805 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
44806 USB_TYPE_VENDOR | USB_DIR_OUT,
44807 0, 0,
44808 - led, sizeof(led), 500);
44809 + led, 8, 500);
44810
44811 mutex_unlock(&d->i2c_mutex);
44812 +
44813 + kfree(led);
44814 +
44815 return ret;
44816 }
44817
44818 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
44819 {
44820 int ret;
44821 - u8 b = 0;
44822 + u8 *b = kzalloc(1, GFP_KERNEL);
44823 +
44824 + if (b == NULL)
44825 + return -ENOMEM;
44826
44827 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
44828 return -EAGAIN;
44829 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
44830 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
44831 USB_TYPE_VENDOR | USB_DIR_OUT,
44832 (red << 8) | green, 0,
44833 - &b, 1, 500);
44834 + b, 1, 500);
44835
44836 mutex_unlock(&d->i2c_mutex);
44837
44838 + kfree(b);
44839 +
44840 return ret;
44841 }
44842
44843 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
44844 struct dvb_usb_device_description **desc, int *cold)
44845 {
44846 int ret;
44847 - u8 version[3];
44848 + u8 *version = kmalloc(3, GFP_KERNEL);
44849
44850 /* first select the interface */
44851 if (usb_set_interface(udev, 0, 1) != 0)
44852 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
44853
44854 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
44855
44856 + if (version == NULL)
44857 + return 0;
44858 +
44859 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
44860 GET_VERSION_INFO_VENDOR_REQUEST,
44861 USB_TYPE_VENDOR | USB_DIR_IN,
44862 0, 0,
44863 - version, sizeof(version), 500);
44864 + version, 3, 500);
44865
44866 if (ret < 0)
44867 *cold = 1;
44868 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
44869 *cold = 0;
44870 }
44871
44872 + kfree(version);
44873 +
44874 return 0;
44875 }
44876
44877 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
44878
44879 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
44880 {
44881 - u8 buf[62], *b;
44882 + u8 *buf, *b;
44883 int ret;
44884 struct ir_raw_event ev;
44885
44886 + buf = kmalloc(62, GFP_KERNEL);
44887 +
44888 + if (buf == NULL)
44889 + return -ENOMEM;
44890 +
44891 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
44892 buf[1] = 0x08;
44893 buf[2] = 0x8f;
44894 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
44895 GET_IR_DATA_VENDOR_REQUEST,
44896 USB_TYPE_VENDOR | USB_DIR_IN,
44897 0x8080, 0,
44898 - buf, sizeof(buf), 500);
44899 + buf, 62, 500);
44900
44901 unlock:
44902 mutex_unlock(&d->i2c_mutex);
44903
44904 - if (ret < 0)
44905 + if (ret < 0) {
44906 + kfree(buf);
44907 return ret;
44908 + }
44909
44910 - if (ret == 1)
44911 + if (ret == 1) {
44912 + kfree(buf);
44913 return 0; /* no key pressed */
44914 + }
44915
44916 /* decoding */
44917 b = buf+1;
44918 @@ -653,6 +686,8 @@ unlock:
44919
44920 ir_raw_event_handle(d->rc_dev);
44921
44922 + kfree(buf);
44923 +
44924 return 1;
44925 }
44926
44927 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44928 index 7e2411c..cef73ca 100644
44929 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44930 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44931 @@ -328,7 +328,7 @@ struct v4l2_buffer32 {
44932 __u32 reserved;
44933 };
44934
44935 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44936 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44937 enum v4l2_memory memory)
44938 {
44939 void __user *up_pln;
44940 @@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44941 return 0;
44942 }
44943
44944 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44945 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44946 enum v4l2_memory memory)
44947 {
44948 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44949 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44950 * by passing a very big num_planes value */
44951 uplane = compat_alloc_user_space(num_planes *
44952 sizeof(struct v4l2_plane));
44953 - kp->m.planes = uplane;
44954 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44955
44956 while (--num_planes >= 0) {
44957 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44958 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44959 if (num_planes == 0)
44960 return 0;
44961
44962 - uplane = kp->m.planes;
44963 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44964 if (get_user(p, &up->m.planes))
44965 return -EFAULT;
44966 uplane32 = compat_ptr(p);
44967 @@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44968 get_user(kp->capability, &up->capability) ||
44969 get_user(kp->flags, &up->flags))
44970 return -EFAULT;
44971 - kp->base = compat_ptr(tmp);
44972 + kp->base = (void __force_kernel *)compat_ptr(tmp);
44973 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44974 return 0;
44975 }
44976 @@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44977 n * sizeof(struct v4l2_ext_control32)))
44978 return -EFAULT;
44979 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44980 - kp->controls = kcontrols;
44981 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44982 while (--n >= 0) {
44983 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44984 return -EFAULT;
44985 @@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44986 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44987 {
44988 struct v4l2_ext_control32 __user *ucontrols;
44989 - struct v4l2_ext_control __user *kcontrols = kp->controls;
44990 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44991 int n = kp->count;
44992 compat_caddr_t p;
44993
44994 @@ -774,7 +774,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
44995 put_user(kp->start_block, &up->start_block) ||
44996 put_user(kp->blocks, &up->blocks) ||
44997 put_user(tmp, &up->edid) ||
44998 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44999 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
45000 return -EFAULT;
45001 return 0;
45002 }
45003 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
45004 index 55c6832..a91c7a6 100644
45005 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
45006 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
45007 @@ -1431,8 +1431,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
45008 return 0;
45009
45010 case V4L2_CTRL_TYPE_STRING:
45011 - len = strlen(c->string);
45012 - if (len < ctrl->minimum)
45013 + len = strlen_user(c->string);
45014 + if (!len || len < ctrl->minimum)
45015 return -ERANGE;
45016 if ((len - ctrl->minimum) % ctrl->step)
45017 return -ERANGE;
45018 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
45019 index 02d1b63..5fd6b16 100644
45020 --- a/drivers/media/v4l2-core/v4l2-device.c
45021 +++ b/drivers/media/v4l2-core/v4l2-device.c
45022 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
45023 EXPORT_SYMBOL_GPL(v4l2_device_put);
45024
45025 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
45026 - atomic_t *instance)
45027 + atomic_unchecked_t *instance)
45028 {
45029 - int num = atomic_inc_return(instance) - 1;
45030 + int num = atomic_inc_return_unchecked(instance) - 1;
45031 int len = strlen(basename);
45032
45033 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
45034 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
45035 index d9113cc..7de6ccc 100644
45036 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
45037 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
45038 @@ -2003,7 +2003,8 @@ struct v4l2_ioctl_info {
45039 struct file *file, void *fh, void *p);
45040 } u;
45041 void (*debug)(const void *arg, bool write_only);
45042 -};
45043 +} __do_const;
45044 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
45045
45046 /* This control needs a priority check */
45047 #define INFO_FL_PRIO (1 << 0)
45048 @@ -2186,7 +2187,7 @@ static long __video_do_ioctl(struct file *file,
45049 struct video_device *vfd = video_devdata(file);
45050 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
45051 bool write_only = false;
45052 - struct v4l2_ioctl_info default_info;
45053 + v4l2_ioctl_info_no_const default_info;
45054 const struct v4l2_ioctl_info *info;
45055 void *fh = file->private_data;
45056 struct v4l2_fh *vfh = NULL;
45057 @@ -2260,7 +2261,7 @@ done:
45058 }
45059
45060 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45061 - void * __user *user_ptr, void ***kernel_ptr)
45062 + void __user **user_ptr, void ***kernel_ptr)
45063 {
45064 int ret = 0;
45065
45066 @@ -2276,7 +2277,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45067 ret = -EINVAL;
45068 break;
45069 }
45070 - *user_ptr = (void __user *)buf->m.planes;
45071 + *user_ptr = (void __force_user *)buf->m.planes;
45072 *kernel_ptr = (void *)&buf->m.planes;
45073 *array_size = sizeof(struct v4l2_plane) * buf->length;
45074 ret = 1;
45075 @@ -2311,7 +2312,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45076 ret = -EINVAL;
45077 break;
45078 }
45079 - *user_ptr = (void __user *)ctrls->controls;
45080 + *user_ptr = (void __force_user *)ctrls->controls;
45081 *kernel_ptr = (void *)&ctrls->controls;
45082 *array_size = sizeof(struct v4l2_ext_control)
45083 * ctrls->count;
45084 @@ -2412,7 +2413,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
45085 }
45086
45087 if (has_array_args) {
45088 - *kernel_ptr = user_ptr;
45089 + *kernel_ptr = (void __force_kernel *)user_ptr;
45090 if (copy_to_user(user_ptr, mbuf, array_size))
45091 err = -EFAULT;
45092 goto out_array_args;
45093 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
45094 index 570b18a..f880314 100644
45095 --- a/drivers/message/fusion/mptbase.c
45096 +++ b/drivers/message/fusion/mptbase.c
45097 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45098 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
45099 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
45100
45101 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45102 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
45103 +#else
45104 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
45105 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
45106 +#endif
45107 +
45108 /*
45109 * Rounding UP to nearest 4-kB boundary here...
45110 */
45111 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45112 ioc->facts.GlobalCredits);
45113
45114 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
45115 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45116 + NULL, NULL);
45117 +#else
45118 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
45119 +#endif
45120 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
45121 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
45122 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
45123 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
45124 index 00d339c..2ea899d 100644
45125 --- a/drivers/message/fusion/mptsas.c
45126 +++ b/drivers/message/fusion/mptsas.c
45127 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
45128 return 0;
45129 }
45130
45131 +static inline void
45132 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45133 +{
45134 + if (phy_info->port_details) {
45135 + phy_info->port_details->rphy = rphy;
45136 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45137 + ioc->name, rphy));
45138 + }
45139 +
45140 + if (rphy) {
45141 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45142 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45143 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45144 + ioc->name, rphy, rphy->dev.release));
45145 + }
45146 +}
45147 +
45148 /* no mutex */
45149 static void
45150 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
45151 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
45152 return NULL;
45153 }
45154
45155 -static inline void
45156 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45157 -{
45158 - if (phy_info->port_details) {
45159 - phy_info->port_details->rphy = rphy;
45160 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45161 - ioc->name, rphy));
45162 - }
45163 -
45164 - if (rphy) {
45165 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45166 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45167 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45168 - ioc->name, rphy, rphy->dev.release));
45169 - }
45170 -}
45171 -
45172 static inline struct sas_port *
45173 mptsas_get_port(struct mptsas_phyinfo *phy_info)
45174 {
45175 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
45176 index 727819c..ad74694 100644
45177 --- a/drivers/message/fusion/mptscsih.c
45178 +++ b/drivers/message/fusion/mptscsih.c
45179 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
45180
45181 h = shost_priv(SChost);
45182
45183 - if (h) {
45184 - if (h->info_kbuf == NULL)
45185 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45186 - return h->info_kbuf;
45187 - h->info_kbuf[0] = '\0';
45188 + if (!h)
45189 + return NULL;
45190
45191 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45192 - h->info_kbuf[size-1] = '\0';
45193 - }
45194 + if (h->info_kbuf == NULL)
45195 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45196 + return h->info_kbuf;
45197 + h->info_kbuf[0] = '\0';
45198 +
45199 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45200 + h->info_kbuf[size-1] = '\0';
45201
45202 return h->info_kbuf;
45203 }
45204 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
45205 index b7d87cd..3fb36da 100644
45206 --- a/drivers/message/i2o/i2o_proc.c
45207 +++ b/drivers/message/i2o/i2o_proc.c
45208 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
45209 "Array Controller Device"
45210 };
45211
45212 -static char *chtostr(char *tmp, u8 *chars, int n)
45213 -{
45214 - tmp[0] = 0;
45215 - return strncat(tmp, (char *)chars, n);
45216 -}
45217 -
45218 static int i2o_report_query_status(struct seq_file *seq, int block_status,
45219 char *group)
45220 {
45221 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
45222 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
45223 {
45224 struct i2o_controller *c = (struct i2o_controller *)seq->private;
45225 - static u32 work32[5];
45226 - static u8 *work8 = (u8 *) work32;
45227 - static u16 *work16 = (u16 *) work32;
45228 + u32 work32[5];
45229 + u8 *work8 = (u8 *) work32;
45230 + u16 *work16 = (u16 *) work32;
45231 int token;
45232 u32 hwcap;
45233
45234 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45235 } *result;
45236
45237 i2o_exec_execute_ddm_table ddm_table;
45238 - char tmp[28 + 1];
45239
45240 result = kmalloc(sizeof(*result), GFP_KERNEL);
45241 if (!result)
45242 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45243
45244 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
45245 seq_printf(seq, "%-#8x", ddm_table.module_id);
45246 - seq_printf(seq, "%-29s",
45247 - chtostr(tmp, ddm_table.module_name_version, 28));
45248 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
45249 seq_printf(seq, "%9d ", ddm_table.data_size);
45250 seq_printf(seq, "%8d", ddm_table.code_size);
45251
45252 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45253
45254 i2o_driver_result_table *result;
45255 i2o_driver_store_table *dst;
45256 - char tmp[28 + 1];
45257
45258 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
45259 if (result == NULL)
45260 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45261
45262 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
45263 seq_printf(seq, "%-#8x", dst->module_id);
45264 - seq_printf(seq, "%-29s",
45265 - chtostr(tmp, dst->module_name_version, 28));
45266 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
45267 + seq_printf(seq, "%-.28s", dst->module_name_version);
45268 + seq_printf(seq, "%-.8s", dst->date);
45269 seq_printf(seq, "%8d ", dst->module_size);
45270 seq_printf(seq, "%8d ", dst->mpb_size);
45271 seq_printf(seq, "0x%04x", dst->module_flags);
45272 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
45273 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45274 {
45275 struct i2o_device *d = (struct i2o_device *)seq->private;
45276 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45277 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45278 // == (allow) 512d bytes (max)
45279 - static u16 *work16 = (u16 *) work32;
45280 + u16 *work16 = (u16 *) work32;
45281 int token;
45282 - char tmp[16 + 1];
45283
45284 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
45285
45286 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45287 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
45288 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
45289 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
45290 - seq_printf(seq, "Vendor info : %s\n",
45291 - chtostr(tmp, (u8 *) (work32 + 2), 16));
45292 - seq_printf(seq, "Product info : %s\n",
45293 - chtostr(tmp, (u8 *) (work32 + 6), 16));
45294 - seq_printf(seq, "Description : %s\n",
45295 - chtostr(tmp, (u8 *) (work32 + 10), 16));
45296 - seq_printf(seq, "Product rev. : %s\n",
45297 - chtostr(tmp, (u8 *) (work32 + 14), 8));
45298 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45299 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45300 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45301 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45302
45303 seq_printf(seq, "Serial number : ");
45304 print_serial_number(seq, (u8 *) (work32 + 16),
45305 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45306 u8 pad[256]; // allow up to 256 byte (max) serial number
45307 } result;
45308
45309 - char tmp[24 + 1];
45310 -
45311 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45312
45313 if (token < 0) {
45314 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45315 }
45316
45317 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45318 - seq_printf(seq, "Module name : %s\n",
45319 - chtostr(tmp, result.module_name, 24));
45320 - seq_printf(seq, "Module revision : %s\n",
45321 - chtostr(tmp, result.module_rev, 8));
45322 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
45323 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45324
45325 seq_printf(seq, "Serial number : ");
45326 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45327 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45328 u8 instance_number[4];
45329 } result;
45330
45331 - char tmp[64 + 1];
45332 -
45333 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45334
45335 if (token < 0) {
45336 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45337 return 0;
45338 }
45339
45340 - seq_printf(seq, "Device name : %s\n",
45341 - chtostr(tmp, result.device_name, 64));
45342 - seq_printf(seq, "Service name : %s\n",
45343 - chtostr(tmp, result.service_name, 64));
45344 - seq_printf(seq, "Physical name : %s\n",
45345 - chtostr(tmp, result.physical_location, 64));
45346 - seq_printf(seq, "Instance number : %s\n",
45347 - chtostr(tmp, result.instance_number, 4));
45348 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
45349 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
45350 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45351 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45352
45353 return 0;
45354 }
45355 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45356 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45357 {
45358 struct i2o_device *d = (struct i2o_device *)seq->private;
45359 - static u32 work32[12];
45360 - static u16 *work16 = (u16 *) work32;
45361 - static u8 *work8 = (u8 *) work32;
45362 + u32 work32[12];
45363 + u16 *work16 = (u16 *) work32;
45364 + u8 *work8 = (u8 *) work32;
45365 int token;
45366
45367 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45368 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45369 index 92752fb..a7494f6 100644
45370 --- a/drivers/message/i2o/iop.c
45371 +++ b/drivers/message/i2o/iop.c
45372 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45373
45374 spin_lock_irqsave(&c->context_list_lock, flags);
45375
45376 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45377 - atomic_inc(&c->context_list_counter);
45378 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45379 + atomic_inc_unchecked(&c->context_list_counter);
45380
45381 - entry->context = atomic_read(&c->context_list_counter);
45382 + entry->context = atomic_read_unchecked(&c->context_list_counter);
45383
45384 list_add(&entry->list, &c->context_list);
45385
45386 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45387
45388 #if BITS_PER_LONG == 64
45389 spin_lock_init(&c->context_list_lock);
45390 - atomic_set(&c->context_list_counter, 0);
45391 + atomic_set_unchecked(&c->context_list_counter, 0);
45392 INIT_LIST_HEAD(&c->context_list);
45393 #endif
45394
45395 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45396 index d1a22aa..d0f7bf7 100644
45397 --- a/drivers/mfd/ab8500-debugfs.c
45398 +++ b/drivers/mfd/ab8500-debugfs.c
45399 @@ -100,7 +100,7 @@ static int irq_last;
45400 static u32 *irq_count;
45401 static int num_irqs;
45402
45403 -static struct device_attribute **dev_attr;
45404 +static device_attribute_no_const **dev_attr;
45405 static char **event_name;
45406
45407 static u8 avg_sample = SAMPLE_16;
45408 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45409 index a83eed5..62a58a9 100644
45410 --- a/drivers/mfd/max8925-i2c.c
45411 +++ b/drivers/mfd/max8925-i2c.c
45412 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45413 const struct i2c_device_id *id)
45414 {
45415 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45416 - static struct max8925_chip *chip;
45417 + struct max8925_chip *chip;
45418 struct device_node *node = client->dev.of_node;
45419
45420 if (node && !pdata) {
45421 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45422 index 460a014..21d3061 100644
45423 --- a/drivers/mfd/tps65910.c
45424 +++ b/drivers/mfd/tps65910.c
45425 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45426 struct tps65910_platform_data *pdata)
45427 {
45428 int ret = 0;
45429 - static struct regmap_irq_chip *tps6591x_irqs_chip;
45430 + struct regmap_irq_chip *tps6591x_irqs_chip;
45431
45432 if (!irq) {
45433 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45434 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45435 index 596b1f6..5b6ab74 100644
45436 --- a/drivers/mfd/twl4030-irq.c
45437 +++ b/drivers/mfd/twl4030-irq.c
45438 @@ -34,6 +34,7 @@
45439 #include <linux/of.h>
45440 #include <linux/irqdomain.h>
45441 #include <linux/i2c/twl.h>
45442 +#include <asm/pgtable.h>
45443
45444 #include "twl-core.h"
45445
45446 @@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45447 * Install an irq handler for each of the SIH modules;
45448 * clone dummy irq_chip since PIH can't *do* anything
45449 */
45450 - twl4030_irq_chip = dummy_irq_chip;
45451 - twl4030_irq_chip.name = "twl4030";
45452 + pax_open_kernel();
45453 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45454 + *(const char **)&twl4030_irq_chip.name = "twl4030";
45455
45456 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45457 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45458 + pax_close_kernel();
45459
45460 for (i = irq_base; i < irq_end; i++) {
45461 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45462 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45463 index 464419b..64bae8d 100644
45464 --- a/drivers/misc/c2port/core.c
45465 +++ b/drivers/misc/c2port/core.c
45466 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45467 goto error_idr_alloc;
45468 c2dev->id = ret;
45469
45470 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45471 + pax_open_kernel();
45472 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45473 + pax_close_kernel();
45474
45475 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45476 "c2port%d", c2dev->id);
45477 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45478 index 3f2b625..945e179 100644
45479 --- a/drivers/misc/eeprom/sunxi_sid.c
45480 +++ b/drivers/misc/eeprom/sunxi_sid.c
45481 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45482
45483 platform_set_drvdata(pdev, sid_data);
45484
45485 - sid_bin_attr.size = sid_data->keysize;
45486 + pax_open_kernel();
45487 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45488 + pax_close_kernel();
45489 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45490 return -ENODEV;
45491
45492 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45493 index 36f5d52..32311c3 100644
45494 --- a/drivers/misc/kgdbts.c
45495 +++ b/drivers/misc/kgdbts.c
45496 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45497 char before[BREAK_INSTR_SIZE];
45498 char after[BREAK_INSTR_SIZE];
45499
45500 - probe_kernel_read(before, (char *)kgdbts_break_test,
45501 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45502 BREAK_INSTR_SIZE);
45503 init_simple_test();
45504 ts.tst = plant_and_detach_test;
45505 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45506 /* Activate test with initial breakpoint */
45507 if (!is_early)
45508 kgdb_breakpoint();
45509 - probe_kernel_read(after, (char *)kgdbts_break_test,
45510 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45511 BREAK_INSTR_SIZE);
45512 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45513 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45514 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45515 index 3ef4627..8d00486 100644
45516 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
45517 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45518 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45519 * the lid is closed. This leads to interrupts as soon as a little move
45520 * is done.
45521 */
45522 - atomic_inc(&lis3->count);
45523 + atomic_inc_unchecked(&lis3->count);
45524
45525 wake_up_interruptible(&lis3->misc_wait);
45526 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45527 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45528 if (lis3->pm_dev)
45529 pm_runtime_get_sync(lis3->pm_dev);
45530
45531 - atomic_set(&lis3->count, 0);
45532 + atomic_set_unchecked(&lis3->count, 0);
45533 return 0;
45534 }
45535
45536 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45537 add_wait_queue(&lis3->misc_wait, &wait);
45538 while (true) {
45539 set_current_state(TASK_INTERRUPTIBLE);
45540 - data = atomic_xchg(&lis3->count, 0);
45541 + data = atomic_xchg_unchecked(&lis3->count, 0);
45542 if (data)
45543 break;
45544
45545 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45546 struct lis3lv02d, miscdev);
45547
45548 poll_wait(file, &lis3->misc_wait, wait);
45549 - if (atomic_read(&lis3->count))
45550 + if (atomic_read_unchecked(&lis3->count))
45551 return POLLIN | POLLRDNORM;
45552 return 0;
45553 }
45554 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45555 index c439c82..1f20f57 100644
45556 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
45557 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45558 @@ -297,7 +297,7 @@ struct lis3lv02d {
45559 struct input_polled_dev *idev; /* input device */
45560 struct platform_device *pdev; /* platform device */
45561 struct regulator_bulk_data regulators[2];
45562 - atomic_t count; /* interrupt count after last read */
45563 + atomic_unchecked_t count; /* interrupt count after last read */
45564 union axis_conversion ac; /* hw -> logical axis */
45565 int mapped_btns[3];
45566
45567 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45568 index 2f30bad..c4c13d0 100644
45569 --- a/drivers/misc/sgi-gru/gruhandles.c
45570 +++ b/drivers/misc/sgi-gru/gruhandles.c
45571 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45572 unsigned long nsec;
45573
45574 nsec = CLKS2NSEC(clks);
45575 - atomic_long_inc(&mcs_op_statistics[op].count);
45576 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
45577 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45578 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45579 if (mcs_op_statistics[op].max < nsec)
45580 mcs_op_statistics[op].max = nsec;
45581 }
45582 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45583 index 4f76359..cdfcb2e 100644
45584 --- a/drivers/misc/sgi-gru/gruprocfs.c
45585 +++ b/drivers/misc/sgi-gru/gruprocfs.c
45586 @@ -32,9 +32,9 @@
45587
45588 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45589
45590 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45591 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45592 {
45593 - unsigned long val = atomic_long_read(v);
45594 + unsigned long val = atomic_long_read_unchecked(v);
45595
45596 seq_printf(s, "%16lu %s\n", val, id);
45597 }
45598 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45599
45600 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45601 for (op = 0; op < mcsop_last; op++) {
45602 - count = atomic_long_read(&mcs_op_statistics[op].count);
45603 - total = atomic_long_read(&mcs_op_statistics[op].total);
45604 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45605 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45606 max = mcs_op_statistics[op].max;
45607 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45608 count ? total / count : 0, max);
45609 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45610 index 5c3ce24..4915ccb 100644
45611 --- a/drivers/misc/sgi-gru/grutables.h
45612 +++ b/drivers/misc/sgi-gru/grutables.h
45613 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45614 * GRU statistics.
45615 */
45616 struct gru_stats_s {
45617 - atomic_long_t vdata_alloc;
45618 - atomic_long_t vdata_free;
45619 - atomic_long_t gts_alloc;
45620 - atomic_long_t gts_free;
45621 - atomic_long_t gms_alloc;
45622 - atomic_long_t gms_free;
45623 - atomic_long_t gts_double_allocate;
45624 - atomic_long_t assign_context;
45625 - atomic_long_t assign_context_failed;
45626 - atomic_long_t free_context;
45627 - atomic_long_t load_user_context;
45628 - atomic_long_t load_kernel_context;
45629 - atomic_long_t lock_kernel_context;
45630 - atomic_long_t unlock_kernel_context;
45631 - atomic_long_t steal_user_context;
45632 - atomic_long_t steal_kernel_context;
45633 - atomic_long_t steal_context_failed;
45634 - atomic_long_t nopfn;
45635 - atomic_long_t asid_new;
45636 - atomic_long_t asid_next;
45637 - atomic_long_t asid_wrap;
45638 - atomic_long_t asid_reuse;
45639 - atomic_long_t intr;
45640 - atomic_long_t intr_cbr;
45641 - atomic_long_t intr_tfh;
45642 - atomic_long_t intr_spurious;
45643 - atomic_long_t intr_mm_lock_failed;
45644 - atomic_long_t call_os;
45645 - atomic_long_t call_os_wait_queue;
45646 - atomic_long_t user_flush_tlb;
45647 - atomic_long_t user_unload_context;
45648 - atomic_long_t user_exception;
45649 - atomic_long_t set_context_option;
45650 - atomic_long_t check_context_retarget_intr;
45651 - atomic_long_t check_context_unload;
45652 - atomic_long_t tlb_dropin;
45653 - atomic_long_t tlb_preload_page;
45654 - atomic_long_t tlb_dropin_fail_no_asid;
45655 - atomic_long_t tlb_dropin_fail_upm;
45656 - atomic_long_t tlb_dropin_fail_invalid;
45657 - atomic_long_t tlb_dropin_fail_range_active;
45658 - atomic_long_t tlb_dropin_fail_idle;
45659 - atomic_long_t tlb_dropin_fail_fmm;
45660 - atomic_long_t tlb_dropin_fail_no_exception;
45661 - atomic_long_t tfh_stale_on_fault;
45662 - atomic_long_t mmu_invalidate_range;
45663 - atomic_long_t mmu_invalidate_page;
45664 - atomic_long_t flush_tlb;
45665 - atomic_long_t flush_tlb_gru;
45666 - atomic_long_t flush_tlb_gru_tgh;
45667 - atomic_long_t flush_tlb_gru_zero_asid;
45668 + atomic_long_unchecked_t vdata_alloc;
45669 + atomic_long_unchecked_t vdata_free;
45670 + atomic_long_unchecked_t gts_alloc;
45671 + atomic_long_unchecked_t gts_free;
45672 + atomic_long_unchecked_t gms_alloc;
45673 + atomic_long_unchecked_t gms_free;
45674 + atomic_long_unchecked_t gts_double_allocate;
45675 + atomic_long_unchecked_t assign_context;
45676 + atomic_long_unchecked_t assign_context_failed;
45677 + atomic_long_unchecked_t free_context;
45678 + atomic_long_unchecked_t load_user_context;
45679 + atomic_long_unchecked_t load_kernel_context;
45680 + atomic_long_unchecked_t lock_kernel_context;
45681 + atomic_long_unchecked_t unlock_kernel_context;
45682 + atomic_long_unchecked_t steal_user_context;
45683 + atomic_long_unchecked_t steal_kernel_context;
45684 + atomic_long_unchecked_t steal_context_failed;
45685 + atomic_long_unchecked_t nopfn;
45686 + atomic_long_unchecked_t asid_new;
45687 + atomic_long_unchecked_t asid_next;
45688 + atomic_long_unchecked_t asid_wrap;
45689 + atomic_long_unchecked_t asid_reuse;
45690 + atomic_long_unchecked_t intr;
45691 + atomic_long_unchecked_t intr_cbr;
45692 + atomic_long_unchecked_t intr_tfh;
45693 + atomic_long_unchecked_t intr_spurious;
45694 + atomic_long_unchecked_t intr_mm_lock_failed;
45695 + atomic_long_unchecked_t call_os;
45696 + atomic_long_unchecked_t call_os_wait_queue;
45697 + atomic_long_unchecked_t user_flush_tlb;
45698 + atomic_long_unchecked_t user_unload_context;
45699 + atomic_long_unchecked_t user_exception;
45700 + atomic_long_unchecked_t set_context_option;
45701 + atomic_long_unchecked_t check_context_retarget_intr;
45702 + atomic_long_unchecked_t check_context_unload;
45703 + atomic_long_unchecked_t tlb_dropin;
45704 + atomic_long_unchecked_t tlb_preload_page;
45705 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45706 + atomic_long_unchecked_t tlb_dropin_fail_upm;
45707 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
45708 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
45709 + atomic_long_unchecked_t tlb_dropin_fail_idle;
45710 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
45711 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45712 + atomic_long_unchecked_t tfh_stale_on_fault;
45713 + atomic_long_unchecked_t mmu_invalidate_range;
45714 + atomic_long_unchecked_t mmu_invalidate_page;
45715 + atomic_long_unchecked_t flush_tlb;
45716 + atomic_long_unchecked_t flush_tlb_gru;
45717 + atomic_long_unchecked_t flush_tlb_gru_tgh;
45718 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45719
45720 - atomic_long_t copy_gpa;
45721 - atomic_long_t read_gpa;
45722 + atomic_long_unchecked_t copy_gpa;
45723 + atomic_long_unchecked_t read_gpa;
45724
45725 - atomic_long_t mesq_receive;
45726 - atomic_long_t mesq_receive_none;
45727 - atomic_long_t mesq_send;
45728 - atomic_long_t mesq_send_failed;
45729 - atomic_long_t mesq_noop;
45730 - atomic_long_t mesq_send_unexpected_error;
45731 - atomic_long_t mesq_send_lb_overflow;
45732 - atomic_long_t mesq_send_qlimit_reached;
45733 - atomic_long_t mesq_send_amo_nacked;
45734 - atomic_long_t mesq_send_put_nacked;
45735 - atomic_long_t mesq_page_overflow;
45736 - atomic_long_t mesq_qf_locked;
45737 - atomic_long_t mesq_qf_noop_not_full;
45738 - atomic_long_t mesq_qf_switch_head_failed;
45739 - atomic_long_t mesq_qf_unexpected_error;
45740 - atomic_long_t mesq_noop_unexpected_error;
45741 - atomic_long_t mesq_noop_lb_overflow;
45742 - atomic_long_t mesq_noop_qlimit_reached;
45743 - atomic_long_t mesq_noop_amo_nacked;
45744 - atomic_long_t mesq_noop_put_nacked;
45745 - atomic_long_t mesq_noop_page_overflow;
45746 + atomic_long_unchecked_t mesq_receive;
45747 + atomic_long_unchecked_t mesq_receive_none;
45748 + atomic_long_unchecked_t mesq_send;
45749 + atomic_long_unchecked_t mesq_send_failed;
45750 + atomic_long_unchecked_t mesq_noop;
45751 + atomic_long_unchecked_t mesq_send_unexpected_error;
45752 + atomic_long_unchecked_t mesq_send_lb_overflow;
45753 + atomic_long_unchecked_t mesq_send_qlimit_reached;
45754 + atomic_long_unchecked_t mesq_send_amo_nacked;
45755 + atomic_long_unchecked_t mesq_send_put_nacked;
45756 + atomic_long_unchecked_t mesq_page_overflow;
45757 + atomic_long_unchecked_t mesq_qf_locked;
45758 + atomic_long_unchecked_t mesq_qf_noop_not_full;
45759 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
45760 + atomic_long_unchecked_t mesq_qf_unexpected_error;
45761 + atomic_long_unchecked_t mesq_noop_unexpected_error;
45762 + atomic_long_unchecked_t mesq_noop_lb_overflow;
45763 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
45764 + atomic_long_unchecked_t mesq_noop_amo_nacked;
45765 + atomic_long_unchecked_t mesq_noop_put_nacked;
45766 + atomic_long_unchecked_t mesq_noop_page_overflow;
45767
45768 };
45769
45770 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45771 tghop_invalidate, mcsop_last};
45772
45773 struct mcs_op_statistic {
45774 - atomic_long_t count;
45775 - atomic_long_t total;
45776 + atomic_long_unchecked_t count;
45777 + atomic_long_unchecked_t total;
45778 unsigned long max;
45779 };
45780
45781 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45782
45783 #define STAT(id) do { \
45784 if (gru_options & OPT_STATS) \
45785 - atomic_long_inc(&gru_stats.id); \
45786 + atomic_long_inc_unchecked(&gru_stats.id); \
45787 } while (0)
45788
45789 #ifdef CONFIG_SGI_GRU_DEBUG
45790 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45791 index c862cd4..0d176fe 100644
45792 --- a/drivers/misc/sgi-xp/xp.h
45793 +++ b/drivers/misc/sgi-xp/xp.h
45794 @@ -288,7 +288,7 @@ struct xpc_interface {
45795 xpc_notify_func, void *);
45796 void (*received) (short, int, void *);
45797 enum xp_retval (*partid_to_nasids) (short, void *);
45798 -};
45799 +} __no_const;
45800
45801 extern struct xpc_interface xpc_interface;
45802
45803 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45804 index 01be66d..e3a0c7e 100644
45805 --- a/drivers/misc/sgi-xp/xp_main.c
45806 +++ b/drivers/misc/sgi-xp/xp_main.c
45807 @@ -78,13 +78,13 @@ xpc_notloaded(void)
45808 }
45809
45810 struct xpc_interface xpc_interface = {
45811 - (void (*)(int))xpc_notloaded,
45812 - (void (*)(int))xpc_notloaded,
45813 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45814 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45815 + .connect = (void (*)(int))xpc_notloaded,
45816 + .disconnect = (void (*)(int))xpc_notloaded,
45817 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45818 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45819 void *))xpc_notloaded,
45820 - (void (*)(short, int, void *))xpc_notloaded,
45821 - (enum xp_retval(*)(short, void *))xpc_notloaded
45822 + .received = (void (*)(short, int, void *))xpc_notloaded,
45823 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45824 };
45825 EXPORT_SYMBOL_GPL(xpc_interface);
45826
45827 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45828 index b94d5f7..7f494c5 100644
45829 --- a/drivers/misc/sgi-xp/xpc.h
45830 +++ b/drivers/misc/sgi-xp/xpc.h
45831 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
45832 void (*received_payload) (struct xpc_channel *, void *);
45833 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45834 };
45835 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45836
45837 /* struct xpc_partition act_state values (for XPC HB) */
45838
45839 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45840 /* found in xpc_main.c */
45841 extern struct device *xpc_part;
45842 extern struct device *xpc_chan;
45843 -extern struct xpc_arch_operations xpc_arch_ops;
45844 +extern xpc_arch_operations_no_const xpc_arch_ops;
45845 extern int xpc_disengage_timelimit;
45846 extern int xpc_disengage_timedout;
45847 extern int xpc_activate_IRQ_rcvd;
45848 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45849 index 82dc574..8539ab2 100644
45850 --- a/drivers/misc/sgi-xp/xpc_main.c
45851 +++ b/drivers/misc/sgi-xp/xpc_main.c
45852 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45853 .notifier_call = xpc_system_die,
45854 };
45855
45856 -struct xpc_arch_operations xpc_arch_ops;
45857 +xpc_arch_operations_no_const xpc_arch_ops;
45858
45859 /*
45860 * Timer function to enforce the timelimit on the partition disengage.
45861 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45862
45863 if (((die_args->trapnr == X86_TRAP_MF) ||
45864 (die_args->trapnr == X86_TRAP_XF)) &&
45865 - !user_mode_vm(die_args->regs))
45866 + !user_mode(die_args->regs))
45867 xpc_die_deactivate();
45868
45869 break;
45870 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45871 index 452782b..0c10e40 100644
45872 --- a/drivers/mmc/card/block.c
45873 +++ b/drivers/mmc/card/block.c
45874 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45875 if (idata->ic.postsleep_min_us)
45876 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45877
45878 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45879 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45880 err = -EFAULT;
45881 goto cmd_rel_host;
45882 }
45883 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45884 index f51b5ba..86614a7 100644
45885 --- a/drivers/mmc/core/mmc_ops.c
45886 +++ b/drivers/mmc/core/mmc_ops.c
45887 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45888 void *data_buf;
45889 int is_on_stack;
45890
45891 - is_on_stack = object_is_on_stack(buf);
45892 + is_on_stack = object_starts_on_stack(buf);
45893 if (is_on_stack) {
45894 /*
45895 * dma onto stack is unsafe/nonportable, but callers to this
45896 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45897 index 6834977..824ee1b 100644
45898 --- a/drivers/mmc/host/dw_mmc.h
45899 +++ b/drivers/mmc/host/dw_mmc.h
45900 @@ -259,5 +259,5 @@ struct dw_mci_drv_data {
45901 int (*parse_dt)(struct dw_mci *host);
45902 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45903 struct dw_mci_tuning_data *tuning_data);
45904 -};
45905 +} __do_const;
45906 #endif /* _DW_MMC_H_ */
45907 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45908 index 771c60a..12cb615 100644
45909 --- a/drivers/mmc/host/mmci.c
45910 +++ b/drivers/mmc/host/mmci.c
45911 @@ -1570,7 +1570,9 @@ static int mmci_probe(struct amba_device *dev,
45912 mmc->caps2 = plat->capabilities2;
45913
45914 if (variant->busy_detect) {
45915 - mmci_ops.card_busy = mmci_card_busy;
45916 + pax_open_kernel();
45917 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
45918 + pax_close_kernel();
45919 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45920 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
45921 mmc->max_busy_timeout = 0;
45922 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45923 index b841bb7..d82712f5 100644
45924 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
45925 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45926 @@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45927 host->mmc->caps |= MMC_CAP_1_8V_DDR;
45928 }
45929
45930 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45931 - sdhci_esdhc_ops.platform_execute_tuning =
45932 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45933 + pax_open_kernel();
45934 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45935 esdhc_executing_tuning;
45936 + pax_close_kernel();
45937 + }
45938
45939 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
45940 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
45941 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45942 index d61eb5a..88c0f5d 100644
45943 --- a/drivers/mmc/host/sdhci-s3c.c
45944 +++ b/drivers/mmc/host/sdhci-s3c.c
45945 @@ -657,9 +657,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45946 * we can use overriding functions instead of default.
45947 */
45948 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45949 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45950 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45951 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45952 + pax_open_kernel();
45953 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45954 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45955 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45956 + pax_close_kernel();
45957 }
45958
45959 /* It supports additional host capabilities if needed */
45960 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45961 index 6293855..3415551 100644
45962 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
45963 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45964 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45965 size_t totlen = 0, thislen;
45966 int ret = 0;
45967 size_t buflen = 0;
45968 - static char *buffer;
45969 + char *buffer;
45970
45971 if (!ECCBUF_SIZE) {
45972 /* We should fall back to a general writev implementation.
45973 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45974 index c07cd57..61c4fbd 100644
45975 --- a/drivers/mtd/nand/denali.c
45976 +++ b/drivers/mtd/nand/denali.c
45977 @@ -24,6 +24,7 @@
45978 #include <linux/slab.h>
45979 #include <linux/mtd/mtd.h>
45980 #include <linux/module.h>
45981 +#include <linux/slab.h>
45982
45983 #include "denali.h"
45984
45985 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45986 index bb77f75..47539b1 100644
45987 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45988 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45989 @@ -370,7 +370,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
45990
45991 /* first try to map the upper buffer directly */
45992 if (virt_addr_valid(this->upper_buf) &&
45993 - !object_is_on_stack(this->upper_buf)) {
45994 + !object_starts_on_stack(this->upper_buf)) {
45995 sg_init_one(sgl, this->upper_buf, this->upper_len);
45996 ret = dma_map_sg(this->dev, sgl, 1, dr);
45997 if (ret == 0)
45998 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45999 index 51b9d6a..52af9a7 100644
46000 --- a/drivers/mtd/nftlmount.c
46001 +++ b/drivers/mtd/nftlmount.c
46002 @@ -24,6 +24,7 @@
46003 #include <asm/errno.h>
46004 #include <linux/delay.h>
46005 #include <linux/slab.h>
46006 +#include <linux/sched.h>
46007 #include <linux/mtd/mtd.h>
46008 #include <linux/mtd/nand.h>
46009 #include <linux/mtd/nftl.h>
46010 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
46011 index cf49c22..971b133 100644
46012 --- a/drivers/mtd/sm_ftl.c
46013 +++ b/drivers/mtd/sm_ftl.c
46014 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
46015 #define SM_CIS_VENDOR_OFFSET 0x59
46016 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
46017 {
46018 - struct attribute_group *attr_group;
46019 + attribute_group_no_const *attr_group;
46020 struct attribute **attributes;
46021 struct sm_sysfs_attribute *vendor_attribute;
46022 char *vendor;
46023 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
46024 index f847e16..fc8dbe9 100644
46025 --- a/drivers/net/bonding/bond_netlink.c
46026 +++ b/drivers/net/bonding/bond_netlink.c
46027 @@ -542,7 +542,7 @@ nla_put_failure:
46028 return -EMSGSIZE;
46029 }
46030
46031 -struct rtnl_link_ops bond_link_ops __read_mostly = {
46032 +struct rtnl_link_ops bond_link_ops = {
46033 .kind = "bond",
46034 .priv_size = sizeof(struct bonding),
46035 .setup = bond_setup,
46036 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
46037 index 9e7d95d..d447b88 100644
46038 --- a/drivers/net/can/Kconfig
46039 +++ b/drivers/net/can/Kconfig
46040 @@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
46041
46042 config CAN_FLEXCAN
46043 tristate "Support for Freescale FLEXCAN based chips"
46044 - depends on ARM || PPC
46045 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
46046 ---help---
46047 Say Y here if you want to support for Freescale FlexCAN.
46048
46049 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
46050 index 455d4c3..3353ee7 100644
46051 --- a/drivers/net/ethernet/8390/ax88796.c
46052 +++ b/drivers/net/ethernet/8390/ax88796.c
46053 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
46054 if (ax->plat->reg_offsets)
46055 ei_local->reg_offset = ax->plat->reg_offsets;
46056 else {
46057 + resource_size_t _mem_size = mem_size;
46058 + do_div(_mem_size, 0x18);
46059 ei_local->reg_offset = ax->reg_offsets;
46060 for (ret = 0; ret < 0x18; ret++)
46061 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
46062 + ax->reg_offsets[ret] = _mem_size * ret;
46063 }
46064
46065 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
46066 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
46067 index 7330681..7e9e463 100644
46068 --- a/drivers/net/ethernet/altera/altera_tse_main.c
46069 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
46070 @@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
46071 return 0;
46072 }
46073
46074 -static struct net_device_ops altera_tse_netdev_ops = {
46075 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
46076 .ndo_open = tse_open,
46077 .ndo_stop = tse_shutdown,
46078 .ndo_start_xmit = tse_start_xmit,
46079 @@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
46080 ndev->netdev_ops = &altera_tse_netdev_ops;
46081 altera_tse_set_ethtool_ops(ndev);
46082
46083 + pax_open_kernel();
46084 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
46085
46086 if (priv->hash_filter)
46087 altera_tse_netdev_ops.ndo_set_rx_mode =
46088 tse_set_rx_mode_hashfilter;
46089 + pax_close_kernel();
46090
46091 /* Scatter/gather IO is not supported,
46092 * so it is turned off
46093 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46094 index 3448cc0..67b2dc4 100644
46095 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46096 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46097 @@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
46098 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
46099 {
46100 /* RX_MODE controlling object */
46101 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
46102 + bnx2x_init_rx_mode_obj(bp);
46103
46104 /* multicast configuration controlling object */
46105 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
46106 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46107 index 31297266..944cf6e 100644
46108 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46109 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46110 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
46111 return rc;
46112 }
46113
46114 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46115 - struct bnx2x_rx_mode_obj *o)
46116 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
46117 {
46118 if (CHIP_IS_E1x(bp)) {
46119 - o->wait_comp = bnx2x_empty_rx_mode_wait;
46120 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
46121 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
46122 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
46123 } else {
46124 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
46125 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
46126 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
46127 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
46128 }
46129 }
46130
46131 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46132 index 80f6c79..fb7d12d 100644
46133 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46134 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46135 @@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
46136
46137 /********************* RX MODE ****************/
46138
46139 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46140 - struct bnx2x_rx_mode_obj *o);
46141 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
46142
46143 /**
46144 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
46145 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
46146 index 04321e5..b51cdc4 100644
46147 --- a/drivers/net/ethernet/broadcom/tg3.h
46148 +++ b/drivers/net/ethernet/broadcom/tg3.h
46149 @@ -150,6 +150,7 @@
46150 #define CHIPREV_ID_5750_A0 0x4000
46151 #define CHIPREV_ID_5750_A1 0x4001
46152 #define CHIPREV_ID_5750_A3 0x4003
46153 +#define CHIPREV_ID_5750_C1 0x4201
46154 #define CHIPREV_ID_5750_C2 0x4202
46155 #define CHIPREV_ID_5752_A0_HW 0x5000
46156 #define CHIPREV_ID_5752_A0 0x6000
46157 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
46158 index 13f9636..228040f 100644
46159 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
46160 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
46161 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
46162 }
46163
46164 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
46165 - bna_cb_ioceth_enable,
46166 - bna_cb_ioceth_disable,
46167 - bna_cb_ioceth_hbfail,
46168 - bna_cb_ioceth_reset
46169 + .enable_cbfn = bna_cb_ioceth_enable,
46170 + .disable_cbfn = bna_cb_ioceth_disable,
46171 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
46172 + .reset_cbfn = bna_cb_ioceth_reset
46173 };
46174
46175 static void bna_attr_init(struct bna_ioceth *ioceth)
46176 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46177 index 8cffcdf..aadf043 100644
46178 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46179 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46180 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
46181 */
46182 struct l2t_skb_cb {
46183 arp_failure_handler_func arp_failure_handler;
46184 -};
46185 +} __no_const;
46186
46187 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
46188
46189 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46190 index 24e16e3..bfe6ef2 100644
46191 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46192 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46193 @@ -2139,7 +2139,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
46194
46195 int i;
46196 struct adapter *ap = netdev2adap(dev);
46197 - static const unsigned int *reg_ranges;
46198 + const unsigned int *reg_ranges;
46199 int arr_size = 0, buf_size = 0;
46200
46201 if (is_t4(ap->params.chip)) {
46202 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
46203 index c05b66d..ed69872 100644
46204 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
46205 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
46206 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46207 for (i=0; i<ETH_ALEN; i++) {
46208 tmp.addr[i] = dev->dev_addr[i];
46209 }
46210 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46211 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46212 break;
46213
46214 case DE4X5_SET_HWADDR: /* Set the hardware address */
46215 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46216 spin_lock_irqsave(&lp->lock, flags);
46217 memcpy(&statbuf, &lp->pktStats, ioc->len);
46218 spin_unlock_irqrestore(&lp->lock, flags);
46219 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
46220 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
46221 return -EFAULT;
46222 break;
46223 }
46224 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
46225 index dc19bc5..f2d4548 100644
46226 --- a/drivers/net/ethernet/emulex/benet/be_main.c
46227 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
46228 @@ -535,7 +535,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
46229
46230 if (wrapped)
46231 newacc += 65536;
46232 - ACCESS_ONCE(*acc) = newacc;
46233 + ACCESS_ONCE_RW(*acc) = newacc;
46234 }
46235
46236 static void populate_erx_stats(struct be_adapter *adapter,
46237 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
46238 index 68069ea..c4484f6 100644
46239 --- a/drivers/net/ethernet/faraday/ftgmac100.c
46240 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
46241 @@ -30,6 +30,8 @@
46242 #include <linux/netdevice.h>
46243 #include <linux/phy.h>
46244 #include <linux/platform_device.h>
46245 +#include <linux/interrupt.h>
46246 +#include <linux/irqreturn.h>
46247 #include <net/ip.h>
46248
46249 #include "ftgmac100.h"
46250 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
46251 index 8be5b40..081bc1b 100644
46252 --- a/drivers/net/ethernet/faraday/ftmac100.c
46253 +++ b/drivers/net/ethernet/faraday/ftmac100.c
46254 @@ -31,6 +31,8 @@
46255 #include <linux/module.h>
46256 #include <linux/netdevice.h>
46257 #include <linux/platform_device.h>
46258 +#include <linux/interrupt.h>
46259 +#include <linux/irqreturn.h>
46260
46261 #include "ftmac100.h"
46262
46263 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46264 index e61e637..9117795 100644
46265 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46266 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46267 @@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
46268 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
46269
46270 /* Update the base adjustement value. */
46271 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
46272 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
46273 smp_mb(); /* Force the above update. */
46274 }
46275
46276 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46277 index 8902ae6..e7bcdce 100644
46278 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46279 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46280 @@ -771,7 +771,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
46281 }
46282
46283 /* update the base incval used to calculate frequency adjustment */
46284 - ACCESS_ONCE(adapter->base_incval) = incval;
46285 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
46286 smp_mb();
46287
46288 /* need lock to prevent incorrect read while modifying cyclecounter */
46289 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46290 index 089b713..28d87ae 100644
46291 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
46292 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46293 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46294 struct __vxge_hw_fifo *fifo;
46295 struct vxge_hw_fifo_config *config;
46296 u32 txdl_size, txdl_per_memblock;
46297 - struct vxge_hw_mempool_cbs fifo_mp_callback;
46298 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
46299 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
46300 + };
46301 +
46302 struct __vxge_hw_virtualpath *vpath;
46303
46304 if ((vp == NULL) || (attr == NULL)) {
46305 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46306 goto exit;
46307 }
46308
46309 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46310 -
46311 fifo->mempool =
46312 __vxge_hw_mempool_create(vpath->hldev,
46313 fifo->config->memblock_size,
46314 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46315 index ba20c72..f30c0fe 100644
46316 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46317 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46318 @@ -2176,7 +2176,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46319 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46320 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46321 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46322 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46323 + pax_open_kernel();
46324 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46325 + pax_close_kernel();
46326 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46327 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46328 max_tx_rings = QLCNIC_MAX_TX_RINGS;
46329 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46330 index be7d7a6..a8983f8 100644
46331 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46332 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46333 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46334 case QLCNIC_NON_PRIV_FUNC:
46335 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46336 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46337 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46338 + pax_open_kernel();
46339 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46340 + pax_close_kernel();
46341 break;
46342 case QLCNIC_PRIV_FUNC:
46343 ahw->op_mode = QLCNIC_PRIV_FUNC;
46344 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46345 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46346 + pax_open_kernel();
46347 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46348 + pax_close_kernel();
46349 break;
46350 case QLCNIC_MGMT_FUNC:
46351 ahw->op_mode = QLCNIC_MGMT_FUNC;
46352 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46353 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46354 + pax_open_kernel();
46355 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46356 + pax_close_kernel();
46357 break;
46358 default:
46359 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46360 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46361 index 37b979b..50f5b95 100644
46362 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46363 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46364 @@ -1217,7 +1217,7 @@ flash_temp:
46365 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46366 {
46367 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46368 - static const struct qlcnic_dump_operations *fw_dump_ops;
46369 + const struct qlcnic_dump_operations *fw_dump_ops;
46370 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
46371 u32 entry_offset, dump, no_entries, buf_offset = 0;
46372 int i, k, ops_cnt, ops_index, dump_size = 0;
46373 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46374 index aa1c079..2b1a3e8 100644
46375 --- a/drivers/net/ethernet/realtek/r8169.c
46376 +++ b/drivers/net/ethernet/realtek/r8169.c
46377 @@ -758,22 +758,22 @@ struct rtl8169_private {
46378 struct mdio_ops {
46379 void (*write)(struct rtl8169_private *, int, int);
46380 int (*read)(struct rtl8169_private *, int);
46381 - } mdio_ops;
46382 + } __no_const mdio_ops;
46383
46384 struct pll_power_ops {
46385 void (*down)(struct rtl8169_private *);
46386 void (*up)(struct rtl8169_private *);
46387 - } pll_power_ops;
46388 + } __no_const pll_power_ops;
46389
46390 struct jumbo_ops {
46391 void (*enable)(struct rtl8169_private *);
46392 void (*disable)(struct rtl8169_private *);
46393 - } jumbo_ops;
46394 + } __no_const jumbo_ops;
46395
46396 struct csi_ops {
46397 void (*write)(struct rtl8169_private *, int, int);
46398 u32 (*read)(struct rtl8169_private *, int);
46399 - } csi_ops;
46400 + } __no_const csi_ops;
46401
46402 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46403 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46404 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46405 index 6b861e3..204ac86 100644
46406 --- a/drivers/net/ethernet/sfc/ptp.c
46407 +++ b/drivers/net/ethernet/sfc/ptp.c
46408 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46409 ptp->start.dma_addr);
46410
46411 /* Clear flag that signals MC ready */
46412 - ACCESS_ONCE(*start) = 0;
46413 + ACCESS_ONCE_RW(*start) = 0;
46414 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46415 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46416 EFX_BUG_ON_PARANOID(rc);
46417 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46418 index 50617c5..b13724c 100644
46419 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46420 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46421 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46422
46423 writel(value, ioaddr + MMC_CNTRL);
46424
46425 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46426 - MMC_CNTRL, value);
46427 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46428 +// MMC_CNTRL, value);
46429 }
46430
46431 /* To mask all all interrupts.*/
46432 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46433 index d18f711d..5755800 100644
46434 --- a/drivers/net/hyperv/hyperv_net.h
46435 +++ b/drivers/net/hyperv/hyperv_net.h
46436 @@ -101,7 +101,7 @@ struct rndis_device {
46437
46438 enum rndis_device_state state;
46439 bool link_state;
46440 - atomic_t new_req_id;
46441 + atomic_unchecked_t new_req_id;
46442
46443 spinlock_t request_lock;
46444 struct list_head req_list;
46445 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46446 index 143a98c..d54fbaa 100644
46447 --- a/drivers/net/hyperv/rndis_filter.c
46448 +++ b/drivers/net/hyperv/rndis_filter.c
46449 @@ -100,7 +100,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46450 * template
46451 */
46452 set = &rndis_msg->msg.set_req;
46453 - set->req_id = atomic_inc_return(&dev->new_req_id);
46454 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46455
46456 /* Add to the request list */
46457 spin_lock_irqsave(&dev->request_lock, flags);
46458 @@ -834,7 +834,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46459
46460 /* Setup the rndis set */
46461 halt = &request->request_msg.msg.halt_req;
46462 - halt->req_id = atomic_inc_return(&dev->new_req_id);
46463 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46464
46465 /* Ignore return since this msg is optional. */
46466 rndis_filter_send_request(dev, request);
46467 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46468 index 78f18be..1d19c62 100644
46469 --- a/drivers/net/ieee802154/fakehard.c
46470 +++ b/drivers/net/ieee802154/fakehard.c
46471 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46472 phy->transmit_power = 0xbf;
46473
46474 dev->netdev_ops = &fake_ops;
46475 - dev->ml_priv = &fake_mlme;
46476 + dev->ml_priv = (void *)&fake_mlme;
46477
46478 priv = netdev_priv(dev);
46479 priv->phy = phy;
46480 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46481 index 7eec598..90b8428 100644
46482 --- a/drivers/net/macvlan.c
46483 +++ b/drivers/net/macvlan.c
46484 @@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46485 int macvlan_link_register(struct rtnl_link_ops *ops)
46486 {
46487 /* common fields */
46488 - ops->priv_size = sizeof(struct macvlan_dev);
46489 - ops->validate = macvlan_validate;
46490 - ops->maxtype = IFLA_MACVLAN_MAX;
46491 - ops->policy = macvlan_policy;
46492 - ops->changelink = macvlan_changelink;
46493 - ops->get_size = macvlan_get_size;
46494 - ops->fill_info = macvlan_fill_info;
46495 + pax_open_kernel();
46496 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46497 + *(void **)&ops->validate = macvlan_validate;
46498 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46499 + *(const void **)&ops->policy = macvlan_policy;
46500 + *(void **)&ops->changelink = macvlan_changelink;
46501 + *(void **)&ops->get_size = macvlan_get_size;
46502 + *(void **)&ops->fill_info = macvlan_fill_info;
46503 + pax_close_kernel();
46504
46505 return rtnl_link_register(ops);
46506 };
46507 @@ -1044,7 +1046,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46508 return NOTIFY_DONE;
46509 }
46510
46511 -static struct notifier_block macvlan_notifier_block __read_mostly = {
46512 +static struct notifier_block macvlan_notifier_block = {
46513 .notifier_call = macvlan_device_event,
46514 };
46515
46516 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46517 index 3381c4f..dea5fd5 100644
46518 --- a/drivers/net/macvtap.c
46519 +++ b/drivers/net/macvtap.c
46520 @@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46521 }
46522
46523 ret = 0;
46524 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46525 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46526 put_user(q->flags, &ifr->ifr_flags))
46527 ret = -EFAULT;
46528 macvtap_put_vlan(vlan);
46529 @@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46530 return NOTIFY_DONE;
46531 }
46532
46533 -static struct notifier_block macvtap_notifier_block __read_mostly = {
46534 +static struct notifier_block macvtap_notifier_block = {
46535 .notifier_call = macvtap_device_event,
46536 };
46537
46538 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46539 index e3923eb..2a0373b 100644
46540 --- a/drivers/net/ppp/ppp_generic.c
46541 +++ b/drivers/net/ppp/ppp_generic.c
46542 @@ -1012,7 +1012,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46543 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46544 struct ppp_stats stats;
46545 struct ppp_comp_stats cstats;
46546 - char *vers;
46547
46548 switch (cmd) {
46549 case SIOCGPPPSTATS:
46550 @@ -1034,8 +1033,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46551 break;
46552
46553 case SIOCGPPPVER:
46554 - vers = PPP_VERSION;
46555 - if (copy_to_user(addr, vers, strlen(vers) + 1))
46556 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46557 break;
46558 err = 0;
46559 break;
46560 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46561 index 1252d9c..80e660b 100644
46562 --- a/drivers/net/slip/slhc.c
46563 +++ b/drivers/net/slip/slhc.c
46564 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46565 register struct tcphdr *thp;
46566 register struct iphdr *ip;
46567 register struct cstate *cs;
46568 - int len, hdrlen;
46569 + long len, hdrlen;
46570 unsigned char *cp = icp;
46571
46572 /* We've got a compressed packet; read the change byte */
46573 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46574 index ce4989b..b40b328 100644
46575 --- a/drivers/net/team/team.c
46576 +++ b/drivers/net/team/team.c
46577 @@ -2868,7 +2868,7 @@ static int team_device_event(struct notifier_block *unused,
46578 return NOTIFY_DONE;
46579 }
46580
46581 -static struct notifier_block team_notifier_block __read_mostly = {
46582 +static struct notifier_block team_notifier_block = {
46583 .notifier_call = team_device_event,
46584 };
46585
46586 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46587 index ee328ba..c4a0041 100644
46588 --- a/drivers/net/tun.c
46589 +++ b/drivers/net/tun.c
46590 @@ -1876,7 +1876,7 @@ unlock:
46591 }
46592
46593 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46594 - unsigned long arg, int ifreq_len)
46595 + unsigned long arg, size_t ifreq_len)
46596 {
46597 struct tun_file *tfile = file->private_data;
46598 struct tun_struct *tun;
46599 @@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46600 unsigned int ifindex;
46601 int ret;
46602
46603 + if (ifreq_len > sizeof ifr)
46604 + return -EFAULT;
46605 +
46606 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46607 if (copy_from_user(&ifr, argp, ifreq_len))
46608 return -EFAULT;
46609 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46610 index 660bd5e..ac59452 100644
46611 --- a/drivers/net/usb/hso.c
46612 +++ b/drivers/net/usb/hso.c
46613 @@ -71,7 +71,7 @@
46614 #include <asm/byteorder.h>
46615 #include <linux/serial_core.h>
46616 #include <linux/serial.h>
46617 -
46618 +#include <asm/local.h>
46619
46620 #define MOD_AUTHOR "Option Wireless"
46621 #define MOD_DESCRIPTION "USB High Speed Option driver"
46622 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46623 struct urb *urb;
46624
46625 urb = serial->rx_urb[0];
46626 - if (serial->port.count > 0) {
46627 + if (atomic_read(&serial->port.count) > 0) {
46628 count = put_rxbuf_data(urb, serial);
46629 if (count == -1)
46630 return;
46631 @@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46632 DUMP1(urb->transfer_buffer, urb->actual_length);
46633
46634 /* Anyone listening? */
46635 - if (serial->port.count == 0)
46636 + if (atomic_read(&serial->port.count) == 0)
46637 return;
46638
46639 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46640 @@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46641 tty_port_tty_set(&serial->port, tty);
46642
46643 /* check for port already opened, if not set the termios */
46644 - serial->port.count++;
46645 - if (serial->port.count == 1) {
46646 + if (atomic_inc_return(&serial->port.count) == 1) {
46647 serial->rx_state = RX_IDLE;
46648 /* Force default termio settings */
46649 _hso_serial_set_termios(tty, NULL);
46650 @@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46651 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46652 if (result) {
46653 hso_stop_serial_device(serial->parent);
46654 - serial->port.count--;
46655 + atomic_dec(&serial->port.count);
46656 kref_put(&serial->parent->ref, hso_serial_ref_free);
46657 }
46658 } else {
46659 @@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46660
46661 /* reset the rts and dtr */
46662 /* do the actual close */
46663 - serial->port.count--;
46664 + atomic_dec(&serial->port.count);
46665
46666 - if (serial->port.count <= 0) {
46667 - serial->port.count = 0;
46668 + if (atomic_read(&serial->port.count) <= 0) {
46669 + atomic_set(&serial->port.count, 0);
46670 tty_port_tty_set(&serial->port, NULL);
46671 if (!usb_gone)
46672 hso_stop_serial_device(serial->parent);
46673 @@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46674
46675 /* the actual setup */
46676 spin_lock_irqsave(&serial->serial_lock, flags);
46677 - if (serial->port.count)
46678 + if (atomic_read(&serial->port.count))
46679 _hso_serial_set_termios(tty, old);
46680 else
46681 tty->termios = *old;
46682 @@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46683 D1("Pending read interrupt on port %d\n", i);
46684 spin_lock(&serial->serial_lock);
46685 if (serial->rx_state == RX_IDLE &&
46686 - serial->port.count > 0) {
46687 + atomic_read(&serial->port.count) > 0) {
46688 /* Setup and send a ctrl req read on
46689 * port i */
46690 if (!serial->rx_urb_filled[0]) {
46691 @@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46692 /* Start all serial ports */
46693 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46694 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46695 - if (dev2ser(serial_table[i])->port.count) {
46696 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46697 result =
46698 hso_start_serial_device(serial_table[i], GFP_NOIO);
46699 hso_kick_transmit(dev2ser(serial_table[i]));
46700 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46701 index 3fbfb08..2c16265 100644
46702 --- a/drivers/net/usb/r8152.c
46703 +++ b/drivers/net/usb/r8152.c
46704 @@ -567,7 +567,7 @@ struct r8152 {
46705 void (*up)(struct r8152 *);
46706 void (*down)(struct r8152 *);
46707 void (*unload)(struct r8152 *);
46708 - } rtl_ops;
46709 + } __no_const rtl_ops;
46710
46711 int intr_interval;
46712 u32 saved_wolopts;
46713 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46714 index a2515887..6d13233 100644
46715 --- a/drivers/net/usb/sierra_net.c
46716 +++ b/drivers/net/usb/sierra_net.c
46717 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46718 /* atomic counter partially included in MAC address to make sure 2 devices
46719 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46720 */
46721 -static atomic_t iface_counter = ATOMIC_INIT(0);
46722 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46723
46724 /*
46725 * SYNC Timer Delay definition used to set the expiry time
46726 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46727 dev->net->netdev_ops = &sierra_net_device_ops;
46728
46729 /* change MAC addr to include, ifacenum, and to be unique */
46730 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46731 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46732 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46733
46734 /* we will have to manufacture ethernet headers, prepare template */
46735 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
46736 index 8a852b5..668a4b6 100644
46737 --- a/drivers/net/virtio_net.c
46738 +++ b/drivers/net/virtio_net.c
46739 @@ -47,7 +47,7 @@ module_param(gso, bool, 0444);
46740 #define RECEIVE_AVG_WEIGHT 64
46741
46742 /* Minimum alignment for mergeable packet buffers. */
46743 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
46744 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
46745
46746 #define VIRTNET_DRIVER_VERSION "1.0.0"
46747
46748 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46749 index 77dcf92..549924a 100644
46750 --- a/drivers/net/vxlan.c
46751 +++ b/drivers/net/vxlan.c
46752 @@ -2839,7 +2839,7 @@ nla_put_failure:
46753 return -EMSGSIZE;
46754 }
46755
46756 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46757 +static struct rtnl_link_ops vxlan_link_ops = {
46758 .kind = "vxlan",
46759 .maxtype = IFLA_VXLAN_MAX,
46760 .policy = vxlan_policy,
46761 @@ -2886,7 +2886,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46762 return NOTIFY_DONE;
46763 }
46764
46765 -static struct notifier_block vxlan_notifier_block __read_mostly = {
46766 +static struct notifier_block vxlan_notifier_block = {
46767 .notifier_call = vxlan_lowerdev_event,
46768 };
46769
46770 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46771 index 5920c99..ff2e4a5 100644
46772 --- a/drivers/net/wan/lmc/lmc_media.c
46773 +++ b/drivers/net/wan/lmc/lmc_media.c
46774 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46775 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46776
46777 lmc_media_t lmc_ds3_media = {
46778 - lmc_ds3_init, /* special media init stuff */
46779 - lmc_ds3_default, /* reset to default state */
46780 - lmc_ds3_set_status, /* reset status to state provided */
46781 - lmc_dummy_set_1, /* set clock source */
46782 - lmc_dummy_set2_1, /* set line speed */
46783 - lmc_ds3_set_100ft, /* set cable length */
46784 - lmc_ds3_set_scram, /* set scrambler */
46785 - lmc_ds3_get_link_status, /* get link status */
46786 - lmc_dummy_set_1, /* set link status */
46787 - lmc_ds3_set_crc_length, /* set CRC length */
46788 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46789 - lmc_ds3_watchdog
46790 + .init = lmc_ds3_init, /* special media init stuff */
46791 + .defaults = lmc_ds3_default, /* reset to default state */
46792 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
46793 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
46794 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46795 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46796 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46797 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
46798 + .set_link_status = lmc_dummy_set_1, /* set link status */
46799 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46800 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46801 + .watchdog = lmc_ds3_watchdog
46802 };
46803
46804 lmc_media_t lmc_hssi_media = {
46805 - lmc_hssi_init, /* special media init stuff */
46806 - lmc_hssi_default, /* reset to default state */
46807 - lmc_hssi_set_status, /* reset status to state provided */
46808 - lmc_hssi_set_clock, /* set clock source */
46809 - lmc_dummy_set2_1, /* set line speed */
46810 - lmc_dummy_set_1, /* set cable length */
46811 - lmc_dummy_set_1, /* set scrambler */
46812 - lmc_hssi_get_link_status, /* get link status */
46813 - lmc_hssi_set_link_status, /* set link status */
46814 - lmc_hssi_set_crc_length, /* set CRC length */
46815 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46816 - lmc_hssi_watchdog
46817 + .init = lmc_hssi_init, /* special media init stuff */
46818 + .defaults = lmc_hssi_default, /* reset to default state */
46819 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
46820 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46821 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46822 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46823 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46824 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
46825 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
46826 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46827 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46828 + .watchdog = lmc_hssi_watchdog
46829 };
46830
46831 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46832 - lmc_ssi_default, /* reset to default state */
46833 - lmc_ssi_set_status, /* reset status to state provided */
46834 - lmc_ssi_set_clock, /* set clock source */
46835 - lmc_ssi_set_speed, /* set line speed */
46836 - lmc_dummy_set_1, /* set cable length */
46837 - lmc_dummy_set_1, /* set scrambler */
46838 - lmc_ssi_get_link_status, /* get link status */
46839 - lmc_ssi_set_link_status, /* set link status */
46840 - lmc_ssi_set_crc_length, /* set CRC length */
46841 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46842 - lmc_ssi_watchdog
46843 +lmc_media_t lmc_ssi_media = {
46844 + .init = lmc_ssi_init, /* special media init stuff */
46845 + .defaults = lmc_ssi_default, /* reset to default state */
46846 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
46847 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46848 + .set_speed = lmc_ssi_set_speed, /* set line speed */
46849 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46850 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46851 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
46852 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
46853 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46854 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46855 + .watchdog = lmc_ssi_watchdog
46856 };
46857
46858 lmc_media_t lmc_t1_media = {
46859 - lmc_t1_init, /* special media init stuff */
46860 - lmc_t1_default, /* reset to default state */
46861 - lmc_t1_set_status, /* reset status to state provided */
46862 - lmc_t1_set_clock, /* set clock source */
46863 - lmc_dummy_set2_1, /* set line speed */
46864 - lmc_dummy_set_1, /* set cable length */
46865 - lmc_dummy_set_1, /* set scrambler */
46866 - lmc_t1_get_link_status, /* get link status */
46867 - lmc_dummy_set_1, /* set link status */
46868 - lmc_t1_set_crc_length, /* set CRC length */
46869 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46870 - lmc_t1_watchdog
46871 + .init = lmc_t1_init, /* special media init stuff */
46872 + .defaults = lmc_t1_default, /* reset to default state */
46873 + .set_status = lmc_t1_set_status, /* reset status to state provided */
46874 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
46875 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46876 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46877 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46878 + .get_link_status = lmc_t1_get_link_status, /* get link status */
46879 + .set_link_status = lmc_dummy_set_1, /* set link status */
46880 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46881 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46882 + .watchdog = lmc_t1_watchdog
46883 };
46884
46885 static void
46886 diff --git a/drivers/net/wan/x25_asy.c b/drivers/net/wan/x25_asy.c
46887 index 5895f19..fa9fdfa 100644
46888 --- a/drivers/net/wan/x25_asy.c
46889 +++ b/drivers/net/wan/x25_asy.c
46890 @@ -122,8 +122,12 @@ static int x25_asy_change_mtu(struct net_device *dev, int newmtu)
46891 {
46892 struct x25_asy *sl = netdev_priv(dev);
46893 unsigned char *xbuff, *rbuff;
46894 - int len = 2 * newmtu;
46895 + int len;
46896
46897 + if (newmtu > 65534)
46898 + return -EINVAL;
46899 +
46900 + len = 2 * newmtu;
46901 xbuff = kmalloc(len + 4, GFP_ATOMIC);
46902 rbuff = kmalloc(len + 4, GFP_ATOMIC);
46903
46904 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46905 index feacc3b..5bac0de 100644
46906 --- a/drivers/net/wan/z85230.c
46907 +++ b/drivers/net/wan/z85230.c
46908 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46909
46910 struct z8530_irqhandler z8530_sync =
46911 {
46912 - z8530_rx,
46913 - z8530_tx,
46914 - z8530_status
46915 + .rx = z8530_rx,
46916 + .tx = z8530_tx,
46917 + .status = z8530_status
46918 };
46919
46920 EXPORT_SYMBOL(z8530_sync);
46921 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46922 }
46923
46924 static struct z8530_irqhandler z8530_dma_sync = {
46925 - z8530_dma_rx,
46926 - z8530_dma_tx,
46927 - z8530_dma_status
46928 + .rx = z8530_dma_rx,
46929 + .tx = z8530_dma_tx,
46930 + .status = z8530_dma_status
46931 };
46932
46933 static struct z8530_irqhandler z8530_txdma_sync = {
46934 - z8530_rx,
46935 - z8530_dma_tx,
46936 - z8530_dma_status
46937 + .rx = z8530_rx,
46938 + .tx = z8530_dma_tx,
46939 + .status = z8530_dma_status
46940 };
46941
46942 /**
46943 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46944
46945 struct z8530_irqhandler z8530_nop=
46946 {
46947 - z8530_rx_clear,
46948 - z8530_tx_clear,
46949 - z8530_status_clear
46950 + .rx = z8530_rx_clear,
46951 + .tx = z8530_tx_clear,
46952 + .status = z8530_status_clear
46953 };
46954
46955
46956 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46957 index 0b60295..b8bfa5b 100644
46958 --- a/drivers/net/wimax/i2400m/rx.c
46959 +++ b/drivers/net/wimax/i2400m/rx.c
46960 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46961 if (i2400m->rx_roq == NULL)
46962 goto error_roq_alloc;
46963
46964 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46965 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46966 GFP_KERNEL);
46967 if (rd == NULL) {
46968 result = -ENOMEM;
46969 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46970 index 64747d4..17c4cf3 100644
46971 --- a/drivers/net/wireless/airo.c
46972 +++ b/drivers/net/wireless/airo.c
46973 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46974 struct airo_info *ai = dev->ml_priv;
46975 int ridcode;
46976 int enabled;
46977 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46978 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46979 unsigned char *iobuf;
46980
46981 /* Only super-user can write RIDs */
46982 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46983 index 99b3bfa..9559372 100644
46984 --- a/drivers/net/wireless/at76c50x-usb.c
46985 +++ b/drivers/net/wireless/at76c50x-usb.c
46986 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46987 }
46988
46989 /* Convert timeout from the DFU status to jiffies */
46990 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
46991 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46992 {
46993 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46994 | (s->poll_timeout[1] << 8)
46995 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46996 index 7f1bccd..ca2ffca 100644
46997 --- a/drivers/net/wireless/ath/ath10k/htc.c
46998 +++ b/drivers/net/wireless/ath/ath10k/htc.c
46999 @@ -840,7 +840,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
47000 /* registered target arrival callback from the HIF layer */
47001 int ath10k_htc_init(struct ath10k *ar)
47002 {
47003 - struct ath10k_hif_cb htc_callbacks;
47004 + static struct ath10k_hif_cb htc_callbacks = {
47005 + .rx_completion = ath10k_htc_rx_completion_handler,
47006 + .tx_completion = ath10k_htc_tx_completion_handler,
47007 + };
47008 struct ath10k_htc_ep *ep = NULL;
47009 struct ath10k_htc *htc = &ar->htc;
47010
47011 @@ -850,8 +853,6 @@ int ath10k_htc_init(struct ath10k *ar)
47012 ath10k_htc_reset_endpoint_states(htc);
47013
47014 /* setup HIF layer callbacks */
47015 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
47016 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
47017 htc->ar = ar;
47018
47019 /* Get HIF default pipe for HTC message exchange */
47020 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
47021 index 4716d33..a688310 100644
47022 --- a/drivers/net/wireless/ath/ath10k/htc.h
47023 +++ b/drivers/net/wireless/ath/ath10k/htc.h
47024 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
47025
47026 struct ath10k_htc_ops {
47027 void (*target_send_suspend_complete)(struct ath10k *ar);
47028 -};
47029 +} __no_const;
47030
47031 struct ath10k_htc_ep_ops {
47032 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
47033 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
47034 void (*ep_tx_credits)(struct ath10k *);
47035 -};
47036 +} __no_const;
47037
47038 /* service connection information */
47039 struct ath10k_htc_svc_conn_req {
47040 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47041 index 741b38d..b7ae41b 100644
47042 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47043 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47044 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47045 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
47046 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
47047
47048 - ACCESS_ONCE(ads->ds_link) = i->link;
47049 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
47050 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
47051 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
47052
47053 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
47054 ctl6 = SM(i->keytype, AR_EncrType);
47055 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47056
47057 if ((i->is_first || i->is_last) &&
47058 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
47059 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
47060 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
47061 | set11nTries(i->rates, 1)
47062 | set11nTries(i->rates, 2)
47063 | set11nTries(i->rates, 3)
47064 | (i->dur_update ? AR_DurUpdateEna : 0)
47065 | SM(0, AR_BurstDur);
47066
47067 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
47068 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
47069 | set11nRate(i->rates, 1)
47070 | set11nRate(i->rates, 2)
47071 | set11nRate(i->rates, 3);
47072 } else {
47073 - ACCESS_ONCE(ads->ds_ctl2) = 0;
47074 - ACCESS_ONCE(ads->ds_ctl3) = 0;
47075 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
47076 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
47077 }
47078
47079 if (!i->is_first) {
47080 - ACCESS_ONCE(ads->ds_ctl0) = 0;
47081 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47082 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47083 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
47084 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47085 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47086 return;
47087 }
47088
47089 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47090 break;
47091 }
47092
47093 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47094 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47095 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47096 | SM(i->txpower, AR_XmitPower)
47097 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47098 @@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47099 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
47100 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
47101
47102 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47103 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47104 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47105 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47106
47107 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
47108 return;
47109
47110 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47111 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47112 | set11nPktDurRTSCTS(i->rates, 1);
47113
47114 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47115 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47116 | set11nPktDurRTSCTS(i->rates, 3);
47117
47118 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47119 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47120 | set11nRateFlags(i->rates, 1)
47121 | set11nRateFlags(i->rates, 2)
47122 | set11nRateFlags(i->rates, 3)
47123 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47124 index 729ffbf..49f50e3 100644
47125 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47126 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47127 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47128 (i->qcu << AR_TxQcuNum_S) | desc_len;
47129
47130 checksum += val;
47131 - ACCESS_ONCE(ads->info) = val;
47132 + ACCESS_ONCE_RW(ads->info) = val;
47133
47134 checksum += i->link;
47135 - ACCESS_ONCE(ads->link) = i->link;
47136 + ACCESS_ONCE_RW(ads->link) = i->link;
47137
47138 checksum += i->buf_addr[0];
47139 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
47140 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
47141 checksum += i->buf_addr[1];
47142 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
47143 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
47144 checksum += i->buf_addr[2];
47145 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
47146 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
47147 checksum += i->buf_addr[3];
47148 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
47149 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
47150
47151 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
47152 - ACCESS_ONCE(ads->ctl3) = val;
47153 + ACCESS_ONCE_RW(ads->ctl3) = val;
47154 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
47155 - ACCESS_ONCE(ads->ctl5) = val;
47156 + ACCESS_ONCE_RW(ads->ctl5) = val;
47157 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
47158 - ACCESS_ONCE(ads->ctl7) = val;
47159 + ACCESS_ONCE_RW(ads->ctl7) = val;
47160 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
47161 - ACCESS_ONCE(ads->ctl9) = val;
47162 + ACCESS_ONCE_RW(ads->ctl9) = val;
47163
47164 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
47165 - ACCESS_ONCE(ads->ctl10) = checksum;
47166 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
47167
47168 if (i->is_first || i->is_last) {
47169 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
47170 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
47171 | set11nTries(i->rates, 1)
47172 | set11nTries(i->rates, 2)
47173 | set11nTries(i->rates, 3)
47174 | (i->dur_update ? AR_DurUpdateEna : 0)
47175 | SM(0, AR_BurstDur);
47176
47177 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
47178 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
47179 | set11nRate(i->rates, 1)
47180 | set11nRate(i->rates, 2)
47181 | set11nRate(i->rates, 3);
47182 } else {
47183 - ACCESS_ONCE(ads->ctl13) = 0;
47184 - ACCESS_ONCE(ads->ctl14) = 0;
47185 + ACCESS_ONCE_RW(ads->ctl13) = 0;
47186 + ACCESS_ONCE_RW(ads->ctl14) = 0;
47187 }
47188
47189 ads->ctl20 = 0;
47190 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47191
47192 ctl17 = SM(i->keytype, AR_EncrType);
47193 if (!i->is_first) {
47194 - ACCESS_ONCE(ads->ctl11) = 0;
47195 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47196 - ACCESS_ONCE(ads->ctl15) = 0;
47197 - ACCESS_ONCE(ads->ctl16) = 0;
47198 - ACCESS_ONCE(ads->ctl17) = ctl17;
47199 - ACCESS_ONCE(ads->ctl18) = 0;
47200 - ACCESS_ONCE(ads->ctl19) = 0;
47201 + ACCESS_ONCE_RW(ads->ctl11) = 0;
47202 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47203 + ACCESS_ONCE_RW(ads->ctl15) = 0;
47204 + ACCESS_ONCE_RW(ads->ctl16) = 0;
47205 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47206 + ACCESS_ONCE_RW(ads->ctl18) = 0;
47207 + ACCESS_ONCE_RW(ads->ctl19) = 0;
47208 return;
47209 }
47210
47211 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47212 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47213 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47214 | SM(i->txpower, AR_XmitPower)
47215 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47216 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47217 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
47218 ctl12 |= SM(val, AR_PAPRDChainMask);
47219
47220 - ACCESS_ONCE(ads->ctl12) = ctl12;
47221 - ACCESS_ONCE(ads->ctl17) = ctl17;
47222 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
47223 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47224
47225 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47226 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47227 | set11nPktDurRTSCTS(i->rates, 1);
47228
47229 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47230 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47231 | set11nPktDurRTSCTS(i->rates, 3);
47232
47233 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
47234 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
47235 | set11nRateFlags(i->rates, 1)
47236 | set11nRateFlags(i->rates, 2)
47237 | set11nRateFlags(i->rates, 3)
47238 | SM(i->rtscts_rate, AR_RTSCTSRate);
47239
47240 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
47241 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
47242 }
47243
47244 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
47245 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
47246 index 0acd4b5..0591c91 100644
47247 --- a/drivers/net/wireless/ath/ath9k/hw.h
47248 +++ b/drivers/net/wireless/ath/ath9k/hw.h
47249 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
47250
47251 /* ANI */
47252 void (*ani_cache_ini_regs)(struct ath_hw *ah);
47253 -};
47254 +} __no_const;
47255
47256 /**
47257 * struct ath_spec_scan - parameters for Atheros spectral scan
47258 @@ -706,7 +706,7 @@ struct ath_hw_ops {
47259 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
47260 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
47261 #endif
47262 -};
47263 +} __no_const;
47264
47265 struct ath_nf_limits {
47266 s16 max;
47267 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
47268 index 92190da..f3a4c4c 100644
47269 --- a/drivers/net/wireless/b43/phy_lp.c
47270 +++ b/drivers/net/wireless/b43/phy_lp.c
47271 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
47272 {
47273 struct ssb_bus *bus = dev->dev->sdev->bus;
47274
47275 - static const struct b206x_channel *chandata = NULL;
47276 + const struct b206x_channel *chandata = NULL;
47277 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
47278 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
47279 u16 old_comm15, scale;
47280 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
47281 index dc1d20c..f7a4f06 100644
47282 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
47283 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
47284 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47285 */
47286 if (il3945_mod_params.disable_hw_scan) {
47287 D_INFO("Disabling hw_scan\n");
47288 - il3945_mac_ops.hw_scan = NULL;
47289 + pax_open_kernel();
47290 + *(void **)&il3945_mac_ops.hw_scan = NULL;
47291 + pax_close_kernel();
47292 }
47293
47294 D_INFO("*** LOAD DRIVER ***\n");
47295 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47296 index d2fe259..0c4c682 100644
47297 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47298 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47299 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
47300 {
47301 struct iwl_priv *priv = file->private_data;
47302 char buf[64];
47303 - int buf_size;
47304 + size_t buf_size;
47305 u32 offset, len;
47306
47307 memset(buf, 0, sizeof(buf));
47308 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
47309 struct iwl_priv *priv = file->private_data;
47310
47311 char buf[8];
47312 - int buf_size;
47313 + size_t buf_size;
47314 u32 reset_flag;
47315
47316 memset(buf, 0, sizeof(buf));
47317 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
47318 {
47319 struct iwl_priv *priv = file->private_data;
47320 char buf[8];
47321 - int buf_size;
47322 + size_t buf_size;
47323 int ht40;
47324
47325 memset(buf, 0, sizeof(buf));
47326 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
47327 {
47328 struct iwl_priv *priv = file->private_data;
47329 char buf[8];
47330 - int buf_size;
47331 + size_t buf_size;
47332 int value;
47333
47334 memset(buf, 0, sizeof(buf));
47335 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47336 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47337 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47338
47339 -static const char *fmt_value = " %-30s %10u\n";
47340 -static const char *fmt_hex = " %-30s 0x%02X\n";
47341 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47342 -static const char *fmt_header =
47343 +static const char fmt_value[] = " %-30s %10u\n";
47344 +static const char fmt_hex[] = " %-30s 0x%02X\n";
47345 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47346 +static const char fmt_header[] =
47347 "%-32s current cumulative delta max\n";
47348
47349 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47350 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47351 {
47352 struct iwl_priv *priv = file->private_data;
47353 char buf[8];
47354 - int buf_size;
47355 + size_t buf_size;
47356 int clear;
47357
47358 memset(buf, 0, sizeof(buf));
47359 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47360 {
47361 struct iwl_priv *priv = file->private_data;
47362 char buf[8];
47363 - int buf_size;
47364 + size_t buf_size;
47365 int trace;
47366
47367 memset(buf, 0, sizeof(buf));
47368 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47369 {
47370 struct iwl_priv *priv = file->private_data;
47371 char buf[8];
47372 - int buf_size;
47373 + size_t buf_size;
47374 int missed;
47375
47376 memset(buf, 0, sizeof(buf));
47377 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47378
47379 struct iwl_priv *priv = file->private_data;
47380 char buf[8];
47381 - int buf_size;
47382 + size_t buf_size;
47383 int plcp;
47384
47385 memset(buf, 0, sizeof(buf));
47386 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47387
47388 struct iwl_priv *priv = file->private_data;
47389 char buf[8];
47390 - int buf_size;
47391 + size_t buf_size;
47392 int flush;
47393
47394 memset(buf, 0, sizeof(buf));
47395 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47396
47397 struct iwl_priv *priv = file->private_data;
47398 char buf[8];
47399 - int buf_size;
47400 + size_t buf_size;
47401 int rts;
47402
47403 if (!priv->cfg->ht_params)
47404 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47405 {
47406 struct iwl_priv *priv = file->private_data;
47407 char buf[8];
47408 - int buf_size;
47409 + size_t buf_size;
47410
47411 memset(buf, 0, sizeof(buf));
47412 buf_size = min(count, sizeof(buf) - 1);
47413 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47414 struct iwl_priv *priv = file->private_data;
47415 u32 event_log_flag;
47416 char buf[8];
47417 - int buf_size;
47418 + size_t buf_size;
47419
47420 /* check that the interface is up */
47421 if (!iwl_is_ready(priv))
47422 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47423 struct iwl_priv *priv = file->private_data;
47424 char buf[8];
47425 u32 calib_disabled;
47426 - int buf_size;
47427 + size_t buf_size;
47428
47429 memset(buf, 0, sizeof(buf));
47430 buf_size = min(count, sizeof(buf) - 1);
47431 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47432 index 6a6df71..eb5c93a 100644
47433 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
47434 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47435 @@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47436 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47437 {
47438 struct iwl_nvm_data *data = priv->nvm_data;
47439 - char *debug_msg;
47440 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47441
47442 if (data->sku_cap_11n_enable &&
47443 !priv->cfg->ht_params) {
47444 @@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47445 return -EINVAL;
47446 }
47447
47448 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47449 IWL_DEBUG_INFO(priv, debug_msg,
47450 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47451 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47452 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47453 index 295b24c..cb4f823 100644
47454 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47455 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47456 @@ -1558,7 +1558,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47457 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47458
47459 char buf[8];
47460 - int buf_size;
47461 + size_t buf_size;
47462 u32 reset_flag;
47463
47464 memset(buf, 0, sizeof(buf));
47465 @@ -1579,7 +1579,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47466 {
47467 struct iwl_trans *trans = file->private_data;
47468 char buf[8];
47469 - int buf_size;
47470 + size_t buf_size;
47471 int csr;
47472
47473 memset(buf, 0, sizeof(buf));
47474 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47475 index 9d7a52f..2729a99 100644
47476 --- a/drivers/net/wireless/mac80211_hwsim.c
47477 +++ b/drivers/net/wireless/mac80211_hwsim.c
47478 @@ -2570,20 +2570,20 @@ static int __init init_mac80211_hwsim(void)
47479 if (channels < 1)
47480 return -EINVAL;
47481
47482 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47483 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47484 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47485 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47486 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47487 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47488 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47489 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47490 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47491 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47492 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47493 - mac80211_hwsim_assign_vif_chanctx;
47494 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47495 - mac80211_hwsim_unassign_vif_chanctx;
47496 + pax_open_kernel();
47497 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47498 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47499 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47500 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47501 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47502 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47503 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47504 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47505 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47506 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47507 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47508 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47509 + pax_close_kernel();
47510
47511 spin_lock_init(&hwsim_radio_lock);
47512 INIT_LIST_HEAD(&hwsim_radios);
47513 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47514 index 39d22a1..4ec8612 100644
47515 --- a/drivers/net/wireless/rndis_wlan.c
47516 +++ b/drivers/net/wireless/rndis_wlan.c
47517 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47518
47519 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47520
47521 - if (rts_threshold < 0 || rts_threshold > 2347)
47522 + if (rts_threshold > 2347)
47523 rts_threshold = 2347;
47524
47525 tmp = cpu_to_le32(rts_threshold);
47526 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47527 index 5d45a1a..6f5f041 100644
47528 --- a/drivers/net/wireless/rt2x00/rt2x00.h
47529 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
47530 @@ -375,7 +375,7 @@ struct rt2x00_intf {
47531 * for hardware which doesn't support hardware
47532 * sequence counting.
47533 */
47534 - atomic_t seqno;
47535 + atomic_unchecked_t seqno;
47536 };
47537
47538 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47539 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47540 index 5642ccc..01f03eb 100644
47541 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47542 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47543 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47544 * sequence counter given by mac80211.
47545 */
47546 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47547 - seqno = atomic_add_return(0x10, &intf->seqno);
47548 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47549 else
47550 - seqno = atomic_read(&intf->seqno);
47551 + seqno = atomic_read_unchecked(&intf->seqno);
47552
47553 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47554 hdr->seq_ctrl |= cpu_to_le16(seqno);
47555 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47556 index b661f896..ddf7d2b 100644
47557 --- a/drivers/net/wireless/ti/wl1251/sdio.c
47558 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
47559 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47560
47561 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47562
47563 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47564 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47565 + pax_open_kernel();
47566 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47567 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47568 + pax_close_kernel();
47569
47570 wl1251_info("using dedicated interrupt line");
47571 } else {
47572 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47573 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47574 + pax_open_kernel();
47575 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47576 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47577 + pax_close_kernel();
47578
47579 wl1251_info("using SDIO interrupt");
47580 }
47581 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47582 index d50dfac..0a6f5be3 100644
47583 --- a/drivers/net/wireless/ti/wl12xx/main.c
47584 +++ b/drivers/net/wireless/ti/wl12xx/main.c
47585 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47586 sizeof(wl->conf.mem));
47587
47588 /* read data preparation is only needed by wl127x */
47589 - wl->ops->prepare_read = wl127x_prepare_read;
47590 + pax_open_kernel();
47591 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47592 + pax_close_kernel();
47593
47594 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47595 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47596 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47597 sizeof(wl->conf.mem));
47598
47599 /* read data preparation is only needed by wl127x */
47600 - wl->ops->prepare_read = wl127x_prepare_read;
47601 + pax_open_kernel();
47602 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47603 + pax_close_kernel();
47604
47605 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47606 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47607 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47608 index de5b4fa..7996ec6 100644
47609 --- a/drivers/net/wireless/ti/wl18xx/main.c
47610 +++ b/drivers/net/wireless/ti/wl18xx/main.c
47611 @@ -1900,8 +1900,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47612 }
47613
47614 if (!checksum_param) {
47615 - wl18xx_ops.set_rx_csum = NULL;
47616 - wl18xx_ops.init_vif = NULL;
47617 + pax_open_kernel();
47618 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
47619 + *(void **)&wl18xx_ops.init_vif = NULL;
47620 + pax_close_kernel();
47621 }
47622
47623 /* Enable 11a Band only if we have 5G antennas */
47624 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47625 index a912dc0..a8225ba 100644
47626 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
47627 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47628 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47629 {
47630 struct zd_usb *usb = urb->context;
47631 struct zd_usb_interrupt *intr = &usb->intr;
47632 - int len;
47633 + unsigned int len;
47634 u16 int_num;
47635
47636 ZD_ASSERT(in_interrupt());
47637 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47638 index 683671a..4519fc2 100644
47639 --- a/drivers/nfc/nfcwilink.c
47640 +++ b/drivers/nfc/nfcwilink.c
47641 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47642
47643 static int nfcwilink_probe(struct platform_device *pdev)
47644 {
47645 - static struct nfcwilink *drv;
47646 + struct nfcwilink *drv;
47647 int rc;
47648 __u32 protocols;
47649
47650 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47651 index d93b2b6..ae50401 100644
47652 --- a/drivers/oprofile/buffer_sync.c
47653 +++ b/drivers/oprofile/buffer_sync.c
47654 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47655 if (cookie == NO_COOKIE)
47656 offset = pc;
47657 if (cookie == INVALID_COOKIE) {
47658 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47659 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47660 offset = pc;
47661 }
47662 if (cookie != last_cookie) {
47663 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47664 /* add userspace sample */
47665
47666 if (!mm) {
47667 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
47668 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47669 return 0;
47670 }
47671
47672 cookie = lookup_dcookie(mm, s->eip, &offset);
47673
47674 if (cookie == INVALID_COOKIE) {
47675 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47676 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47677 return 0;
47678 }
47679
47680 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47681 /* ignore backtraces if failed to add a sample */
47682 if (state == sb_bt_start) {
47683 state = sb_bt_ignore;
47684 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47685 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47686 }
47687 }
47688 release_mm(mm);
47689 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47690 index c0cc4e7..44d4e54 100644
47691 --- a/drivers/oprofile/event_buffer.c
47692 +++ b/drivers/oprofile/event_buffer.c
47693 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47694 }
47695
47696 if (buffer_pos == buffer_size) {
47697 - atomic_inc(&oprofile_stats.event_lost_overflow);
47698 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47699 return;
47700 }
47701
47702 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47703 index ed2c3ec..deda85a 100644
47704 --- a/drivers/oprofile/oprof.c
47705 +++ b/drivers/oprofile/oprof.c
47706 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47707 if (oprofile_ops.switch_events())
47708 return;
47709
47710 - atomic_inc(&oprofile_stats.multiplex_counter);
47711 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47712 start_switch_worker();
47713 }
47714
47715 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47716 index ee2cfce..7f8f699 100644
47717 --- a/drivers/oprofile/oprofile_files.c
47718 +++ b/drivers/oprofile/oprofile_files.c
47719 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47720
47721 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47722
47723 -static ssize_t timeout_read(struct file *file, char __user *buf,
47724 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47725 size_t count, loff_t *offset)
47726 {
47727 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47728 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47729 index 59659ce..6c860a0 100644
47730 --- a/drivers/oprofile/oprofile_stats.c
47731 +++ b/drivers/oprofile/oprofile_stats.c
47732 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47733 cpu_buf->sample_invalid_eip = 0;
47734 }
47735
47736 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47737 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47738 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
47739 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47740 - atomic_set(&oprofile_stats.multiplex_counter, 0);
47741 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47742 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47743 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47744 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47745 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47746 }
47747
47748
47749 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47750 index 1fc622b..8c48fc3 100644
47751 --- a/drivers/oprofile/oprofile_stats.h
47752 +++ b/drivers/oprofile/oprofile_stats.h
47753 @@ -13,11 +13,11 @@
47754 #include <linux/atomic.h>
47755
47756 struct oprofile_stat_struct {
47757 - atomic_t sample_lost_no_mm;
47758 - atomic_t sample_lost_no_mapping;
47759 - atomic_t bt_lost_no_mapping;
47760 - atomic_t event_lost_overflow;
47761 - atomic_t multiplex_counter;
47762 + atomic_unchecked_t sample_lost_no_mm;
47763 + atomic_unchecked_t sample_lost_no_mapping;
47764 + atomic_unchecked_t bt_lost_no_mapping;
47765 + atomic_unchecked_t event_lost_overflow;
47766 + atomic_unchecked_t multiplex_counter;
47767 };
47768
47769 extern struct oprofile_stat_struct oprofile_stats;
47770 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47771 index 3f49345..c750d0b 100644
47772 --- a/drivers/oprofile/oprofilefs.c
47773 +++ b/drivers/oprofile/oprofilefs.c
47774 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47775
47776 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47777 {
47778 - atomic_t *val = file->private_data;
47779 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47780 + atomic_unchecked_t *val = file->private_data;
47781 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47782 }
47783
47784
47785 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47786
47787
47788 int oprofilefs_create_ro_atomic(struct dentry *root,
47789 - char const *name, atomic_t *val)
47790 + char const *name, atomic_unchecked_t *val)
47791 {
47792 return __oprofilefs_create_file(root, name,
47793 &atomic_ro_fops, 0444, val);
47794 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47795 index 61be1d9..dec05d7 100644
47796 --- a/drivers/oprofile/timer_int.c
47797 +++ b/drivers/oprofile/timer_int.c
47798 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47799 return NOTIFY_OK;
47800 }
47801
47802 -static struct notifier_block __refdata oprofile_cpu_notifier = {
47803 +static struct notifier_block oprofile_cpu_notifier = {
47804 .notifier_call = oprofile_cpu_notify,
47805 };
47806
47807 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47808 index 92ed045..62d39bd7 100644
47809 --- a/drivers/parport/procfs.c
47810 +++ b/drivers/parport/procfs.c
47811 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47812
47813 *ppos += len;
47814
47815 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47816 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47817 }
47818
47819 #ifdef CONFIG_PARPORT_1284
47820 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47821
47822 *ppos += len;
47823
47824 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47825 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47826 }
47827 #endif /* IEEE1284.3 support. */
47828
47829 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47830 index 8dcccff..35d701d 100644
47831 --- a/drivers/pci/hotplug/acpiphp_ibm.c
47832 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
47833 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47834 goto init_cleanup;
47835 }
47836
47837 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47838 + pax_open_kernel();
47839 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47840 + pax_close_kernel();
47841 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47842
47843 return retval;
47844 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47845 index 7536eef..52dc8fa 100644
47846 --- a/drivers/pci/hotplug/cpcihp_generic.c
47847 +++ b/drivers/pci/hotplug/cpcihp_generic.c
47848 @@ -73,7 +73,6 @@ static u16 port;
47849 static unsigned int enum_bit;
47850 static u8 enum_mask;
47851
47852 -static struct cpci_hp_controller_ops generic_hpc_ops;
47853 static struct cpci_hp_controller generic_hpc;
47854
47855 static int __init validate_parameters(void)
47856 @@ -139,6 +138,10 @@ static int query_enum(void)
47857 return ((value & enum_mask) == enum_mask);
47858 }
47859
47860 +static struct cpci_hp_controller_ops generic_hpc_ops = {
47861 + .query_enum = query_enum,
47862 +};
47863 +
47864 static int __init cpcihp_generic_init(void)
47865 {
47866 int status;
47867 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47868 pci_dev_put(dev);
47869
47870 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47871 - generic_hpc_ops.query_enum = query_enum;
47872 generic_hpc.ops = &generic_hpc_ops;
47873
47874 status = cpci_hp_register_controller(&generic_hpc);
47875 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47876 index e8c4a7c..7046f5c 100644
47877 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
47878 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47879 @@ -59,7 +59,6 @@
47880 /* local variables */
47881 static bool debug;
47882 static bool poll;
47883 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
47884 static struct cpci_hp_controller zt5550_hpc;
47885
47886 /* Primary cPCI bus bridge device */
47887 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47888 return 0;
47889 }
47890
47891 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47892 + .query_enum = zt5550_hc_query_enum,
47893 +};
47894 +
47895 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47896 {
47897 int status;
47898 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47899 dbg("returned from zt5550_hc_config");
47900
47901 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47902 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47903 zt5550_hpc.ops = &zt5550_hpc_ops;
47904 if(!poll) {
47905 zt5550_hpc.irq = hc_dev->irq;
47906 zt5550_hpc.irq_flags = IRQF_SHARED;
47907 zt5550_hpc.dev_id = hc_dev;
47908
47909 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47910 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47911 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47912 + pax_open_kernel();
47913 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47914 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47915 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47916 + pax_open_kernel();
47917 } else {
47918 info("using ENUM# polling mode");
47919 }
47920 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47921 index 76ba8a1..20ca857 100644
47922 --- a/drivers/pci/hotplug/cpqphp_nvram.c
47923 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
47924 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47925
47926 void compaq_nvram_init (void __iomem *rom_start)
47927 {
47928 +
47929 +#ifndef CONFIG_PAX_KERNEXEC
47930 if (rom_start) {
47931 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47932 }
47933 +#endif
47934 +
47935 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47936
47937 /* initialize our int15 lock */
47938 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47939 index cfa92a9..29539c5 100644
47940 --- a/drivers/pci/hotplug/pci_hotplug_core.c
47941 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
47942 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47943 return -EINVAL;
47944 }
47945
47946 - slot->ops->owner = owner;
47947 - slot->ops->mod_name = mod_name;
47948 + pax_open_kernel();
47949 + *(struct module **)&slot->ops->owner = owner;
47950 + *(const char **)&slot->ops->mod_name = mod_name;
47951 + pax_close_kernel();
47952
47953 mutex_lock(&pci_hp_mutex);
47954 /*
47955 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47956 index 0e0a2ff..29dff57 100644
47957 --- a/drivers/pci/hotplug/pciehp_core.c
47958 +++ b/drivers/pci/hotplug/pciehp_core.c
47959 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47960 struct slot *slot = ctrl->slot;
47961 struct hotplug_slot *hotplug = NULL;
47962 struct hotplug_slot_info *info = NULL;
47963 - struct hotplug_slot_ops *ops = NULL;
47964 + hotplug_slot_ops_no_const *ops = NULL;
47965 char name[SLOT_NAME_SIZE];
47966 int retval = -ENOMEM;
47967
47968 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
47969 index fb02fc2..83dc2c3 100644
47970 --- a/drivers/pci/msi.c
47971 +++ b/drivers/pci/msi.c
47972 @@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
47973 {
47974 struct attribute **msi_attrs;
47975 struct attribute *msi_attr;
47976 - struct device_attribute *msi_dev_attr;
47977 - struct attribute_group *msi_irq_group;
47978 + device_attribute_no_const *msi_dev_attr;
47979 + attribute_group_no_const *msi_irq_group;
47980 const struct attribute_group **msi_irq_groups;
47981 struct msi_desc *entry;
47982 int ret = -ENOMEM;
47983 @@ -589,7 +589,7 @@ error_attrs:
47984 count = 0;
47985 msi_attr = msi_attrs[count];
47986 while (msi_attr) {
47987 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
47988 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
47989 kfree(msi_attr->name);
47990 kfree(msi_dev_attr);
47991 ++count;
47992 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47993 index 4e0acef..bd98e31 100644
47994 --- a/drivers/pci/pci-sysfs.c
47995 +++ b/drivers/pci/pci-sysfs.c
47996 @@ -1101,7 +1101,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47997 {
47998 /* allocate attribute structure, piggyback attribute name */
47999 int name_len = write_combine ? 13 : 10;
48000 - struct bin_attribute *res_attr;
48001 + bin_attribute_no_const *res_attr;
48002 int retval;
48003
48004 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
48005 @@ -1286,7 +1286,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
48006 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
48007 {
48008 int retval;
48009 - struct bin_attribute *attr;
48010 + bin_attribute_no_const *attr;
48011
48012 /* If the device has VPD, try to expose it in sysfs. */
48013 if (dev->vpd) {
48014 @@ -1333,7 +1333,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
48015 {
48016 int retval;
48017 int rom_size = 0;
48018 - struct bin_attribute *attr;
48019 + bin_attribute_no_const *attr;
48020
48021 if (!sysfs_initialized)
48022 return -EACCES;
48023 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
48024 index 6bd0822..35bc2b3 100644
48025 --- a/drivers/pci/pci.h
48026 +++ b/drivers/pci/pci.h
48027 @@ -91,7 +91,7 @@ struct pci_vpd_ops {
48028 struct pci_vpd {
48029 unsigned int len;
48030 const struct pci_vpd_ops *ops;
48031 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
48032 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
48033 };
48034
48035 int pci_vpd_pci22_init(struct pci_dev *dev);
48036 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
48037 index e1e7026..d28dd33 100644
48038 --- a/drivers/pci/pcie/aspm.c
48039 +++ b/drivers/pci/pcie/aspm.c
48040 @@ -27,9 +27,9 @@
48041 #define MODULE_PARAM_PREFIX "pcie_aspm."
48042
48043 /* Note: those are not register definitions */
48044 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
48045 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
48046 -#define ASPM_STATE_L1 (4) /* L1 state */
48047 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
48048 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
48049 +#define ASPM_STATE_L1 (4U) /* L1 state */
48050 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
48051 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
48052
48053 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
48054 index ef09f5f..49ac62f 100644
48055 --- a/drivers/pci/probe.c
48056 +++ b/drivers/pci/probe.c
48057 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
48058 struct pci_bus_region region, inverted_region;
48059 bool bar_too_big = false, bar_disabled = false;
48060
48061 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
48062 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
48063
48064 /* No printks while decoding is disabled! */
48065 if (!dev->mmio_always_on) {
48066 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
48067 index 46d1378..30e452b 100644
48068 --- a/drivers/pci/proc.c
48069 +++ b/drivers/pci/proc.c
48070 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
48071 static int __init pci_proc_init(void)
48072 {
48073 struct pci_dev *dev = NULL;
48074 +
48075 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48076 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48077 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
48078 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48079 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48080 +#endif
48081 +#else
48082 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
48083 +#endif
48084 proc_create("devices", 0, proc_bus_pci_dir,
48085 &proc_bus_pci_dev_operations);
48086 proc_initialized = 1;
48087 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
48088 index 7f3aad0..7d604bb 100644
48089 --- a/drivers/platform/chrome/chromeos_laptop.c
48090 +++ b/drivers/platform/chrome/chromeos_laptop.c
48091 @@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
48092 .callback = chromeos_laptop_dmi_matched, \
48093 .driver_data = (void *)&board_
48094
48095 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
48096 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
48097 {
48098 .ident = "Samsung Series 5 550",
48099 .matches = {
48100 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
48101 index 541f951..4dfd598 100644
48102 --- a/drivers/platform/x86/alienware-wmi.c
48103 +++ b/drivers/platform/x86/alienware-wmi.c
48104 @@ -132,7 +132,7 @@ struct wmax_led_args {
48105 } __packed;
48106
48107 static struct platform_device *platform_device;
48108 -static struct device_attribute *zone_dev_attrs;
48109 +static device_attribute_no_const *zone_dev_attrs;
48110 static struct attribute **zone_attrs;
48111 static struct platform_zone *zone_data;
48112
48113 @@ -143,7 +143,7 @@ static struct platform_driver platform_driver = {
48114 }
48115 };
48116
48117 -static struct attribute_group zone_attribute_group = {
48118 +static attribute_group_no_const zone_attribute_group = {
48119 .name = "rgb_zones",
48120 };
48121
48122 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
48123 index c5e082f..d6307a0 100644
48124 --- a/drivers/platform/x86/asus-wmi.c
48125 +++ b/drivers/platform/x86/asus-wmi.c
48126 @@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
48127 int err;
48128 u32 retval = -1;
48129
48130 +#ifdef CONFIG_GRKERNSEC_KMEM
48131 + return -EPERM;
48132 +#endif
48133 +
48134 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
48135
48136 if (err < 0)
48137 @@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
48138 int err;
48139 u32 retval = -1;
48140
48141 +#ifdef CONFIG_GRKERNSEC_KMEM
48142 + return -EPERM;
48143 +#endif
48144 +
48145 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
48146 &retval);
48147
48148 @@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
48149 union acpi_object *obj;
48150 acpi_status status;
48151
48152 +#ifdef CONFIG_GRKERNSEC_KMEM
48153 + return -EPERM;
48154 +#endif
48155 +
48156 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
48157 1, asus->debug.method_id,
48158 &input, &output);
48159 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
48160 index 62f8030..c7f2a45 100644
48161 --- a/drivers/platform/x86/msi-laptop.c
48162 +++ b/drivers/platform/x86/msi-laptop.c
48163 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
48164
48165 if (!quirks->ec_read_only) {
48166 /* allow userland write sysfs file */
48167 - dev_attr_bluetooth.store = store_bluetooth;
48168 - dev_attr_wlan.store = store_wlan;
48169 - dev_attr_threeg.store = store_threeg;
48170 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
48171 - dev_attr_wlan.attr.mode |= S_IWUSR;
48172 - dev_attr_threeg.attr.mode |= S_IWUSR;
48173 + pax_open_kernel();
48174 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
48175 + *(void **)&dev_attr_wlan.store = store_wlan;
48176 + *(void **)&dev_attr_threeg.store = store_threeg;
48177 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
48178 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
48179 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
48180 + pax_close_kernel();
48181 }
48182
48183 /* disable hardware control by fn key */
48184 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
48185 index 70222f2..8c8ce66 100644
48186 --- a/drivers/platform/x86/msi-wmi.c
48187 +++ b/drivers/platform/x86/msi-wmi.c
48188 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
48189 static void msi_wmi_notify(u32 value, void *context)
48190 {
48191 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
48192 - static struct key_entry *key;
48193 + struct key_entry *key;
48194 union acpi_object *obj;
48195 acpi_status status;
48196
48197 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
48198 index 9c5a074..06c976a 100644
48199 --- a/drivers/platform/x86/sony-laptop.c
48200 +++ b/drivers/platform/x86/sony-laptop.c
48201 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
48202 }
48203
48204 /* High speed charging function */
48205 -static struct device_attribute *hsc_handle;
48206 +static device_attribute_no_const *hsc_handle;
48207
48208 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
48209 struct device_attribute *attr,
48210 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
48211 }
48212
48213 /* low battery function */
48214 -static struct device_attribute *lowbatt_handle;
48215 +static device_attribute_no_const *lowbatt_handle;
48216
48217 static ssize_t sony_nc_lowbatt_store(struct device *dev,
48218 struct device_attribute *attr,
48219 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
48220 }
48221
48222 /* fan speed function */
48223 -static struct device_attribute *fan_handle, *hsf_handle;
48224 +static device_attribute_no_const *fan_handle, *hsf_handle;
48225
48226 static ssize_t sony_nc_hsfan_store(struct device *dev,
48227 struct device_attribute *attr,
48228 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
48229 }
48230
48231 /* USB charge function */
48232 -static struct device_attribute *uc_handle;
48233 +static device_attribute_no_const *uc_handle;
48234
48235 static ssize_t sony_nc_usb_charge_store(struct device *dev,
48236 struct device_attribute *attr,
48237 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
48238 }
48239
48240 /* Panel ID function */
48241 -static struct device_attribute *panel_handle;
48242 +static device_attribute_no_const *panel_handle;
48243
48244 static ssize_t sony_nc_panelid_show(struct device *dev,
48245 struct device_attribute *attr, char *buffer)
48246 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
48247 }
48248
48249 /* smart connect function */
48250 -static struct device_attribute *sc_handle;
48251 +static device_attribute_no_const *sc_handle;
48252
48253 static ssize_t sony_nc_smart_conn_store(struct device *dev,
48254 struct device_attribute *attr,
48255 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
48256 index 15e61c1..40a39c7 100644
48257 --- a/drivers/platform/x86/thinkpad_acpi.c
48258 +++ b/drivers/platform/x86/thinkpad_acpi.c
48259 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
48260 return 0;
48261 }
48262
48263 -void static hotkey_mask_warn_incomplete_mask(void)
48264 +static void hotkey_mask_warn_incomplete_mask(void)
48265 {
48266 /* log only what the user can fix... */
48267 const u32 wantedmask = hotkey_driver_mask &
48268 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48269 && !tp_features.bright_unkfw)
48270 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48271 }
48272 +}
48273
48274 #undef TPACPI_COMPARE_KEY
48275 #undef TPACPI_MAY_SEND_KEY
48276 -}
48277
48278 /*
48279 * Polling driver
48280 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
48281 index 438d4c7..ca8a2fb 100644
48282 --- a/drivers/pnp/pnpbios/bioscalls.c
48283 +++ b/drivers/pnp/pnpbios/bioscalls.c
48284 @@ -59,7 +59,7 @@ do { \
48285 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
48286 } while(0)
48287
48288 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
48289 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
48290 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48291
48292 /*
48293 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48294
48295 cpu = get_cpu();
48296 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48297 +
48298 + pax_open_kernel();
48299 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48300 + pax_close_kernel();
48301
48302 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48303 spin_lock_irqsave(&pnp_bios_lock, flags);
48304 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48305 :"memory");
48306 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48307
48308 + pax_open_kernel();
48309 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48310 + pax_close_kernel();
48311 +
48312 put_cpu();
48313
48314 /* If we get here and this is set then the PnP BIOS faulted on us. */
48315 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48316 return status;
48317 }
48318
48319 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
48320 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48321 {
48322 int i;
48323
48324 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48325 pnp_bios_callpoint.offset = header->fields.pm16offset;
48326 pnp_bios_callpoint.segment = PNP_CS16;
48327
48328 + pax_open_kernel();
48329 +
48330 for_each_possible_cpu(i) {
48331 struct desc_struct *gdt = get_cpu_gdt_table(i);
48332 if (!gdt)
48333 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48334 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48335 (unsigned long)__va(header->fields.pm16dseg));
48336 }
48337 +
48338 + pax_close_kernel();
48339 }
48340 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48341 index 01712cb..782e822 100644
48342 --- a/drivers/pnp/resource.c
48343 +++ b/drivers/pnp/resource.c
48344 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48345 return 1;
48346
48347 /* check if the resource is valid */
48348 - if (*irq < 0 || *irq > 15)
48349 + if (*irq > 15)
48350 return 0;
48351
48352 /* check if the resource is reserved */
48353 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48354 return 1;
48355
48356 /* check if the resource is valid */
48357 - if (*dma < 0 || *dma == 4 || *dma > 7)
48358 + if (*dma == 4 || *dma > 7)
48359 return 0;
48360
48361 /* check if the resource is reserved */
48362 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48363 index 0c52e2a..3421ab7 100644
48364 --- a/drivers/power/pda_power.c
48365 +++ b/drivers/power/pda_power.c
48366 @@ -37,7 +37,11 @@ static int polling;
48367
48368 #if IS_ENABLED(CONFIG_USB_PHY)
48369 static struct usb_phy *transceiver;
48370 -static struct notifier_block otg_nb;
48371 +static int otg_handle_notification(struct notifier_block *nb,
48372 + unsigned long event, void *unused);
48373 +static struct notifier_block otg_nb = {
48374 + .notifier_call = otg_handle_notification
48375 +};
48376 #endif
48377
48378 static struct regulator *ac_draw;
48379 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48380
48381 #if IS_ENABLED(CONFIG_USB_PHY)
48382 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48383 - otg_nb.notifier_call = otg_handle_notification;
48384 ret = usb_register_notifier(transceiver, &otg_nb);
48385 if (ret) {
48386 dev_err(dev, "failure to register otg notifier\n");
48387 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48388 index cc439fd..8fa30df 100644
48389 --- a/drivers/power/power_supply.h
48390 +++ b/drivers/power/power_supply.h
48391 @@ -16,12 +16,12 @@ struct power_supply;
48392
48393 #ifdef CONFIG_SYSFS
48394
48395 -extern void power_supply_init_attrs(struct device_type *dev_type);
48396 +extern void power_supply_init_attrs(void);
48397 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48398
48399 #else
48400
48401 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48402 +static inline void power_supply_init_attrs(void) {}
48403 #define power_supply_uevent NULL
48404
48405 #endif /* CONFIG_SYSFS */
48406 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48407 index 2660664..75fcb04 100644
48408 --- a/drivers/power/power_supply_core.c
48409 +++ b/drivers/power/power_supply_core.c
48410 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48411 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48412 EXPORT_SYMBOL_GPL(power_supply_notifier);
48413
48414 -static struct device_type power_supply_dev_type;
48415 +extern const struct attribute_group *power_supply_attr_groups[];
48416 +static struct device_type power_supply_dev_type = {
48417 + .groups = power_supply_attr_groups,
48418 +};
48419
48420 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48421 struct power_supply *supply)
48422 @@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48423 return PTR_ERR(power_supply_class);
48424
48425 power_supply_class->dev_uevent = power_supply_uevent;
48426 - power_supply_init_attrs(&power_supply_dev_type);
48427 + power_supply_init_attrs();
48428
48429 return 0;
48430 }
48431 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48432 index 44420d1..967126e 100644
48433 --- a/drivers/power/power_supply_sysfs.c
48434 +++ b/drivers/power/power_supply_sysfs.c
48435 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48436 .is_visible = power_supply_attr_is_visible,
48437 };
48438
48439 -static const struct attribute_group *power_supply_attr_groups[] = {
48440 +const struct attribute_group *power_supply_attr_groups[] = {
48441 &power_supply_attr_group,
48442 NULL,
48443 };
48444
48445 -void power_supply_init_attrs(struct device_type *dev_type)
48446 +void power_supply_init_attrs(void)
48447 {
48448 int i;
48449
48450 - dev_type->groups = power_supply_attr_groups;
48451 -
48452 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48453 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48454 }
48455 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48456 index 84419af..268ede8 100644
48457 --- a/drivers/powercap/powercap_sys.c
48458 +++ b/drivers/powercap/powercap_sys.c
48459 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48460 struct device_attribute name_attr;
48461 };
48462
48463 +static ssize_t show_constraint_name(struct device *dev,
48464 + struct device_attribute *dev_attr,
48465 + char *buf);
48466 +
48467 static struct powercap_constraint_attr
48468 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48469 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48470 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48471 + .power_limit_attr = {
48472 + .attr = {
48473 + .name = NULL,
48474 + .mode = S_IWUSR | S_IRUGO
48475 + },
48476 + .show = show_constraint_power_limit_uw,
48477 + .store = store_constraint_power_limit_uw
48478 + },
48479 +
48480 + .time_window_attr = {
48481 + .attr = {
48482 + .name = NULL,
48483 + .mode = S_IWUSR | S_IRUGO
48484 + },
48485 + .show = show_constraint_time_window_us,
48486 + .store = store_constraint_time_window_us
48487 + },
48488 +
48489 + .max_power_attr = {
48490 + .attr = {
48491 + .name = NULL,
48492 + .mode = S_IRUGO
48493 + },
48494 + .show = show_constraint_max_power_uw,
48495 + .store = NULL
48496 + },
48497 +
48498 + .min_power_attr = {
48499 + .attr = {
48500 + .name = NULL,
48501 + .mode = S_IRUGO
48502 + },
48503 + .show = show_constraint_min_power_uw,
48504 + .store = NULL
48505 + },
48506 +
48507 + .max_time_window_attr = {
48508 + .attr = {
48509 + .name = NULL,
48510 + .mode = S_IRUGO
48511 + },
48512 + .show = show_constraint_max_time_window_us,
48513 + .store = NULL
48514 + },
48515 +
48516 + .min_time_window_attr = {
48517 + .attr = {
48518 + .name = NULL,
48519 + .mode = S_IRUGO
48520 + },
48521 + .show = show_constraint_min_time_window_us,
48522 + .store = NULL
48523 + },
48524 +
48525 + .name_attr = {
48526 + .attr = {
48527 + .name = NULL,
48528 + .mode = S_IRUGO
48529 + },
48530 + .show = show_constraint_name,
48531 + .store = NULL
48532 + }
48533 + }
48534 +};
48535
48536 /* A list of powercap control_types */
48537 static LIST_HEAD(powercap_cntrl_list);
48538 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48539 }
48540
48541 static int create_constraint_attribute(int id, const char *name,
48542 - int mode,
48543 - struct device_attribute *dev_attr,
48544 - ssize_t (*show)(struct device *,
48545 - struct device_attribute *, char *),
48546 - ssize_t (*store)(struct device *,
48547 - struct device_attribute *,
48548 - const char *, size_t)
48549 - )
48550 + struct device_attribute *dev_attr)
48551 {
48552 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48553
48554 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48555 - id, name);
48556 - if (!dev_attr->attr.name)
48557 + if (!name)
48558 return -ENOMEM;
48559 - dev_attr->attr.mode = mode;
48560 - dev_attr->show = show;
48561 - dev_attr->store = store;
48562 +
48563 + pax_open_kernel();
48564 + *(const char **)&dev_attr->attr.name = name;
48565 + pax_close_kernel();
48566
48567 return 0;
48568 }
48569 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48570
48571 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48572 ret = create_constraint_attribute(i, "power_limit_uw",
48573 - S_IWUSR | S_IRUGO,
48574 - &constraint_attrs[i].power_limit_attr,
48575 - show_constraint_power_limit_uw,
48576 - store_constraint_power_limit_uw);
48577 + &constraint_attrs[i].power_limit_attr);
48578 if (ret)
48579 goto err_alloc;
48580 ret = create_constraint_attribute(i, "time_window_us",
48581 - S_IWUSR | S_IRUGO,
48582 - &constraint_attrs[i].time_window_attr,
48583 - show_constraint_time_window_us,
48584 - store_constraint_time_window_us);
48585 + &constraint_attrs[i].time_window_attr);
48586 if (ret)
48587 goto err_alloc;
48588 - ret = create_constraint_attribute(i, "name", S_IRUGO,
48589 - &constraint_attrs[i].name_attr,
48590 - show_constraint_name,
48591 - NULL);
48592 + ret = create_constraint_attribute(i, "name",
48593 + &constraint_attrs[i].name_attr);
48594 if (ret)
48595 goto err_alloc;
48596 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48597 - &constraint_attrs[i].max_power_attr,
48598 - show_constraint_max_power_uw,
48599 - NULL);
48600 + ret = create_constraint_attribute(i, "max_power_uw",
48601 + &constraint_attrs[i].max_power_attr);
48602 if (ret)
48603 goto err_alloc;
48604 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48605 - &constraint_attrs[i].min_power_attr,
48606 - show_constraint_min_power_uw,
48607 - NULL);
48608 + ret = create_constraint_attribute(i, "min_power_uw",
48609 + &constraint_attrs[i].min_power_attr);
48610 if (ret)
48611 goto err_alloc;
48612 ret = create_constraint_attribute(i, "max_time_window_us",
48613 - S_IRUGO,
48614 - &constraint_attrs[i].max_time_window_attr,
48615 - show_constraint_max_time_window_us,
48616 - NULL);
48617 + &constraint_attrs[i].max_time_window_attr);
48618 if (ret)
48619 goto err_alloc;
48620 ret = create_constraint_attribute(i, "min_time_window_us",
48621 - S_IRUGO,
48622 - &constraint_attrs[i].min_time_window_attr,
48623 - show_constraint_min_time_window_us,
48624 - NULL);
48625 + &constraint_attrs[i].min_time_window_attr);
48626 if (ret)
48627 goto err_alloc;
48628
48629 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48630 power_zone->zone_dev_attrs[count++] =
48631 &dev_attr_max_energy_range_uj.attr;
48632 if (power_zone->ops->get_energy_uj) {
48633 + pax_open_kernel();
48634 if (power_zone->ops->reset_energy_uj)
48635 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48636 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48637 else
48638 - dev_attr_energy_uj.attr.mode = S_IRUGO;
48639 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48640 + pax_close_kernel();
48641 power_zone->zone_dev_attrs[count++] =
48642 &dev_attr_energy_uj.attr;
48643 }
48644 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
48645 index 9c5d414..c7900ce 100644
48646 --- a/drivers/ptp/ptp_private.h
48647 +++ b/drivers/ptp/ptp_private.h
48648 @@ -51,7 +51,7 @@ struct ptp_clock {
48649 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
48650 wait_queue_head_t tsev_wq;
48651 int defunct; /* tells readers to go away when clock is being removed */
48652 - struct device_attribute *pin_dev_attr;
48653 + device_attribute_no_const *pin_dev_attr;
48654 struct attribute **pin_attr;
48655 struct attribute_group pin_attr_group;
48656 };
48657 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
48658 index 302e626..12579af 100644
48659 --- a/drivers/ptp/ptp_sysfs.c
48660 +++ b/drivers/ptp/ptp_sysfs.c
48661 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
48662 goto no_pin_attr;
48663
48664 for (i = 0; i < n_pins; i++) {
48665 - struct device_attribute *da = &ptp->pin_dev_attr[i];
48666 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
48667 sysfs_attr_init(&da->attr);
48668 da->attr.name = info->pin_config[i].name;
48669 da->attr.mode = 0644;
48670 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48671 index 9a09f3c..450b523 100644
48672 --- a/drivers/regulator/core.c
48673 +++ b/drivers/regulator/core.c
48674 @@ -3380,7 +3380,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48675 {
48676 const struct regulation_constraints *constraints = NULL;
48677 const struct regulator_init_data *init_data;
48678 - static atomic_t regulator_no = ATOMIC_INIT(0);
48679 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48680 struct regulator_dev *rdev;
48681 struct device *dev;
48682 int ret, i;
48683 @@ -3450,7 +3450,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48684 rdev->dev.of_node = config->of_node;
48685 rdev->dev.parent = dev;
48686 dev_set_name(&rdev->dev, "regulator.%d",
48687 - atomic_inc_return(&regulator_no) - 1);
48688 + atomic_inc_return_unchecked(&regulator_no) - 1);
48689 ret = device_register(&rdev->dev);
48690 if (ret != 0) {
48691 put_device(&rdev->dev);
48692 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48693 index 2fc4111..6aa88ca 100644
48694 --- a/drivers/regulator/max8660.c
48695 +++ b/drivers/regulator/max8660.c
48696 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
48697 max8660->shadow_regs[MAX8660_OVER1] = 5;
48698 } else {
48699 /* Otherwise devices can be toggled via software */
48700 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
48701 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
48702 + pax_open_kernel();
48703 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48704 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48705 + pax_close_kernel();
48706 }
48707
48708 /*
48709 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48710 index dbedf17..18ff6b7 100644
48711 --- a/drivers/regulator/max8973-regulator.c
48712 +++ b/drivers/regulator/max8973-regulator.c
48713 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
48714 if (!pdata || !pdata->enable_ext_control) {
48715 max->desc.enable_reg = MAX8973_VOUT;
48716 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48717 - max->ops.enable = regulator_enable_regmap;
48718 - max->ops.disable = regulator_disable_regmap;
48719 - max->ops.is_enabled = regulator_is_enabled_regmap;
48720 + pax_open_kernel();
48721 + *(void **)&max->ops.enable = regulator_enable_regmap;
48722 + *(void **)&max->ops.disable = regulator_disable_regmap;
48723 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48724 + pax_close_kernel();
48725 }
48726
48727 if (pdata) {
48728 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48729 index f374fa5..26f0683 100644
48730 --- a/drivers/regulator/mc13892-regulator.c
48731 +++ b/drivers/regulator/mc13892-regulator.c
48732 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48733 }
48734 mc13xxx_unlock(mc13892);
48735
48736 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48737 + pax_open_kernel();
48738 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48739 = mc13892_vcam_set_mode;
48740 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48741 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48742 = mc13892_vcam_get_mode;
48743 + pax_close_kernel();
48744
48745 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48746 ARRAY_SIZE(mc13892_regulators));
48747 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48748 index 0963c93..ea29cce 100644
48749 --- a/drivers/rtc/rtc-cmos.c
48750 +++ b/drivers/rtc/rtc-cmos.c
48751 @@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48752 hpet_rtc_timer_init();
48753
48754 /* export at least the first block of NVRAM */
48755 - nvram.size = address_space - NVRAM_OFFSET;
48756 + pax_open_kernel();
48757 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48758 + pax_close_kernel();
48759 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48760 if (retval < 0) {
48761 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48762 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48763 index d049393..bb20be0 100644
48764 --- a/drivers/rtc/rtc-dev.c
48765 +++ b/drivers/rtc/rtc-dev.c
48766 @@ -16,6 +16,7 @@
48767 #include <linux/module.h>
48768 #include <linux/rtc.h>
48769 #include <linux/sched.h>
48770 +#include <linux/grsecurity.h>
48771 #include "rtc-core.h"
48772
48773 static dev_t rtc_devt;
48774 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48775 if (copy_from_user(&tm, uarg, sizeof(tm)))
48776 return -EFAULT;
48777
48778 + gr_log_timechange();
48779 +
48780 return rtc_set_time(rtc, &tm);
48781
48782 case RTC_PIE_ON:
48783 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48784 index f03d5ba..8325bf6 100644
48785 --- a/drivers/rtc/rtc-ds1307.c
48786 +++ b/drivers/rtc/rtc-ds1307.c
48787 @@ -107,7 +107,7 @@ struct ds1307 {
48788 u8 offset; /* register's offset */
48789 u8 regs[11];
48790 u16 nvram_offset;
48791 - struct bin_attribute *nvram;
48792 + bin_attribute_no_const *nvram;
48793 enum ds_type type;
48794 unsigned long flags;
48795 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48796 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48797 index 11880c1..b823aa4 100644
48798 --- a/drivers/rtc/rtc-m48t59.c
48799 +++ b/drivers/rtc/rtc-m48t59.c
48800 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48801 if (IS_ERR(m48t59->rtc))
48802 return PTR_ERR(m48t59->rtc);
48803
48804 - m48t59_nvram_attr.size = pdata->offset;
48805 + pax_open_kernel();
48806 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48807 + pax_close_kernel();
48808
48809 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48810 if (ret)
48811 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48812 index 14b5f8d..cc9bd26 100644
48813 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48814 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48815 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48816 for (bit = 0; bit < 8; bit++) {
48817
48818 if ((pci_status[i] & (0x1 << bit)) != 0) {
48819 - static const char *s;
48820 + const char *s;
48821
48822 s = pci_status_strings[bit];
48823 if (i == 7/*TARG*/ && bit == 3)
48824 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48825
48826 for (bit = 0; bit < 8; bit++) {
48827
48828 - if ((split_status[i] & (0x1 << bit)) != 0) {
48829 - static const char *s;
48830 -
48831 - s = split_status_strings[bit];
48832 - printk(s, ahd_name(ahd),
48833 + if ((split_status[i] & (0x1 << bit)) != 0)
48834 + printk(split_status_strings[bit], ahd_name(ahd),
48835 split_status_source[i]);
48836 - }
48837
48838 if (i > 1)
48839 continue;
48840
48841 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48842 - static const char *s;
48843 -
48844 - s = split_status_strings[bit];
48845 - printk(s, ahd_name(ahd), "SG");
48846 - }
48847 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
48848 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
48849 }
48850 }
48851 /*
48852 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48853 index e693af6..2e525b6 100644
48854 --- a/drivers/scsi/bfa/bfa_fcpim.h
48855 +++ b/drivers/scsi/bfa/bfa_fcpim.h
48856 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
48857
48858 struct bfa_itn_s {
48859 bfa_isr_func_t isr;
48860 -};
48861 +} __no_const;
48862
48863 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48864 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48865 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48866 index a3ab5cc..8143622 100644
48867 --- a/drivers/scsi/bfa/bfa_fcs.c
48868 +++ b/drivers/scsi/bfa/bfa_fcs.c
48869 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48870 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48871
48872 static struct bfa_fcs_mod_s fcs_modules[] = {
48873 - { bfa_fcs_port_attach, NULL, NULL },
48874 - { bfa_fcs_uf_attach, NULL, NULL },
48875 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48876 - bfa_fcs_fabric_modexit },
48877 + {
48878 + .attach = bfa_fcs_port_attach,
48879 + .modinit = NULL,
48880 + .modexit = NULL
48881 + },
48882 + {
48883 + .attach = bfa_fcs_uf_attach,
48884 + .modinit = NULL,
48885 + .modexit = NULL
48886 + },
48887 + {
48888 + .attach = bfa_fcs_fabric_attach,
48889 + .modinit = bfa_fcs_fabric_modinit,
48890 + .modexit = bfa_fcs_fabric_modexit
48891 + },
48892 };
48893
48894 /*
48895 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48896 index ff75ef8..2dfe00a 100644
48897 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
48898 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48899 @@ -89,15 +89,26 @@ static struct {
48900 void (*offline) (struct bfa_fcs_lport_s *port);
48901 } __port_action[] = {
48902 {
48903 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48904 - bfa_fcs_lport_unknown_offline}, {
48905 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48906 - bfa_fcs_lport_fab_offline}, {
48907 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48908 - bfa_fcs_lport_n2n_offline}, {
48909 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48910 - bfa_fcs_lport_loop_offline},
48911 - };
48912 + .init = bfa_fcs_lport_unknown_init,
48913 + .online = bfa_fcs_lport_unknown_online,
48914 + .offline = bfa_fcs_lport_unknown_offline
48915 + },
48916 + {
48917 + .init = bfa_fcs_lport_fab_init,
48918 + .online = bfa_fcs_lport_fab_online,
48919 + .offline = bfa_fcs_lport_fab_offline
48920 + },
48921 + {
48922 + .init = bfa_fcs_lport_n2n_init,
48923 + .online = bfa_fcs_lport_n2n_online,
48924 + .offline = bfa_fcs_lport_n2n_offline
48925 + },
48926 + {
48927 + .init = bfa_fcs_lport_loop_init,
48928 + .online = bfa_fcs_lport_loop_online,
48929 + .offline = bfa_fcs_lport_loop_offline
48930 + },
48931 +};
48932
48933 /*
48934 * fcs_port_sm FCS logical port state machine
48935 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48936 index 2e28392..9d865b6 100644
48937 --- a/drivers/scsi/bfa/bfa_ioc.h
48938 +++ b/drivers/scsi/bfa/bfa_ioc.h
48939 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48940 bfa_ioc_disable_cbfn_t disable_cbfn;
48941 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48942 bfa_ioc_reset_cbfn_t reset_cbfn;
48943 -};
48944 +} __no_const;
48945
48946 /*
48947 * IOC event notification mechanism.
48948 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48949 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48950 enum bfi_ioc_state fwstate);
48951 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48952 -};
48953 +} __no_const;
48954
48955 /*
48956 * Queue element to wait for room in request queue. FIFO order is
48957 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48958 index a14c784..6de6790 100644
48959 --- a/drivers/scsi/bfa/bfa_modules.h
48960 +++ b/drivers/scsi/bfa/bfa_modules.h
48961 @@ -78,12 +78,12 @@ enum {
48962 \
48963 extern struct bfa_module_s hal_mod_ ## __mod; \
48964 struct bfa_module_s hal_mod_ ## __mod = { \
48965 - bfa_ ## __mod ## _meminfo, \
48966 - bfa_ ## __mod ## _attach, \
48967 - bfa_ ## __mod ## _detach, \
48968 - bfa_ ## __mod ## _start, \
48969 - bfa_ ## __mod ## _stop, \
48970 - bfa_ ## __mod ## _iocdisable, \
48971 + .meminfo = bfa_ ## __mod ## _meminfo, \
48972 + .attach = bfa_ ## __mod ## _attach, \
48973 + .detach = bfa_ ## __mod ## _detach, \
48974 + .start = bfa_ ## __mod ## _start, \
48975 + .stop = bfa_ ## __mod ## _stop, \
48976 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
48977 }
48978
48979 #define BFA_CACHELINE_SZ (256)
48980 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48981 index 045c4e1..13de803 100644
48982 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
48983 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48984 @@ -33,8 +33,8 @@
48985 */
48986 #include "libfcoe.h"
48987
48988 -static atomic_t ctlr_num;
48989 -static atomic_t fcf_num;
48990 +static atomic_unchecked_t ctlr_num;
48991 +static atomic_unchecked_t fcf_num;
48992
48993 /*
48994 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48995 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48996 if (!ctlr)
48997 goto out;
48998
48999 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
49000 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
49001 ctlr->f = f;
49002 ctlr->mode = FIP_CONN_TYPE_FABRIC;
49003 INIT_LIST_HEAD(&ctlr->fcfs);
49004 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
49005 fcf->dev.parent = &ctlr->dev;
49006 fcf->dev.bus = &fcoe_bus_type;
49007 fcf->dev.type = &fcoe_fcf_device_type;
49008 - fcf->id = atomic_inc_return(&fcf_num) - 1;
49009 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
49010 fcf->state = FCOE_FCF_STATE_UNKNOWN;
49011
49012 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
49013 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
49014 {
49015 int error;
49016
49017 - atomic_set(&ctlr_num, 0);
49018 - atomic_set(&fcf_num, 0);
49019 + atomic_set_unchecked(&ctlr_num, 0);
49020 + atomic_set_unchecked(&fcf_num, 0);
49021
49022 error = bus_register(&fcoe_bus_type);
49023 if (error)
49024 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
49025 index 3cbb57a..95e47a3 100644
49026 --- a/drivers/scsi/hosts.c
49027 +++ b/drivers/scsi/hosts.c
49028 @@ -42,7 +42,7 @@
49029 #include "scsi_logging.h"
49030
49031
49032 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49033 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49034
49035
49036 static void scsi_host_cls_release(struct device *dev)
49037 @@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
49038 * subtract one because we increment first then return, but we need to
49039 * know what the next host number was before increment
49040 */
49041 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
49042 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
49043 shost->dma_channel = 0xff;
49044
49045 /* These three are default values which can be overridden */
49046 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
49047 index fda6cf1..7a6b5d8 100644
49048 --- a/drivers/scsi/hpsa.c
49049 +++ b/drivers/scsi/hpsa.c
49050 @@ -699,10 +699,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
49051 unsigned long flags;
49052
49053 if (h->transMethod & CFGTBL_Trans_io_accel1)
49054 - return h->access.command_completed(h, q);
49055 + return h->access->command_completed(h, q);
49056
49057 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
49058 - return h->access.command_completed(h, q);
49059 + return h->access->command_completed(h, q);
49060
49061 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
49062 a = rq->head[rq->current_entry];
49063 @@ -5460,7 +5460,7 @@ static void start_io(struct ctlr_info *h)
49064 while (!list_empty(&h->reqQ)) {
49065 c = list_entry(h->reqQ.next, struct CommandList, list);
49066 /* can't do anything if fifo is full */
49067 - if ((h->access.fifo_full(h))) {
49068 + if ((h->access->fifo_full(h))) {
49069 h->fifo_recently_full = 1;
49070 dev_warn(&h->pdev->dev, "fifo full\n");
49071 break;
49072 @@ -5484,7 +5484,7 @@ static void start_io(struct ctlr_info *h)
49073
49074 /* Tell the controller execute command */
49075 spin_unlock_irqrestore(&h->lock, flags);
49076 - h->access.submit_command(h, c);
49077 + h->access->submit_command(h, c);
49078 spin_lock_irqsave(&h->lock, flags);
49079 }
49080 spin_unlock_irqrestore(&h->lock, flags);
49081 @@ -5492,17 +5492,17 @@ static void start_io(struct ctlr_info *h)
49082
49083 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
49084 {
49085 - return h->access.command_completed(h, q);
49086 + return h->access->command_completed(h, q);
49087 }
49088
49089 static inline bool interrupt_pending(struct ctlr_info *h)
49090 {
49091 - return h->access.intr_pending(h);
49092 + return h->access->intr_pending(h);
49093 }
49094
49095 static inline long interrupt_not_for_us(struct ctlr_info *h)
49096 {
49097 - return (h->access.intr_pending(h) == 0) ||
49098 + return (h->access->intr_pending(h) == 0) ||
49099 (h->interrupts_enabled == 0);
49100 }
49101
49102 @@ -6456,7 +6456,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
49103 if (prod_index < 0)
49104 return -ENODEV;
49105 h->product_name = products[prod_index].product_name;
49106 - h->access = *(products[prod_index].access);
49107 + h->access = products[prod_index].access;
49108
49109 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
49110 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
49111 @@ -6735,7 +6735,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
49112 {
49113 unsigned long flags;
49114
49115 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49116 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49117 spin_lock_irqsave(&h->lock, flags);
49118 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
49119 spin_unlock_irqrestore(&h->lock, flags);
49120 @@ -6963,7 +6963,7 @@ reinit_after_soft_reset:
49121 }
49122
49123 /* make sure the board interrupts are off */
49124 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49125 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49126
49127 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
49128 goto clean2;
49129 @@ -6998,7 +6998,7 @@ reinit_after_soft_reset:
49130 * fake ones to scoop up any residual completions.
49131 */
49132 spin_lock_irqsave(&h->lock, flags);
49133 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49134 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49135 spin_unlock_irqrestore(&h->lock, flags);
49136 free_irqs(h);
49137 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
49138 @@ -7017,9 +7017,9 @@ reinit_after_soft_reset:
49139 dev_info(&h->pdev->dev, "Board READY.\n");
49140 dev_info(&h->pdev->dev,
49141 "Waiting for stale completions to drain.\n");
49142 - h->access.set_intr_mask(h, HPSA_INTR_ON);
49143 + h->access->set_intr_mask(h, HPSA_INTR_ON);
49144 msleep(10000);
49145 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49146 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49147
49148 rc = controller_reset_failed(h->cfgtable);
49149 if (rc)
49150 @@ -7045,7 +7045,7 @@ reinit_after_soft_reset:
49151 h->drv_req_rescan = 0;
49152
49153 /* Turn the interrupts on so we can service requests */
49154 - h->access.set_intr_mask(h, HPSA_INTR_ON);
49155 + h->access->set_intr_mask(h, HPSA_INTR_ON);
49156
49157 hpsa_hba_inquiry(h);
49158 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
49159 @@ -7114,7 +7114,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
49160 * To write all data in the battery backed cache to disks
49161 */
49162 hpsa_flush_cache(h);
49163 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49164 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49165 hpsa_free_irqs_and_disable_msix(h);
49166 }
49167
49168 @@ -7232,7 +7232,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
49169 CFGTBL_Trans_enable_directed_msix |
49170 (trans_support & (CFGTBL_Trans_io_accel1 |
49171 CFGTBL_Trans_io_accel2));
49172 - struct access_method access = SA5_performant_access;
49173 + struct access_method *access = &SA5_performant_access;
49174
49175 /* This is a bit complicated. There are 8 registers on
49176 * the controller which we write to to tell it 8 different
49177 @@ -7297,12 +7297,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
49178 * enable outbound interrupt coalescing in accelerator mode;
49179 */
49180 if (trans_support & CFGTBL_Trans_io_accel1) {
49181 - access = SA5_ioaccel_mode1_access;
49182 + access = &SA5_ioaccel_mode1_access;
49183 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
49184 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
49185 } else {
49186 if (trans_support & CFGTBL_Trans_io_accel2) {
49187 - access = SA5_ioaccel_mode2_access;
49188 + access = &SA5_ioaccel_mode2_access;
49189 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
49190 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
49191 }
49192 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
49193 index 44235a2..962e91b 100644
49194 --- a/drivers/scsi/hpsa.h
49195 +++ b/drivers/scsi/hpsa.h
49196 @@ -128,7 +128,7 @@ struct ctlr_info {
49197 unsigned int msix_vector;
49198 unsigned int msi_vector;
49199 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
49200 - struct access_method access;
49201 + struct access_method *access;
49202 char hba_mode_enabled;
49203
49204 /* queue and queue Info */
49205 @@ -541,35 +541,35 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
49206 }
49207
49208 static struct access_method SA5_access = {
49209 - SA5_submit_command,
49210 - SA5_intr_mask,
49211 - SA5_fifo_full,
49212 - SA5_intr_pending,
49213 - SA5_completed,
49214 + .submit_command = SA5_submit_command,
49215 + .set_intr_mask = SA5_intr_mask,
49216 + .fifo_full = SA5_fifo_full,
49217 + .intr_pending = SA5_intr_pending,
49218 + .command_completed = SA5_completed,
49219 };
49220
49221 static struct access_method SA5_ioaccel_mode1_access = {
49222 - SA5_submit_command,
49223 - SA5_performant_intr_mask,
49224 - SA5_fifo_full,
49225 - SA5_ioaccel_mode1_intr_pending,
49226 - SA5_ioaccel_mode1_completed,
49227 + .submit_command = SA5_submit_command,
49228 + .set_intr_mask = SA5_performant_intr_mask,
49229 + .fifo_full = SA5_fifo_full,
49230 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
49231 + .command_completed = SA5_ioaccel_mode1_completed,
49232 };
49233
49234 static struct access_method SA5_ioaccel_mode2_access = {
49235 - SA5_submit_command_ioaccel2,
49236 - SA5_performant_intr_mask,
49237 - SA5_fifo_full,
49238 - SA5_performant_intr_pending,
49239 - SA5_performant_completed,
49240 + .submit_command = SA5_submit_command_ioaccel2,
49241 + .set_intr_mask = SA5_performant_intr_mask,
49242 + .fifo_full = SA5_fifo_full,
49243 + .intr_pending = SA5_performant_intr_pending,
49244 + .command_completed = SA5_performant_completed,
49245 };
49246
49247 static struct access_method SA5_performant_access = {
49248 - SA5_submit_command,
49249 - SA5_performant_intr_mask,
49250 - SA5_fifo_full,
49251 - SA5_performant_intr_pending,
49252 - SA5_performant_completed,
49253 + .submit_command = SA5_submit_command,
49254 + .set_intr_mask = SA5_performant_intr_mask,
49255 + .fifo_full = SA5_fifo_full,
49256 + .intr_pending = SA5_performant_intr_pending,
49257 + .command_completed = SA5_performant_completed,
49258 };
49259
49260 struct board_type {
49261 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
49262 index 1b3a094..068e683 100644
49263 --- a/drivers/scsi/libfc/fc_exch.c
49264 +++ b/drivers/scsi/libfc/fc_exch.c
49265 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
49266 u16 pool_max_index;
49267
49268 struct {
49269 - atomic_t no_free_exch;
49270 - atomic_t no_free_exch_xid;
49271 - atomic_t xid_not_found;
49272 - atomic_t xid_busy;
49273 - atomic_t seq_not_found;
49274 - atomic_t non_bls_resp;
49275 + atomic_unchecked_t no_free_exch;
49276 + atomic_unchecked_t no_free_exch_xid;
49277 + atomic_unchecked_t xid_not_found;
49278 + atomic_unchecked_t xid_busy;
49279 + atomic_unchecked_t seq_not_found;
49280 + atomic_unchecked_t non_bls_resp;
49281 } stats;
49282 };
49283
49284 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
49285 /* allocate memory for exchange */
49286 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
49287 if (!ep) {
49288 - atomic_inc(&mp->stats.no_free_exch);
49289 + atomic_inc_unchecked(&mp->stats.no_free_exch);
49290 goto out;
49291 }
49292 memset(ep, 0, sizeof(*ep));
49293 @@ -874,7 +874,7 @@ out:
49294 return ep;
49295 err:
49296 spin_unlock_bh(&pool->lock);
49297 - atomic_inc(&mp->stats.no_free_exch_xid);
49298 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
49299 mempool_free(ep, mp->ep_pool);
49300 return NULL;
49301 }
49302 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49303 xid = ntohs(fh->fh_ox_id); /* we originated exch */
49304 ep = fc_exch_find(mp, xid);
49305 if (!ep) {
49306 - atomic_inc(&mp->stats.xid_not_found);
49307 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49308 reject = FC_RJT_OX_ID;
49309 goto out;
49310 }
49311 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49312 ep = fc_exch_find(mp, xid);
49313 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
49314 if (ep) {
49315 - atomic_inc(&mp->stats.xid_busy);
49316 + atomic_inc_unchecked(&mp->stats.xid_busy);
49317 reject = FC_RJT_RX_ID;
49318 goto rel;
49319 }
49320 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49321 }
49322 xid = ep->xid; /* get our XID */
49323 } else if (!ep) {
49324 - atomic_inc(&mp->stats.xid_not_found);
49325 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49326 reject = FC_RJT_RX_ID; /* XID not found */
49327 goto out;
49328 }
49329 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49330 } else {
49331 sp = &ep->seq;
49332 if (sp->id != fh->fh_seq_id) {
49333 - atomic_inc(&mp->stats.seq_not_found);
49334 + atomic_inc_unchecked(&mp->stats.seq_not_found);
49335 if (f_ctl & FC_FC_END_SEQ) {
49336 /*
49337 * Update sequence_id based on incoming last
49338 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49339
49340 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49341 if (!ep) {
49342 - atomic_inc(&mp->stats.xid_not_found);
49343 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49344 goto out;
49345 }
49346 if (ep->esb_stat & ESB_ST_COMPLETE) {
49347 - atomic_inc(&mp->stats.xid_not_found);
49348 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49349 goto rel;
49350 }
49351 if (ep->rxid == FC_XID_UNKNOWN)
49352 ep->rxid = ntohs(fh->fh_rx_id);
49353 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49354 - atomic_inc(&mp->stats.xid_not_found);
49355 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49356 goto rel;
49357 }
49358 if (ep->did != ntoh24(fh->fh_s_id) &&
49359 ep->did != FC_FID_FLOGI) {
49360 - atomic_inc(&mp->stats.xid_not_found);
49361 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49362 goto rel;
49363 }
49364 sof = fr_sof(fp);
49365 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49366 sp->ssb_stat |= SSB_ST_RESP;
49367 sp->id = fh->fh_seq_id;
49368 } else if (sp->id != fh->fh_seq_id) {
49369 - atomic_inc(&mp->stats.seq_not_found);
49370 + atomic_inc_unchecked(&mp->stats.seq_not_found);
49371 goto rel;
49372 }
49373
49374 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49375 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49376
49377 if (!sp)
49378 - atomic_inc(&mp->stats.xid_not_found);
49379 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49380 else
49381 - atomic_inc(&mp->stats.non_bls_resp);
49382 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
49383
49384 fc_frame_free(fp);
49385 }
49386 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49387
49388 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49389 mp = ema->mp;
49390 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49391 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49392 st->fc_no_free_exch_xid +=
49393 - atomic_read(&mp->stats.no_free_exch_xid);
49394 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49395 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49396 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49397 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49398 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49399 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49400 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49401 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49402 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49403 }
49404 }
49405 EXPORT_SYMBOL(fc_exch_update_stats);
49406 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49407 index 766098a..1c6c971 100644
49408 --- a/drivers/scsi/libsas/sas_ata.c
49409 +++ b/drivers/scsi/libsas/sas_ata.c
49410 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49411 .postreset = ata_std_postreset,
49412 .error_handler = ata_std_error_handler,
49413 .post_internal_cmd = sas_ata_post_internal,
49414 - .qc_defer = ata_std_qc_defer,
49415 + .qc_defer = ata_std_qc_defer,
49416 .qc_prep = ata_noop_qc_prep,
49417 .qc_issue = sas_ata_qc_issue,
49418 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49419 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49420 index 94a3caf..a118dec 100644
49421 --- a/drivers/scsi/lpfc/lpfc.h
49422 +++ b/drivers/scsi/lpfc/lpfc.h
49423 @@ -430,7 +430,7 @@ struct lpfc_vport {
49424 struct dentry *debug_nodelist;
49425 struct dentry *vport_debugfs_root;
49426 struct lpfc_debugfs_trc *disc_trc;
49427 - atomic_t disc_trc_cnt;
49428 + atomic_unchecked_t disc_trc_cnt;
49429 #endif
49430 uint8_t stat_data_enabled;
49431 uint8_t stat_data_blocked;
49432 @@ -879,8 +879,8 @@ struct lpfc_hba {
49433 struct timer_list fabric_block_timer;
49434 unsigned long bit_flags;
49435 #define FABRIC_COMANDS_BLOCKED 0
49436 - atomic_t num_rsrc_err;
49437 - atomic_t num_cmd_success;
49438 + atomic_unchecked_t num_rsrc_err;
49439 + atomic_unchecked_t num_cmd_success;
49440 unsigned long last_rsrc_error_time;
49441 unsigned long last_ramp_down_time;
49442 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
49443 @@ -915,7 +915,7 @@ struct lpfc_hba {
49444
49445 struct dentry *debug_slow_ring_trc;
49446 struct lpfc_debugfs_trc *slow_ring_trc;
49447 - atomic_t slow_ring_trc_cnt;
49448 + atomic_unchecked_t slow_ring_trc_cnt;
49449 /* iDiag debugfs sub-directory */
49450 struct dentry *idiag_root;
49451 struct dentry *idiag_pci_cfg;
49452 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49453 index 828c08e..e3378e0 100644
49454 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
49455 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49456 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49457
49458 #include <linux/debugfs.h>
49459
49460 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49461 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49462 static unsigned long lpfc_debugfs_start_time = 0L;
49463
49464 /* iDiag */
49465 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49466 lpfc_debugfs_enable = 0;
49467
49468 len = 0;
49469 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49470 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49471 (lpfc_debugfs_max_disc_trc - 1);
49472 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49473 dtp = vport->disc_trc + i;
49474 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49475 lpfc_debugfs_enable = 0;
49476
49477 len = 0;
49478 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49479 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49480 (lpfc_debugfs_max_slow_ring_trc - 1);
49481 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49482 dtp = phba->slow_ring_trc + i;
49483 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49484 !vport || !vport->disc_trc)
49485 return;
49486
49487 - index = atomic_inc_return(&vport->disc_trc_cnt) &
49488 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49489 (lpfc_debugfs_max_disc_trc - 1);
49490 dtp = vport->disc_trc + index;
49491 dtp->fmt = fmt;
49492 dtp->data1 = data1;
49493 dtp->data2 = data2;
49494 dtp->data3 = data3;
49495 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49496 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49497 dtp->jif = jiffies;
49498 #endif
49499 return;
49500 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49501 !phba || !phba->slow_ring_trc)
49502 return;
49503
49504 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49505 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49506 (lpfc_debugfs_max_slow_ring_trc - 1);
49507 dtp = phba->slow_ring_trc + index;
49508 dtp->fmt = fmt;
49509 dtp->data1 = data1;
49510 dtp->data2 = data2;
49511 dtp->data3 = data3;
49512 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49513 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49514 dtp->jif = jiffies;
49515 #endif
49516 return;
49517 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49518 "slow_ring buffer\n");
49519 goto debug_failed;
49520 }
49521 - atomic_set(&phba->slow_ring_trc_cnt, 0);
49522 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49523 memset(phba->slow_ring_trc, 0,
49524 (sizeof(struct lpfc_debugfs_trc) *
49525 lpfc_debugfs_max_slow_ring_trc));
49526 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49527 "buffer\n");
49528 goto debug_failed;
49529 }
49530 - atomic_set(&vport->disc_trc_cnt, 0);
49531 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49532
49533 snprintf(name, sizeof(name), "discovery_trace");
49534 vport->debug_disc_trc =
49535 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49536 index 635eeb3..038aef6 100644
49537 --- a/drivers/scsi/lpfc/lpfc_init.c
49538 +++ b/drivers/scsi/lpfc/lpfc_init.c
49539 @@ -11194,8 +11194,10 @@ lpfc_init(void)
49540 "misc_register returned with status %d", error);
49541
49542 if (lpfc_enable_npiv) {
49543 - lpfc_transport_functions.vport_create = lpfc_vport_create;
49544 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49545 + pax_open_kernel();
49546 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49547 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49548 + pax_close_kernel();
49549 }
49550 lpfc_transport_template =
49551 fc_attach_transport(&lpfc_transport_functions);
49552 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49553 index 462453e..c0023a6 100644
49554 --- a/drivers/scsi/lpfc/lpfc_scsi.c
49555 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
49556 @@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49557 uint32_t evt_posted;
49558
49559 spin_lock_irqsave(&phba->hbalock, flags);
49560 - atomic_inc(&phba->num_rsrc_err);
49561 + atomic_inc_unchecked(&phba->num_rsrc_err);
49562 phba->last_rsrc_error_time = jiffies;
49563
49564 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49565 @@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49566 unsigned long num_rsrc_err, num_cmd_success;
49567 int i;
49568
49569 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49570 - num_cmd_success = atomic_read(&phba->num_cmd_success);
49571 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49572 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49573
49574 /*
49575 * The error and success command counters are global per
49576 @@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49577 }
49578 }
49579 lpfc_destroy_vport_work_array(phba, vports);
49580 - atomic_set(&phba->num_rsrc_err, 0);
49581 - atomic_set(&phba->num_cmd_success, 0);
49582 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49583 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49584 }
49585
49586 /**
49587 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49588 index 6fd7d40..b444223 100644
49589 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49590 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49591 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49592 {
49593 struct scsi_device *sdev = to_scsi_device(dev);
49594 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49595 - static struct _raid_device *raid_device;
49596 + struct _raid_device *raid_device;
49597 unsigned long flags;
49598 Mpi2RaidVolPage0_t vol_pg0;
49599 Mpi2ConfigReply_t mpi_reply;
49600 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49601 {
49602 struct scsi_device *sdev = to_scsi_device(dev);
49603 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49604 - static struct _raid_device *raid_device;
49605 + struct _raid_device *raid_device;
49606 unsigned long flags;
49607 Mpi2RaidVolPage0_t vol_pg0;
49608 Mpi2ConfigReply_t mpi_reply;
49609 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49610 struct fw_event_work *fw_event)
49611 {
49612 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49613 - static struct _raid_device *raid_device;
49614 + struct _raid_device *raid_device;
49615 unsigned long flags;
49616 u16 handle;
49617
49618 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49619 u64 sas_address;
49620 struct _sas_device *sas_device;
49621 struct _sas_node *expander_device;
49622 - static struct _raid_device *raid_device;
49623 + struct _raid_device *raid_device;
49624 u8 retry_count;
49625 unsigned long flags;
49626
49627 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49628 index be8ce54..94ed33a 100644
49629 --- a/drivers/scsi/pmcraid.c
49630 +++ b/drivers/scsi/pmcraid.c
49631 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49632 res->scsi_dev = scsi_dev;
49633 scsi_dev->hostdata = res;
49634 res->change_detected = 0;
49635 - atomic_set(&res->read_failures, 0);
49636 - atomic_set(&res->write_failures, 0);
49637 + atomic_set_unchecked(&res->read_failures, 0);
49638 + atomic_set_unchecked(&res->write_failures, 0);
49639 rc = 0;
49640 }
49641 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49642 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49643
49644 /* If this was a SCSI read/write command keep count of errors */
49645 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49646 - atomic_inc(&res->read_failures);
49647 + atomic_inc_unchecked(&res->read_failures);
49648 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49649 - atomic_inc(&res->write_failures);
49650 + atomic_inc_unchecked(&res->write_failures);
49651
49652 if (!RES_IS_GSCSI(res->cfg_entry) &&
49653 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49654 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49655 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49656 * hrrq_id assigned here in queuecommand
49657 */
49658 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49659 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49660 pinstance->num_hrrq;
49661 cmd->cmd_done = pmcraid_io_done;
49662
49663 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49664 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49665 * hrrq_id assigned here in queuecommand
49666 */
49667 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49668 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49669 pinstance->num_hrrq;
49670
49671 if (request_size) {
49672 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49673
49674 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49675 /* add resources only after host is added into system */
49676 - if (!atomic_read(&pinstance->expose_resources))
49677 + if (!atomic_read_unchecked(&pinstance->expose_resources))
49678 return;
49679
49680 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49681 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49682 init_waitqueue_head(&pinstance->reset_wait_q);
49683
49684 atomic_set(&pinstance->outstanding_cmds, 0);
49685 - atomic_set(&pinstance->last_message_id, 0);
49686 - atomic_set(&pinstance->expose_resources, 0);
49687 + atomic_set_unchecked(&pinstance->last_message_id, 0);
49688 + atomic_set_unchecked(&pinstance->expose_resources, 0);
49689
49690 INIT_LIST_HEAD(&pinstance->free_res_q);
49691 INIT_LIST_HEAD(&pinstance->used_res_q);
49692 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49693 /* Schedule worker thread to handle CCN and take care of adding and
49694 * removing devices to OS
49695 */
49696 - atomic_set(&pinstance->expose_resources, 1);
49697 + atomic_set_unchecked(&pinstance->expose_resources, 1);
49698 schedule_work(&pinstance->worker_q);
49699 return rc;
49700
49701 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49702 index e1d150f..6c6df44 100644
49703 --- a/drivers/scsi/pmcraid.h
49704 +++ b/drivers/scsi/pmcraid.h
49705 @@ -748,7 +748,7 @@ struct pmcraid_instance {
49706 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49707
49708 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49709 - atomic_t last_message_id;
49710 + atomic_unchecked_t last_message_id;
49711
49712 /* configuration table */
49713 struct pmcraid_config_table *cfg_table;
49714 @@ -777,7 +777,7 @@ struct pmcraid_instance {
49715 atomic_t outstanding_cmds;
49716
49717 /* should add/delete resources to mid-layer now ?*/
49718 - atomic_t expose_resources;
49719 + atomic_unchecked_t expose_resources;
49720
49721
49722
49723 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49724 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49725 };
49726 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49727 - atomic_t read_failures; /* count of failed READ commands */
49728 - atomic_t write_failures; /* count of failed WRITE commands */
49729 + atomic_unchecked_t read_failures; /* count of failed READ commands */
49730 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49731
49732 /* To indicate add/delete/modify during CCN */
49733 u8 change_detected;
49734 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49735 index 07befcf..c0bff13 100644
49736 --- a/drivers/scsi/qla2xxx/qla_attr.c
49737 +++ b/drivers/scsi/qla2xxx/qla_attr.c
49738 @@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49739 return 0;
49740 }
49741
49742 -struct fc_function_template qla2xxx_transport_functions = {
49743 +fc_function_template_no_const qla2xxx_transport_functions = {
49744
49745 .show_host_node_name = 1,
49746 .show_host_port_name = 1,
49747 @@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49748 .bsg_timeout = qla24xx_bsg_timeout,
49749 };
49750
49751 -struct fc_function_template qla2xxx_transport_vport_functions = {
49752 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
49753
49754 .show_host_node_name = 1,
49755 .show_host_port_name = 1,
49756 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49757 index e665e81..16e84e6 100644
49758 --- a/drivers/scsi/qla2xxx/qla_gbl.h
49759 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
49760 @@ -557,8 +557,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49761 struct device_attribute;
49762 extern struct device_attribute *qla2x00_host_attrs[];
49763 struct fc_function_template;
49764 -extern struct fc_function_template qla2xxx_transport_functions;
49765 -extern struct fc_function_template qla2xxx_transport_vport_functions;
49766 +extern fc_function_template_no_const qla2xxx_transport_functions;
49767 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49768 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49769 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49770 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49771 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49772 index 19e99cc..b3c0b7b 100644
49773 --- a/drivers/scsi/qla2xxx/qla_os.c
49774 +++ b/drivers/scsi/qla2xxx/qla_os.c
49775 @@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49776 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49777 /* Ok, a 64bit DMA mask is applicable. */
49778 ha->flags.enable_64bit_addressing = 1;
49779 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49780 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49781 + pax_open_kernel();
49782 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49783 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49784 + pax_close_kernel();
49785 return;
49786 }
49787 }
49788 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49789 index 73a5022..4e0797c 100644
49790 --- a/drivers/scsi/qla4xxx/ql4_def.h
49791 +++ b/drivers/scsi/qla4xxx/ql4_def.h
49792 @@ -305,7 +305,7 @@ struct ddb_entry {
49793 * (4000 only) */
49794 atomic_t relogin_timer; /* Max Time to wait for
49795 * relogin to complete */
49796 - atomic_t relogin_retry_count; /* Num of times relogin has been
49797 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49798 * retried */
49799 uint32_t default_time2wait; /* Default Min time between
49800 * relogins (+aens) */
49801 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49802 index 459b9f7..2930a68 100644
49803 --- a/drivers/scsi/qla4xxx/ql4_os.c
49804 +++ b/drivers/scsi/qla4xxx/ql4_os.c
49805 @@ -4499,12 +4499,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49806 */
49807 if (!iscsi_is_session_online(cls_sess)) {
49808 /* Reset retry relogin timer */
49809 - atomic_inc(&ddb_entry->relogin_retry_count);
49810 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49811 DEBUG2(ql4_printk(KERN_INFO, ha,
49812 "%s: index[%d] relogin timed out-retrying"
49813 " relogin (%d), retry (%d)\n", __func__,
49814 ddb_entry->fw_ddb_index,
49815 - atomic_read(&ddb_entry->relogin_retry_count),
49816 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49817 ddb_entry->default_time2wait + 4));
49818 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49819 atomic_set(&ddb_entry->retry_relogin_timer,
49820 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49821
49822 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49823 atomic_set(&ddb_entry->relogin_timer, 0);
49824 - atomic_set(&ddb_entry->relogin_retry_count, 0);
49825 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49826 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49827 ddb_entry->default_relogin_timeout =
49828 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49829 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49830 index 88d46fe..7351be5 100644
49831 --- a/drivers/scsi/scsi.c
49832 +++ b/drivers/scsi/scsi.c
49833 @@ -640,7 +640,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49834 struct Scsi_Host *host = cmd->device->host;
49835 int rtn = 0;
49836
49837 - atomic_inc(&cmd->device->iorequest_cnt);
49838 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49839
49840 /* check if the device is still usable */
49841 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49842 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49843 index 9db097a..ca5c291 100644
49844 --- a/drivers/scsi/scsi_lib.c
49845 +++ b/drivers/scsi/scsi_lib.c
49846 @@ -1464,7 +1464,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49847 shost = sdev->host;
49848 scsi_init_cmd_errh(cmd);
49849 cmd->result = DID_NO_CONNECT << 16;
49850 - atomic_inc(&cmd->device->iorequest_cnt);
49851 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49852
49853 /*
49854 * SCSI request completion path will do scsi_device_unbusy(),
49855 @@ -1490,9 +1490,9 @@ static void scsi_softirq_done(struct request *rq)
49856
49857 INIT_LIST_HEAD(&cmd->eh_entry);
49858
49859 - atomic_inc(&cmd->device->iodone_cnt);
49860 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
49861 if (cmd->result)
49862 - atomic_inc(&cmd->device->ioerr_cnt);
49863 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49864
49865 disposition = scsi_decide_disposition(cmd);
49866 if (disposition != SUCCESS &&
49867 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49868 index 074e8cc..f612e5c 100644
49869 --- a/drivers/scsi/scsi_sysfs.c
49870 +++ b/drivers/scsi/scsi_sysfs.c
49871 @@ -780,7 +780,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49872 char *buf) \
49873 { \
49874 struct scsi_device *sdev = to_scsi_device(dev); \
49875 - unsigned long long count = atomic_read(&sdev->field); \
49876 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
49877 return snprintf(buf, 20, "0x%llx\n", count); \
49878 } \
49879 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49880 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49881 index e51add0..1e06a96 100644
49882 --- a/drivers/scsi/scsi_tgt_lib.c
49883 +++ b/drivers/scsi/scsi_tgt_lib.c
49884 @@ -363,7 +363,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49885 int err;
49886
49887 dprintk("%lx %u\n", uaddr, len);
49888 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49889 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49890 if (err) {
49891 /*
49892 * TODO: need to fixup sg_tablesize, max_segment_size,
49893 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49894 index f80908f..22aba76 100644
49895 --- a/drivers/scsi/scsi_transport_fc.c
49896 +++ b/drivers/scsi/scsi_transport_fc.c
49897 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49898 * Netlink Infrastructure
49899 */
49900
49901 -static atomic_t fc_event_seq;
49902 +static atomic_unchecked_t fc_event_seq;
49903
49904 /**
49905 * fc_get_event_number - Obtain the next sequential FC event number
49906 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
49907 u32
49908 fc_get_event_number(void)
49909 {
49910 - return atomic_add_return(1, &fc_event_seq);
49911 + return atomic_add_return_unchecked(1, &fc_event_seq);
49912 }
49913 EXPORT_SYMBOL(fc_get_event_number);
49914
49915 @@ -655,7 +655,7 @@ static __init int fc_transport_init(void)
49916 {
49917 int error;
49918
49919 - atomic_set(&fc_event_seq, 0);
49920 + atomic_set_unchecked(&fc_event_seq, 0);
49921
49922 error = transport_class_register(&fc_host_class);
49923 if (error)
49924 @@ -845,7 +845,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49925 char *cp;
49926
49927 *val = simple_strtoul(buf, &cp, 0);
49928 - if ((*cp && (*cp != '\n')) || (*val < 0))
49929 + if (*cp && (*cp != '\n'))
49930 return -EINVAL;
49931 /*
49932 * Check for overflow; dev_loss_tmo is u32
49933 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49934 index 0102a2d..cc3f8e9 100644
49935 --- a/drivers/scsi/scsi_transport_iscsi.c
49936 +++ b/drivers/scsi/scsi_transport_iscsi.c
49937 @@ -79,7 +79,7 @@ struct iscsi_internal {
49938 struct transport_container session_cont;
49939 };
49940
49941 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49942 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49943 static struct workqueue_struct *iscsi_eh_timer_workq;
49944
49945 static DEFINE_IDA(iscsi_sess_ida);
49946 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49947 int err;
49948
49949 ihost = shost->shost_data;
49950 - session->sid = atomic_add_return(1, &iscsi_session_nr);
49951 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49952
49953 if (target_id == ISCSI_MAX_TARGET) {
49954 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49955 @@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
49956 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49957 ISCSI_TRANSPORT_VERSION);
49958
49959 - atomic_set(&iscsi_session_nr, 0);
49960 + atomic_set_unchecked(&iscsi_session_nr, 0);
49961
49962 err = class_register(&iscsi_transport_class);
49963 if (err)
49964 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49965 index 13e8983..d306a68 100644
49966 --- a/drivers/scsi/scsi_transport_srp.c
49967 +++ b/drivers/scsi/scsi_transport_srp.c
49968 @@ -36,7 +36,7 @@
49969 #include "scsi_transport_srp_internal.h"
49970
49971 struct srp_host_attrs {
49972 - atomic_t next_port_id;
49973 + atomic_unchecked_t next_port_id;
49974 };
49975 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49976
49977 @@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49978 struct Scsi_Host *shost = dev_to_shost(dev);
49979 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49980
49981 - atomic_set(&srp_host->next_port_id, 0);
49982 + atomic_set_unchecked(&srp_host->next_port_id, 0);
49983 return 0;
49984 }
49985
49986 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49987 rport_fast_io_fail_timedout);
49988 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49989
49990 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49991 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49992 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49993
49994 transport_setup_device(&rport->dev);
49995 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49996 index bffbd4b..cb1b68a 100644
49997 --- a/drivers/scsi/sd.c
49998 +++ b/drivers/scsi/sd.c
49999 @@ -2971,7 +2971,7 @@ static int sd_probe(struct device *dev)
50000 sdkp->disk = gd;
50001 sdkp->index = index;
50002 atomic_set(&sdkp->openers, 0);
50003 - atomic_set(&sdkp->device->ioerr_cnt, 0);
50004 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
50005
50006 if (!sdp->request_queue->rq_timeout) {
50007 if (sdp->type != TYPE_MOD)
50008 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
50009 index df5e961..df6b97f 100644
50010 --- a/drivers/scsi/sg.c
50011 +++ b/drivers/scsi/sg.c
50012 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
50013 sdp->disk->disk_name,
50014 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
50015 NULL,
50016 - (char *)arg);
50017 + (char __user *)arg);
50018 case BLKTRACESTART:
50019 return blk_trace_startstop(sdp->device->request_queue, 1);
50020 case BLKTRACESTOP:
50021 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
50022 index 939edf4..3f50423 100644
50023 --- a/drivers/spi/spi.c
50024 +++ b/drivers/spi/spi.c
50025 @@ -2204,7 +2204,7 @@ int spi_bus_unlock(struct spi_master *master)
50026 EXPORT_SYMBOL_GPL(spi_bus_unlock);
50027
50028 /* portable code must never pass more than 32 bytes */
50029 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
50030 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
50031
50032 static u8 *buf;
50033
50034 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
50035 index 2c61783..4d49e4e 100644
50036 --- a/drivers/staging/android/timed_output.c
50037 +++ b/drivers/staging/android/timed_output.c
50038 @@ -25,7 +25,7 @@
50039 #include "timed_output.h"
50040
50041 static struct class *timed_output_class;
50042 -static atomic_t device_count;
50043 +static atomic_unchecked_t device_count;
50044
50045 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
50046 char *buf)
50047 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
50048 timed_output_class = class_create(THIS_MODULE, "timed_output");
50049 if (IS_ERR(timed_output_class))
50050 return PTR_ERR(timed_output_class);
50051 - atomic_set(&device_count, 0);
50052 + atomic_set_unchecked(&device_count, 0);
50053 timed_output_class->dev_groups = timed_output_groups;
50054 }
50055
50056 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
50057 if (ret < 0)
50058 return ret;
50059
50060 - tdev->index = atomic_inc_return(&device_count);
50061 + tdev->index = atomic_inc_return_unchecked(&device_count);
50062 tdev->dev = device_create(timed_output_class, NULL,
50063 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
50064 if (IS_ERR(tdev->dev))
50065 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
50066 index fe47cd3..19a1bd1 100644
50067 --- a/drivers/staging/gdm724x/gdm_tty.c
50068 +++ b/drivers/staging/gdm724x/gdm_tty.c
50069 @@ -44,7 +44,7 @@
50070 #define gdm_tty_send_control(n, r, v, d, l) (\
50071 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
50072
50073 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
50074 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
50075
50076 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
50077 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
50078 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
50079 index c270c9a..94ddf82 100644
50080 --- a/drivers/staging/imx-drm/imx-drm-core.c
50081 +++ b/drivers/staging/imx-drm/imx-drm-core.c
50082 @@ -362,7 +362,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
50083 if (imxdrm->pipes >= MAX_CRTC)
50084 return -EINVAL;
50085
50086 - if (imxdrm->drm->open_count)
50087 + if (local_read(&imxdrm->drm->open_count))
50088 return -EBUSY;
50089
50090 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
50091 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
50092 index 3f8020c..649fded 100644
50093 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
50094 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
50095 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
50096 return 0;
50097 }
50098
50099 -sfw_test_client_ops_t brw_test_client;
50100 -void brw_init_test_client(void)
50101 -{
50102 - brw_test_client.tso_init = brw_client_init;
50103 - brw_test_client.tso_fini = brw_client_fini;
50104 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
50105 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
50106 +sfw_test_client_ops_t brw_test_client = {
50107 + .tso_init = brw_client_init,
50108 + .tso_fini = brw_client_fini,
50109 + .tso_prep_rpc = brw_client_prep_rpc,
50110 + .tso_done_rpc = brw_client_done_rpc,
50111 };
50112
50113 srpc_service_t brw_test_service;
50114 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
50115 index 050723a..fa6fdf1 100644
50116 --- a/drivers/staging/lustre/lnet/selftest/framework.c
50117 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
50118 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
50119
50120 extern sfw_test_client_ops_t ping_test_client;
50121 extern srpc_service_t ping_test_service;
50122 -extern void ping_init_test_client(void);
50123 extern void ping_init_test_service(void);
50124
50125 extern sfw_test_client_ops_t brw_test_client;
50126 extern srpc_service_t brw_test_service;
50127 -extern void brw_init_test_client(void);
50128 extern void brw_init_test_service(void);
50129
50130
50131 @@ -1684,12 +1682,10 @@ sfw_startup (void)
50132 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
50133 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
50134
50135 - brw_init_test_client();
50136 brw_init_test_service();
50137 rc = sfw_register_test(&brw_test_service, &brw_test_client);
50138 LASSERT (rc == 0);
50139
50140 - ping_init_test_client();
50141 ping_init_test_service();
50142 rc = sfw_register_test(&ping_test_service, &ping_test_client);
50143 LASSERT (rc == 0);
50144 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
50145 index 750cac4..e4d751f 100644
50146 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
50147 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
50148 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
50149 return 0;
50150 }
50151
50152 -sfw_test_client_ops_t ping_test_client;
50153 -void ping_init_test_client(void)
50154 -{
50155 - ping_test_client.tso_init = ping_client_init;
50156 - ping_test_client.tso_fini = ping_client_fini;
50157 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
50158 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
50159 -}
50160 +sfw_test_client_ops_t ping_test_client = {
50161 + .tso_init = ping_client_init,
50162 + .tso_fini = ping_client_fini,
50163 + .tso_prep_rpc = ping_client_prep_rpc,
50164 + .tso_done_rpc = ping_client_done_rpc,
50165 +};
50166
50167 srpc_service_t ping_test_service;
50168 void ping_init_test_service(void)
50169 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50170 index 3e25f00..0d59cf5 100644
50171 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
50172 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50173 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
50174 ldlm_completion_callback lcs_completion;
50175 ldlm_blocking_callback lcs_blocking;
50176 ldlm_glimpse_callback lcs_glimpse;
50177 -};
50178 +} __no_const;
50179
50180 /* ldlm_lockd.c */
50181 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
50182 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
50183 index 72cf3fe..4beac19 100644
50184 --- a/drivers/staging/lustre/lustre/include/obd.h
50185 +++ b/drivers/staging/lustre/lustre/include/obd.h
50186 @@ -1427,7 +1427,7 @@ struct md_ops {
50187 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
50188 * wrapper function in include/linux/obd_class.h.
50189 */
50190 -};
50191 +} __no_const;
50192
50193 struct lsm_operations {
50194 void (*lsm_free)(struct lov_stripe_md *);
50195 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50196 index 986bf38..eab2558f 100644
50197 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50198 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50199 @@ -259,7 +259,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
50200 int added = (mode == LCK_NL);
50201 int overlaps = 0;
50202 int splitted = 0;
50203 - const struct ldlm_callback_suite null_cbs = { NULL };
50204 + const struct ldlm_callback_suite null_cbs = { };
50205
50206 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
50207 LPU64" end "LPU64"\n", *flags,
50208 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50209 index e947b91..f408990 100644
50210 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50211 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50212 @@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
50213 int LL_PROC_PROTO(proc_console_max_delay_cs)
50214 {
50215 int rc, max_delay_cs;
50216 - ctl_table_t dummy = *table;
50217 + ctl_table_no_const dummy = *table;
50218 cfs_duration_t d;
50219
50220 dummy.data = &max_delay_cs;
50221 @@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
50222 int LL_PROC_PROTO(proc_console_min_delay_cs)
50223 {
50224 int rc, min_delay_cs;
50225 - ctl_table_t dummy = *table;
50226 + ctl_table_no_const dummy = *table;
50227 cfs_duration_t d;
50228
50229 dummy.data = &min_delay_cs;
50230 @@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
50231 int LL_PROC_PROTO(proc_console_backoff)
50232 {
50233 int rc, backoff;
50234 - ctl_table_t dummy = *table;
50235 + ctl_table_no_const dummy = *table;
50236
50237 dummy.data = &backoff;
50238 dummy.proc_handler = &proc_dointvec;
50239 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
50240 index 24ae26d..9d09cab 100644
50241 --- a/drivers/staging/lustre/lustre/libcfs/module.c
50242 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
50243 @@ -313,11 +313,11 @@ out:
50244
50245
50246 struct cfs_psdev_ops libcfs_psdev_ops = {
50247 - libcfs_psdev_open,
50248 - libcfs_psdev_release,
50249 - NULL,
50250 - NULL,
50251 - libcfs_ioctl
50252 + .p_open = libcfs_psdev_open,
50253 + .p_close = libcfs_psdev_release,
50254 + .p_read = NULL,
50255 + .p_write = NULL,
50256 + .p_ioctl = libcfs_ioctl
50257 };
50258
50259 extern int insert_proc(void);
50260 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
50261 index 7fbc18e..f982071 100644
50262 --- a/drivers/staging/lustre/lustre/llite/dir.c
50263 +++ b/drivers/staging/lustre/lustre/llite/dir.c
50264 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
50265 int mode;
50266 int err;
50267
50268 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
50269 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
50270 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
50271 strlen(filename), mode, LUSTRE_OPC_MKDIR,
50272 lump);
50273 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
50274 index f670469..03b7438 100644
50275 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
50276 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
50277 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
50278
50279 static int solo_sysfs_init(struct solo_dev *solo_dev)
50280 {
50281 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
50282 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
50283 struct device *dev = &solo_dev->dev;
50284 const char *driver;
50285 int i;
50286 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
50287 index 74f037b..5b5bb76 100644
50288 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
50289 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
50290 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
50291
50292 int solo_g723_init(struct solo_dev *solo_dev)
50293 {
50294 - static struct snd_device_ops ops = { NULL };
50295 + static struct snd_device_ops ops = { };
50296 struct snd_card *card;
50297 struct snd_kcontrol_new kctl;
50298 char name[32];
50299 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50300 index 7f2f247..d999137 100644
50301 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50302 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50303 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50304
50305 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50306 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50307 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50308 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50309 if (p2m_id < 0)
50310 p2m_id = -p2m_id;
50311 }
50312 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50313 index 8964f8b..36eb087 100644
50314 --- a/drivers/staging/media/solo6x10/solo6x10.h
50315 +++ b/drivers/staging/media/solo6x10/solo6x10.h
50316 @@ -237,7 +237,7 @@ struct solo_dev {
50317
50318 /* P2M DMA Engine */
50319 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50320 - atomic_t p2m_count;
50321 + atomic_unchecked_t p2m_count;
50322 int p2m_jiffies;
50323 unsigned int p2m_timeouts;
50324
50325 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50326 index a0f4868..139f1fb 100644
50327 --- a/drivers/staging/octeon/ethernet-rx.c
50328 +++ b/drivers/staging/octeon/ethernet-rx.c
50329 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50330 /* Increment RX stats for virtual ports */
50331 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50332 #ifdef CONFIG_64BIT
50333 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50334 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50335 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50336 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50337 #else
50338 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50339 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50340 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50341 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50342 #endif
50343 }
50344 netif_receive_skb(skb);
50345 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50346 dev->name);
50347 */
50348 #ifdef CONFIG_64BIT
50349 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50350 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50351 #else
50352 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50353 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50354 #endif
50355 dev_kfree_skb_irq(skb);
50356 }
50357 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50358 index ff7214a..6dd90f0 100644
50359 --- a/drivers/staging/octeon/ethernet.c
50360 +++ b/drivers/staging/octeon/ethernet.c
50361 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50362 * since the RX tasklet also increments it.
50363 */
50364 #ifdef CONFIG_64BIT
50365 - atomic64_add(rx_status.dropped_packets,
50366 - (atomic64_t *)&priv->stats.rx_dropped);
50367 + atomic64_add_unchecked(rx_status.dropped_packets,
50368 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50369 #else
50370 - atomic_add(rx_status.dropped_packets,
50371 - (atomic_t *)&priv->stats.rx_dropped);
50372 + atomic_add_unchecked(rx_status.dropped_packets,
50373 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
50374 #endif
50375 }
50376
50377 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50378 index c274b34..f84de76 100644
50379 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
50380 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50381 @@ -271,7 +271,7 @@ struct hal_ops {
50382 s32 (*c2h_handler)(struct adapter *padapter,
50383 struct c2h_evt_hdr *c2h_evt);
50384 c2h_id_filter c2h_id_filter_ccx;
50385 -};
50386 +} __no_const;
50387
50388 enum rt_eeprom_type {
50389 EEPROM_93C46,
50390 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50391 index e8790f8..b4a5980 100644
50392 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
50393 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50394 @@ -124,7 +124,7 @@ struct _io_ops {
50395 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50396 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50397 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50398 -};
50399 +} __no_const;
50400
50401 struct io_req {
50402 struct list_head list;
50403 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50404 index dc23395..cf7e9b1 100644
50405 --- a/drivers/staging/rtl8712/rtl871x_io.h
50406 +++ b/drivers/staging/rtl8712/rtl871x_io.h
50407 @@ -108,7 +108,7 @@ struct _io_ops {
50408 u8 *pmem);
50409 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50410 u8 *pmem);
50411 -};
50412 +} __no_const;
50413
50414 struct io_req {
50415 struct list_head list;
50416 diff --git a/drivers/staging/rtl8723au/include/hal_intf.h b/drivers/staging/rtl8723au/include/hal_intf.h
50417 index d183f4b..3f4903d 100644
50418 --- a/drivers/staging/rtl8723au/include/hal_intf.h
50419 +++ b/drivers/staging/rtl8723au/include/hal_intf.h
50420 @@ -251,7 +251,7 @@ struct hal_ops {
50421 void (*hal_reset_security_engine)(struct rtw_adapter *adapter);
50422 s32 (*c2h_handler)(struct rtw_adapter *padapter, struct c2h_evt_hdr *c2h_evt);
50423 c2h_id_filter c2h_id_filter_ccx;
50424 -};
50425 +} __no_const;
50426
50427 enum rt_eeprom_type {
50428 EEPROM_93C46,
50429 diff --git a/drivers/staging/rtl8723au/include/rtw_io.h b/drivers/staging/rtl8723au/include/rtw_io.h
50430 index 8d39d800..3f21c0c 100644
50431 --- a/drivers/staging/rtl8723au/include/rtw_io.h
50432 +++ b/drivers/staging/rtl8723au/include/rtw_io.h
50433 @@ -130,7 +130,7 @@ struct _io_ops
50434 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50435 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50436
50437 -};
50438 +} __no_const;
50439
50440 struct io_req {
50441 struct list_head list;
50442 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50443 index fe6c951..72935ba 100644
50444 --- a/drivers/staging/sbe-2t3e3/netdev.c
50445 +++ b/drivers/staging/sbe-2t3e3/netdev.c
50446 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50447 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50448
50449 if (rlen)
50450 - if (copy_to_user(data, &resp, rlen))
50451 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50452 return -EFAULT;
50453
50454 return 0;
50455 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50456 index a863a98..d272795 100644
50457 --- a/drivers/staging/usbip/vhci.h
50458 +++ b/drivers/staging/usbip/vhci.h
50459 @@ -83,7 +83,7 @@ struct vhci_hcd {
50460 unsigned resuming:1;
50461 unsigned long re_timeout;
50462
50463 - atomic_t seqnum;
50464 + atomic_unchecked_t seqnum;
50465
50466 /*
50467 * NOTE:
50468 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50469 index 70e1755..de41855 100644
50470 --- a/drivers/staging/usbip/vhci_hcd.c
50471 +++ b/drivers/staging/usbip/vhci_hcd.c
50472 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
50473
50474 spin_lock(&vdev->priv_lock);
50475
50476 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50477 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50478 if (priv->seqnum == 0xffff)
50479 dev_info(&urb->dev->dev, "seqnum max\n");
50480
50481 @@ -685,7 +685,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50482 return -ENOMEM;
50483 }
50484
50485 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50486 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50487 if (unlink->seqnum == 0xffff)
50488 pr_info("seqnum max\n");
50489
50490 @@ -889,7 +889,7 @@ static int vhci_start(struct usb_hcd *hcd)
50491 vdev->rhport = rhport;
50492 }
50493
50494 - atomic_set(&vhci->seqnum, 0);
50495 + atomic_set_unchecked(&vhci->seqnum, 0);
50496 spin_lock_init(&vhci->lock);
50497
50498 hcd->power_budget = 0; /* no limit */
50499 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50500 index d07fcb5..358e1e1 100644
50501 --- a/drivers/staging/usbip/vhci_rx.c
50502 +++ b/drivers/staging/usbip/vhci_rx.c
50503 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50504 if (!urb) {
50505 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50506 pr_info("max seqnum %d\n",
50507 - atomic_read(&the_controller->seqnum));
50508 + atomic_read_unchecked(&the_controller->seqnum));
50509 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50510 return;
50511 }
50512 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50513 index 6eecd53..29317c6 100644
50514 --- a/drivers/staging/vt6655/hostap.c
50515 +++ b/drivers/staging/vt6655/hostap.c
50516 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50517 *
50518 */
50519
50520 +static net_device_ops_no_const apdev_netdev_ops;
50521 +
50522 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50523 {
50524 PSDevice apdev_priv;
50525 struct net_device *dev = pDevice->dev;
50526 int ret;
50527 - const struct net_device_ops apdev_netdev_ops = {
50528 - .ndo_start_xmit = pDevice->tx_80211,
50529 - };
50530
50531 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50532
50533 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50534 *apdev_priv = *pDevice;
50535 eth_hw_addr_inherit(pDevice->apdev, dev);
50536
50537 + /* only half broken now */
50538 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50539 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50540
50541 pDevice->apdev->type = ARPHRD_IEEE80211;
50542 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50543 index 67ba48b..24e602f 100644
50544 --- a/drivers/staging/vt6656/hostap.c
50545 +++ b/drivers/staging/vt6656/hostap.c
50546 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50547 *
50548 */
50549
50550 +static net_device_ops_no_const apdev_netdev_ops;
50551 +
50552 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50553 {
50554 struct vnt_private *apdev_priv;
50555 struct net_device *dev = pDevice->dev;
50556 int ret;
50557 - const struct net_device_ops apdev_netdev_ops = {
50558 - .ndo_start_xmit = pDevice->tx_80211,
50559 - };
50560
50561 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50562
50563 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50564 *apdev_priv = *pDevice;
50565 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50566
50567 + /* only half broken now */
50568 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50569 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50570
50571 pDevice->apdev->type = ARPHRD_IEEE80211;
50572 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50573 index e7e9372..161f530 100644
50574 --- a/drivers/target/sbp/sbp_target.c
50575 +++ b/drivers/target/sbp/sbp_target.c
50576 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50577
50578 #define SESSION_MAINTENANCE_INTERVAL HZ
50579
50580 -static atomic_t login_id = ATOMIC_INIT(0);
50581 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50582
50583 static void session_maintenance_work(struct work_struct *);
50584 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50585 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
50586 login->lun = se_lun;
50587 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50588 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50589 - login->login_id = atomic_inc_return(&login_id);
50590 + login->login_id = atomic_inc_return_unchecked(&login_id);
50591
50592 login->tgt_agt = sbp_target_agent_register(login);
50593 if (IS_ERR(login->tgt_agt)) {
50594 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50595 index 6ea95d2..88607b4 100644
50596 --- a/drivers/target/target_core_device.c
50597 +++ b/drivers/target/target_core_device.c
50598 @@ -1525,7 +1525,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50599 spin_lock_init(&dev->se_tmr_lock);
50600 spin_lock_init(&dev->qf_cmd_lock);
50601 sema_init(&dev->caw_sem, 1);
50602 - atomic_set(&dev->dev_ordered_id, 0);
50603 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
50604 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50605 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50606 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50607 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50608 index 14772e9..42d9f63 100644
50609 --- a/drivers/target/target_core_transport.c
50610 +++ b/drivers/target/target_core_transport.c
50611 @@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50612 * Used to determine when ORDERED commands should go from
50613 * Dormant to Active status.
50614 */
50615 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50616 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50617 smp_mb__after_atomic_inc();
50618 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50619 cmd->se_ordered_id, cmd->sam_task_attr,
50620 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50621 index 04b1be7..5eff86d 100644
50622 --- a/drivers/thermal/of-thermal.c
50623 +++ b/drivers/thermal/of-thermal.c
50624 @@ -30,6 +30,7 @@
50625 #include <linux/err.h>
50626 #include <linux/export.h>
50627 #include <linux/string.h>
50628 +#include <linux/mm.h>
50629
50630 #include "thermal_core.h"
50631
50632 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50633 tz->get_trend = get_trend;
50634 tz->sensor_data = data;
50635
50636 - tzd->ops->get_temp = of_thermal_get_temp;
50637 - tzd->ops->get_trend = of_thermal_get_trend;
50638 + pax_open_kernel();
50639 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50640 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50641 + pax_close_kernel();
50642 mutex_unlock(&tzd->lock);
50643
50644 return tzd;
50645 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50646 return;
50647
50648 mutex_lock(&tzd->lock);
50649 - tzd->ops->get_temp = NULL;
50650 - tzd->ops->get_trend = NULL;
50651 + pax_open_kernel();
50652 + *(void **)&tzd->ops->get_temp = NULL;
50653 + *(void **)&tzd->ops->get_trend = NULL;
50654 + pax_close_kernel();
50655
50656 tz->get_temp = NULL;
50657 tz->get_trend = NULL;
50658 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50659 index a57bb5a..1f727d33 100644
50660 --- a/drivers/tty/cyclades.c
50661 +++ b/drivers/tty/cyclades.c
50662 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50663 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50664 info->port.count);
50665 #endif
50666 - info->port.count++;
50667 + atomic_inc(&info->port.count);
50668 #ifdef CY_DEBUG_COUNT
50669 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50670 - current->pid, info->port.count);
50671 + current->pid, atomic_read(&info->port.count));
50672 #endif
50673
50674 /*
50675 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50676 for (j = 0; j < cy_card[i].nports; j++) {
50677 info = &cy_card[i].ports[j];
50678
50679 - if (info->port.count) {
50680 + if (atomic_read(&info->port.count)) {
50681 /* XXX is the ldisc num worth this? */
50682 struct tty_struct *tty;
50683 struct tty_ldisc *ld;
50684 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50685 index 0ff7fda..dbc7d52 100644
50686 --- a/drivers/tty/hvc/hvc_console.c
50687 +++ b/drivers/tty/hvc/hvc_console.c
50688 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50689
50690 spin_lock_irqsave(&hp->port.lock, flags);
50691 /* Check and then increment for fast path open. */
50692 - if (hp->port.count++ > 0) {
50693 + if (atomic_inc_return(&hp->port.count) > 1) {
50694 spin_unlock_irqrestore(&hp->port.lock, flags);
50695 hvc_kick();
50696 return 0;
50697 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50698
50699 spin_lock_irqsave(&hp->port.lock, flags);
50700
50701 - if (--hp->port.count == 0) {
50702 + if (atomic_dec_return(&hp->port.count) == 0) {
50703 spin_unlock_irqrestore(&hp->port.lock, flags);
50704 /* We are done with the tty pointer now. */
50705 tty_port_tty_set(&hp->port, NULL);
50706 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50707 */
50708 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50709 } else {
50710 - if (hp->port.count < 0)
50711 + if (atomic_read(&hp->port.count) < 0)
50712 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50713 - hp->vtermno, hp->port.count);
50714 + hp->vtermno, atomic_read(&hp->port.count));
50715 spin_unlock_irqrestore(&hp->port.lock, flags);
50716 }
50717 }
50718 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50719 * open->hangup case this can be called after the final close so prevent
50720 * that from happening for now.
50721 */
50722 - if (hp->port.count <= 0) {
50723 + if (atomic_read(&hp->port.count) <= 0) {
50724 spin_unlock_irqrestore(&hp->port.lock, flags);
50725 return;
50726 }
50727
50728 - hp->port.count = 0;
50729 + atomic_set(&hp->port.count, 0);
50730 spin_unlock_irqrestore(&hp->port.lock, flags);
50731 tty_port_tty_set(&hp->port, NULL);
50732
50733 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50734 return -EPIPE;
50735
50736 /* FIXME what's this (unprotected) check for? */
50737 - if (hp->port.count <= 0)
50738 + if (atomic_read(&hp->port.count) <= 0)
50739 return -EIO;
50740
50741 spin_lock_irqsave(&hp->lock, flags);
50742 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50743 index 81e939e..95ead10 100644
50744 --- a/drivers/tty/hvc/hvcs.c
50745 +++ b/drivers/tty/hvc/hvcs.c
50746 @@ -83,6 +83,7 @@
50747 #include <asm/hvcserver.h>
50748 #include <asm/uaccess.h>
50749 #include <asm/vio.h>
50750 +#include <asm/local.h>
50751
50752 /*
50753 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50754 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50755
50756 spin_lock_irqsave(&hvcsd->lock, flags);
50757
50758 - if (hvcsd->port.count > 0) {
50759 + if (atomic_read(&hvcsd->port.count) > 0) {
50760 spin_unlock_irqrestore(&hvcsd->lock, flags);
50761 printk(KERN_INFO "HVCS: vterm state unchanged. "
50762 "The hvcs device node is still in use.\n");
50763 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50764 }
50765 }
50766
50767 - hvcsd->port.count = 0;
50768 + atomic_set(&hvcsd->port.count, 0);
50769 hvcsd->port.tty = tty;
50770 tty->driver_data = hvcsd;
50771
50772 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50773 unsigned long flags;
50774
50775 spin_lock_irqsave(&hvcsd->lock, flags);
50776 - hvcsd->port.count++;
50777 + atomic_inc(&hvcsd->port.count);
50778 hvcsd->todo_mask |= HVCS_SCHED_READ;
50779 spin_unlock_irqrestore(&hvcsd->lock, flags);
50780
50781 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50782 hvcsd = tty->driver_data;
50783
50784 spin_lock_irqsave(&hvcsd->lock, flags);
50785 - if (--hvcsd->port.count == 0) {
50786 + if (atomic_dec_and_test(&hvcsd->port.count)) {
50787
50788 vio_disable_interrupts(hvcsd->vdev);
50789
50790 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50791
50792 free_irq(irq, hvcsd);
50793 return;
50794 - } else if (hvcsd->port.count < 0) {
50795 + } else if (atomic_read(&hvcsd->port.count) < 0) {
50796 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50797 " is missmanaged.\n",
50798 - hvcsd->vdev->unit_address, hvcsd->port.count);
50799 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50800 }
50801
50802 spin_unlock_irqrestore(&hvcsd->lock, flags);
50803 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50804
50805 spin_lock_irqsave(&hvcsd->lock, flags);
50806 /* Preserve this so that we know how many kref refs to put */
50807 - temp_open_count = hvcsd->port.count;
50808 + temp_open_count = atomic_read(&hvcsd->port.count);
50809
50810 /*
50811 * Don't kref put inside the spinlock because the destruction
50812 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50813 tty->driver_data = NULL;
50814 hvcsd->port.tty = NULL;
50815
50816 - hvcsd->port.count = 0;
50817 + atomic_set(&hvcsd->port.count, 0);
50818
50819 /* This will drop any buffered data on the floor which is OK in a hangup
50820 * scenario. */
50821 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50822 * the middle of a write operation? This is a crummy place to do this
50823 * but we want to keep it all in the spinlock.
50824 */
50825 - if (hvcsd->port.count <= 0) {
50826 + if (atomic_read(&hvcsd->port.count) <= 0) {
50827 spin_unlock_irqrestore(&hvcsd->lock, flags);
50828 return -ENODEV;
50829 }
50830 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50831 {
50832 struct hvcs_struct *hvcsd = tty->driver_data;
50833
50834 - if (!hvcsd || hvcsd->port.count <= 0)
50835 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50836 return 0;
50837
50838 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50839 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50840 index 4190199..06d5bfa 100644
50841 --- a/drivers/tty/hvc/hvsi.c
50842 +++ b/drivers/tty/hvc/hvsi.c
50843 @@ -85,7 +85,7 @@ struct hvsi_struct {
50844 int n_outbuf;
50845 uint32_t vtermno;
50846 uint32_t virq;
50847 - atomic_t seqno; /* HVSI packet sequence number */
50848 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
50849 uint16_t mctrl;
50850 uint8_t state; /* HVSI protocol state */
50851 uint8_t flags;
50852 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50853
50854 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50855 packet.hdr.len = sizeof(struct hvsi_query_response);
50856 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50857 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50858 packet.verb = VSV_SEND_VERSION_NUMBER;
50859 packet.u.version = HVSI_VERSION;
50860 packet.query_seqno = query_seqno+1;
50861 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50862
50863 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50864 packet.hdr.len = sizeof(struct hvsi_query);
50865 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50866 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50867 packet.verb = verb;
50868
50869 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50870 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50871 int wrote;
50872
50873 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50874 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50875 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50876 packet.hdr.len = sizeof(struct hvsi_control);
50877 packet.verb = VSV_SET_MODEM_CTL;
50878 packet.mask = HVSI_TSDTR;
50879 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50880 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50881
50882 packet.hdr.type = VS_DATA_PACKET_HEADER;
50883 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50884 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50885 packet.hdr.len = count + sizeof(struct hvsi_header);
50886 memcpy(&packet.data, buf, count);
50887
50888 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50889 struct hvsi_control packet __ALIGNED__;
50890
50891 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50892 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50893 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50894 packet.hdr.len = 6;
50895 packet.verb = VSV_CLOSE_PROTOCOL;
50896
50897 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50898
50899 tty_port_tty_set(&hp->port, tty);
50900 spin_lock_irqsave(&hp->lock, flags);
50901 - hp->port.count++;
50902 + atomic_inc(&hp->port.count);
50903 atomic_set(&hp->seqno, 0);
50904 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50905 spin_unlock_irqrestore(&hp->lock, flags);
50906 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50907
50908 spin_lock_irqsave(&hp->lock, flags);
50909
50910 - if (--hp->port.count == 0) {
50911 + if (atomic_dec_return(&hp->port.count) == 0) {
50912 tty_port_tty_set(&hp->port, NULL);
50913 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50914
50915 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50916
50917 spin_lock_irqsave(&hp->lock, flags);
50918 }
50919 - } else if (hp->port.count < 0)
50920 + } else if (atomic_read(&hp->port.count) < 0)
50921 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50922 - hp - hvsi_ports, hp->port.count);
50923 + hp - hvsi_ports, atomic_read(&hp->port.count));
50924
50925 spin_unlock_irqrestore(&hp->lock, flags);
50926 }
50927 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50928 tty_port_tty_set(&hp->port, NULL);
50929
50930 spin_lock_irqsave(&hp->lock, flags);
50931 - hp->port.count = 0;
50932 + atomic_set(&hp->port.count, 0);
50933 hp->n_outbuf = 0;
50934 spin_unlock_irqrestore(&hp->lock, flags);
50935 }
50936 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50937 index 7ae6c29..05c6dba 100644
50938 --- a/drivers/tty/hvc/hvsi_lib.c
50939 +++ b/drivers/tty/hvc/hvsi_lib.c
50940 @@ -8,7 +8,7 @@
50941
50942 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50943 {
50944 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50945 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50946
50947 /* Assumes that always succeeds, works in practice */
50948 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50949 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50950
50951 /* Reset state */
50952 pv->established = 0;
50953 - atomic_set(&pv->seqno, 0);
50954 + atomic_set_unchecked(&pv->seqno, 0);
50955
50956 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50957
50958 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50959 index 17ee3bf..8d2520d 100644
50960 --- a/drivers/tty/ipwireless/tty.c
50961 +++ b/drivers/tty/ipwireless/tty.c
50962 @@ -28,6 +28,7 @@
50963 #include <linux/tty_driver.h>
50964 #include <linux/tty_flip.h>
50965 #include <linux/uaccess.h>
50966 +#include <asm/local.h>
50967
50968 #include "tty.h"
50969 #include "network.h"
50970 @@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50971 mutex_unlock(&tty->ipw_tty_mutex);
50972 return -ENODEV;
50973 }
50974 - if (tty->port.count == 0)
50975 + if (atomic_read(&tty->port.count) == 0)
50976 tty->tx_bytes_queued = 0;
50977
50978 - tty->port.count++;
50979 + atomic_inc(&tty->port.count);
50980
50981 tty->port.tty = linux_tty;
50982 linux_tty->driver_data = tty;
50983 @@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50984
50985 static void do_ipw_close(struct ipw_tty *tty)
50986 {
50987 - tty->port.count--;
50988 -
50989 - if (tty->port.count == 0) {
50990 + if (atomic_dec_return(&tty->port.count) == 0) {
50991 struct tty_struct *linux_tty = tty->port.tty;
50992
50993 if (linux_tty != NULL) {
50994 @@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50995 return;
50996
50997 mutex_lock(&tty->ipw_tty_mutex);
50998 - if (tty->port.count == 0) {
50999 + if (atomic_read(&tty->port.count) == 0) {
51000 mutex_unlock(&tty->ipw_tty_mutex);
51001 return;
51002 }
51003 @@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
51004
51005 mutex_lock(&tty->ipw_tty_mutex);
51006
51007 - if (!tty->port.count) {
51008 + if (!atomic_read(&tty->port.count)) {
51009 mutex_unlock(&tty->ipw_tty_mutex);
51010 return;
51011 }
51012 @@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
51013 return -ENODEV;
51014
51015 mutex_lock(&tty->ipw_tty_mutex);
51016 - if (!tty->port.count) {
51017 + if (!atomic_read(&tty->port.count)) {
51018 mutex_unlock(&tty->ipw_tty_mutex);
51019 return -EINVAL;
51020 }
51021 @@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
51022 if (!tty)
51023 return -ENODEV;
51024
51025 - if (!tty->port.count)
51026 + if (!atomic_read(&tty->port.count))
51027 return -EINVAL;
51028
51029 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
51030 @@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
51031 if (!tty)
51032 return 0;
51033
51034 - if (!tty->port.count)
51035 + if (!atomic_read(&tty->port.count))
51036 return 0;
51037
51038 return tty->tx_bytes_queued;
51039 @@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
51040 if (!tty)
51041 return -ENODEV;
51042
51043 - if (!tty->port.count)
51044 + if (!atomic_read(&tty->port.count))
51045 return -EINVAL;
51046
51047 return get_control_lines(tty);
51048 @@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
51049 if (!tty)
51050 return -ENODEV;
51051
51052 - if (!tty->port.count)
51053 + if (!atomic_read(&tty->port.count))
51054 return -EINVAL;
51055
51056 return set_control_lines(tty, set, clear);
51057 @@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
51058 if (!tty)
51059 return -ENODEV;
51060
51061 - if (!tty->port.count)
51062 + if (!atomic_read(&tty->port.count))
51063 return -EINVAL;
51064
51065 /* FIXME: Exactly how is the tty object locked here .. */
51066 @@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
51067 * are gone */
51068 mutex_lock(&ttyj->ipw_tty_mutex);
51069 }
51070 - while (ttyj->port.count)
51071 + while (atomic_read(&ttyj->port.count))
51072 do_ipw_close(ttyj);
51073 ipwireless_disassociate_network_ttys(network,
51074 ttyj->channel_idx);
51075 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
51076 index 1deaca4..c8582d4 100644
51077 --- a/drivers/tty/moxa.c
51078 +++ b/drivers/tty/moxa.c
51079 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
51080 }
51081
51082 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
51083 - ch->port.count++;
51084 + atomic_inc(&ch->port.count);
51085 tty->driver_data = ch;
51086 tty_port_tty_set(&ch->port, tty);
51087 mutex_lock(&ch->port.mutex);
51088 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
51089 index 2ebe47b..3205833 100644
51090 --- a/drivers/tty/n_gsm.c
51091 +++ b/drivers/tty/n_gsm.c
51092 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
51093 spin_lock_init(&dlci->lock);
51094 mutex_init(&dlci->mutex);
51095 dlci->fifo = &dlci->_fifo;
51096 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
51097 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
51098 kfree(dlci);
51099 return NULL;
51100 }
51101 @@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
51102 struct gsm_dlci *dlci = tty->driver_data;
51103 struct tty_port *port = &dlci->port;
51104
51105 - port->count++;
51106 + atomic_inc(&port->count);
51107 tty_port_tty_set(port, tty);
51108
51109 dlci->modem_rx = 0;
51110 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
51111 index 0391f17..31fa586 100644
51112 --- a/drivers/tty/n_tty.c
51113 +++ b/drivers/tty/n_tty.c
51114 @@ -115,7 +115,7 @@ struct n_tty_data {
51115 int minimum_to_wake;
51116
51117 /* consumer-published */
51118 - size_t read_tail;
51119 + size_t read_tail __intentional_overflow(-1);
51120 size_t line_start;
51121
51122 /* protected by output lock */
51123 @@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
51124 {
51125 *ops = tty_ldisc_N_TTY;
51126 ops->owner = NULL;
51127 - ops->refcount = ops->flags = 0;
51128 + atomic_set(&ops->refcount, 0);
51129 + ops->flags = 0;
51130 }
51131 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
51132 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
51133 index 25c9bc7..24077b7 100644
51134 --- a/drivers/tty/pty.c
51135 +++ b/drivers/tty/pty.c
51136 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
51137 panic("Couldn't register Unix98 pts driver");
51138
51139 /* Now create the /dev/ptmx special device */
51140 + pax_open_kernel();
51141 tty_default_fops(&ptmx_fops);
51142 - ptmx_fops.open = ptmx_open;
51143 + *(void **)&ptmx_fops.open = ptmx_open;
51144 + pax_close_kernel();
51145
51146 cdev_init(&ptmx_cdev, &ptmx_fops);
51147 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
51148 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
51149 index 383c4c7..d408e21 100644
51150 --- a/drivers/tty/rocket.c
51151 +++ b/drivers/tty/rocket.c
51152 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51153 tty->driver_data = info;
51154 tty_port_tty_set(port, tty);
51155
51156 - if (port->count++ == 0) {
51157 + if (atomic_inc_return(&port->count) == 1) {
51158 atomic_inc(&rp_num_ports_open);
51159
51160 #ifdef ROCKET_DEBUG_OPEN
51161 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51162 #endif
51163 }
51164 #ifdef ROCKET_DEBUG_OPEN
51165 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
51166 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
51167 #endif
51168
51169 /*
51170 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
51171 spin_unlock_irqrestore(&info->port.lock, flags);
51172 return;
51173 }
51174 - if (info->port.count)
51175 + if (atomic_read(&info->port.count))
51176 atomic_dec(&rp_num_ports_open);
51177 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
51178 spin_unlock_irqrestore(&info->port.lock, flags);
51179 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
51180 index 1274499..f541382 100644
51181 --- a/drivers/tty/serial/ioc4_serial.c
51182 +++ b/drivers/tty/serial/ioc4_serial.c
51183 @@ -437,7 +437,7 @@ struct ioc4_soft {
51184 } is_intr_info[MAX_IOC4_INTR_ENTS];
51185
51186 /* Number of entries active in the above array */
51187 - atomic_t is_num_intrs;
51188 + atomic_unchecked_t is_num_intrs;
51189 } is_intr_type[IOC4_NUM_INTR_TYPES];
51190
51191 /* is_ir_lock must be held while
51192 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
51193 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
51194 || (type == IOC4_OTHER_INTR_TYPE)));
51195
51196 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
51197 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
51198 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
51199
51200 /* Save off the lower level interrupt handler */
51201 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
51202
51203 soft = arg;
51204 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
51205 - num_intrs = (int)atomic_read(
51206 + num_intrs = (int)atomic_read_unchecked(
51207 &soft->is_intr_type[intr_type].is_num_intrs);
51208
51209 this_mir = this_ir = pending_intrs(soft, intr_type);
51210 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
51211 index a260cde..6b2b5ce 100644
51212 --- a/drivers/tty/serial/kgdboc.c
51213 +++ b/drivers/tty/serial/kgdboc.c
51214 @@ -24,8 +24,9 @@
51215 #define MAX_CONFIG_LEN 40
51216
51217 static struct kgdb_io kgdboc_io_ops;
51218 +static struct kgdb_io kgdboc_io_ops_console;
51219
51220 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
51221 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
51222 static int configured = -1;
51223
51224 static char config[MAX_CONFIG_LEN];
51225 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
51226 kgdboc_unregister_kbd();
51227 if (configured == 1)
51228 kgdb_unregister_io_module(&kgdboc_io_ops);
51229 + else if (configured == 2)
51230 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
51231 }
51232
51233 static int configure_kgdboc(void)
51234 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
51235 int err;
51236 char *cptr = config;
51237 struct console *cons;
51238 + int is_console = 0;
51239
51240 err = kgdboc_option_setup(config);
51241 if (err || !strlen(config) || isspace(config[0]))
51242 goto noconfig;
51243
51244 err = -ENODEV;
51245 - kgdboc_io_ops.is_console = 0;
51246 kgdb_tty_driver = NULL;
51247
51248 kgdboc_use_kms = 0;
51249 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
51250 int idx;
51251 if (cons->device && cons->device(cons, &idx) == p &&
51252 idx == tty_line) {
51253 - kgdboc_io_ops.is_console = 1;
51254 + is_console = 1;
51255 break;
51256 }
51257 cons = cons->next;
51258 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
51259 kgdb_tty_line = tty_line;
51260
51261 do_register:
51262 - err = kgdb_register_io_module(&kgdboc_io_ops);
51263 + if (is_console) {
51264 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
51265 + configured = 2;
51266 + } else {
51267 + err = kgdb_register_io_module(&kgdboc_io_ops);
51268 + configured = 1;
51269 + }
51270 if (err)
51271 goto noconfig;
51272
51273 @@ -205,8 +214,6 @@ do_register:
51274 if (err)
51275 goto nmi_con_failed;
51276
51277 - configured = 1;
51278 -
51279 return 0;
51280
51281 nmi_con_failed:
51282 @@ -223,7 +230,7 @@ noconfig:
51283 static int __init init_kgdboc(void)
51284 {
51285 /* Already configured? */
51286 - if (configured == 1)
51287 + if (configured >= 1)
51288 return 0;
51289
51290 return configure_kgdboc();
51291 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
51292 if (config[len - 1] == '\n')
51293 config[len - 1] = '\0';
51294
51295 - if (configured == 1)
51296 + if (configured >= 1)
51297 cleanup_kgdboc();
51298
51299 /* Go and configure with the new params. */
51300 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
51301 .post_exception = kgdboc_post_exp_handler,
51302 };
51303
51304 +static struct kgdb_io kgdboc_io_ops_console = {
51305 + .name = "kgdboc",
51306 + .read_char = kgdboc_get_char,
51307 + .write_char = kgdboc_put_char,
51308 + .pre_exception = kgdboc_pre_exp_handler,
51309 + .post_exception = kgdboc_post_exp_handler,
51310 + .is_console = 1
51311 +};
51312 +
51313 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
51314 /* This is only available if kgdboc is a built in for early debugging */
51315 static int __init kgdboc_early_init(char *opt)
51316 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
51317 index 7307dc4..ce4fe90 100644
51318 --- a/drivers/tty/serial/msm_serial.c
51319 +++ b/drivers/tty/serial/msm_serial.c
51320 @@ -1026,7 +1026,7 @@ static struct uart_driver msm_uart_driver = {
51321 .cons = MSM_CONSOLE,
51322 };
51323
51324 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51325 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51326
51327 static const struct of_device_id msm_uartdm_table[] = {
51328 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
51329 @@ -1045,7 +1045,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51330 int irq;
51331
51332 if (pdev->id == -1)
51333 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51334 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51335
51336 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51337 return -ENXIO;
51338 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51339 index 1f5505e..a1a767d 100644
51340 --- a/drivers/tty/serial/samsung.c
51341 +++ b/drivers/tty/serial/samsung.c
51342 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51343 }
51344 }
51345
51346 +static int s3c64xx_serial_startup(struct uart_port *port);
51347 static int s3c24xx_serial_startup(struct uart_port *port)
51348 {
51349 struct s3c24xx_uart_port *ourport = to_ourport(port);
51350 int ret;
51351
51352 + /* Startup sequence is different for s3c64xx and higher SoC's */
51353 + if (s3c24xx_serial_has_interrupt_mask(port))
51354 + return s3c64xx_serial_startup(port);
51355 +
51356 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51357 port->mapbase, port->membase);
51358
51359 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51360 /* setup info for port */
51361 port->dev = &platdev->dev;
51362
51363 - /* Startup sequence is different for s3c64xx and higher SoC's */
51364 - if (s3c24xx_serial_has_interrupt_mask(port))
51365 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51366 -
51367 port->uartclk = 1;
51368
51369 if (cfg->uart_flags & UPF_CONS_FLOW) {
51370 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51371 index b68550d..a62d7f8 100644
51372 --- a/drivers/tty/serial/serial_core.c
51373 +++ b/drivers/tty/serial/serial_core.c
51374 @@ -1329,7 +1329,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
51375
51376 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
51377
51378 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
51379 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
51380 return;
51381
51382 /*
51383 @@ -1456,7 +1456,7 @@ static void uart_hangup(struct tty_struct *tty)
51384 uart_flush_buffer(tty);
51385 uart_shutdown(tty, state);
51386 spin_lock_irqsave(&port->lock, flags);
51387 - port->count = 0;
51388 + atomic_set(&port->count, 0);
51389 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51390 spin_unlock_irqrestore(&port->lock, flags);
51391 tty_port_tty_set(port, NULL);
51392 @@ -1554,7 +1554,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51393 goto end;
51394 }
51395
51396 - port->count++;
51397 + atomic_inc(&port->count);
51398 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51399 retval = -ENXIO;
51400 goto err_dec_count;
51401 @@ -1594,7 +1594,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51402 end:
51403 return retval;
51404 err_dec_count:
51405 - port->count--;
51406 + atomic_inc(&port->count);
51407 mutex_unlock(&port->mutex);
51408 goto end;
51409 }
51410 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51411 index d48e040..0f52764 100644
51412 --- a/drivers/tty/synclink.c
51413 +++ b/drivers/tty/synclink.c
51414 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51415
51416 if (debug_level >= DEBUG_LEVEL_INFO)
51417 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51418 - __FILE__,__LINE__, info->device_name, info->port.count);
51419 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51420
51421 if (tty_port_close_start(&info->port, tty, filp) == 0)
51422 goto cleanup;
51423 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51424 cleanup:
51425 if (debug_level >= DEBUG_LEVEL_INFO)
51426 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51427 - tty->driver->name, info->port.count);
51428 + tty->driver->name, atomic_read(&info->port.count));
51429
51430 } /* end of mgsl_close() */
51431
51432 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51433
51434 mgsl_flush_buffer(tty);
51435 shutdown(info);
51436 -
51437 - info->port.count = 0;
51438 +
51439 + atomic_set(&info->port.count, 0);
51440 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51441 info->port.tty = NULL;
51442
51443 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51444
51445 if (debug_level >= DEBUG_LEVEL_INFO)
51446 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51447 - __FILE__,__LINE__, tty->driver->name, port->count );
51448 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51449
51450 spin_lock_irqsave(&info->irq_spinlock, flags);
51451 if (!tty_hung_up_p(filp)) {
51452 extra_count = true;
51453 - port->count--;
51454 + atomic_dec(&port->count);
51455 }
51456 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51457 port->blocked_open++;
51458 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51459
51460 if (debug_level >= DEBUG_LEVEL_INFO)
51461 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51462 - __FILE__,__LINE__, tty->driver->name, port->count );
51463 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51464
51465 tty_unlock(tty);
51466 schedule();
51467 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51468
51469 /* FIXME: Racy on hangup during close wait */
51470 if (extra_count)
51471 - port->count++;
51472 + atomic_inc(&port->count);
51473 port->blocked_open--;
51474
51475 if (debug_level >= DEBUG_LEVEL_INFO)
51476 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51477 - __FILE__,__LINE__, tty->driver->name, port->count );
51478 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51479
51480 if (!retval)
51481 port->flags |= ASYNC_NORMAL_ACTIVE;
51482 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51483
51484 if (debug_level >= DEBUG_LEVEL_INFO)
51485 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51486 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51487 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51488
51489 /* If port is closing, signal caller to try again */
51490 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51491 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51492 spin_unlock_irqrestore(&info->netlock, flags);
51493 goto cleanup;
51494 }
51495 - info->port.count++;
51496 + atomic_inc(&info->port.count);
51497 spin_unlock_irqrestore(&info->netlock, flags);
51498
51499 - if (info->port.count == 1) {
51500 + if (atomic_read(&info->port.count) == 1) {
51501 /* 1st open on this device, init hardware */
51502 retval = startup(info);
51503 if (retval < 0)
51504 @@ -3446,8 +3446,8 @@ cleanup:
51505 if (retval) {
51506 if (tty->count == 1)
51507 info->port.tty = NULL; /* tty layer will release tty struct */
51508 - if(info->port.count)
51509 - info->port.count--;
51510 + if (atomic_read(&info->port.count))
51511 + atomic_dec(&info->port.count);
51512 }
51513
51514 return retval;
51515 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51516 unsigned short new_crctype;
51517
51518 /* return error if TTY interface open */
51519 - if (info->port.count)
51520 + if (atomic_read(&info->port.count))
51521 return -EBUSY;
51522
51523 switch (encoding)
51524 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51525
51526 /* arbitrate between network and tty opens */
51527 spin_lock_irqsave(&info->netlock, flags);
51528 - if (info->port.count != 0 || info->netcount != 0) {
51529 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51530 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51531 spin_unlock_irqrestore(&info->netlock, flags);
51532 return -EBUSY;
51533 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51534 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51535
51536 /* return error if TTY interface open */
51537 - if (info->port.count)
51538 + if (atomic_read(&info->port.count))
51539 return -EBUSY;
51540
51541 if (cmd != SIOCWANDEV)
51542 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51543 index c359a91..959fc26 100644
51544 --- a/drivers/tty/synclink_gt.c
51545 +++ b/drivers/tty/synclink_gt.c
51546 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51547 tty->driver_data = info;
51548 info->port.tty = tty;
51549
51550 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51551 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51552
51553 /* If port is closing, signal caller to try again */
51554 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51555 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51556 mutex_unlock(&info->port.mutex);
51557 goto cleanup;
51558 }
51559 - info->port.count++;
51560 + atomic_inc(&info->port.count);
51561 spin_unlock_irqrestore(&info->netlock, flags);
51562
51563 - if (info->port.count == 1) {
51564 + if (atomic_read(&info->port.count) == 1) {
51565 /* 1st open on this device, init hardware */
51566 retval = startup(info);
51567 if (retval < 0) {
51568 @@ -715,8 +715,8 @@ cleanup:
51569 if (retval) {
51570 if (tty->count == 1)
51571 info->port.tty = NULL; /* tty layer will release tty struct */
51572 - if(info->port.count)
51573 - info->port.count--;
51574 + if(atomic_read(&info->port.count))
51575 + atomic_dec(&info->port.count);
51576 }
51577
51578 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51579 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51580
51581 if (sanity_check(info, tty->name, "close"))
51582 return;
51583 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51584 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51585
51586 if (tty_port_close_start(&info->port, tty, filp) == 0)
51587 goto cleanup;
51588 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51589 tty_port_close_end(&info->port, tty);
51590 info->port.tty = NULL;
51591 cleanup:
51592 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51593 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51594 }
51595
51596 static void hangup(struct tty_struct *tty)
51597 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51598 shutdown(info);
51599
51600 spin_lock_irqsave(&info->port.lock, flags);
51601 - info->port.count = 0;
51602 + atomic_set(&info->port.count, 0);
51603 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51604 info->port.tty = NULL;
51605 spin_unlock_irqrestore(&info->port.lock, flags);
51606 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51607 unsigned short new_crctype;
51608
51609 /* return error if TTY interface open */
51610 - if (info->port.count)
51611 + if (atomic_read(&info->port.count))
51612 return -EBUSY;
51613
51614 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51615 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51616
51617 /* arbitrate between network and tty opens */
51618 spin_lock_irqsave(&info->netlock, flags);
51619 - if (info->port.count != 0 || info->netcount != 0) {
51620 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51621 DBGINFO(("%s hdlc_open busy\n", dev->name));
51622 spin_unlock_irqrestore(&info->netlock, flags);
51623 return -EBUSY;
51624 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51625 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51626
51627 /* return error if TTY interface open */
51628 - if (info->port.count)
51629 + if (atomic_read(&info->port.count))
51630 return -EBUSY;
51631
51632 if (cmd != SIOCWANDEV)
51633 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51634 if (port == NULL)
51635 continue;
51636 spin_lock(&port->lock);
51637 - if ((port->port.count || port->netcount) &&
51638 + if ((atomic_read(&port->port.count) || port->netcount) &&
51639 port->pending_bh && !port->bh_running &&
51640 !port->bh_requested) {
51641 DBGISR(("%s bh queued\n", port->device_name));
51642 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51643 spin_lock_irqsave(&info->lock, flags);
51644 if (!tty_hung_up_p(filp)) {
51645 extra_count = true;
51646 - port->count--;
51647 + atomic_dec(&port->count);
51648 }
51649 spin_unlock_irqrestore(&info->lock, flags);
51650 port->blocked_open++;
51651 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51652 remove_wait_queue(&port->open_wait, &wait);
51653
51654 if (extra_count)
51655 - port->count++;
51656 + atomic_inc(&port->count);
51657 port->blocked_open--;
51658
51659 if (!retval)
51660 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51661 index 53ba853..3c30f6d 100644
51662 --- a/drivers/tty/synclinkmp.c
51663 +++ b/drivers/tty/synclinkmp.c
51664 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51665
51666 if (debug_level >= DEBUG_LEVEL_INFO)
51667 printk("%s(%d):%s open(), old ref count = %d\n",
51668 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51669 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51670
51671 /* If port is closing, signal caller to try again */
51672 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51673 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51674 spin_unlock_irqrestore(&info->netlock, flags);
51675 goto cleanup;
51676 }
51677 - info->port.count++;
51678 + atomic_inc(&info->port.count);
51679 spin_unlock_irqrestore(&info->netlock, flags);
51680
51681 - if (info->port.count == 1) {
51682 + if (atomic_read(&info->port.count) == 1) {
51683 /* 1st open on this device, init hardware */
51684 retval = startup(info);
51685 if (retval < 0)
51686 @@ -796,8 +796,8 @@ cleanup:
51687 if (retval) {
51688 if (tty->count == 1)
51689 info->port.tty = NULL; /* tty layer will release tty struct */
51690 - if(info->port.count)
51691 - info->port.count--;
51692 + if(atomic_read(&info->port.count))
51693 + atomic_dec(&info->port.count);
51694 }
51695
51696 return retval;
51697 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51698
51699 if (debug_level >= DEBUG_LEVEL_INFO)
51700 printk("%s(%d):%s close() entry, count=%d\n",
51701 - __FILE__,__LINE__, info->device_name, info->port.count);
51702 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51703
51704 if (tty_port_close_start(&info->port, tty, filp) == 0)
51705 goto cleanup;
51706 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51707 cleanup:
51708 if (debug_level >= DEBUG_LEVEL_INFO)
51709 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51710 - tty->driver->name, info->port.count);
51711 + tty->driver->name, atomic_read(&info->port.count));
51712 }
51713
51714 /* Called by tty_hangup() when a hangup is signaled.
51715 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51716 shutdown(info);
51717
51718 spin_lock_irqsave(&info->port.lock, flags);
51719 - info->port.count = 0;
51720 + atomic_set(&info->port.count, 0);
51721 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51722 info->port.tty = NULL;
51723 spin_unlock_irqrestore(&info->port.lock, flags);
51724 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51725 unsigned short new_crctype;
51726
51727 /* return error if TTY interface open */
51728 - if (info->port.count)
51729 + if (atomic_read(&info->port.count))
51730 return -EBUSY;
51731
51732 switch (encoding)
51733 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51734
51735 /* arbitrate between network and tty opens */
51736 spin_lock_irqsave(&info->netlock, flags);
51737 - if (info->port.count != 0 || info->netcount != 0) {
51738 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51739 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51740 spin_unlock_irqrestore(&info->netlock, flags);
51741 return -EBUSY;
51742 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51743 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51744
51745 /* return error if TTY interface open */
51746 - if (info->port.count)
51747 + if (atomic_read(&info->port.count))
51748 return -EBUSY;
51749
51750 if (cmd != SIOCWANDEV)
51751 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51752 * do not request bottom half processing if the
51753 * device is not open in a normal mode.
51754 */
51755 - if ( port && (port->port.count || port->netcount) &&
51756 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51757 port->pending_bh && !port->bh_running &&
51758 !port->bh_requested ) {
51759 if ( debug_level >= DEBUG_LEVEL_ISR )
51760 @@ -3319,12 +3319,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51761
51762 if (debug_level >= DEBUG_LEVEL_INFO)
51763 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51764 - __FILE__,__LINE__, tty->driver->name, port->count );
51765 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51766
51767 spin_lock_irqsave(&info->lock, flags);
51768 if (!tty_hung_up_p(filp)) {
51769 extra_count = true;
51770 - port->count--;
51771 + atomic_dec(&port->count);
51772 }
51773 spin_unlock_irqrestore(&info->lock, flags);
51774 port->blocked_open++;
51775 @@ -3353,7 +3353,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51776
51777 if (debug_level >= DEBUG_LEVEL_INFO)
51778 printk("%s(%d):%s block_til_ready() count=%d\n",
51779 - __FILE__,__LINE__, tty->driver->name, port->count );
51780 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51781
51782 tty_unlock(tty);
51783 schedule();
51784 @@ -3364,12 +3364,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51785 remove_wait_queue(&port->open_wait, &wait);
51786
51787 if (extra_count)
51788 - port->count++;
51789 + atomic_inc(&port->count);
51790 port->blocked_open--;
51791
51792 if (debug_level >= DEBUG_LEVEL_INFO)
51793 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51794 - __FILE__,__LINE__, tty->driver->name, port->count );
51795 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51796
51797 if (!retval)
51798 port->flags |= ASYNC_NORMAL_ACTIVE;
51799 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51800 index ce396ec..04a37be 100644
51801 --- a/drivers/tty/sysrq.c
51802 +++ b/drivers/tty/sysrq.c
51803 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51804 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51805 size_t count, loff_t *ppos)
51806 {
51807 - if (count) {
51808 + if (count && capable(CAP_SYS_ADMIN)) {
51809 char c;
51810
51811 if (get_user(c, buf))
51812 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51813 index 3411071..86f2cf2 100644
51814 --- a/drivers/tty/tty_io.c
51815 +++ b/drivers/tty/tty_io.c
51816 @@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51817
51818 void tty_default_fops(struct file_operations *fops)
51819 {
51820 - *fops = tty_fops;
51821 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51822 }
51823
51824 /*
51825 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51826 index 2d822aa..a566234 100644
51827 --- a/drivers/tty/tty_ldisc.c
51828 +++ b/drivers/tty/tty_ldisc.c
51829 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51830 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51831 tty_ldiscs[disc] = new_ldisc;
51832 new_ldisc->num = disc;
51833 - new_ldisc->refcount = 0;
51834 + atomic_set(&new_ldisc->refcount, 0);
51835 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51836
51837 return ret;
51838 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51839 return -EINVAL;
51840
51841 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51842 - if (tty_ldiscs[disc]->refcount)
51843 + if (atomic_read(&tty_ldiscs[disc]->refcount))
51844 ret = -EBUSY;
51845 else
51846 tty_ldiscs[disc] = NULL;
51847 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51848 if (ldops) {
51849 ret = ERR_PTR(-EAGAIN);
51850 if (try_module_get(ldops->owner)) {
51851 - ldops->refcount++;
51852 + atomic_inc(&ldops->refcount);
51853 ret = ldops;
51854 }
51855 }
51856 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51857 unsigned long flags;
51858
51859 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51860 - ldops->refcount--;
51861 + atomic_dec(&ldops->refcount);
51862 module_put(ldops->owner);
51863 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51864 }
51865 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51866 index 3f746c8..2f2fcaa 100644
51867 --- a/drivers/tty/tty_port.c
51868 +++ b/drivers/tty/tty_port.c
51869 @@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51870 unsigned long flags;
51871
51872 spin_lock_irqsave(&port->lock, flags);
51873 - port->count = 0;
51874 + atomic_set(&port->count, 0);
51875 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51876 tty = port->tty;
51877 if (tty)
51878 @@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51879 /* The port lock protects the port counts */
51880 spin_lock_irqsave(&port->lock, flags);
51881 if (!tty_hung_up_p(filp))
51882 - port->count--;
51883 + atomic_dec(&port->count);
51884 port->blocked_open++;
51885 spin_unlock_irqrestore(&port->lock, flags);
51886
51887 @@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51888 we must not mess that up further */
51889 spin_lock_irqsave(&port->lock, flags);
51890 if (!tty_hung_up_p(filp))
51891 - port->count++;
51892 + atomic_inc(&port->count);
51893 port->blocked_open--;
51894 if (retval == 0)
51895 port->flags |= ASYNC_NORMAL_ACTIVE;
51896 @@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51897 return 0;
51898 }
51899
51900 - if (tty->count == 1 && port->count != 1) {
51901 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
51902 printk(KERN_WARNING
51903 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51904 - port->count);
51905 - port->count = 1;
51906 + atomic_read(&port->count));
51907 + atomic_set(&port->count, 1);
51908 }
51909 - if (--port->count < 0) {
51910 + if (atomic_dec_return(&port->count) < 0) {
51911 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51912 - port->count);
51913 - port->count = 0;
51914 + atomic_read(&port->count));
51915 + atomic_set(&port->count, 0);
51916 }
51917
51918 - if (port->count) {
51919 + if (atomic_read(&port->count)) {
51920 spin_unlock_irqrestore(&port->lock, flags);
51921 return 0;
51922 }
51923 @@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51924 {
51925 spin_lock_irq(&port->lock);
51926 if (!tty_hung_up_p(filp))
51927 - ++port->count;
51928 + atomic_inc(&port->count);
51929 spin_unlock_irq(&port->lock);
51930 tty_port_tty_set(port, tty);
51931
51932 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51933 index d0e3a44..5f8b754 100644
51934 --- a/drivers/tty/vt/keyboard.c
51935 +++ b/drivers/tty/vt/keyboard.c
51936 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51937 kbd->kbdmode == VC_OFF) &&
51938 value != KVAL(K_SAK))
51939 return; /* SAK is allowed even in raw mode */
51940 +
51941 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51942 + {
51943 + void *func = fn_handler[value];
51944 + if (func == fn_show_state || func == fn_show_ptregs ||
51945 + func == fn_show_mem)
51946 + return;
51947 + }
51948 +#endif
51949 +
51950 fn_handler[value](vc);
51951 }
51952
51953 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51954 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51955 return -EFAULT;
51956
51957 - if (!capable(CAP_SYS_TTY_CONFIG))
51958 - perm = 0;
51959 -
51960 switch (cmd) {
51961 case KDGKBENT:
51962 /* Ensure another thread doesn't free it under us */
51963 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51964 spin_unlock_irqrestore(&kbd_event_lock, flags);
51965 return put_user(val, &user_kbe->kb_value);
51966 case KDSKBENT:
51967 + if (!capable(CAP_SYS_TTY_CONFIG))
51968 + perm = 0;
51969 +
51970 if (!perm)
51971 return -EPERM;
51972 if (!i && v == K_NOSUCHMAP) {
51973 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51974 int i, j, k;
51975 int ret;
51976
51977 - if (!capable(CAP_SYS_TTY_CONFIG))
51978 - perm = 0;
51979 -
51980 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51981 if (!kbs) {
51982 ret = -ENOMEM;
51983 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51984 kfree(kbs);
51985 return ((p && *p) ? -EOVERFLOW : 0);
51986 case KDSKBSENT:
51987 + if (!capable(CAP_SYS_TTY_CONFIG))
51988 + perm = 0;
51989 +
51990 if (!perm) {
51991 ret = -EPERM;
51992 goto reterr;
51993 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51994 index a673e5b..36e5d32 100644
51995 --- a/drivers/uio/uio.c
51996 +++ b/drivers/uio/uio.c
51997 @@ -25,6 +25,7 @@
51998 #include <linux/kobject.h>
51999 #include <linux/cdev.h>
52000 #include <linux/uio_driver.h>
52001 +#include <asm/local.h>
52002
52003 #define UIO_MAX_DEVICES (1U << MINORBITS)
52004
52005 @@ -32,7 +33,7 @@ struct uio_device {
52006 struct module *owner;
52007 struct device *dev;
52008 int minor;
52009 - atomic_t event;
52010 + atomic_unchecked_t event;
52011 struct fasync_struct *async_queue;
52012 wait_queue_head_t wait;
52013 struct uio_info *info;
52014 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
52015 struct device_attribute *attr, char *buf)
52016 {
52017 struct uio_device *idev = dev_get_drvdata(dev);
52018 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
52019 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
52020 }
52021 static DEVICE_ATTR_RO(event);
52022
52023 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
52024 {
52025 struct uio_device *idev = info->uio_dev;
52026
52027 - atomic_inc(&idev->event);
52028 + atomic_inc_unchecked(&idev->event);
52029 wake_up_interruptible(&idev->wait);
52030 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
52031 }
52032 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
52033 }
52034
52035 listener->dev = idev;
52036 - listener->event_count = atomic_read(&idev->event);
52037 + listener->event_count = atomic_read_unchecked(&idev->event);
52038 filep->private_data = listener;
52039
52040 if (idev->info->open) {
52041 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
52042 return -EIO;
52043
52044 poll_wait(filep, &idev->wait, wait);
52045 - if (listener->event_count != atomic_read(&idev->event))
52046 + if (listener->event_count != atomic_read_unchecked(&idev->event))
52047 return POLLIN | POLLRDNORM;
52048 return 0;
52049 }
52050 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
52051 do {
52052 set_current_state(TASK_INTERRUPTIBLE);
52053
52054 - event_count = atomic_read(&idev->event);
52055 + event_count = atomic_read_unchecked(&idev->event);
52056 if (event_count != listener->event_count) {
52057 if (copy_to_user(buf, &event_count, count))
52058 retval = -EFAULT;
52059 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
52060 static int uio_find_mem_index(struct vm_area_struct *vma)
52061 {
52062 struct uio_device *idev = vma->vm_private_data;
52063 + unsigned long size;
52064
52065 if (vma->vm_pgoff < MAX_UIO_MAPS) {
52066 - if (idev->info->mem[vma->vm_pgoff].size == 0)
52067 + size = idev->info->mem[vma->vm_pgoff].size;
52068 + if (size == 0)
52069 + return -1;
52070 + if (vma->vm_end - vma->vm_start > size)
52071 return -1;
52072 return (int)vma->vm_pgoff;
52073 }
52074 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
52075 idev->owner = owner;
52076 idev->info = info;
52077 init_waitqueue_head(&idev->wait);
52078 - atomic_set(&idev->event, 0);
52079 + atomic_set_unchecked(&idev->event, 0);
52080
52081 ret = uio_get_minor(idev);
52082 if (ret)
52083 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
52084 index 813d4d3..a71934f 100644
52085 --- a/drivers/usb/atm/cxacru.c
52086 +++ b/drivers/usb/atm/cxacru.c
52087 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
52088 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
52089 if (ret < 2)
52090 return -EINVAL;
52091 - if (index < 0 || index > 0x7f)
52092 + if (index > 0x7f)
52093 return -EINVAL;
52094 pos += tmp;
52095
52096 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
52097 index dada014..1d0d517 100644
52098 --- a/drivers/usb/atm/usbatm.c
52099 +++ b/drivers/usb/atm/usbatm.c
52100 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52101 if (printk_ratelimit())
52102 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
52103 __func__, vpi, vci);
52104 - atomic_inc(&vcc->stats->rx_err);
52105 + atomic_inc_unchecked(&vcc->stats->rx_err);
52106 return;
52107 }
52108
52109 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52110 if (length > ATM_MAX_AAL5_PDU) {
52111 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
52112 __func__, length, vcc);
52113 - atomic_inc(&vcc->stats->rx_err);
52114 + atomic_inc_unchecked(&vcc->stats->rx_err);
52115 goto out;
52116 }
52117
52118 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52119 if (sarb->len < pdu_length) {
52120 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
52121 __func__, pdu_length, sarb->len, vcc);
52122 - atomic_inc(&vcc->stats->rx_err);
52123 + atomic_inc_unchecked(&vcc->stats->rx_err);
52124 goto out;
52125 }
52126
52127 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
52128 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
52129 __func__, vcc);
52130 - atomic_inc(&vcc->stats->rx_err);
52131 + atomic_inc_unchecked(&vcc->stats->rx_err);
52132 goto out;
52133 }
52134
52135 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52136 if (printk_ratelimit())
52137 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
52138 __func__, length);
52139 - atomic_inc(&vcc->stats->rx_drop);
52140 + atomic_inc_unchecked(&vcc->stats->rx_drop);
52141 goto out;
52142 }
52143
52144 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52145
52146 vcc->push(vcc, skb);
52147
52148 - atomic_inc(&vcc->stats->rx);
52149 + atomic_inc_unchecked(&vcc->stats->rx);
52150 out:
52151 skb_trim(sarb, 0);
52152 }
52153 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
52154 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
52155
52156 usbatm_pop(vcc, skb);
52157 - atomic_inc(&vcc->stats->tx);
52158 + atomic_inc_unchecked(&vcc->stats->tx);
52159
52160 skb = skb_dequeue(&instance->sndqueue);
52161 }
52162 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
52163 if (!left--)
52164 return sprintf(page,
52165 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
52166 - atomic_read(&atm_dev->stats.aal5.tx),
52167 - atomic_read(&atm_dev->stats.aal5.tx_err),
52168 - atomic_read(&atm_dev->stats.aal5.rx),
52169 - atomic_read(&atm_dev->stats.aal5.rx_err),
52170 - atomic_read(&atm_dev->stats.aal5.rx_drop));
52171 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
52172 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
52173 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
52174 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
52175 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
52176
52177 if (!left--) {
52178 if (instance->disconnected)
52179 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
52180 index 2a3bbdf..91d72cf 100644
52181 --- a/drivers/usb/core/devices.c
52182 +++ b/drivers/usb/core/devices.c
52183 @@ -126,7 +126,7 @@ static const char format_endpt[] =
52184 * time it gets called.
52185 */
52186 static struct device_connect_event {
52187 - atomic_t count;
52188 + atomic_unchecked_t count;
52189 wait_queue_head_t wait;
52190 } device_event = {
52191 .count = ATOMIC_INIT(1),
52192 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
52193
52194 void usbfs_conn_disc_event(void)
52195 {
52196 - atomic_add(2, &device_event.count);
52197 + atomic_add_unchecked(2, &device_event.count);
52198 wake_up(&device_event.wait);
52199 }
52200
52201 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
52202
52203 poll_wait(file, &device_event.wait, wait);
52204
52205 - event_count = atomic_read(&device_event.count);
52206 + event_count = atomic_read_unchecked(&device_event.count);
52207 if (file->f_version != event_count) {
52208 file->f_version = event_count;
52209 return POLLIN | POLLRDNORM;
52210 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
52211 index 257876e..4304364 100644
52212 --- a/drivers/usb/core/devio.c
52213 +++ b/drivers/usb/core/devio.c
52214 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52215 struct usb_dev_state *ps = file->private_data;
52216 struct usb_device *dev = ps->dev;
52217 ssize_t ret = 0;
52218 - unsigned len;
52219 + size_t len;
52220 loff_t pos;
52221 int i;
52222
52223 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52224 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
52225 struct usb_config_descriptor *config =
52226 (struct usb_config_descriptor *)dev->rawdescriptors[i];
52227 - unsigned int length = le16_to_cpu(config->wTotalLength);
52228 + size_t length = le16_to_cpu(config->wTotalLength);
52229
52230 if (*ppos < pos + length) {
52231
52232 /* The descriptor may claim to be longer than it
52233 * really is. Here is the actual allocated length. */
52234 - unsigned alloclen =
52235 + size_t alloclen =
52236 le16_to_cpu(dev->config[i].desc.wTotalLength);
52237
52238 - len = length - (*ppos - pos);
52239 + len = length + pos - *ppos;
52240 if (len > nbytes)
52241 len = nbytes;
52242
52243 /* Simply don't write (skip over) unallocated parts */
52244 if (alloclen > (*ppos - pos)) {
52245 - alloclen -= (*ppos - pos);
52246 + alloclen = alloclen + pos - *ppos;
52247 if (copy_to_user(buf,
52248 dev->rawdescriptors[i] + (*ppos - pos),
52249 min(len, alloclen))) {
52250 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
52251 index 9c4e292..b89877f 100644
52252 --- a/drivers/usb/core/hcd.c
52253 +++ b/drivers/usb/core/hcd.c
52254 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52255 */
52256 usb_get_urb(urb);
52257 atomic_inc(&urb->use_count);
52258 - atomic_inc(&urb->dev->urbnum);
52259 + atomic_inc_unchecked(&urb->dev->urbnum);
52260 usbmon_urb_submit(&hcd->self, urb);
52261
52262 /* NOTE requirements on root-hub callers (usbfs and the hub
52263 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52264 urb->hcpriv = NULL;
52265 INIT_LIST_HEAD(&urb->urb_list);
52266 atomic_dec(&urb->use_count);
52267 - atomic_dec(&urb->dev->urbnum);
52268 + atomic_dec_unchecked(&urb->dev->urbnum);
52269 if (atomic_read(&urb->reject))
52270 wake_up(&usb_kill_urb_queue);
52271 usb_put_urb(urb);
52272 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
52273 index 229a73f..ef86f98 100644
52274 --- a/drivers/usb/core/hub.c
52275 +++ b/drivers/usb/core/hub.c
52276 @@ -27,6 +27,7 @@
52277 #include <linux/freezer.h>
52278 #include <linux/random.h>
52279 #include <linux/pm_qos.h>
52280 +#include <linux/grsecurity.h>
52281
52282 #include <asm/uaccess.h>
52283 #include <asm/byteorder.h>
52284 @@ -4512,6 +4513,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
52285 goto done;
52286 return;
52287 }
52288 +
52289 + if (gr_handle_new_usb())
52290 + goto done;
52291 +
52292 if (hub_is_superspeed(hub->hdev))
52293 unit_load = 150;
52294 else
52295 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
52296 index 0c8a7fc..c45b40a 100644
52297 --- a/drivers/usb/core/message.c
52298 +++ b/drivers/usb/core/message.c
52299 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
52300 * Return: If successful, the number of bytes transferred. Otherwise, a negative
52301 * error number.
52302 */
52303 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52304 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52305 __u8 requesttype, __u16 value, __u16 index, void *data,
52306 __u16 size, int timeout)
52307 {
52308 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
52309 * If successful, 0. Otherwise a negative error number. The number of actual
52310 * bytes transferred will be stored in the @actual_length parameter.
52311 */
52312 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52313 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52314 void *data, int len, int *actual_length, int timeout)
52315 {
52316 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
52317 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
52318 * bytes transferred will be stored in the @actual_length parameter.
52319 *
52320 */
52321 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52322 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52323 void *data, int len, int *actual_length, int timeout)
52324 {
52325 struct urb *urb;
52326 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52327 index 1236c60..d47a51c 100644
52328 --- a/drivers/usb/core/sysfs.c
52329 +++ b/drivers/usb/core/sysfs.c
52330 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52331 struct usb_device *udev;
52332
52333 udev = to_usb_device(dev);
52334 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52335 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52336 }
52337 static DEVICE_ATTR_RO(urbnum);
52338
52339 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52340 index 4d11449..f4ccabf 100644
52341 --- a/drivers/usb/core/usb.c
52342 +++ b/drivers/usb/core/usb.c
52343 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52344 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52345 dev->state = USB_STATE_ATTACHED;
52346 dev->lpm_disable_count = 1;
52347 - atomic_set(&dev->urbnum, 0);
52348 + atomic_set_unchecked(&dev->urbnum, 0);
52349
52350 INIT_LIST_HEAD(&dev->ep0.urb_list);
52351 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52352 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52353 index 85f398d..d375bbe 100644
52354 --- a/drivers/usb/dwc3/gadget.c
52355 +++ b/drivers/usb/dwc3/gadget.c
52356 @@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52357 if (!usb_endpoint_xfer_isoc(desc))
52358 return 0;
52359
52360 - memset(&trb_link, 0, sizeof(trb_link));
52361 -
52362 /* Link TRB for ISOC. The HWO bit is never reset */
52363 trb_st_hw = &dep->trb_pool[0];
52364
52365 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52366 index 8cfc319..4868255 100644
52367 --- a/drivers/usb/early/ehci-dbgp.c
52368 +++ b/drivers/usb/early/ehci-dbgp.c
52369 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52370
52371 #ifdef CONFIG_KGDB
52372 static struct kgdb_io kgdbdbgp_io_ops;
52373 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52374 +static struct kgdb_io kgdbdbgp_io_ops_console;
52375 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52376 #else
52377 #define dbgp_kgdb_mode (0)
52378 #endif
52379 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52380 .write_char = kgdbdbgp_write_char,
52381 };
52382
52383 +static struct kgdb_io kgdbdbgp_io_ops_console = {
52384 + .name = "kgdbdbgp",
52385 + .read_char = kgdbdbgp_read_char,
52386 + .write_char = kgdbdbgp_write_char,
52387 + .is_console = 1
52388 +};
52389 +
52390 static int kgdbdbgp_wait_time;
52391
52392 static int __init kgdbdbgp_parse_config(char *str)
52393 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52394 ptr++;
52395 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52396 }
52397 - kgdb_register_io_module(&kgdbdbgp_io_ops);
52398 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52399 + if (early_dbgp_console.index != -1)
52400 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52401 + else
52402 + kgdb_register_io_module(&kgdbdbgp_io_ops);
52403
52404 return 0;
52405 }
52406 diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52407 index 2b4c82d..06a8ee6 100644
52408 --- a/drivers/usb/gadget/f_uac1.c
52409 +++ b/drivers/usb/gadget/f_uac1.c
52410 @@ -13,6 +13,7 @@
52411 #include <linux/kernel.h>
52412 #include <linux/device.h>
52413 #include <linux/atomic.h>
52414 +#include <linux/module.h>
52415
52416 #include "u_uac1.h"
52417
52418 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52419 index ad0aca8..8ff84865 100644
52420 --- a/drivers/usb/gadget/u_serial.c
52421 +++ b/drivers/usb/gadget/u_serial.c
52422 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52423 spin_lock_irq(&port->port_lock);
52424
52425 /* already open? Great. */
52426 - if (port->port.count) {
52427 + if (atomic_read(&port->port.count)) {
52428 status = 0;
52429 - port->port.count++;
52430 + atomic_inc(&port->port.count);
52431
52432 /* currently opening/closing? wait ... */
52433 } else if (port->openclose) {
52434 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52435 tty->driver_data = port;
52436 port->port.tty = tty;
52437
52438 - port->port.count = 1;
52439 + atomic_set(&port->port.count, 1);
52440 port->openclose = false;
52441
52442 /* if connected, start the I/O stream */
52443 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52444
52445 spin_lock_irq(&port->port_lock);
52446
52447 - if (port->port.count != 1) {
52448 - if (port->port.count == 0)
52449 + if (atomic_read(&port->port.count) != 1) {
52450 + if (atomic_read(&port->port.count) == 0)
52451 WARN_ON(1);
52452 else
52453 - --port->port.count;
52454 + atomic_dec(&port->port.count);
52455 goto exit;
52456 }
52457
52458 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52459 * and sleep if necessary
52460 */
52461 port->openclose = true;
52462 - port->port.count = 0;
52463 + atomic_set(&port->port.count, 0);
52464
52465 gser = port->port_usb;
52466 if (gser && gser->disconnect)
52467 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52468 int cond;
52469
52470 spin_lock_irq(&port->port_lock);
52471 - cond = (port->port.count == 0) && !port->openclose;
52472 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52473 spin_unlock_irq(&port->port_lock);
52474 return cond;
52475 }
52476 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52477 /* if it's already open, start I/O ... and notify the serial
52478 * protocol about open/close status (connect/disconnect).
52479 */
52480 - if (port->port.count) {
52481 + if (atomic_read(&port->port.count)) {
52482 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52483 gs_start_io(port);
52484 if (gser->connect)
52485 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52486
52487 port->port_usb = NULL;
52488 gser->ioport = NULL;
52489 - if (port->port.count > 0 || port->openclose) {
52490 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
52491 wake_up_interruptible(&port->drain_wait);
52492 if (port->port.tty)
52493 tty_hangup(port->port.tty);
52494 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52495
52496 /* finally, free any unused/unusable I/O buffers */
52497 spin_lock_irqsave(&port->port_lock, flags);
52498 - if (port->port.count == 0 && !port->openclose)
52499 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
52500 gs_buf_free(&port->port_write_buf);
52501 gs_free_requests(gser->out, &port->read_pool, NULL);
52502 gs_free_requests(gser->out, &port->read_queue, NULL);
52503 diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52504 index 7a55fea..cc0ed4f 100644
52505 --- a/drivers/usb/gadget/u_uac1.c
52506 +++ b/drivers/usb/gadget/u_uac1.c
52507 @@ -16,6 +16,7 @@
52508 #include <linux/ctype.h>
52509 #include <linux/random.h>
52510 #include <linux/syscalls.h>
52511 +#include <linux/module.h>
52512
52513 #include "u_uac1.h"
52514
52515 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52516 index 7ae0c4d..35521b7 100644
52517 --- a/drivers/usb/host/ehci-hub.c
52518 +++ b/drivers/usb/host/ehci-hub.c
52519 @@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52520 urb->transfer_flags = URB_DIR_IN;
52521 usb_get_urb(urb);
52522 atomic_inc(&urb->use_count);
52523 - atomic_inc(&urb->dev->urbnum);
52524 + atomic_inc_unchecked(&urb->dev->urbnum);
52525 urb->setup_dma = dma_map_single(
52526 hcd->self.controller,
52527 urb->setup_packet,
52528 @@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52529 urb->status = -EINPROGRESS;
52530 usb_get_urb(urb);
52531 atomic_inc(&urb->use_count);
52532 - atomic_inc(&urb->dev->urbnum);
52533 + atomic_inc_unchecked(&urb->dev->urbnum);
52534 retval = submit_single_step_set_feature(hcd, urb, 0);
52535 if (!retval && !wait_for_completion_timeout(&done,
52536 msecs_to_jiffies(2000))) {
52537 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
52538 index d0d8fad..668ef7b 100644
52539 --- a/drivers/usb/host/hwa-hc.c
52540 +++ b/drivers/usb/host/hwa-hc.c
52541 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
52542 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
52543 struct wahc *wa = &hwahc->wa;
52544 struct device *dev = &wa->usb_iface->dev;
52545 - u8 mas_le[UWB_NUM_MAS/8];
52546 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
52547 +
52548 + if (mas_le == NULL)
52549 + return -ENOMEM;
52550
52551 /* Set the stream index */
52552 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
52553 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
52554 WUSB_REQ_SET_WUSB_MAS,
52555 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
52556 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
52557 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
52558 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
52559 if (result < 0)
52560 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
52561 out:
52562 + kfree(mas_le);
52563 +
52564 return result;
52565 }
52566
52567 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52568 index ba6a5d6..f88f7f3 100644
52569 --- a/drivers/usb/misc/appledisplay.c
52570 +++ b/drivers/usb/misc/appledisplay.c
52571 @@ -83,7 +83,7 @@ struct appledisplay {
52572 spinlock_t lock;
52573 };
52574
52575 -static atomic_t count_displays = ATOMIC_INIT(0);
52576 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52577 static struct workqueue_struct *wq;
52578
52579 static void appledisplay_complete(struct urb *urb)
52580 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52581
52582 /* Register backlight device */
52583 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52584 - atomic_inc_return(&count_displays) - 1);
52585 + atomic_inc_return_unchecked(&count_displays) - 1);
52586 memset(&props, 0, sizeof(struct backlight_properties));
52587 props.type = BACKLIGHT_RAW;
52588 props.max_brightness = 0xff;
52589 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52590 index 8d7fc48..01c4986 100644
52591 --- a/drivers/usb/serial/console.c
52592 +++ b/drivers/usb/serial/console.c
52593 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52594
52595 info->port = port;
52596
52597 - ++port->port.count;
52598 + atomic_inc(&port->port.count);
52599 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52600 if (serial->type->set_termios) {
52601 /*
52602 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52603 }
52604 /* Now that any required fake tty operations are completed restore
52605 * the tty port count */
52606 - --port->port.count;
52607 + atomic_dec(&port->port.count);
52608 /* The console is special in terms of closing the device so
52609 * indicate this port is now acting as a system console. */
52610 port->port.console = 1;
52611 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52612 free_tty:
52613 kfree(tty);
52614 reset_open_count:
52615 - port->port.count = 0;
52616 + atomic_set(&port->port.count, 0);
52617 usb_autopm_put_interface(serial->interface);
52618 error_get_interface:
52619 usb_serial_put(serial);
52620 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52621 static void usb_console_write(struct console *co,
52622 const char *buf, unsigned count)
52623 {
52624 - static struct usbcons_info *info = &usbcons_info;
52625 + struct usbcons_info *info = &usbcons_info;
52626 struct usb_serial_port *port = info->port;
52627 struct usb_serial *serial;
52628 int retval = -ENODEV;
52629 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52630 index 307e339..6aa97cb 100644
52631 --- a/drivers/usb/storage/usb.h
52632 +++ b/drivers/usb/storage/usb.h
52633 @@ -63,7 +63,7 @@ struct us_unusual_dev {
52634 __u8 useProtocol;
52635 __u8 useTransport;
52636 int (*initFunction)(struct us_data *);
52637 -};
52638 +} __do_const;
52639
52640
52641 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52642 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52643 index f2a8d29..7bc3fe7 100644
52644 --- a/drivers/usb/wusbcore/wa-hc.h
52645 +++ b/drivers/usb/wusbcore/wa-hc.h
52646 @@ -240,7 +240,7 @@ struct wahc {
52647 spinlock_t xfer_list_lock;
52648 struct work_struct xfer_enqueue_work;
52649 struct work_struct xfer_error_work;
52650 - atomic_t xfer_id_count;
52651 + atomic_unchecked_t xfer_id_count;
52652
52653 kernel_ulong_t quirks;
52654 };
52655 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
52656 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52657 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52658 wa->dto_in_use = 0;
52659 - atomic_set(&wa->xfer_id_count, 1);
52660 + atomic_set_unchecked(&wa->xfer_id_count, 1);
52661 /* init the buf in URBs */
52662 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
52663 usb_init_urb(&(wa->buf_in_urbs[index]));
52664 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52665 index 3e2e4ed..060c9b8 100644
52666 --- a/drivers/usb/wusbcore/wa-xfer.c
52667 +++ b/drivers/usb/wusbcore/wa-xfer.c
52668 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52669 */
52670 static void wa_xfer_id_init(struct wa_xfer *xfer)
52671 {
52672 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52673 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52674 }
52675
52676 /* Return the xfer's ID. */
52677 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52678 index 512f479..7e041d0 100644
52679 --- a/drivers/vfio/vfio.c
52680 +++ b/drivers/vfio/vfio.c
52681 @@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52682 return 0;
52683
52684 /* TODO Prevent device auto probing */
52685 - WARN("Device %s added to live group %d!\n", dev_name(dev),
52686 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52687 iommu_group_id(group->iommu_group));
52688
52689 return 0;
52690 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52691 index 5174eba..451e6bc 100644
52692 --- a/drivers/vhost/vringh.c
52693 +++ b/drivers/vhost/vringh.c
52694 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52695 /* Userspace access helpers: in this case, addresses are really userspace. */
52696 static inline int getu16_user(u16 *val, const u16 *p)
52697 {
52698 - return get_user(*val, (__force u16 __user *)p);
52699 + return get_user(*val, (u16 __force_user *)p);
52700 }
52701
52702 static inline int putu16_user(u16 *p, u16 val)
52703 {
52704 - return put_user(val, (__force u16 __user *)p);
52705 + return put_user(val, (u16 __force_user *)p);
52706 }
52707
52708 static inline int copydesc_user(void *dst, const void *src, size_t len)
52709 {
52710 - return copy_from_user(dst, (__force void __user *)src, len) ?
52711 + return copy_from_user(dst, (void __force_user *)src, len) ?
52712 -EFAULT : 0;
52713 }
52714
52715 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52716 const struct vring_used_elem *src,
52717 unsigned int num)
52718 {
52719 - return copy_to_user((__force void __user *)dst, src,
52720 + return copy_to_user((void __force_user *)dst, src,
52721 sizeof(*dst) * num) ? -EFAULT : 0;
52722 }
52723
52724 static inline int xfer_from_user(void *src, void *dst, size_t len)
52725 {
52726 - return copy_from_user(dst, (__force void __user *)src, len) ?
52727 + return copy_from_user(dst, (void __force_user *)src, len) ?
52728 -EFAULT : 0;
52729 }
52730
52731 static inline int xfer_to_user(void *dst, void *src, size_t len)
52732 {
52733 - return copy_to_user((__force void __user *)dst, src, len) ?
52734 + return copy_to_user((void __force_user *)dst, src, len) ?
52735 -EFAULT : 0;
52736 }
52737
52738 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52739 vrh->last_used_idx = 0;
52740 vrh->vring.num = num;
52741 /* vring expects kernel addresses, but only used via accessors. */
52742 - vrh->vring.desc = (__force struct vring_desc *)desc;
52743 - vrh->vring.avail = (__force struct vring_avail *)avail;
52744 - vrh->vring.used = (__force struct vring_used *)used;
52745 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52746 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52747 + vrh->vring.used = (__force_kernel struct vring_used *)used;
52748 return 0;
52749 }
52750 EXPORT_SYMBOL(vringh_init_user);
52751 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52752
52753 static inline int putu16_kern(u16 *p, u16 val)
52754 {
52755 - ACCESS_ONCE(*p) = val;
52756 + ACCESS_ONCE_RW(*p) = val;
52757 return 0;
52758 }
52759
52760 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52761 index 84a110a..96312c3 100644
52762 --- a/drivers/video/backlight/kb3886_bl.c
52763 +++ b/drivers/video/backlight/kb3886_bl.c
52764 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52765 static unsigned long kb3886bl_flags;
52766 #define KB3886BL_SUSPENDED 0x01
52767
52768 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52769 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52770 {
52771 .ident = "Sahara Touch-iT",
52772 .matches = {
52773 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
52774 index 1b0b233..6f34c2c 100644
52775 --- a/drivers/video/fbdev/arcfb.c
52776 +++ b/drivers/video/fbdev/arcfb.c
52777 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52778 return -ENOSPC;
52779
52780 err = 0;
52781 - if ((count + p) > fbmemlength) {
52782 + if (count > (fbmemlength - p)) {
52783 count = fbmemlength - p;
52784 err = -ENOSPC;
52785 }
52786 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
52787 index 52108be..c7c110d 100644
52788 --- a/drivers/video/fbdev/aty/aty128fb.c
52789 +++ b/drivers/video/fbdev/aty/aty128fb.c
52790 @@ -149,7 +149,7 @@ enum {
52791 };
52792
52793 /* Must match above enum */
52794 -static char * const r128_family[] = {
52795 +static const char * const r128_family[] = {
52796 "AGP",
52797 "PCI",
52798 "PRO AGP",
52799 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
52800 index c3d0074..0b9077e 100644
52801 --- a/drivers/video/fbdev/aty/atyfb_base.c
52802 +++ b/drivers/video/fbdev/aty/atyfb_base.c
52803 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52804 par->accel_flags = var->accel_flags; /* hack */
52805
52806 if (var->accel_flags) {
52807 - info->fbops->fb_sync = atyfb_sync;
52808 + pax_open_kernel();
52809 + *(void **)&info->fbops->fb_sync = atyfb_sync;
52810 + pax_close_kernel();
52811 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52812 } else {
52813 - info->fbops->fb_sync = NULL;
52814 + pax_open_kernel();
52815 + *(void **)&info->fbops->fb_sync = NULL;
52816 + pax_close_kernel();
52817 info->flags |= FBINFO_HWACCEL_DISABLED;
52818 }
52819
52820 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
52821 index 2fa0317..4983f2a 100644
52822 --- a/drivers/video/fbdev/aty/mach64_cursor.c
52823 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
52824 @@ -8,6 +8,7 @@
52825 #include "../core/fb_draw.h"
52826
52827 #include <asm/io.h>
52828 +#include <asm/pgtable.h>
52829
52830 #ifdef __sparc__
52831 #include <asm/fbio.h>
52832 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
52833 info->sprite.buf_align = 16; /* and 64 lines tall. */
52834 info->sprite.flags = FB_PIXMAP_IO;
52835
52836 - info->fbops->fb_cursor = atyfb_cursor;
52837 + pax_open_kernel();
52838 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52839 + pax_close_kernel();
52840
52841 return 0;
52842 }
52843 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
52844 index 900aa4e..6d49418 100644
52845 --- a/drivers/video/fbdev/core/fb_defio.c
52846 +++ b/drivers/video/fbdev/core/fb_defio.c
52847 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52848
52849 BUG_ON(!fbdefio);
52850 mutex_init(&fbdefio->lock);
52851 - info->fbops->fb_mmap = fb_deferred_io_mmap;
52852 + pax_open_kernel();
52853 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52854 + pax_close_kernel();
52855 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52856 INIT_LIST_HEAD(&fbdefio->pagelist);
52857 if (fbdefio->delay == 0) /* set a default of 1 s */
52858 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52859 page->mapping = NULL;
52860 }
52861
52862 - info->fbops->fb_mmap = NULL;
52863 + *(void **)&info->fbops->fb_mmap = NULL;
52864 mutex_destroy(&fbdefio->lock);
52865 }
52866 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52867 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
52868 index b6d5008..5bca7bf 100644
52869 --- a/drivers/video/fbdev/core/fbmem.c
52870 +++ b/drivers/video/fbdev/core/fbmem.c
52871 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52872 image->dx += image->width + 8;
52873 }
52874 } else if (rotate == FB_ROTATE_UD) {
52875 - for (x = 0; x < num && image->dx >= 0; x++) {
52876 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52877 info->fbops->fb_imageblit(info, image);
52878 image->dx -= image->width + 8;
52879 }
52880 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52881 image->dy += image->height + 8;
52882 }
52883 } else if (rotate == FB_ROTATE_CCW) {
52884 - for (x = 0; x < num && image->dy >= 0; x++) {
52885 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52886 info->fbops->fb_imageblit(info, image);
52887 image->dy -= image->height + 8;
52888 }
52889 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52890 return -EFAULT;
52891 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52892 return -EINVAL;
52893 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52894 + if (con2fb.framebuffer >= FB_MAX)
52895 return -EINVAL;
52896 if (!registered_fb[con2fb.framebuffer])
52897 request_module("fb%d", con2fb.framebuffer);
52898 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52899 __u32 data;
52900 int err;
52901
52902 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52903 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52904
52905 data = (__u32) (unsigned long) fix->smem_start;
52906 err |= put_user(data, &fix32->smem_start);
52907 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
52908 index e23392e..8a77540 100644
52909 --- a/drivers/video/fbdev/hyperv_fb.c
52910 +++ b/drivers/video/fbdev/hyperv_fb.c
52911 @@ -235,7 +235,7 @@ static uint screen_fb_size;
52912 static inline int synthvid_send(struct hv_device *hdev,
52913 struct synthvid_msg *msg)
52914 {
52915 - static atomic64_t request_id = ATOMIC64_INIT(0);
52916 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52917 int ret;
52918
52919 msg->pipe_hdr.type = PIPE_MSG_DATA;
52920 @@ -243,7 +243,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52921
52922 ret = vmbus_sendpacket(hdev->channel, msg,
52923 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52924 - atomic64_inc_return(&request_id),
52925 + atomic64_inc_return_unchecked(&request_id),
52926 VM_PKT_DATA_INBAND, 0);
52927
52928 if (ret)
52929 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
52930 index 7672d2e..b56437f 100644
52931 --- a/drivers/video/fbdev/i810/i810_accel.c
52932 +++ b/drivers/video/fbdev/i810/i810_accel.c
52933 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52934 }
52935 }
52936 printk("ringbuffer lockup!!!\n");
52937 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52938 i810_report_error(mmio);
52939 par->dev_flags |= LOCKUP;
52940 info->pixmap.scan_align = 1;
52941 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52942 index a01147f..5d896f8 100644
52943 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52944 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52945 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
52946
52947 #ifdef CONFIG_FB_MATROX_MYSTIQUE
52948 struct matrox_switch matrox_mystique = {
52949 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
52950 + .preinit = MGA1064_preinit,
52951 + .reset = MGA1064_reset,
52952 + .init = MGA1064_init,
52953 + .restore = MGA1064_restore,
52954 };
52955 EXPORT_SYMBOL(matrox_mystique);
52956 #endif
52957
52958 #ifdef CONFIG_FB_MATROX_G
52959 struct matrox_switch matrox_G100 = {
52960 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
52961 + .preinit = MGAG100_preinit,
52962 + .reset = MGAG100_reset,
52963 + .init = MGAG100_init,
52964 + .restore = MGAG100_restore,
52965 };
52966 EXPORT_SYMBOL(matrox_G100);
52967 #endif
52968 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52969 index 195ad7c..09743fc 100644
52970 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52971 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52972 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
52973 }
52974
52975 struct matrox_switch matrox_millennium = {
52976 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
52977 + .preinit = Ti3026_preinit,
52978 + .reset = Ti3026_reset,
52979 + .init = Ti3026_init,
52980 + .restore = Ti3026_restore
52981 };
52982 EXPORT_SYMBOL(matrox_millennium);
52983 #endif
52984 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52985 index fe92eed..106e085 100644
52986 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52987 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52988 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
52989 struct mb862xxfb_par *par = info->par;
52990
52991 if (info->var.bits_per_pixel == 32) {
52992 - info->fbops->fb_fillrect = cfb_fillrect;
52993 - info->fbops->fb_copyarea = cfb_copyarea;
52994 - info->fbops->fb_imageblit = cfb_imageblit;
52995 + pax_open_kernel();
52996 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52997 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52998 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52999 + pax_close_kernel();
53000 } else {
53001 outreg(disp, GC_L0EM, 3);
53002 - info->fbops->fb_fillrect = mb86290fb_fillrect;
53003 - info->fbops->fb_copyarea = mb86290fb_copyarea;
53004 - info->fbops->fb_imageblit = mb86290fb_imageblit;
53005 + pax_open_kernel();
53006 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
53007 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
53008 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
53009 + pax_close_kernel();
53010 }
53011 outreg(draw, GDC_REG_DRAW_BASE, 0);
53012 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
53013 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
53014 index def0412..fed6529 100644
53015 --- a/drivers/video/fbdev/nvidia/nvidia.c
53016 +++ b/drivers/video/fbdev/nvidia/nvidia.c
53017 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
53018 info->fix.line_length = (info->var.xres_virtual *
53019 info->var.bits_per_pixel) >> 3;
53020 if (info->var.accel_flags) {
53021 - info->fbops->fb_imageblit = nvidiafb_imageblit;
53022 - info->fbops->fb_fillrect = nvidiafb_fillrect;
53023 - info->fbops->fb_copyarea = nvidiafb_copyarea;
53024 - info->fbops->fb_sync = nvidiafb_sync;
53025 + pax_open_kernel();
53026 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
53027 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
53028 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
53029 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
53030 + pax_close_kernel();
53031 info->pixmap.scan_align = 4;
53032 info->flags &= ~FBINFO_HWACCEL_DISABLED;
53033 info->flags |= FBINFO_READS_FAST;
53034 NVResetGraphics(info);
53035 } else {
53036 - info->fbops->fb_imageblit = cfb_imageblit;
53037 - info->fbops->fb_fillrect = cfb_fillrect;
53038 - info->fbops->fb_copyarea = cfb_copyarea;
53039 - info->fbops->fb_sync = NULL;
53040 + pax_open_kernel();
53041 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
53042 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
53043 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
53044 + *(void **)&info->fbops->fb_sync = NULL;
53045 + pax_close_kernel();
53046 info->pixmap.scan_align = 1;
53047 info->flags |= FBINFO_HWACCEL_DISABLED;
53048 info->flags &= ~FBINFO_READS_FAST;
53049 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
53050 info->pixmap.size = 8 * 1024;
53051 info->pixmap.flags = FB_PIXMAP_SYSTEM;
53052
53053 - if (!hwcur)
53054 - info->fbops->fb_cursor = NULL;
53055 + if (!hwcur) {
53056 + pax_open_kernel();
53057 + *(void **)&info->fbops->fb_cursor = NULL;
53058 + pax_close_kernel();
53059 + }
53060
53061 info->var.accel_flags = (!noaccel);
53062
53063 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
53064 index 2412a0d..294215b 100644
53065 --- a/drivers/video/fbdev/omap2/dss/display.c
53066 +++ b/drivers/video/fbdev/omap2/dss/display.c
53067 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
53068 if (dssdev->name == NULL)
53069 dssdev->name = dssdev->alias;
53070
53071 + pax_open_kernel();
53072 if (drv && drv->get_resolution == NULL)
53073 - drv->get_resolution = omapdss_default_get_resolution;
53074 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
53075 if (drv && drv->get_recommended_bpp == NULL)
53076 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
53077 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
53078 if (drv && drv->get_timings == NULL)
53079 - drv->get_timings = omapdss_default_get_timings;
53080 + *(void **)&drv->get_timings = omapdss_default_get_timings;
53081 + pax_close_kernel();
53082
53083 mutex_lock(&panel_list_mutex);
53084 list_add_tail(&dssdev->panel_list, &panel_list);
53085 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
53086 index 83433cb..71e9b98 100644
53087 --- a/drivers/video/fbdev/s1d13xxxfb.c
53088 +++ b/drivers/video/fbdev/s1d13xxxfb.c
53089 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
53090
53091 switch(prod_id) {
53092 case S1D13506_PROD_ID: /* activate acceleration */
53093 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
53094 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
53095 + pax_open_kernel();
53096 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
53097 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
53098 + pax_close_kernel();
53099 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
53100 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
53101 break;
53102 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
53103 index 2bcc84a..29dd1ea 100644
53104 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
53105 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
53106 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
53107 }
53108
53109 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
53110 - lcdc_sys_write_index,
53111 - lcdc_sys_write_data,
53112 - lcdc_sys_read_data,
53113 + .write_index = lcdc_sys_write_index,
53114 + .write_data = lcdc_sys_write_data,
53115 + .read_data = lcdc_sys_read_data,
53116 };
53117
53118 static int sh_mobile_lcdc_sginit(struct fb_info *info,
53119 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
53120 index d513ed6..90b0de9 100644
53121 --- a/drivers/video/fbdev/smscufx.c
53122 +++ b/drivers/video/fbdev/smscufx.c
53123 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
53124 fb_deferred_io_cleanup(info);
53125 kfree(info->fbdefio);
53126 info->fbdefio = NULL;
53127 - info->fbops->fb_mmap = ufx_ops_mmap;
53128 + pax_open_kernel();
53129 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
53130 + pax_close_kernel();
53131 }
53132
53133 pr_debug("released /dev/fb%d user=%d count=%d",
53134 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
53135 index 77b890e..458e666 100644
53136 --- a/drivers/video/fbdev/udlfb.c
53137 +++ b/drivers/video/fbdev/udlfb.c
53138 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
53139 dlfb_urb_completion(urb);
53140
53141 error:
53142 - atomic_add(bytes_sent, &dev->bytes_sent);
53143 - atomic_add(bytes_identical, &dev->bytes_identical);
53144 - atomic_add(width*height*2, &dev->bytes_rendered);
53145 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
53146 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
53147 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
53148 end_cycles = get_cycles();
53149 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
53150 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
53151 >> 10)), /* Kcycles */
53152 &dev->cpu_kcycles_used);
53153
53154 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
53155 dlfb_urb_completion(urb);
53156
53157 error:
53158 - atomic_add(bytes_sent, &dev->bytes_sent);
53159 - atomic_add(bytes_identical, &dev->bytes_identical);
53160 - atomic_add(bytes_rendered, &dev->bytes_rendered);
53161 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
53162 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
53163 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
53164 end_cycles = get_cycles();
53165 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
53166 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
53167 >> 10)), /* Kcycles */
53168 &dev->cpu_kcycles_used);
53169 }
53170 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
53171 fb_deferred_io_cleanup(info);
53172 kfree(info->fbdefio);
53173 info->fbdefio = NULL;
53174 - info->fbops->fb_mmap = dlfb_ops_mmap;
53175 + pax_open_kernel();
53176 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
53177 + pax_close_kernel();
53178 }
53179
53180 pr_warn("released /dev/fb%d user=%d count=%d\n",
53181 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
53182 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53183 struct dlfb_data *dev = fb_info->par;
53184 return snprintf(buf, PAGE_SIZE, "%u\n",
53185 - atomic_read(&dev->bytes_rendered));
53186 + atomic_read_unchecked(&dev->bytes_rendered));
53187 }
53188
53189 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
53190 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
53191 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53192 struct dlfb_data *dev = fb_info->par;
53193 return snprintf(buf, PAGE_SIZE, "%u\n",
53194 - atomic_read(&dev->bytes_identical));
53195 + atomic_read_unchecked(&dev->bytes_identical));
53196 }
53197
53198 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
53199 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
53200 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53201 struct dlfb_data *dev = fb_info->par;
53202 return snprintf(buf, PAGE_SIZE, "%u\n",
53203 - atomic_read(&dev->bytes_sent));
53204 + atomic_read_unchecked(&dev->bytes_sent));
53205 }
53206
53207 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
53208 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
53209 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53210 struct dlfb_data *dev = fb_info->par;
53211 return snprintf(buf, PAGE_SIZE, "%u\n",
53212 - atomic_read(&dev->cpu_kcycles_used));
53213 + atomic_read_unchecked(&dev->cpu_kcycles_used));
53214 }
53215
53216 static ssize_t edid_show(
53217 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
53218 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53219 struct dlfb_data *dev = fb_info->par;
53220
53221 - atomic_set(&dev->bytes_rendered, 0);
53222 - atomic_set(&dev->bytes_identical, 0);
53223 - atomic_set(&dev->bytes_sent, 0);
53224 - atomic_set(&dev->cpu_kcycles_used, 0);
53225 + atomic_set_unchecked(&dev->bytes_rendered, 0);
53226 + atomic_set_unchecked(&dev->bytes_identical, 0);
53227 + atomic_set_unchecked(&dev->bytes_sent, 0);
53228 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
53229
53230 return count;
53231 }
53232 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
53233 index 509d452..7c9d2de 100644
53234 --- a/drivers/video/fbdev/uvesafb.c
53235 +++ b/drivers/video/fbdev/uvesafb.c
53236 @@ -19,6 +19,7 @@
53237 #include <linux/io.h>
53238 #include <linux/mutex.h>
53239 #include <linux/slab.h>
53240 +#include <linux/moduleloader.h>
53241 #include <video/edid.h>
53242 #include <video/uvesafb.h>
53243 #ifdef CONFIG_X86
53244 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
53245 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
53246 par->pmi_setpal = par->ypan = 0;
53247 } else {
53248 +
53249 +#ifdef CONFIG_PAX_KERNEXEC
53250 +#ifdef CONFIG_MODULES
53251 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
53252 +#endif
53253 + if (!par->pmi_code) {
53254 + par->pmi_setpal = par->ypan = 0;
53255 + return 0;
53256 + }
53257 +#endif
53258 +
53259 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
53260 + task->t.regs.edi);
53261 +
53262 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53263 + pax_open_kernel();
53264 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
53265 + pax_close_kernel();
53266 +
53267 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
53268 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
53269 +#else
53270 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
53271 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
53272 +#endif
53273 +
53274 printk(KERN_INFO "uvesafb: protected mode interface info at "
53275 "%04x:%04x\n",
53276 (u16)task->t.regs.es, (u16)task->t.regs.edi);
53277 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
53278 par->ypan = ypan;
53279
53280 if (par->pmi_setpal || par->ypan) {
53281 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
53282 if (__supported_pte_mask & _PAGE_NX) {
53283 par->pmi_setpal = par->ypan = 0;
53284 printk(KERN_WARNING "uvesafb: NX protection is active, "
53285 "better not use the PMI.\n");
53286 - } else {
53287 + } else
53288 +#endif
53289 uvesafb_vbe_getpmi(task, par);
53290 - }
53291 }
53292 #else
53293 /* The protected mode interface is not available on non-x86. */
53294 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53295 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
53296
53297 /* Disable blanking if the user requested so. */
53298 - if (!blank)
53299 - info->fbops->fb_blank = NULL;
53300 + if (!blank) {
53301 + pax_open_kernel();
53302 + *(void **)&info->fbops->fb_blank = NULL;
53303 + pax_close_kernel();
53304 + }
53305
53306 /*
53307 * Find out how much IO memory is required for the mode with
53308 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53309 info->flags = FBINFO_FLAG_DEFAULT |
53310 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
53311
53312 - if (!par->ypan)
53313 - info->fbops->fb_pan_display = NULL;
53314 + if (!par->ypan) {
53315 + pax_open_kernel();
53316 + *(void **)&info->fbops->fb_pan_display = NULL;
53317 + pax_close_kernel();
53318 + }
53319 }
53320
53321 static void uvesafb_init_mtrr(struct fb_info *info)
53322 @@ -1787,6 +1817,11 @@ out_mode:
53323 out:
53324 kfree(par->vbe_modes);
53325
53326 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53327 + if (par->pmi_code)
53328 + module_free_exec(NULL, par->pmi_code);
53329 +#endif
53330 +
53331 framebuffer_release(info);
53332 return err;
53333 }
53334 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
53335 kfree(par->vbe_state_orig);
53336 kfree(par->vbe_state_saved);
53337
53338 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53339 + if (par->pmi_code)
53340 + module_free_exec(NULL, par->pmi_code);
53341 +#endif
53342 +
53343 framebuffer_release(info);
53344 }
53345 return 0;
53346 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
53347 index 6170e7f..dd63031 100644
53348 --- a/drivers/video/fbdev/vesafb.c
53349 +++ b/drivers/video/fbdev/vesafb.c
53350 @@ -9,6 +9,7 @@
53351 */
53352
53353 #include <linux/module.h>
53354 +#include <linux/moduleloader.h>
53355 #include <linux/kernel.h>
53356 #include <linux/errno.h>
53357 #include <linux/string.h>
53358 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
53359 static int vram_total; /* Set total amount of memory */
53360 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
53361 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
53362 -static void (*pmi_start)(void) __read_mostly;
53363 -static void (*pmi_pal) (void) __read_mostly;
53364 +static void (*pmi_start)(void) __read_only;
53365 +static void (*pmi_pal) (void) __read_only;
53366 static int depth __read_mostly;
53367 static int vga_compat __read_mostly;
53368 /* --------------------------------------------------------------------- */
53369 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
53370 unsigned int size_remap;
53371 unsigned int size_total;
53372 char *option = NULL;
53373 + void *pmi_code = NULL;
53374
53375 /* ignore error return of fb_get_options */
53376 fb_get_options("vesafb", &option);
53377 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
53378 size_remap = size_total;
53379 vesafb_fix.smem_len = size_remap;
53380
53381 -#ifndef __i386__
53382 - screen_info.vesapm_seg = 0;
53383 -#endif
53384 -
53385 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
53386 printk(KERN_WARNING
53387 "vesafb: cannot reserve video memory at 0x%lx\n",
53388 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
53389 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
53390 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
53391
53392 +#ifdef __i386__
53393 +
53394 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53395 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
53396 + if (!pmi_code)
53397 +#elif !defined(CONFIG_PAX_KERNEXEC)
53398 + if (0)
53399 +#endif
53400 +
53401 +#endif
53402 + screen_info.vesapm_seg = 0;
53403 +
53404 if (screen_info.vesapm_seg) {
53405 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
53406 - screen_info.vesapm_seg,screen_info.vesapm_off);
53407 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
53408 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
53409 }
53410
53411 if (screen_info.vesapm_seg < 0xc000)
53412 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
53413
53414 if (ypan || pmi_setpal) {
53415 unsigned short *pmi_base;
53416 +
53417 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
53418 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
53419 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
53420 +
53421 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53422 + pax_open_kernel();
53423 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
53424 +#else
53425 + pmi_code = pmi_base;
53426 +#endif
53427 +
53428 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
53429 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
53430 +
53431 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53432 + pmi_start = ktva_ktla(pmi_start);
53433 + pmi_pal = ktva_ktla(pmi_pal);
53434 + pax_close_kernel();
53435 +#endif
53436 +
53437 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
53438 if (pmi_base[3]) {
53439 printk(KERN_INFO "vesafb: pmi: ports = ");
53440 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
53441 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
53442 (ypan ? FBINFO_HWACCEL_YPAN : 0);
53443
53444 - if (!ypan)
53445 - info->fbops->fb_pan_display = NULL;
53446 + if (!ypan) {
53447 + pax_open_kernel();
53448 + *(void **)&info->fbops->fb_pan_display = NULL;
53449 + pax_close_kernel();
53450 + }
53451
53452 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
53453 err = -ENOMEM;
53454 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
53455 fb_info(info, "%s frame buffer device\n", info->fix.id);
53456 return 0;
53457 err:
53458 +
53459 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53460 + module_free_exec(NULL, pmi_code);
53461 +#endif
53462 +
53463 if (info->screen_base)
53464 iounmap(info->screen_base);
53465 framebuffer_release(info);
53466 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
53467 index 88714ae..16c2e11 100644
53468 --- a/drivers/video/fbdev/via/via_clock.h
53469 +++ b/drivers/video/fbdev/via/via_clock.h
53470 @@ -56,7 +56,7 @@ struct via_clock {
53471
53472 void (*set_engine_pll_state)(u8 state);
53473 void (*set_engine_pll)(struct via_pll_config config);
53474 -};
53475 +} __no_const;
53476
53477
53478 static inline u32 get_pll_internal_frequency(u32 ref_freq,
53479 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53480 index 3c14e43..2630570 100644
53481 --- a/drivers/video/logo/logo_linux_clut224.ppm
53482 +++ b/drivers/video/logo/logo_linux_clut224.ppm
53483 @@ -2,1603 +2,1123 @@ P3
53484 # Standard 224-color Linux logo
53485 80 80
53486 255
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 0 0 0 0
53494 - 0 0 0 0 0 0 0 0 0 0 0 0
53495 - 0 0 0 0 0 0 0 0 0 0 0 0
53496 - 6 6 6 6 6 6 10 10 10 10 10 10
53497 - 10 10 10 6 6 6 6 6 6 6 6 6
53498 - 0 0 0 0 0 0 0 0 0 0 0 0
53499 - 0 0 0 0 0 0 0 0 0 0 0 0
53500 - 0 0 0 0 0 0 0 0 0 0 0 0
53501 - 0 0 0 0 0 0 0 0 0 0 0 0
53502 - 0 0 0 0 0 0 0 0 0 0 0 0
53503 - 0 0 0 0 0 0 0 0 0 0 0 0
53504 - 0 0 0 0 0 0 0 0 0 0 0 0
53505 - 0 0 0 0 0 0 0 0 0 0 0 0
53506 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
53514 - 0 0 0 0 0 0 0 0 0 0 0 0
53515 - 0 0 0 6 6 6 10 10 10 14 14 14
53516 - 22 22 22 26 26 26 30 30 30 34 34 34
53517 - 30 30 30 30 30 30 26 26 26 18 18 18
53518 - 14 14 14 10 10 10 6 6 6 0 0 0
53519 - 0 0 0 0 0 0 0 0 0 0 0 0
53520 - 0 0 0 0 0 0 0 0 0 0 0 0
53521 - 0 0 0 0 0 0 0 0 0 0 0 0
53522 - 0 0 0 0 0 0 0 0 0 0 0 0
53523 - 0 0 0 0 0 0 0 0 0 0 0 0
53524 - 0 0 0 0 0 0 0 0 0 0 0 0
53525 - 0 0 0 0 0 0 0 0 0 0 0 0
53526 - 0 0 0 0 0 0 0 0 0 0 0 0
53527 - 0 0 0 0 0 0 0 0 0 0 0 0
53528 - 0 0 0 0 0 1 0 0 1 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 - 6 6 6 14 14 14 26 26 26 42 42 42
53536 - 54 54 54 66 66 66 78 78 78 78 78 78
53537 - 78 78 78 74 74 74 66 66 66 54 54 54
53538 - 42 42 42 26 26 26 18 18 18 10 10 10
53539 - 6 6 6 0 0 0 0 0 0 0 0 0
53540 - 0 0 0 0 0 0 0 0 0 0 0 0
53541 - 0 0 0 0 0 0 0 0 0 0 0 0
53542 - 0 0 0 0 0 0 0 0 0 0 0 0
53543 - 0 0 0 0 0 0 0 0 0 0 0 0
53544 - 0 0 0 0 0 0 0 0 0 0 0 0
53545 - 0 0 0 0 0 0 0 0 0 0 0 0
53546 - 0 0 0 0 0 0 0 0 0 0 0 0
53547 - 0 0 0 0 0 0 0 0 0 0 0 0
53548 - 0 0 1 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 10 10 10
53555 - 22 22 22 42 42 42 66 66 66 86 86 86
53556 - 66 66 66 38 38 38 38 38 38 22 22 22
53557 - 26 26 26 34 34 34 54 54 54 66 66 66
53558 - 86 86 86 70 70 70 46 46 46 26 26 26
53559 - 14 14 14 6 6 6 0 0 0 0 0 0
53560 - 0 0 0 0 0 0 0 0 0 0 0 0
53561 - 0 0 0 0 0 0 0 0 0 0 0 0
53562 - 0 0 0 0 0 0 0 0 0 0 0 0
53563 - 0 0 0 0 0 0 0 0 0 0 0 0
53564 - 0 0 0 0 0 0 0 0 0 0 0 0
53565 - 0 0 0 0 0 0 0 0 0 0 0 0
53566 - 0 0 0 0 0 0 0 0 0 0 0 0
53567 - 0 0 0 0 0 0 0 0 0 0 0 0
53568 - 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
53575 - 50 50 50 82 82 82 58 58 58 6 6 6
53576 - 2 2 6 2 2 6 2 2 6 2 2 6
53577 - 2 2 6 2 2 6 2 2 6 2 2 6
53578 - 6 6 6 54 54 54 86 86 86 66 66 66
53579 - 38 38 38 18 18 18 6 6 6 0 0 0
53580 - 0 0 0 0 0 0 0 0 0 0 0 0
53581 - 0 0 0 0 0 0 0 0 0 0 0 0
53582 - 0 0 0 0 0 0 0 0 0 0 0 0
53583 - 0 0 0 0 0 0 0 0 0 0 0 0
53584 - 0 0 0 0 0 0 0 0 0 0 0 0
53585 - 0 0 0 0 0 0 0 0 0 0 0 0
53586 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 22 22 22 50 50 50
53595 - 78 78 78 34 34 34 2 2 6 2 2 6
53596 - 2 2 6 2 2 6 2 2 6 2 2 6
53597 - 2 2 6 2 2 6 2 2 6 2 2 6
53598 - 2 2 6 2 2 6 6 6 6 70 70 70
53599 - 78 78 78 46 46 46 22 22 22 6 6 6
53600 - 0 0 0 0 0 0 0 0 0 0 0 0
53601 - 0 0 0 0 0 0 0 0 0 0 0 0
53602 - 0 0 0 0 0 0 0 0 0 0 0 0
53603 - 0 0 0 0 0 0 0 0 0 0 0 0
53604 - 0 0 0 0 0 0 0 0 0 0 0 0
53605 - 0 0 0 0 0 0 0 0 0 0 0 0
53606 - 0 0 0 0 0 0 0 0 0 0 0 0
53607 - 0 0 0 0 0 0 0 0 0 0 0 0
53608 - 0 0 1 0 0 1 0 0 1 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 - 6 6 6 18 18 18 42 42 42 82 82 82
53615 - 26 26 26 2 2 6 2 2 6 2 2 6
53616 - 2 2 6 2 2 6 2 2 6 2 2 6
53617 - 2 2 6 2 2 6 2 2 6 14 14 14
53618 - 46 46 46 34 34 34 6 6 6 2 2 6
53619 - 42 42 42 78 78 78 42 42 42 18 18 18
53620 - 6 6 6 0 0 0 0 0 0 0 0 0
53621 - 0 0 0 0 0 0 0 0 0 0 0 0
53622 - 0 0 0 0 0 0 0 0 0 0 0 0
53623 - 0 0 0 0 0 0 0 0 0 0 0 0
53624 - 0 0 0 0 0 0 0 0 0 0 0 0
53625 - 0 0 0 0 0 0 0 0 0 0 0 0
53626 - 0 0 0 0 0 0 0 0 0 0 0 0
53627 - 0 0 0 0 0 0 0 0 0 0 0 0
53628 - 0 0 1 0 0 0 0 0 1 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 - 10 10 10 30 30 30 66 66 66 58 58 58
53635 - 2 2 6 2 2 6 2 2 6 2 2 6
53636 - 2 2 6 2 2 6 2 2 6 2 2 6
53637 - 2 2 6 2 2 6 2 2 6 26 26 26
53638 - 86 86 86 101 101 101 46 46 46 10 10 10
53639 - 2 2 6 58 58 58 70 70 70 34 34 34
53640 - 10 10 10 0 0 0 0 0 0 0 0 0
53641 - 0 0 0 0 0 0 0 0 0 0 0 0
53642 - 0 0 0 0 0 0 0 0 0 0 0 0
53643 - 0 0 0 0 0 0 0 0 0 0 0 0
53644 - 0 0 0 0 0 0 0 0 0 0 0 0
53645 - 0 0 0 0 0 0 0 0 0 0 0 0
53646 - 0 0 0 0 0 0 0 0 0 0 0 0
53647 - 0 0 0 0 0 0 0 0 0 0 0 0
53648 - 0 0 1 0 0 1 0 0 1 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 - 14 14 14 42 42 42 86 86 86 10 10 10
53655 - 2 2 6 2 2 6 2 2 6 2 2 6
53656 - 2 2 6 2 2 6 2 2 6 2 2 6
53657 - 2 2 6 2 2 6 2 2 6 30 30 30
53658 - 94 94 94 94 94 94 58 58 58 26 26 26
53659 - 2 2 6 6 6 6 78 78 78 54 54 54
53660 - 22 22 22 6 6 6 0 0 0 0 0 0
53661 - 0 0 0 0 0 0 0 0 0 0 0 0
53662 - 0 0 0 0 0 0 0 0 0 0 0 0
53663 - 0 0 0 0 0 0 0 0 0 0 0 0
53664 - 0 0 0 0 0 0 0 0 0 0 0 0
53665 - 0 0 0 0 0 0 0 0 0 0 0 0
53666 - 0 0 0 0 0 0 0 0 0 0 0 0
53667 - 0 0 0 0 0 0 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 6 6 6
53674 - 22 22 22 62 62 62 62 62 62 2 2 6
53675 - 2 2 6 2 2 6 2 2 6 2 2 6
53676 - 2 2 6 2 2 6 2 2 6 2 2 6
53677 - 2 2 6 2 2 6 2 2 6 26 26 26
53678 - 54 54 54 38 38 38 18 18 18 10 10 10
53679 - 2 2 6 2 2 6 34 34 34 82 82 82
53680 - 38 38 38 14 14 14 0 0 0 0 0 0
53681 - 0 0 0 0 0 0 0 0 0 0 0 0
53682 - 0 0 0 0 0 0 0 0 0 0 0 0
53683 - 0 0 0 0 0 0 0 0 0 0 0 0
53684 - 0 0 0 0 0 0 0 0 0 0 0 0
53685 - 0 0 0 0 0 0 0 0 0 0 0 0
53686 - 0 0 0 0 0 0 0 0 0 0 0 0
53687 - 0 0 0 0 0 0 0 0 0 0 0 0
53688 - 0 0 0 0 0 1 0 0 1 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 6 6 6
53694 - 30 30 30 78 78 78 30 30 30 2 2 6
53695 - 2 2 6 2 2 6 2 2 6 2 2 6
53696 - 2 2 6 2 2 6 2 2 6 2 2 6
53697 - 2 2 6 2 2 6 2 2 6 10 10 10
53698 - 10 10 10 2 2 6 2 2 6 2 2 6
53699 - 2 2 6 2 2 6 2 2 6 78 78 78
53700 - 50 50 50 18 18 18 6 6 6 0 0 0
53701 - 0 0 0 0 0 0 0 0 0 0 0 0
53702 - 0 0 0 0 0 0 0 0 0 0 0 0
53703 - 0 0 0 0 0 0 0 0 0 0 0 0
53704 - 0 0 0 0 0 0 0 0 0 0 0 0
53705 - 0 0 0 0 0 0 0 0 0 0 0 0
53706 - 0 0 0 0 0 0 0 0 0 0 0 0
53707 - 0 0 0 0 0 0 0 0 0 0 0 0
53708 - 0 0 1 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 10 10 10
53714 - 38 38 38 86 86 86 14 14 14 2 2 6
53715 - 2 2 6 2 2 6 2 2 6 2 2 6
53716 - 2 2 6 2 2 6 2 2 6 2 2 6
53717 - 2 2 6 2 2 6 2 2 6 2 2 6
53718 - 2 2 6 2 2 6 2 2 6 2 2 6
53719 - 2 2 6 2 2 6 2 2 6 54 54 54
53720 - 66 66 66 26 26 26 6 6 6 0 0 0
53721 - 0 0 0 0 0 0 0 0 0 0 0 0
53722 - 0 0 0 0 0 0 0 0 0 0 0 0
53723 - 0 0 0 0 0 0 0 0 0 0 0 0
53724 - 0 0 0 0 0 0 0 0 0 0 0 0
53725 - 0 0 0 0 0 0 0 0 0 0 0 0
53726 - 0 0 0 0 0 0 0 0 0 0 0 0
53727 - 0 0 0 0 0 0 0 0 0 0 0 0
53728 - 0 0 0 0 0 1 0 0 1 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 14 14 14
53734 - 42 42 42 82 82 82 2 2 6 2 2 6
53735 - 2 2 6 6 6 6 10 10 10 2 2 6
53736 - 2 2 6 2 2 6 2 2 6 2 2 6
53737 - 2 2 6 2 2 6 2 2 6 6 6 6
53738 - 14 14 14 10 10 10 2 2 6 2 2 6
53739 - 2 2 6 2 2 6 2 2 6 18 18 18
53740 - 82 82 82 34 34 34 10 10 10 0 0 0
53741 - 0 0 0 0 0 0 0 0 0 0 0 0
53742 - 0 0 0 0 0 0 0 0 0 0 0 0
53743 - 0 0 0 0 0 0 0 0 0 0 0 0
53744 - 0 0 0 0 0 0 0 0 0 0 0 0
53745 - 0 0 0 0 0 0 0 0 0 0 0 0
53746 - 0 0 0 0 0 0 0 0 0 0 0 0
53747 - 0 0 0 0 0 0 0 0 0 0 0 0
53748 - 0 0 1 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 14 14 14
53754 - 46 46 46 86 86 86 2 2 6 2 2 6
53755 - 6 6 6 6 6 6 22 22 22 34 34 34
53756 - 6 6 6 2 2 6 2 2 6 2 2 6
53757 - 2 2 6 2 2 6 18 18 18 34 34 34
53758 - 10 10 10 50 50 50 22 22 22 2 2 6
53759 - 2 2 6 2 2 6 2 2 6 10 10 10
53760 - 86 86 86 42 42 42 14 14 14 0 0 0
53761 - 0 0 0 0 0 0 0 0 0 0 0 0
53762 - 0 0 0 0 0 0 0 0 0 0 0 0
53763 - 0 0 0 0 0 0 0 0 0 0 0 0
53764 - 0 0 0 0 0 0 0 0 0 0 0 0
53765 - 0 0 0 0 0 0 0 0 0 0 0 0
53766 - 0 0 0 0 0 0 0 0 0 0 0 0
53767 - 0 0 0 0 0 0 0 0 0 0 0 0
53768 - 0 0 1 0 0 1 0 0 1 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 14 14 14
53774 - 46 46 46 86 86 86 2 2 6 2 2 6
53775 - 38 38 38 116 116 116 94 94 94 22 22 22
53776 - 22 22 22 2 2 6 2 2 6 2 2 6
53777 - 14 14 14 86 86 86 138 138 138 162 162 162
53778 -154 154 154 38 38 38 26 26 26 6 6 6
53779 - 2 2 6 2 2 6 2 2 6 2 2 6
53780 - 86 86 86 46 46 46 14 14 14 0 0 0
53781 - 0 0 0 0 0 0 0 0 0 0 0 0
53782 - 0 0 0 0 0 0 0 0 0 0 0 0
53783 - 0 0 0 0 0 0 0 0 0 0 0 0
53784 - 0 0 0 0 0 0 0 0 0 0 0 0
53785 - 0 0 0 0 0 0 0 0 0 0 0 0
53786 - 0 0 0 0 0 0 0 0 0 0 0 0
53787 - 0 0 0 0 0 0 0 0 0 0 0 0
53788 - 0 0 0 0 0 0 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 14 14 14
53794 - 46 46 46 86 86 86 2 2 6 14 14 14
53795 -134 134 134 198 198 198 195 195 195 116 116 116
53796 - 10 10 10 2 2 6 2 2 6 6 6 6
53797 -101 98 89 187 187 187 210 210 210 218 218 218
53798 -214 214 214 134 134 134 14 14 14 6 6 6
53799 - 2 2 6 2 2 6 2 2 6 2 2 6
53800 - 86 86 86 50 50 50 18 18 18 6 6 6
53801 - 0 0 0 0 0 0 0 0 0 0 0 0
53802 - 0 0 0 0 0 0 0 0 0 0 0 0
53803 - 0 0 0 0 0 0 0 0 0 0 0 0
53804 - 0 0 0 0 0 0 0 0 0 0 0 0
53805 - 0 0 0 0 0 0 0 0 0 0 0 0
53806 - 0 0 0 0 0 0 0 0 0 0 0 0
53807 - 0 0 0 0 0 0 0 0 1 0 0 0
53808 - 0 0 1 0 0 1 0 0 1 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 14 14 14
53814 - 46 46 46 86 86 86 2 2 6 54 54 54
53815 -218 218 218 195 195 195 226 226 226 246 246 246
53816 - 58 58 58 2 2 6 2 2 6 30 30 30
53817 -210 210 210 253 253 253 174 174 174 123 123 123
53818 -221 221 221 234 234 234 74 74 74 2 2 6
53819 - 2 2 6 2 2 6 2 2 6 2 2 6
53820 - 70 70 70 58 58 58 22 22 22 6 6 6
53821 - 0 0 0 0 0 0 0 0 0 0 0 0
53822 - 0 0 0 0 0 0 0 0 0 0 0 0
53823 - 0 0 0 0 0 0 0 0 0 0 0 0
53824 - 0 0 0 0 0 0 0 0 0 0 0 0
53825 - 0 0 0 0 0 0 0 0 0 0 0 0
53826 - 0 0 0 0 0 0 0 0 0 0 0 0
53827 - 0 0 0 0 0 0 0 0 0 0 0 0
53828 - 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
53834 - 46 46 46 82 82 82 2 2 6 106 106 106
53835 -170 170 170 26 26 26 86 86 86 226 226 226
53836 -123 123 123 10 10 10 14 14 14 46 46 46
53837 -231 231 231 190 190 190 6 6 6 70 70 70
53838 - 90 90 90 238 238 238 158 158 158 2 2 6
53839 - 2 2 6 2 2 6 2 2 6 2 2 6
53840 - 70 70 70 58 58 58 22 22 22 6 6 6
53841 - 0 0 0 0 0 0 0 0 0 0 0 0
53842 - 0 0 0 0 0 0 0 0 0 0 0 0
53843 - 0 0 0 0 0 0 0 0 0 0 0 0
53844 - 0 0 0 0 0 0 0 0 0 0 0 0
53845 - 0 0 0 0 0 0 0 0 0 0 0 0
53846 - 0 0 0 0 0 0 0 0 0 0 0 0
53847 - 0 0 0 0 0 0 0 0 1 0 0 0
53848 - 0 0 1 0 0 1 0 0 1 0 0 0
53849 - 0 0 0 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 14 14 14
53854 - 42 42 42 86 86 86 6 6 6 116 116 116
53855 -106 106 106 6 6 6 70 70 70 149 149 149
53856 -128 128 128 18 18 18 38 38 38 54 54 54
53857 -221 221 221 106 106 106 2 2 6 14 14 14
53858 - 46 46 46 190 190 190 198 198 198 2 2 6
53859 - 2 2 6 2 2 6 2 2 6 2 2 6
53860 - 74 74 74 62 62 62 22 22 22 6 6 6
53861 - 0 0 0 0 0 0 0 0 0 0 0 0
53862 - 0 0 0 0 0 0 0 0 0 0 0 0
53863 - 0 0 0 0 0 0 0 0 0 0 0 0
53864 - 0 0 0 0 0 0 0 0 0 0 0 0
53865 - 0 0 0 0 0 0 0 0 0 0 0 0
53866 - 0 0 0 0 0 0 0 0 0 0 0 0
53867 - 0 0 0 0 0 0 0 0 1 0 0 0
53868 - 0 0 1 0 0 0 0 0 1 0 0 0
53869 - 0 0 0 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 14 14 14
53874 - 42 42 42 94 94 94 14 14 14 101 101 101
53875 -128 128 128 2 2 6 18 18 18 116 116 116
53876 -118 98 46 121 92 8 121 92 8 98 78 10
53877 -162 162 162 106 106 106 2 2 6 2 2 6
53878 - 2 2 6 195 195 195 195 195 195 6 6 6
53879 - 2 2 6 2 2 6 2 2 6 2 2 6
53880 - 74 74 74 62 62 62 22 22 22 6 6 6
53881 - 0 0 0 0 0 0 0 0 0 0 0 0
53882 - 0 0 0 0 0 0 0 0 0 0 0 0
53883 - 0 0 0 0 0 0 0 0 0 0 0 0
53884 - 0 0 0 0 0 0 0 0 0 0 0 0
53885 - 0 0 0 0 0 0 0 0 0 0 0 0
53886 - 0 0 0 0 0 0 0 0 0 0 0 0
53887 - 0 0 0 0 0 0 0 0 1 0 0 1
53888 - 0 0 1 0 0 0 0 0 1 0 0 0
53889 - 0 0 0 0 0 0 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 10 10 10
53894 - 38 38 38 90 90 90 14 14 14 58 58 58
53895 -210 210 210 26 26 26 54 38 6 154 114 10
53896 -226 170 11 236 186 11 225 175 15 184 144 12
53897 -215 174 15 175 146 61 37 26 9 2 2 6
53898 - 70 70 70 246 246 246 138 138 138 2 2 6
53899 - 2 2 6 2 2 6 2 2 6 2 2 6
53900 - 70 70 70 66 66 66 26 26 26 6 6 6
53901 - 0 0 0 0 0 0 0 0 0 0 0 0
53902 - 0 0 0 0 0 0 0 0 0 0 0 0
53903 - 0 0 0 0 0 0 0 0 0 0 0 0
53904 - 0 0 0 0 0 0 0 0 0 0 0 0
53905 - 0 0 0 0 0 0 0 0 0 0 0 0
53906 - 0 0 0 0 0 0 0 0 0 0 0 0
53907 - 0 0 0 0 0 0 0 0 0 0 0 0
53908 - 0 0 0 0 0 0 0 0 0 0 0 0
53909 - 0 0 0 0 0 0 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 10 10 10
53914 - 38 38 38 86 86 86 14 14 14 10 10 10
53915 -195 195 195 188 164 115 192 133 9 225 175 15
53916 -239 182 13 234 190 10 232 195 16 232 200 30
53917 -245 207 45 241 208 19 232 195 16 184 144 12
53918 -218 194 134 211 206 186 42 42 42 2 2 6
53919 - 2 2 6 2 2 6 2 2 6 2 2 6
53920 - 50 50 50 74 74 74 30 30 30 6 6 6
53921 - 0 0 0 0 0 0 0 0 0 0 0 0
53922 - 0 0 0 0 0 0 0 0 0 0 0 0
53923 - 0 0 0 0 0 0 0 0 0 0 0 0
53924 - 0 0 0 0 0 0 0 0 0 0 0 0
53925 - 0 0 0 0 0 0 0 0 0 0 0 0
53926 - 0 0 0 0 0 0 0 0 0 0 0 0
53927 - 0 0 0 0 0 0 0 0 0 0 0 0
53928 - 0 0 0 0 0 0 0 0 0 0 0 0
53929 - 0 0 0 0 0 0 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 10 10 10
53934 - 34 34 34 86 86 86 14 14 14 2 2 6
53935 -121 87 25 192 133 9 219 162 10 239 182 13
53936 -236 186 11 232 195 16 241 208 19 244 214 54
53937 -246 218 60 246 218 38 246 215 20 241 208 19
53938 -241 208 19 226 184 13 121 87 25 2 2 6
53939 - 2 2 6 2 2 6 2 2 6 2 2 6
53940 - 50 50 50 82 82 82 34 34 34 10 10 10
53941 - 0 0 0 0 0 0 0 0 0 0 0 0
53942 - 0 0 0 0 0 0 0 0 0 0 0 0
53943 - 0 0 0 0 0 0 0 0 0 0 0 0
53944 - 0 0 0 0 0 0 0 0 0 0 0 0
53945 - 0 0 0 0 0 0 0 0 0 0 0 0
53946 - 0 0 0 0 0 0 0 0 0 0 0 0
53947 - 0 0 0 0 0 0 0 0 0 0 0 0
53948 - 0 0 0 0 0 0 0 0 0 0 0 0
53949 - 0 0 0 0 0 0 0 0 0 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 10 10 10
53954 - 34 34 34 82 82 82 30 30 30 61 42 6
53955 -180 123 7 206 145 10 230 174 11 239 182 13
53956 -234 190 10 238 202 15 241 208 19 246 218 74
53957 -246 218 38 246 215 20 246 215 20 246 215 20
53958 -226 184 13 215 174 15 184 144 12 6 6 6
53959 - 2 2 6 2 2 6 2 2 6 2 2 6
53960 - 26 26 26 94 94 94 42 42 42 14 14 14
53961 - 0 0 0 0 0 0 0 0 0 0 0 0
53962 - 0 0 0 0 0 0 0 0 0 0 0 0
53963 - 0 0 0 0 0 0 0 0 0 0 0 0
53964 - 0 0 0 0 0 0 0 0 0 0 0 0
53965 - 0 0 0 0 0 0 0 0 0 0 0 0
53966 - 0 0 0 0 0 0 0 0 0 0 0 0
53967 - 0 0 0 0 0 0 0 0 0 0 0 0
53968 - 0 0 0 0 0 0 0 0 0 0 0 0
53969 - 0 0 0 0 0 0 0 0 0 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 10 10 10
53974 - 30 30 30 78 78 78 50 50 50 104 69 6
53975 -192 133 9 216 158 10 236 178 12 236 186 11
53976 -232 195 16 241 208 19 244 214 54 245 215 43
53977 -246 215 20 246 215 20 241 208 19 198 155 10
53978 -200 144 11 216 158 10 156 118 10 2 2 6
53979 - 2 2 6 2 2 6 2 2 6 2 2 6
53980 - 6 6 6 90 90 90 54 54 54 18 18 18
53981 - 6 6 6 0 0 0 0 0 0 0 0 0
53982 - 0 0 0 0 0 0 0 0 0 0 0 0
53983 - 0 0 0 0 0 0 0 0 0 0 0 0
53984 - 0 0 0 0 0 0 0 0 0 0 0 0
53985 - 0 0 0 0 0 0 0 0 0 0 0 0
53986 - 0 0 0 0 0 0 0 0 0 0 0 0
53987 - 0 0 0 0 0 0 0 0 0 0 0 0
53988 - 0 0 0 0 0 0 0 0 0 0 0 0
53989 - 0 0 0 0 0 0 0 0 0 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 10 10 10
53994 - 30 30 30 78 78 78 46 46 46 22 22 22
53995 -137 92 6 210 162 10 239 182 13 238 190 10
53996 -238 202 15 241 208 19 246 215 20 246 215 20
53997 -241 208 19 203 166 17 185 133 11 210 150 10
53998 -216 158 10 210 150 10 102 78 10 2 2 6
53999 - 6 6 6 54 54 54 14 14 14 2 2 6
54000 - 2 2 6 62 62 62 74 74 74 30 30 30
54001 - 10 10 10 0 0 0 0 0 0 0 0 0
54002 - 0 0 0 0 0 0 0 0 0 0 0 0
54003 - 0 0 0 0 0 0 0 0 0 0 0 0
54004 - 0 0 0 0 0 0 0 0 0 0 0 0
54005 - 0 0 0 0 0 0 0 0 0 0 0 0
54006 - 0 0 0 0 0 0 0 0 0 0 0 0
54007 - 0 0 0 0 0 0 0 0 0 0 0 0
54008 - 0 0 0 0 0 0 0 0 0 0 0 0
54009 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
54014 - 34 34 34 78 78 78 50 50 50 6 6 6
54015 - 94 70 30 139 102 15 190 146 13 226 184 13
54016 -232 200 30 232 195 16 215 174 15 190 146 13
54017 -168 122 10 192 133 9 210 150 10 213 154 11
54018 -202 150 34 182 157 106 101 98 89 2 2 6
54019 - 2 2 6 78 78 78 116 116 116 58 58 58
54020 - 2 2 6 22 22 22 90 90 90 46 46 46
54021 - 18 18 18 6 6 6 0 0 0 0 0 0
54022 - 0 0 0 0 0 0 0 0 0 0 0 0
54023 - 0 0 0 0 0 0 0 0 0 0 0 0
54024 - 0 0 0 0 0 0 0 0 0 0 0 0
54025 - 0 0 0 0 0 0 0 0 0 0 0 0
54026 - 0 0 0 0 0 0 0 0 0 0 0 0
54027 - 0 0 0 0 0 0 0 0 0 0 0 0
54028 - 0 0 0 0 0 0 0 0 0 0 0 0
54029 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
54034 - 38 38 38 86 86 86 50 50 50 6 6 6
54035 -128 128 128 174 154 114 156 107 11 168 122 10
54036 -198 155 10 184 144 12 197 138 11 200 144 11
54037 -206 145 10 206 145 10 197 138 11 188 164 115
54038 -195 195 195 198 198 198 174 174 174 14 14 14
54039 - 2 2 6 22 22 22 116 116 116 116 116 116
54040 - 22 22 22 2 2 6 74 74 74 70 70 70
54041 - 30 30 30 10 10 10 0 0 0 0 0 0
54042 - 0 0 0 0 0 0 0 0 0 0 0 0
54043 - 0 0 0 0 0 0 0 0 0 0 0 0
54044 - 0 0 0 0 0 0 0 0 0 0 0 0
54045 - 0 0 0 0 0 0 0 0 0 0 0 0
54046 - 0 0 0 0 0 0 0 0 0 0 0 0
54047 - 0 0 0 0 0 0 0 0 0 0 0 0
54048 - 0 0 0 0 0 0 0 0 0 0 0 0
54049 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
54054 - 50 50 50 101 101 101 26 26 26 10 10 10
54055 -138 138 138 190 190 190 174 154 114 156 107 11
54056 -197 138 11 200 144 11 197 138 11 192 133 9
54057 -180 123 7 190 142 34 190 178 144 187 187 187
54058 -202 202 202 221 221 221 214 214 214 66 66 66
54059 - 2 2 6 2 2 6 50 50 50 62 62 62
54060 - 6 6 6 2 2 6 10 10 10 90 90 90
54061 - 50 50 50 18 18 18 6 6 6 0 0 0
54062 - 0 0 0 0 0 0 0 0 0 0 0 0
54063 - 0 0 0 0 0 0 0 0 0 0 0 0
54064 - 0 0 0 0 0 0 0 0 0 0 0 0
54065 - 0 0 0 0 0 0 0 0 0 0 0 0
54066 - 0 0 0 0 0 0 0 0 0 0 0 0
54067 - 0 0 0 0 0 0 0 0 0 0 0 0
54068 - 0 0 0 0 0 0 0 0 0 0 0 0
54069 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 34 34 34
54074 - 74 74 74 74 74 74 2 2 6 6 6 6
54075 -144 144 144 198 198 198 190 190 190 178 166 146
54076 -154 121 60 156 107 11 156 107 11 168 124 44
54077 -174 154 114 187 187 187 190 190 190 210 210 210
54078 -246 246 246 253 253 253 253 253 253 182 182 182
54079 - 6 6 6 2 2 6 2 2 6 2 2 6
54080 - 2 2 6 2 2 6 2 2 6 62 62 62
54081 - 74 74 74 34 34 34 14 14 14 0 0 0
54082 - 0 0 0 0 0 0 0 0 0 0 0 0
54083 - 0 0 0 0 0 0 0 0 0 0 0 0
54084 - 0 0 0 0 0 0 0 0 0 0 0 0
54085 - 0 0 0 0 0 0 0 0 0 0 0 0
54086 - 0 0 0 0 0 0 0 0 0 0 0 0
54087 - 0 0 0 0 0 0 0 0 0 0 0 0
54088 - 0 0 0 0 0 0 0 0 0 0 0 0
54089 - 0 0 0 0 0 0 0 0 0 0 0 0
54090 - 0 0 0 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 10 10 10 22 22 22 54 54 54
54094 - 94 94 94 18 18 18 2 2 6 46 46 46
54095 -234 234 234 221 221 221 190 190 190 190 190 190
54096 -190 190 190 187 187 187 187 187 187 190 190 190
54097 -190 190 190 195 195 195 214 214 214 242 242 242
54098 -253 253 253 253 253 253 253 253 253 253 253 253
54099 - 82 82 82 2 2 6 2 2 6 2 2 6
54100 - 2 2 6 2 2 6 2 2 6 14 14 14
54101 - 86 86 86 54 54 54 22 22 22 6 6 6
54102 - 0 0 0 0 0 0 0 0 0 0 0 0
54103 - 0 0 0 0 0 0 0 0 0 0 0 0
54104 - 0 0 0 0 0 0 0 0 0 0 0 0
54105 - 0 0 0 0 0 0 0 0 0 0 0 0
54106 - 0 0 0 0 0 0 0 0 0 0 0 0
54107 - 0 0 0 0 0 0 0 0 0 0 0 0
54108 - 0 0 0 0 0 0 0 0 0 0 0 0
54109 - 0 0 0 0 0 0 0 0 0 0 0 0
54110 - 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
54114 - 46 46 46 18 18 18 6 6 6 182 182 182
54115 -253 253 253 246 246 246 206 206 206 190 190 190
54116 -190 190 190 190 190 190 190 190 190 190 190 190
54117 -206 206 206 231 231 231 250 250 250 253 253 253
54118 -253 253 253 253 253 253 253 253 253 253 253 253
54119 -202 202 202 14 14 14 2 2 6 2 2 6
54120 - 2 2 6 2 2 6 2 2 6 2 2 6
54121 - 42 42 42 86 86 86 42 42 42 18 18 18
54122 - 6 6 6 0 0 0 0 0 0 0 0 0
54123 - 0 0 0 0 0 0 0 0 0 0 0 0
54124 - 0 0 0 0 0 0 0 0 0 0 0 0
54125 - 0 0 0 0 0 0 0 0 0 0 0 0
54126 - 0 0 0 0 0 0 0 0 0 0 0 0
54127 - 0 0 0 0 0 0 0 0 0 0 0 0
54128 - 0 0 0 0 0 0 0 0 0 0 0 0
54129 - 0 0 0 0 0 0 0 0 0 0 0 0
54130 - 0 0 0 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 6 6 6
54133 - 14 14 14 38 38 38 74 74 74 66 66 66
54134 - 2 2 6 6 6 6 90 90 90 250 250 250
54135 -253 253 253 253 253 253 238 238 238 198 198 198
54136 -190 190 190 190 190 190 195 195 195 221 221 221
54137 -246 246 246 253 253 253 253 253 253 253 253 253
54138 -253 253 253 253 253 253 253 253 253 253 253 253
54139 -253 253 253 82 82 82 2 2 6 2 2 6
54140 - 2 2 6 2 2 6 2 2 6 2 2 6
54141 - 2 2 6 78 78 78 70 70 70 34 34 34
54142 - 14 14 14 6 6 6 0 0 0 0 0 0
54143 - 0 0 0 0 0 0 0 0 0 0 0 0
54144 - 0 0 0 0 0 0 0 0 0 0 0 0
54145 - 0 0 0 0 0 0 0 0 0 0 0 0
54146 - 0 0 0 0 0 0 0 0 0 0 0 0
54147 - 0 0 0 0 0 0 0 0 0 0 0 0
54148 - 0 0 0 0 0 0 0 0 0 0 0 0
54149 - 0 0 0 0 0 0 0 0 0 0 0 0
54150 - 0 0 0 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 14 14 14
54153 - 34 34 34 66 66 66 78 78 78 6 6 6
54154 - 2 2 6 18 18 18 218 218 218 253 253 253
54155 -253 253 253 253 253 253 253 253 253 246 246 246
54156 -226 226 226 231 231 231 246 246 246 253 253 253
54157 -253 253 253 253 253 253 253 253 253 253 253 253
54158 -253 253 253 253 253 253 253 253 253 253 253 253
54159 -253 253 253 178 178 178 2 2 6 2 2 6
54160 - 2 2 6 2 2 6 2 2 6 2 2 6
54161 - 2 2 6 18 18 18 90 90 90 62 62 62
54162 - 30 30 30 10 10 10 0 0 0 0 0 0
54163 - 0 0 0 0 0 0 0 0 0 0 0 0
54164 - 0 0 0 0 0 0 0 0 0 0 0 0
54165 - 0 0 0 0 0 0 0 0 0 0 0 0
54166 - 0 0 0 0 0 0 0 0 0 0 0 0
54167 - 0 0 0 0 0 0 0 0 0 0 0 0
54168 - 0 0 0 0 0 0 0 0 0 0 0 0
54169 - 0 0 0 0 0 0 0 0 0 0 0 0
54170 - 0 0 0 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 10 10 10 26 26 26
54173 - 58 58 58 90 90 90 18 18 18 2 2 6
54174 - 2 2 6 110 110 110 253 253 253 253 253 253
54175 -253 253 253 253 253 253 253 253 253 253 253 253
54176 -250 250 250 253 253 253 253 253 253 253 253 253
54177 -253 253 253 253 253 253 253 253 253 253 253 253
54178 -253 253 253 253 253 253 253 253 253 253 253 253
54179 -253 253 253 231 231 231 18 18 18 2 2 6
54180 - 2 2 6 2 2 6 2 2 6 2 2 6
54181 - 2 2 6 2 2 6 18 18 18 94 94 94
54182 - 54 54 54 26 26 26 10 10 10 0 0 0
54183 - 0 0 0 0 0 0 0 0 0 0 0 0
54184 - 0 0 0 0 0 0 0 0 0 0 0 0
54185 - 0 0 0 0 0 0 0 0 0 0 0 0
54186 - 0 0 0 0 0 0 0 0 0 0 0 0
54187 - 0 0 0 0 0 0 0 0 0 0 0 0
54188 - 0 0 0 0 0 0 0 0 0 0 0 0
54189 - 0 0 0 0 0 0 0 0 0 0 0 0
54190 - 0 0 0 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 6 6 6 22 22 22 50 50 50
54193 - 90 90 90 26 26 26 2 2 6 2 2 6
54194 - 14 14 14 195 195 195 250 250 250 253 253 253
54195 -253 253 253 253 253 253 253 253 253 253 253 253
54196 -253 253 253 253 253 253 253 253 253 253 253 253
54197 -253 253 253 253 253 253 253 253 253 253 253 253
54198 -253 253 253 253 253 253 253 253 253 253 253 253
54199 -250 250 250 242 242 242 54 54 54 2 2 6
54200 - 2 2 6 2 2 6 2 2 6 2 2 6
54201 - 2 2 6 2 2 6 2 2 6 38 38 38
54202 - 86 86 86 50 50 50 22 22 22 6 6 6
54203 - 0 0 0 0 0 0 0 0 0 0 0 0
54204 - 0 0 0 0 0 0 0 0 0 0 0 0
54205 - 0 0 0 0 0 0 0 0 0 0 0 0
54206 - 0 0 0 0 0 0 0 0 0 0 0 0
54207 - 0 0 0 0 0 0 0 0 0 0 0 0
54208 - 0 0 0 0 0 0 0 0 0 0 0 0
54209 - 0 0 0 0 0 0 0 0 0 0 0 0
54210 - 0 0 0 0 0 0 0 0 0 0 0 0
54211 - 0 0 0 0 0 0 0 0 0 0 0 0
54212 - 6 6 6 14 14 14 38 38 38 82 82 82
54213 - 34 34 34 2 2 6 2 2 6 2 2 6
54214 - 42 42 42 195 195 195 246 246 246 253 253 253
54215 -253 253 253 253 253 253 253 253 253 250 250 250
54216 -242 242 242 242 242 242 250 250 250 253 253 253
54217 -253 253 253 253 253 253 253 253 253 253 253 253
54218 -253 253 253 250 250 250 246 246 246 238 238 238
54219 -226 226 226 231 231 231 101 101 101 6 6 6
54220 - 2 2 6 2 2 6 2 2 6 2 2 6
54221 - 2 2 6 2 2 6 2 2 6 2 2 6
54222 - 38 38 38 82 82 82 42 42 42 14 14 14
54223 - 6 6 6 0 0 0 0 0 0 0 0 0
54224 - 0 0 0 0 0 0 0 0 0 0 0 0
54225 - 0 0 0 0 0 0 0 0 0 0 0 0
54226 - 0 0 0 0 0 0 0 0 0 0 0 0
54227 - 0 0 0 0 0 0 0 0 0 0 0 0
54228 - 0 0 0 0 0 0 0 0 0 0 0 0
54229 - 0 0 0 0 0 0 0 0 0 0 0 0
54230 - 0 0 0 0 0 0 0 0 0 0 0 0
54231 - 0 0 0 0 0 0 0 0 0 0 0 0
54232 - 10 10 10 26 26 26 62 62 62 66 66 66
54233 - 2 2 6 2 2 6 2 2 6 6 6 6
54234 - 70 70 70 170 170 170 206 206 206 234 234 234
54235 -246 246 246 250 250 250 250 250 250 238 238 238
54236 -226 226 226 231 231 231 238 238 238 250 250 250
54237 -250 250 250 250 250 250 246 246 246 231 231 231
54238 -214 214 214 206 206 206 202 202 202 202 202 202
54239 -198 198 198 202 202 202 182 182 182 18 18 18
54240 - 2 2 6 2 2 6 2 2 6 2 2 6
54241 - 2 2 6 2 2 6 2 2 6 2 2 6
54242 - 2 2 6 62 62 62 66 66 66 30 30 30
54243 - 10 10 10 0 0 0 0 0 0 0 0 0
54244 - 0 0 0 0 0 0 0 0 0 0 0 0
54245 - 0 0 0 0 0 0 0 0 0 0 0 0
54246 - 0 0 0 0 0 0 0 0 0 0 0 0
54247 - 0 0 0 0 0 0 0 0 0 0 0 0
54248 - 0 0 0 0 0 0 0 0 0 0 0 0
54249 - 0 0 0 0 0 0 0 0 0 0 0 0
54250 - 0 0 0 0 0 0 0 0 0 0 0 0
54251 - 0 0 0 0 0 0 0 0 0 0 0 0
54252 - 14 14 14 42 42 42 82 82 82 18 18 18
54253 - 2 2 6 2 2 6 2 2 6 10 10 10
54254 - 94 94 94 182 182 182 218 218 218 242 242 242
54255 -250 250 250 253 253 253 253 253 253 250 250 250
54256 -234 234 234 253 253 253 253 253 253 253 253 253
54257 -253 253 253 253 253 253 253 253 253 246 246 246
54258 -238 238 238 226 226 226 210 210 210 202 202 202
54259 -195 195 195 195 195 195 210 210 210 158 158 158
54260 - 6 6 6 14 14 14 50 50 50 14 14 14
54261 - 2 2 6 2 2 6 2 2 6 2 2 6
54262 - 2 2 6 6 6 6 86 86 86 46 46 46
54263 - 18 18 18 6 6 6 0 0 0 0 0 0
54264 - 0 0 0 0 0 0 0 0 0 0 0 0
54265 - 0 0 0 0 0 0 0 0 0 0 0 0
54266 - 0 0 0 0 0 0 0 0 0 0 0 0
54267 - 0 0 0 0 0 0 0 0 0 0 0 0
54268 - 0 0 0 0 0 0 0 0 0 0 0 0
54269 - 0 0 0 0 0 0 0 0 0 0 0 0
54270 - 0 0 0 0 0 0 0 0 0 0 0 0
54271 - 0 0 0 0 0 0 0 0 0 6 6 6
54272 - 22 22 22 54 54 54 70 70 70 2 2 6
54273 - 2 2 6 10 10 10 2 2 6 22 22 22
54274 -166 166 166 231 231 231 250 250 250 253 253 253
54275 -253 253 253 253 253 253 253 253 253 250 250 250
54276 -242 242 242 253 253 253 253 253 253 253 253 253
54277 -253 253 253 253 253 253 253 253 253 253 253 253
54278 -253 253 253 253 253 253 253 253 253 246 246 246
54279 -231 231 231 206 206 206 198 198 198 226 226 226
54280 - 94 94 94 2 2 6 6 6 6 38 38 38
54281 - 30 30 30 2 2 6 2 2 6 2 2 6
54282 - 2 2 6 2 2 6 62 62 62 66 66 66
54283 - 26 26 26 10 10 10 0 0 0 0 0 0
54284 - 0 0 0 0 0 0 0 0 0 0 0 0
54285 - 0 0 0 0 0 0 0 0 0 0 0 0
54286 - 0 0 0 0 0 0 0 0 0 0 0 0
54287 - 0 0 0 0 0 0 0 0 0 0 0 0
54288 - 0 0 0 0 0 0 0 0 0 0 0 0
54289 - 0 0 0 0 0 0 0 0 0 0 0 0
54290 - 0 0 0 0 0 0 0 0 0 0 0 0
54291 - 0 0 0 0 0 0 0 0 0 10 10 10
54292 - 30 30 30 74 74 74 50 50 50 2 2 6
54293 - 26 26 26 26 26 26 2 2 6 106 106 106
54294 -238 238 238 253 253 253 253 253 253 253 253 253
54295 -253 253 253 253 253 253 253 253 253 253 253 253
54296 -253 253 253 253 253 253 253 253 253 253 253 253
54297 -253 253 253 253 253 253 253 253 253 253 253 253
54298 -253 253 253 253 253 253 253 253 253 253 253 253
54299 -253 253 253 246 246 246 218 218 218 202 202 202
54300 -210 210 210 14 14 14 2 2 6 2 2 6
54301 - 30 30 30 22 22 22 2 2 6 2 2 6
54302 - 2 2 6 2 2 6 18 18 18 86 86 86
54303 - 42 42 42 14 14 14 0 0 0 0 0 0
54304 - 0 0 0 0 0 0 0 0 0 0 0 0
54305 - 0 0 0 0 0 0 0 0 0 0 0 0
54306 - 0 0 0 0 0 0 0 0 0 0 0 0
54307 - 0 0 0 0 0 0 0 0 0 0 0 0
54308 - 0 0 0 0 0 0 0 0 0 0 0 0
54309 - 0 0 0 0 0 0 0 0 0 0 0 0
54310 - 0 0 0 0 0 0 0 0 0 0 0 0
54311 - 0 0 0 0 0 0 0 0 0 14 14 14
54312 - 42 42 42 90 90 90 22 22 22 2 2 6
54313 - 42 42 42 2 2 6 18 18 18 218 218 218
54314 -253 253 253 253 253 253 253 253 253 253 253 253
54315 -253 253 253 253 253 253 253 253 253 253 253 253
54316 -253 253 253 253 253 253 253 253 253 253 253 253
54317 -253 253 253 253 253 253 253 253 253 253 253 253
54318 -253 253 253 253 253 253 253 253 253 253 253 253
54319 -253 253 253 253 253 253 250 250 250 221 221 221
54320 -218 218 218 101 101 101 2 2 6 14 14 14
54321 - 18 18 18 38 38 38 10 10 10 2 2 6
54322 - 2 2 6 2 2 6 2 2 6 78 78 78
54323 - 58 58 58 22 22 22 6 6 6 0 0 0
54324 - 0 0 0 0 0 0 0 0 0 0 0 0
54325 - 0 0 0 0 0 0 0 0 0 0 0 0
54326 - 0 0 0 0 0 0 0 0 0 0 0 0
54327 - 0 0 0 0 0 0 0 0 0 0 0 0
54328 - 0 0 0 0 0 0 0 0 0 0 0 0
54329 - 0 0 0 0 0 0 0 0 0 0 0 0
54330 - 0 0 0 0 0 0 0 0 0 0 0 0
54331 - 0 0 0 0 0 0 6 6 6 18 18 18
54332 - 54 54 54 82 82 82 2 2 6 26 26 26
54333 - 22 22 22 2 2 6 123 123 123 253 253 253
54334 -253 253 253 253 253 253 253 253 253 253 253 253
54335 -253 253 253 253 253 253 253 253 253 253 253 253
54336 -253 253 253 253 253 253 253 253 253 253 253 253
54337 -253 253 253 253 253 253 253 253 253 253 253 253
54338 -253 253 253 253 253 253 253 253 253 253 253 253
54339 -253 253 253 253 253 253 253 253 253 250 250 250
54340 -238 238 238 198 198 198 6 6 6 38 38 38
54341 - 58 58 58 26 26 26 38 38 38 2 2 6
54342 - 2 2 6 2 2 6 2 2 6 46 46 46
54343 - 78 78 78 30 30 30 10 10 10 0 0 0
54344 - 0 0 0 0 0 0 0 0 0 0 0 0
54345 - 0 0 0 0 0 0 0 0 0 0 0 0
54346 - 0 0 0 0 0 0 0 0 0 0 0 0
54347 - 0 0 0 0 0 0 0 0 0 0 0 0
54348 - 0 0 0 0 0 0 0 0 0 0 0 0
54349 - 0 0 0 0 0 0 0 0 0 0 0 0
54350 - 0 0 0 0 0 0 0 0 0 0 0 0
54351 - 0 0 0 0 0 0 10 10 10 30 30 30
54352 - 74 74 74 58 58 58 2 2 6 42 42 42
54353 - 2 2 6 22 22 22 231 231 231 253 253 253
54354 -253 253 253 253 253 253 253 253 253 253 253 253
54355 -253 253 253 253 253 253 253 253 253 250 250 250
54356 -253 253 253 253 253 253 253 253 253 253 253 253
54357 -253 253 253 253 253 253 253 253 253 253 253 253
54358 -253 253 253 253 253 253 253 253 253 253 253 253
54359 -253 253 253 253 253 253 253 253 253 253 253 253
54360 -253 253 253 246 246 246 46 46 46 38 38 38
54361 - 42 42 42 14 14 14 38 38 38 14 14 14
54362 - 2 2 6 2 2 6 2 2 6 6 6 6
54363 - 86 86 86 46 46 46 14 14 14 0 0 0
54364 - 0 0 0 0 0 0 0 0 0 0 0 0
54365 - 0 0 0 0 0 0 0 0 0 0 0 0
54366 - 0 0 0 0 0 0 0 0 0 0 0 0
54367 - 0 0 0 0 0 0 0 0 0 0 0 0
54368 - 0 0 0 0 0 0 0 0 0 0 0 0
54369 - 0 0 0 0 0 0 0 0 0 0 0 0
54370 - 0 0 0 0 0 0 0 0 0 0 0 0
54371 - 0 0 0 6 6 6 14 14 14 42 42 42
54372 - 90 90 90 18 18 18 18 18 18 26 26 26
54373 - 2 2 6 116 116 116 253 253 253 253 253 253
54374 -253 253 253 253 253 253 253 253 253 253 253 253
54375 -253 253 253 253 253 253 250 250 250 238 238 238
54376 -253 253 253 253 253 253 253 253 253 253 253 253
54377 -253 253 253 253 253 253 253 253 253 253 253 253
54378 -253 253 253 253 253 253 253 253 253 253 253 253
54379 -253 253 253 253 253 253 253 253 253 253 253 253
54380 -253 253 253 253 253 253 94 94 94 6 6 6
54381 - 2 2 6 2 2 6 10 10 10 34 34 34
54382 - 2 2 6 2 2 6 2 2 6 2 2 6
54383 - 74 74 74 58 58 58 22 22 22 6 6 6
54384 - 0 0 0 0 0 0 0 0 0 0 0 0
54385 - 0 0 0 0 0 0 0 0 0 0 0 0
54386 - 0 0 0 0 0 0 0 0 0 0 0 0
54387 - 0 0 0 0 0 0 0 0 0 0 0 0
54388 - 0 0 0 0 0 0 0 0 0 0 0 0
54389 - 0 0 0 0 0 0 0 0 0 0 0 0
54390 - 0 0 0 0 0 0 0 0 0 0 0 0
54391 - 0 0 0 10 10 10 26 26 26 66 66 66
54392 - 82 82 82 2 2 6 38 38 38 6 6 6
54393 - 14 14 14 210 210 210 253 253 253 253 253 253
54394 -253 253 253 253 253 253 253 253 253 253 253 253
54395 -253 253 253 253 253 253 246 246 246 242 242 242
54396 -253 253 253 253 253 253 253 253 253 253 253 253
54397 -253 253 253 253 253 253 253 253 253 253 253 253
54398 -253 253 253 253 253 253 253 253 253 253 253 253
54399 -253 253 253 253 253 253 253 253 253 253 253 253
54400 -253 253 253 253 253 253 144 144 144 2 2 6
54401 - 2 2 6 2 2 6 2 2 6 46 46 46
54402 - 2 2 6 2 2 6 2 2 6 2 2 6
54403 - 42 42 42 74 74 74 30 30 30 10 10 10
54404 - 0 0 0 0 0 0 0 0 0 0 0 0
54405 - 0 0 0 0 0 0 0 0 0 0 0 0
54406 - 0 0 0 0 0 0 0 0 0 0 0 0
54407 - 0 0 0 0 0 0 0 0 0 0 0 0
54408 - 0 0 0 0 0 0 0 0 0 0 0 0
54409 - 0 0 0 0 0 0 0 0 0 0 0 0
54410 - 0 0 0 0 0 0 0 0 0 0 0 0
54411 - 6 6 6 14 14 14 42 42 42 90 90 90
54412 - 26 26 26 6 6 6 42 42 42 2 2 6
54413 - 74 74 74 250 250 250 253 253 253 253 253 253
54414 -253 253 253 253 253 253 253 253 253 253 253 253
54415 -253 253 253 253 253 253 242 242 242 242 242 242
54416 -253 253 253 253 253 253 253 253 253 253 253 253
54417 -253 253 253 253 253 253 253 253 253 253 253 253
54418 -253 253 253 253 253 253 253 253 253 253 253 253
54419 -253 253 253 253 253 253 253 253 253 253 253 253
54420 -253 253 253 253 253 253 182 182 182 2 2 6
54421 - 2 2 6 2 2 6 2 2 6 46 46 46
54422 - 2 2 6 2 2 6 2 2 6 2 2 6
54423 - 10 10 10 86 86 86 38 38 38 10 10 10
54424 - 0 0 0 0 0 0 0 0 0 0 0 0
54425 - 0 0 0 0 0 0 0 0 0 0 0 0
54426 - 0 0 0 0 0 0 0 0 0 0 0 0
54427 - 0 0 0 0 0 0 0 0 0 0 0 0
54428 - 0 0 0 0 0 0 0 0 0 0 0 0
54429 - 0 0 0 0 0 0 0 0 0 0 0 0
54430 - 0 0 0 0 0 0 0 0 0 0 0 0
54431 - 10 10 10 26 26 26 66 66 66 82 82 82
54432 - 2 2 6 22 22 22 18 18 18 2 2 6
54433 -149 149 149 253 253 253 253 253 253 253 253 253
54434 -253 253 253 253 253 253 253 253 253 253 253 253
54435 -253 253 253 253 253 253 234 234 234 242 242 242
54436 -253 253 253 253 253 253 253 253 253 253 253 253
54437 -253 253 253 253 253 253 253 253 253 253 253 253
54438 -253 253 253 253 253 253 253 253 253 253 253 253
54439 -253 253 253 253 253 253 253 253 253 253 253 253
54440 -253 253 253 253 253 253 206 206 206 2 2 6
54441 - 2 2 6 2 2 6 2 2 6 38 38 38
54442 - 2 2 6 2 2 6 2 2 6 2 2 6
54443 - 6 6 6 86 86 86 46 46 46 14 14 14
54444 - 0 0 0 0 0 0 0 0 0 0 0 0
54445 - 0 0 0 0 0 0 0 0 0 0 0 0
54446 - 0 0 0 0 0 0 0 0 0 0 0 0
54447 - 0 0 0 0 0 0 0 0 0 0 0 0
54448 - 0 0 0 0 0 0 0 0 0 0 0 0
54449 - 0 0 0 0 0 0 0 0 0 0 0 0
54450 - 0 0 0 0 0 0 0 0 0 6 6 6
54451 - 18 18 18 46 46 46 86 86 86 18 18 18
54452 - 2 2 6 34 34 34 10 10 10 6 6 6
54453 -210 210 210 253 253 253 253 253 253 253 253 253
54454 -253 253 253 253 253 253 253 253 253 253 253 253
54455 -253 253 253 253 253 253 234 234 234 242 242 242
54456 -253 253 253 253 253 253 253 253 253 253 253 253
54457 -253 253 253 253 253 253 253 253 253 253 253 253
54458 -253 253 253 253 253 253 253 253 253 253 253 253
54459 -253 253 253 253 253 253 253 253 253 253 253 253
54460 -253 253 253 253 253 253 221 221 221 6 6 6
54461 - 2 2 6 2 2 6 6 6 6 30 30 30
54462 - 2 2 6 2 2 6 2 2 6 2 2 6
54463 - 2 2 6 82 82 82 54 54 54 18 18 18
54464 - 6 6 6 0 0 0 0 0 0 0 0 0
54465 - 0 0 0 0 0 0 0 0 0 0 0 0
54466 - 0 0 0 0 0 0 0 0 0 0 0 0
54467 - 0 0 0 0 0 0 0 0 0 0 0 0
54468 - 0 0 0 0 0 0 0 0 0 0 0 0
54469 - 0 0 0 0 0 0 0 0 0 0 0 0
54470 - 0 0 0 0 0 0 0 0 0 10 10 10
54471 - 26 26 26 66 66 66 62 62 62 2 2 6
54472 - 2 2 6 38 38 38 10 10 10 26 26 26
54473 -238 238 238 253 253 253 253 253 253 253 253 253
54474 -253 253 253 253 253 253 253 253 253 253 253 253
54475 -253 253 253 253 253 253 231 231 231 238 238 238
54476 -253 253 253 253 253 253 253 253 253 253 253 253
54477 -253 253 253 253 253 253 253 253 253 253 253 253
54478 -253 253 253 253 253 253 253 253 253 253 253 253
54479 -253 253 253 253 253 253 253 253 253 253 253 253
54480 -253 253 253 253 253 253 231 231 231 6 6 6
54481 - 2 2 6 2 2 6 10 10 10 30 30 30
54482 - 2 2 6 2 2 6 2 2 6 2 2 6
54483 - 2 2 6 66 66 66 58 58 58 22 22 22
54484 - 6 6 6 0 0 0 0 0 0 0 0 0
54485 - 0 0 0 0 0 0 0 0 0 0 0 0
54486 - 0 0 0 0 0 0 0 0 0 0 0 0
54487 - 0 0 0 0 0 0 0 0 0 0 0 0
54488 - 0 0 0 0 0 0 0 0 0 0 0 0
54489 - 0 0 0 0 0 0 0 0 0 0 0 0
54490 - 0 0 0 0 0 0 0 0 0 10 10 10
54491 - 38 38 38 78 78 78 6 6 6 2 2 6
54492 - 2 2 6 46 46 46 14 14 14 42 42 42
54493 -246 246 246 253 253 253 253 253 253 253 253 253
54494 -253 253 253 253 253 253 253 253 253 253 253 253
54495 -253 253 253 253 253 253 231 231 231 242 242 242
54496 -253 253 253 253 253 253 253 253 253 253 253 253
54497 -253 253 253 253 253 253 253 253 253 253 253 253
54498 -253 253 253 253 253 253 253 253 253 253 253 253
54499 -253 253 253 253 253 253 253 253 253 253 253 253
54500 -253 253 253 253 253 253 234 234 234 10 10 10
54501 - 2 2 6 2 2 6 22 22 22 14 14 14
54502 - 2 2 6 2 2 6 2 2 6 2 2 6
54503 - 2 2 6 66 66 66 62 62 62 22 22 22
54504 - 6 6 6 0 0 0 0 0 0 0 0 0
54505 - 0 0 0 0 0 0 0 0 0 0 0 0
54506 - 0 0 0 0 0 0 0 0 0 0 0 0
54507 - 0 0 0 0 0 0 0 0 0 0 0 0
54508 - 0 0 0 0 0 0 0 0 0 0 0 0
54509 - 0 0 0 0 0 0 0 0 0 0 0 0
54510 - 0 0 0 0 0 0 6 6 6 18 18 18
54511 - 50 50 50 74 74 74 2 2 6 2 2 6
54512 - 14 14 14 70 70 70 34 34 34 62 62 62
54513 -250 250 250 253 253 253 253 253 253 253 253 253
54514 -253 253 253 253 253 253 253 253 253 253 253 253
54515 -253 253 253 253 253 253 231 231 231 246 246 246
54516 -253 253 253 253 253 253 253 253 253 253 253 253
54517 -253 253 253 253 253 253 253 253 253 253 253 253
54518 -253 253 253 253 253 253 253 253 253 253 253 253
54519 -253 253 253 253 253 253 253 253 253 253 253 253
54520 -253 253 253 253 253 253 234 234 234 14 14 14
54521 - 2 2 6 2 2 6 30 30 30 2 2 6
54522 - 2 2 6 2 2 6 2 2 6 2 2 6
54523 - 2 2 6 66 66 66 62 62 62 22 22 22
54524 - 6 6 6 0 0 0 0 0 0 0 0 0
54525 - 0 0 0 0 0 0 0 0 0 0 0 0
54526 - 0 0 0 0 0 0 0 0 0 0 0 0
54527 - 0 0 0 0 0 0 0 0 0 0 0 0
54528 - 0 0 0 0 0 0 0 0 0 0 0 0
54529 - 0 0 0 0 0 0 0 0 0 0 0 0
54530 - 0 0 0 0 0 0 6 6 6 18 18 18
54531 - 54 54 54 62 62 62 2 2 6 2 2 6
54532 - 2 2 6 30 30 30 46 46 46 70 70 70
54533 -250 250 250 253 253 253 253 253 253 253 253 253
54534 -253 253 253 253 253 253 253 253 253 253 253 253
54535 -253 253 253 253 253 253 231 231 231 246 246 246
54536 -253 253 253 253 253 253 253 253 253 253 253 253
54537 -253 253 253 253 253 253 253 253 253 253 253 253
54538 -253 253 253 253 253 253 253 253 253 253 253 253
54539 -253 253 253 253 253 253 253 253 253 253 253 253
54540 -253 253 253 253 253 253 226 226 226 10 10 10
54541 - 2 2 6 6 6 6 30 30 30 2 2 6
54542 - 2 2 6 2 2 6 2 2 6 2 2 6
54543 - 2 2 6 66 66 66 58 58 58 22 22 22
54544 - 6 6 6 0 0 0 0 0 0 0 0 0
54545 - 0 0 0 0 0 0 0 0 0 0 0 0
54546 - 0 0 0 0 0 0 0 0 0 0 0 0
54547 - 0 0 0 0 0 0 0 0 0 0 0 0
54548 - 0 0 0 0 0 0 0 0 0 0 0 0
54549 - 0 0 0 0 0 0 0 0 0 0 0 0
54550 - 0 0 0 0 0 0 6 6 6 22 22 22
54551 - 58 58 58 62 62 62 2 2 6 2 2 6
54552 - 2 2 6 2 2 6 30 30 30 78 78 78
54553 -250 250 250 253 253 253 253 253 253 253 253 253
54554 -253 253 253 253 253 253 253 253 253 253 253 253
54555 -253 253 253 253 253 253 231 231 231 246 246 246
54556 -253 253 253 253 253 253 253 253 253 253 253 253
54557 -253 253 253 253 253 253 253 253 253 253 253 253
54558 -253 253 253 253 253 253 253 253 253 253 253 253
54559 -253 253 253 253 253 253 253 253 253 253 253 253
54560 -253 253 253 253 253 253 206 206 206 2 2 6
54561 - 22 22 22 34 34 34 18 14 6 22 22 22
54562 - 26 26 26 18 18 18 6 6 6 2 2 6
54563 - 2 2 6 82 82 82 54 54 54 18 18 18
54564 - 6 6 6 0 0 0 0 0 0 0 0 0
54565 - 0 0 0 0 0 0 0 0 0 0 0 0
54566 - 0 0 0 0 0 0 0 0 0 0 0 0
54567 - 0 0 0 0 0 0 0 0 0 0 0 0
54568 - 0 0 0 0 0 0 0 0 0 0 0 0
54569 - 0 0 0 0 0 0 0 0 0 0 0 0
54570 - 0 0 0 0 0 0 6 6 6 26 26 26
54571 - 62 62 62 106 106 106 74 54 14 185 133 11
54572 -210 162 10 121 92 8 6 6 6 62 62 62
54573 -238 238 238 253 253 253 253 253 253 253 253 253
54574 -253 253 253 253 253 253 253 253 253 253 253 253
54575 -253 253 253 253 253 253 231 231 231 246 246 246
54576 -253 253 253 253 253 253 253 253 253 253 253 253
54577 -253 253 253 253 253 253 253 253 253 253 253 253
54578 -253 253 253 253 253 253 253 253 253 253 253 253
54579 -253 253 253 253 253 253 253 253 253 253 253 253
54580 -253 253 253 253 253 253 158 158 158 18 18 18
54581 - 14 14 14 2 2 6 2 2 6 2 2 6
54582 - 6 6 6 18 18 18 66 66 66 38 38 38
54583 - 6 6 6 94 94 94 50 50 50 18 18 18
54584 - 6 6 6 0 0 0 0 0 0 0 0 0
54585 - 0 0 0 0 0 0 0 0 0 0 0 0
54586 - 0 0 0 0 0 0 0 0 0 0 0 0
54587 - 0 0 0 0 0 0 0 0 0 0 0 0
54588 - 0 0 0 0 0 0 0 0 0 0 0 0
54589 - 0 0 0 0 0 0 0 0 0 6 6 6
54590 - 10 10 10 10 10 10 18 18 18 38 38 38
54591 - 78 78 78 142 134 106 216 158 10 242 186 14
54592 -246 190 14 246 190 14 156 118 10 10 10 10
54593 - 90 90 90 238 238 238 253 253 253 253 253 253
54594 -253 253 253 253 253 253 253 253 253 253 253 253
54595 -253 253 253 253 253 253 231 231 231 250 250 250
54596 -253 253 253 253 253 253 253 253 253 253 253 253
54597 -253 253 253 253 253 253 253 253 253 253 253 253
54598 -253 253 253 253 253 253 253 253 253 253 253 253
54599 -253 253 253 253 253 253 253 253 253 246 230 190
54600 -238 204 91 238 204 91 181 142 44 37 26 9
54601 - 2 2 6 2 2 6 2 2 6 2 2 6
54602 - 2 2 6 2 2 6 38 38 38 46 46 46
54603 - 26 26 26 106 106 106 54 54 54 18 18 18
54604 - 6 6 6 0 0 0 0 0 0 0 0 0
54605 - 0 0 0 0 0 0 0 0 0 0 0 0
54606 - 0 0 0 0 0 0 0 0 0 0 0 0
54607 - 0 0 0 0 0 0 0 0 0 0 0 0
54608 - 0 0 0 0 0 0 0 0 0 0 0 0
54609 - 0 0 0 6 6 6 14 14 14 22 22 22
54610 - 30 30 30 38 38 38 50 50 50 70 70 70
54611 -106 106 106 190 142 34 226 170 11 242 186 14
54612 -246 190 14 246 190 14 246 190 14 154 114 10
54613 - 6 6 6 74 74 74 226 226 226 253 253 253
54614 -253 253 253 253 253 253 253 253 253 253 253 253
54615 -253 253 253 253 253 253 231 231 231 250 250 250
54616 -253 253 253 253 253 253 253 253 253 253 253 253
54617 -253 253 253 253 253 253 253 253 253 253 253 253
54618 -253 253 253 253 253 253 253 253 253 253 253 253
54619 -253 253 253 253 253 253 253 253 253 228 184 62
54620 -241 196 14 241 208 19 232 195 16 38 30 10
54621 - 2 2 6 2 2 6 2 2 6 2 2 6
54622 - 2 2 6 6 6 6 30 30 30 26 26 26
54623 -203 166 17 154 142 90 66 66 66 26 26 26
54624 - 6 6 6 0 0 0 0 0 0 0 0 0
54625 - 0 0 0 0 0 0 0 0 0 0 0 0
54626 - 0 0 0 0 0 0 0 0 0 0 0 0
54627 - 0 0 0 0 0 0 0 0 0 0 0 0
54628 - 0 0 0 0 0 0 0 0 0 0 0 0
54629 - 6 6 6 18 18 18 38 38 38 58 58 58
54630 - 78 78 78 86 86 86 101 101 101 123 123 123
54631 -175 146 61 210 150 10 234 174 13 246 186 14
54632 -246 190 14 246 190 14 246 190 14 238 190 10
54633 -102 78 10 2 2 6 46 46 46 198 198 198
54634 -253 253 253 253 253 253 253 253 253 253 253 253
54635 -253 253 253 253 253 253 234 234 234 242 242 242
54636 -253 253 253 253 253 253 253 253 253 253 253 253
54637 -253 253 253 253 253 253 253 253 253 253 253 253
54638 -253 253 253 253 253 253 253 253 253 253 253 253
54639 -253 253 253 253 253 253 253 253 253 224 178 62
54640 -242 186 14 241 196 14 210 166 10 22 18 6
54641 - 2 2 6 2 2 6 2 2 6 2 2 6
54642 - 2 2 6 2 2 6 6 6 6 121 92 8
54643 -238 202 15 232 195 16 82 82 82 34 34 34
54644 - 10 10 10 0 0 0 0 0 0 0 0 0
54645 - 0 0 0 0 0 0 0 0 0 0 0 0
54646 - 0 0 0 0 0 0 0 0 0 0 0 0
54647 - 0 0 0 0 0 0 0 0 0 0 0 0
54648 - 0 0 0 0 0 0 0 0 0 0 0 0
54649 - 14 14 14 38 38 38 70 70 70 154 122 46
54650 -190 142 34 200 144 11 197 138 11 197 138 11
54651 -213 154 11 226 170 11 242 186 14 246 190 14
54652 -246 190 14 246 190 14 246 190 14 246 190 14
54653 -225 175 15 46 32 6 2 2 6 22 22 22
54654 -158 158 158 250 250 250 253 253 253 253 253 253
54655 -253 253 253 253 253 253 253 253 253 253 253 253
54656 -253 253 253 253 253 253 253 253 253 253 253 253
54657 -253 253 253 253 253 253 253 253 253 253 253 253
54658 -253 253 253 253 253 253 253 253 253 253 253 253
54659 -253 253 253 250 250 250 242 242 242 224 178 62
54660 -239 182 13 236 186 11 213 154 11 46 32 6
54661 - 2 2 6 2 2 6 2 2 6 2 2 6
54662 - 2 2 6 2 2 6 61 42 6 225 175 15
54663 -238 190 10 236 186 11 112 100 78 42 42 42
54664 - 14 14 14 0 0 0 0 0 0 0 0 0
54665 - 0 0 0 0 0 0 0 0 0 0 0 0
54666 - 0 0 0 0 0 0 0 0 0 0 0 0
54667 - 0 0 0 0 0 0 0 0 0 0 0 0
54668 - 0 0 0 0 0 0 0 0 0 6 6 6
54669 - 22 22 22 54 54 54 154 122 46 213 154 11
54670 -226 170 11 230 174 11 226 170 11 226 170 11
54671 -236 178 12 242 186 14 246 190 14 246 190 14
54672 -246 190 14 246 190 14 246 190 14 246 190 14
54673 -241 196 14 184 144 12 10 10 10 2 2 6
54674 - 6 6 6 116 116 116 242 242 242 253 253 253
54675 -253 253 253 253 253 253 253 253 253 253 253 253
54676 -253 253 253 253 253 253 253 253 253 253 253 253
54677 -253 253 253 253 253 253 253 253 253 253 253 253
54678 -253 253 253 253 253 253 253 253 253 253 253 253
54679 -253 253 253 231 231 231 198 198 198 214 170 54
54680 -236 178 12 236 178 12 210 150 10 137 92 6
54681 - 18 14 6 2 2 6 2 2 6 2 2 6
54682 - 6 6 6 70 47 6 200 144 11 236 178 12
54683 -239 182 13 239 182 13 124 112 88 58 58 58
54684 - 22 22 22 6 6 6 0 0 0 0 0 0
54685 - 0 0 0 0 0 0 0 0 0 0 0 0
54686 - 0 0 0 0 0 0 0 0 0 0 0 0
54687 - 0 0 0 0 0 0 0 0 0 0 0 0
54688 - 0 0 0 0 0 0 0 0 0 10 10 10
54689 - 30 30 30 70 70 70 180 133 36 226 170 11
54690 -239 182 13 242 186 14 242 186 14 246 186 14
54691 -246 190 14 246 190 14 246 190 14 246 190 14
54692 -246 190 14 246 190 14 246 190 14 246 190 14
54693 -246 190 14 232 195 16 98 70 6 2 2 6
54694 - 2 2 6 2 2 6 66 66 66 221 221 221
54695 -253 253 253 253 253 253 253 253 253 253 253 253
54696 -253 253 253 253 253 253 253 253 253 253 253 253
54697 -253 253 253 253 253 253 253 253 253 253 253 253
54698 -253 253 253 253 253 253 253 253 253 253 253 253
54699 -253 253 253 206 206 206 198 198 198 214 166 58
54700 -230 174 11 230 174 11 216 158 10 192 133 9
54701 -163 110 8 116 81 8 102 78 10 116 81 8
54702 -167 114 7 197 138 11 226 170 11 239 182 13
54703 -242 186 14 242 186 14 162 146 94 78 78 78
54704 - 34 34 34 14 14 14 6 6 6 0 0 0
54705 - 0 0 0 0 0 0 0 0 0 0 0 0
54706 - 0 0 0 0 0 0 0 0 0 0 0 0
54707 - 0 0 0 0 0 0 0 0 0 0 0 0
54708 - 0 0 0 0 0 0 0 0 0 6 6 6
54709 - 30 30 30 78 78 78 190 142 34 226 170 11
54710 -239 182 13 246 190 14 246 190 14 246 190 14
54711 -246 190 14 246 190 14 246 190 14 246 190 14
54712 -246 190 14 246 190 14 246 190 14 246 190 14
54713 -246 190 14 241 196 14 203 166 17 22 18 6
54714 - 2 2 6 2 2 6 2 2 6 38 38 38
54715 -218 218 218 253 253 253 253 253 253 253 253 253
54716 -253 253 253 253 253 253 253 253 253 253 253 253
54717 -253 253 253 253 253 253 253 253 253 253 253 253
54718 -253 253 253 253 253 253 253 253 253 253 253 253
54719 -250 250 250 206 206 206 198 198 198 202 162 69
54720 -226 170 11 236 178 12 224 166 10 210 150 10
54721 -200 144 11 197 138 11 192 133 9 197 138 11
54722 -210 150 10 226 170 11 242 186 14 246 190 14
54723 -246 190 14 246 186 14 225 175 15 124 112 88
54724 - 62 62 62 30 30 30 14 14 14 6 6 6
54725 - 0 0 0 0 0 0 0 0 0 0 0 0
54726 - 0 0 0 0 0 0 0 0 0 0 0 0
54727 - 0 0 0 0 0 0 0 0 0 0 0 0
54728 - 0 0 0 0 0 0 0 0 0 10 10 10
54729 - 30 30 30 78 78 78 174 135 50 224 166 10
54730 -239 182 13 246 190 14 246 190 14 246 190 14
54731 -246 190 14 246 190 14 246 190 14 246 190 14
54732 -246 190 14 246 190 14 246 190 14 246 190 14
54733 -246 190 14 246 190 14 241 196 14 139 102 15
54734 - 2 2 6 2 2 6 2 2 6 2 2 6
54735 - 78 78 78 250 250 250 253 253 253 253 253 253
54736 -253 253 253 253 253 253 253 253 253 253 253 253
54737 -253 253 253 253 253 253 253 253 253 253 253 253
54738 -253 253 253 253 253 253 253 253 253 253 253 253
54739 -250 250 250 214 214 214 198 198 198 190 150 46
54740 -219 162 10 236 178 12 234 174 13 224 166 10
54741 -216 158 10 213 154 11 213 154 11 216 158 10
54742 -226 170 11 239 182 13 246 190 14 246 190 14
54743 -246 190 14 246 190 14 242 186 14 206 162 42
54744 -101 101 101 58 58 58 30 30 30 14 14 14
54745 - 6 6 6 0 0 0 0 0 0 0 0 0
54746 - 0 0 0 0 0 0 0 0 0 0 0 0
54747 - 0 0 0 0 0 0 0 0 0 0 0 0
54748 - 0 0 0 0 0 0 0 0 0 10 10 10
54749 - 30 30 30 74 74 74 174 135 50 216 158 10
54750 -236 178 12 246 190 14 246 190 14 246 190 14
54751 -246 190 14 246 190 14 246 190 14 246 190 14
54752 -246 190 14 246 190 14 246 190 14 246 190 14
54753 -246 190 14 246 190 14 241 196 14 226 184 13
54754 - 61 42 6 2 2 6 2 2 6 2 2 6
54755 - 22 22 22 238 238 238 253 253 253 253 253 253
54756 -253 253 253 253 253 253 253 253 253 253 253 253
54757 -253 253 253 253 253 253 253 253 253 253 253 253
54758 -253 253 253 253 253 253 253 253 253 253 253 253
54759 -253 253 253 226 226 226 187 187 187 180 133 36
54760 -216 158 10 236 178 12 239 182 13 236 178 12
54761 -230 174 11 226 170 11 226 170 11 230 174 11
54762 -236 178 12 242 186 14 246 190 14 246 190 14
54763 -246 190 14 246 190 14 246 186 14 239 182 13
54764 -206 162 42 106 106 106 66 66 66 34 34 34
54765 - 14 14 14 6 6 6 0 0 0 0 0 0
54766 - 0 0 0 0 0 0 0 0 0 0 0 0
54767 - 0 0 0 0 0 0 0 0 0 0 0 0
54768 - 0 0 0 0 0 0 0 0 0 6 6 6
54769 - 26 26 26 70 70 70 163 133 67 213 154 11
54770 -236 178 12 246 190 14 246 190 14 246 190 14
54771 -246 190 14 246 190 14 246 190 14 246 190 14
54772 -246 190 14 246 190 14 246 190 14 246 190 14
54773 -246 190 14 246 190 14 246 190 14 241 196 14
54774 -190 146 13 18 14 6 2 2 6 2 2 6
54775 - 46 46 46 246 246 246 253 253 253 253 253 253
54776 -253 253 253 253 253 253 253 253 253 253 253 253
54777 -253 253 253 253 253 253 253 253 253 253 253 253
54778 -253 253 253 253 253 253 253 253 253 253 253 253
54779 -253 253 253 221 221 221 86 86 86 156 107 11
54780 -216 158 10 236 178 12 242 186 14 246 186 14
54781 -242 186 14 239 182 13 239 182 13 242 186 14
54782 -242 186 14 246 186 14 246 190 14 246 190 14
54783 -246 190 14 246 190 14 246 190 14 246 190 14
54784 -242 186 14 225 175 15 142 122 72 66 66 66
54785 - 30 30 30 10 10 10 0 0 0 0 0 0
54786 - 0 0 0 0 0 0 0 0 0 0 0 0
54787 - 0 0 0 0 0 0 0 0 0 0 0 0
54788 - 0 0 0 0 0 0 0 0 0 6 6 6
54789 - 26 26 26 70 70 70 163 133 67 210 150 10
54790 -236 178 12 246 190 14 246 190 14 246 190 14
54791 -246 190 14 246 190 14 246 190 14 246 190 14
54792 -246 190 14 246 190 14 246 190 14 246 190 14
54793 -246 190 14 246 190 14 246 190 14 246 190 14
54794 -232 195 16 121 92 8 34 34 34 106 106 106
54795 -221 221 221 253 253 253 253 253 253 253 253 253
54796 -253 253 253 253 253 253 253 253 253 253 253 253
54797 -253 253 253 253 253 253 253 253 253 253 253 253
54798 -253 253 253 253 253 253 253 253 253 253 253 253
54799 -242 242 242 82 82 82 18 14 6 163 110 8
54800 -216 158 10 236 178 12 242 186 14 246 190 14
54801 -246 190 14 246 190 14 246 190 14 246 190 14
54802 -246 190 14 246 190 14 246 190 14 246 190 14
54803 -246 190 14 246 190 14 246 190 14 246 190 14
54804 -246 190 14 246 190 14 242 186 14 163 133 67
54805 - 46 46 46 18 18 18 6 6 6 0 0 0
54806 - 0 0 0 0 0 0 0 0 0 0 0 0
54807 - 0 0 0 0 0 0 0 0 0 0 0 0
54808 - 0 0 0 0 0 0 0 0 0 10 10 10
54809 - 30 30 30 78 78 78 163 133 67 210 150 10
54810 -236 178 12 246 186 14 246 190 14 246 190 14
54811 -246 190 14 246 190 14 246 190 14 246 190 14
54812 -246 190 14 246 190 14 246 190 14 246 190 14
54813 -246 190 14 246 190 14 246 190 14 246 190 14
54814 -241 196 14 215 174 15 190 178 144 253 253 253
54815 -253 253 253 253 253 253 253 253 253 253 253 253
54816 -253 253 253 253 253 253 253 253 253 253 253 253
54817 -253 253 253 253 253 253 253 253 253 253 253 253
54818 -253 253 253 253 253 253 253 253 253 218 218 218
54819 - 58 58 58 2 2 6 22 18 6 167 114 7
54820 -216 158 10 236 178 12 246 186 14 246 190 14
54821 -246 190 14 246 190 14 246 190 14 246 190 14
54822 -246 190 14 246 190 14 246 190 14 246 190 14
54823 -246 190 14 246 190 14 246 190 14 246 190 14
54824 -246 190 14 246 186 14 242 186 14 190 150 46
54825 - 54 54 54 22 22 22 6 6 6 0 0 0
54826 - 0 0 0 0 0 0 0 0 0 0 0 0
54827 - 0 0 0 0 0 0 0 0 0 0 0 0
54828 - 0 0 0 0 0 0 0 0 0 14 14 14
54829 - 38 38 38 86 86 86 180 133 36 213 154 11
54830 -236 178 12 246 186 14 246 190 14 246 190 14
54831 -246 190 14 246 190 14 246 190 14 246 190 14
54832 -246 190 14 246 190 14 246 190 14 246 190 14
54833 -246 190 14 246 190 14 246 190 14 246 190 14
54834 -246 190 14 232 195 16 190 146 13 214 214 214
54835 -253 253 253 253 253 253 253 253 253 253 253 253
54836 -253 253 253 253 253 253 253 253 253 253 253 253
54837 -253 253 253 253 253 253 253 253 253 253 253 253
54838 -253 253 253 250 250 250 170 170 170 26 26 26
54839 - 2 2 6 2 2 6 37 26 9 163 110 8
54840 -219 162 10 239 182 13 246 186 14 246 190 14
54841 -246 190 14 246 190 14 246 190 14 246 190 14
54842 -246 190 14 246 190 14 246 190 14 246 190 14
54843 -246 190 14 246 190 14 246 190 14 246 190 14
54844 -246 186 14 236 178 12 224 166 10 142 122 72
54845 - 46 46 46 18 18 18 6 6 6 0 0 0
54846 - 0 0 0 0 0 0 0 0 0 0 0 0
54847 - 0 0 0 0 0 0 0 0 0 0 0 0
54848 - 0 0 0 0 0 0 6 6 6 18 18 18
54849 - 50 50 50 109 106 95 192 133 9 224 166 10
54850 -242 186 14 246 190 14 246 190 14 246 190 14
54851 -246 190 14 246 190 14 246 190 14 246 190 14
54852 -246 190 14 246 190 14 246 190 14 246 190 14
54853 -246 190 14 246 190 14 246 190 14 246 190 14
54854 -242 186 14 226 184 13 210 162 10 142 110 46
54855 -226 226 226 253 253 253 253 253 253 253 253 253
54856 -253 253 253 253 253 253 253 253 253 253 253 253
54857 -253 253 253 253 253 253 253 253 253 253 253 253
54858 -198 198 198 66 66 66 2 2 6 2 2 6
54859 - 2 2 6 2 2 6 50 34 6 156 107 11
54860 -219 162 10 239 182 13 246 186 14 246 190 14
54861 -246 190 14 246 190 14 246 190 14 246 190 14
54862 -246 190 14 246 190 14 246 190 14 246 190 14
54863 -246 190 14 246 190 14 246 190 14 242 186 14
54864 -234 174 13 213 154 11 154 122 46 66 66 66
54865 - 30 30 30 10 10 10 0 0 0 0 0 0
54866 - 0 0 0 0 0 0 0 0 0 0 0 0
54867 - 0 0 0 0 0 0 0 0 0 0 0 0
54868 - 0 0 0 0 0 0 6 6 6 22 22 22
54869 - 58 58 58 154 121 60 206 145 10 234 174 13
54870 -242 186 14 246 186 14 246 190 14 246 190 14
54871 -246 190 14 246 190 14 246 190 14 246 190 14
54872 -246 190 14 246 190 14 246 190 14 246 190 14
54873 -246 190 14 246 190 14 246 190 14 246 190 14
54874 -246 186 14 236 178 12 210 162 10 163 110 8
54875 - 61 42 6 138 138 138 218 218 218 250 250 250
54876 -253 253 253 253 253 253 253 253 253 250 250 250
54877 -242 242 242 210 210 210 144 144 144 66 66 66
54878 - 6 6 6 2 2 6 2 2 6 2 2 6
54879 - 2 2 6 2 2 6 61 42 6 163 110 8
54880 -216 158 10 236 178 12 246 190 14 246 190 14
54881 -246 190 14 246 190 14 246 190 14 246 190 14
54882 -246 190 14 246 190 14 246 190 14 246 190 14
54883 -246 190 14 239 182 13 230 174 11 216 158 10
54884 -190 142 34 124 112 88 70 70 70 38 38 38
54885 - 18 18 18 6 6 6 0 0 0 0 0 0
54886 - 0 0 0 0 0 0 0 0 0 0 0 0
54887 - 0 0 0 0 0 0 0 0 0 0 0 0
54888 - 0 0 0 0 0 0 6 6 6 22 22 22
54889 - 62 62 62 168 124 44 206 145 10 224 166 10
54890 -236 178 12 239 182 13 242 186 14 242 186 14
54891 -246 186 14 246 190 14 246 190 14 246 190 14
54892 -246 190 14 246 190 14 246 190 14 246 190 14
54893 -246 190 14 246 190 14 246 190 14 246 190 14
54894 -246 190 14 236 178 12 216 158 10 175 118 6
54895 - 80 54 7 2 2 6 6 6 6 30 30 30
54896 - 54 54 54 62 62 62 50 50 50 38 38 38
54897 - 14 14 14 2 2 6 2 2 6 2 2 6
54898 - 2 2 6 2 2 6 2 2 6 2 2 6
54899 - 2 2 6 6 6 6 80 54 7 167 114 7
54900 -213 154 11 236 178 12 246 190 14 246 190 14
54901 -246 190 14 246 190 14 246 190 14 246 190 14
54902 -246 190 14 242 186 14 239 182 13 239 182 13
54903 -230 174 11 210 150 10 174 135 50 124 112 88
54904 - 82 82 82 54 54 54 34 34 34 18 18 18
54905 - 6 6 6 0 0 0 0 0 0 0 0 0
54906 - 0 0 0 0 0 0 0 0 0 0 0 0
54907 - 0 0 0 0 0 0 0 0 0 0 0 0
54908 - 0 0 0 0 0 0 6 6 6 18 18 18
54909 - 50 50 50 158 118 36 192 133 9 200 144 11
54910 -216 158 10 219 162 10 224 166 10 226 170 11
54911 -230 174 11 236 178 12 239 182 13 239 182 13
54912 -242 186 14 246 186 14 246 190 14 246 190 14
54913 -246 190 14 246 190 14 246 190 14 246 190 14
54914 -246 186 14 230 174 11 210 150 10 163 110 8
54915 -104 69 6 10 10 10 2 2 6 2 2 6
54916 - 2 2 6 2 2 6 2 2 6 2 2 6
54917 - 2 2 6 2 2 6 2 2 6 2 2 6
54918 - 2 2 6 2 2 6 2 2 6 2 2 6
54919 - 2 2 6 6 6 6 91 60 6 167 114 7
54920 -206 145 10 230 174 11 242 186 14 246 190 14
54921 -246 190 14 246 190 14 246 186 14 242 186 14
54922 -239 182 13 230 174 11 224 166 10 213 154 11
54923 -180 133 36 124 112 88 86 86 86 58 58 58
54924 - 38 38 38 22 22 22 10 10 10 6 6 6
54925 - 0 0 0 0 0 0 0 0 0 0 0 0
54926 - 0 0 0 0 0 0 0 0 0 0 0 0
54927 - 0 0 0 0 0 0 0 0 0 0 0 0
54928 - 0 0 0 0 0 0 0 0 0 14 14 14
54929 - 34 34 34 70 70 70 138 110 50 158 118 36
54930 -167 114 7 180 123 7 192 133 9 197 138 11
54931 -200 144 11 206 145 10 213 154 11 219 162 10
54932 -224 166 10 230 174 11 239 182 13 242 186 14
54933 -246 186 14 246 186 14 246 186 14 246 186 14
54934 -239 182 13 216 158 10 185 133 11 152 99 6
54935 -104 69 6 18 14 6 2 2 6 2 2 6
54936 - 2 2 6 2 2 6 2 2 6 2 2 6
54937 - 2 2 6 2 2 6 2 2 6 2 2 6
54938 - 2 2 6 2 2 6 2 2 6 2 2 6
54939 - 2 2 6 6 6 6 80 54 7 152 99 6
54940 -192 133 9 219 162 10 236 178 12 239 182 13
54941 -246 186 14 242 186 14 239 182 13 236 178 12
54942 -224 166 10 206 145 10 192 133 9 154 121 60
54943 - 94 94 94 62 62 62 42 42 42 22 22 22
54944 - 14 14 14 6 6 6 0 0 0 0 0 0
54945 - 0 0 0 0 0 0 0 0 0 0 0 0
54946 - 0 0 0 0 0 0 0 0 0 0 0 0
54947 - 0 0 0 0 0 0 0 0 0 0 0 0
54948 - 0 0 0 0 0 0 0 0 0 6 6 6
54949 - 18 18 18 34 34 34 58 58 58 78 78 78
54950 -101 98 89 124 112 88 142 110 46 156 107 11
54951 -163 110 8 167 114 7 175 118 6 180 123 7
54952 -185 133 11 197 138 11 210 150 10 219 162 10
54953 -226 170 11 236 178 12 236 178 12 234 174 13
54954 -219 162 10 197 138 11 163 110 8 130 83 6
54955 - 91 60 6 10 10 10 2 2 6 2 2 6
54956 - 18 18 18 38 38 38 38 38 38 38 38 38
54957 - 38 38 38 38 38 38 38 38 38 38 38 38
54958 - 38 38 38 38 38 38 26 26 26 2 2 6
54959 - 2 2 6 6 6 6 70 47 6 137 92 6
54960 -175 118 6 200 144 11 219 162 10 230 174 11
54961 -234 174 13 230 174 11 219 162 10 210 150 10
54962 -192 133 9 163 110 8 124 112 88 82 82 82
54963 - 50 50 50 30 30 30 14 14 14 6 6 6
54964 - 0 0 0 0 0 0 0 0 0 0 0 0
54965 - 0 0 0 0 0 0 0 0 0 0 0 0
54966 - 0 0 0 0 0 0 0 0 0 0 0 0
54967 - 0 0 0 0 0 0 0 0 0 0 0 0
54968 - 0 0 0 0 0 0 0 0 0 0 0 0
54969 - 6 6 6 14 14 14 22 22 22 34 34 34
54970 - 42 42 42 58 58 58 74 74 74 86 86 86
54971 -101 98 89 122 102 70 130 98 46 121 87 25
54972 -137 92 6 152 99 6 163 110 8 180 123 7
54973 -185 133 11 197 138 11 206 145 10 200 144 11
54974 -180 123 7 156 107 11 130 83 6 104 69 6
54975 - 50 34 6 54 54 54 110 110 110 101 98 89
54976 - 86 86 86 82 82 82 78 78 78 78 78 78
54977 - 78 78 78 78 78 78 78 78 78 78 78 78
54978 - 78 78 78 82 82 82 86 86 86 94 94 94
54979 -106 106 106 101 101 101 86 66 34 124 80 6
54980 -156 107 11 180 123 7 192 133 9 200 144 11
54981 -206 145 10 200 144 11 192 133 9 175 118 6
54982 -139 102 15 109 106 95 70 70 70 42 42 42
54983 - 22 22 22 10 10 10 0 0 0 0 0 0
54984 - 0 0 0 0 0 0 0 0 0 0 0 0
54985 - 0 0 0 0 0 0 0 0 0 0 0 0
54986 - 0 0 0 0 0 0 0 0 0 0 0 0
54987 - 0 0 0 0 0 0 0 0 0 0 0 0
54988 - 0 0 0 0 0 0 0 0 0 0 0 0
54989 - 0 0 0 0 0 0 6 6 6 10 10 10
54990 - 14 14 14 22 22 22 30 30 30 38 38 38
54991 - 50 50 50 62 62 62 74 74 74 90 90 90
54992 -101 98 89 112 100 78 121 87 25 124 80 6
54993 -137 92 6 152 99 6 152 99 6 152 99 6
54994 -138 86 6 124 80 6 98 70 6 86 66 30
54995 -101 98 89 82 82 82 58 58 58 46 46 46
54996 - 38 38 38 34 34 34 34 34 34 34 34 34
54997 - 34 34 34 34 34 34 34 34 34 34 34 34
54998 - 34 34 34 34 34 34 38 38 38 42 42 42
54999 - 54 54 54 82 82 82 94 86 76 91 60 6
55000 -134 86 6 156 107 11 167 114 7 175 118 6
55001 -175 118 6 167 114 7 152 99 6 121 87 25
55002 -101 98 89 62 62 62 34 34 34 18 18 18
55003 - 6 6 6 0 0 0 0 0 0 0 0 0
55004 - 0 0 0 0 0 0 0 0 0 0 0 0
55005 - 0 0 0 0 0 0 0 0 0 0 0 0
55006 - 0 0 0 0 0 0 0 0 0 0 0 0
55007 - 0 0 0 0 0 0 0 0 0 0 0 0
55008 - 0 0 0 0 0 0 0 0 0 0 0 0
55009 - 0 0 0 0 0 0 0 0 0 0 0 0
55010 - 0 0 0 6 6 6 6 6 6 10 10 10
55011 - 18 18 18 22 22 22 30 30 30 42 42 42
55012 - 50 50 50 66 66 66 86 86 86 101 98 89
55013 -106 86 58 98 70 6 104 69 6 104 69 6
55014 -104 69 6 91 60 6 82 62 34 90 90 90
55015 - 62 62 62 38 38 38 22 22 22 14 14 14
55016 - 10 10 10 10 10 10 10 10 10 10 10 10
55017 - 10 10 10 10 10 10 6 6 6 10 10 10
55018 - 10 10 10 10 10 10 10 10 10 14 14 14
55019 - 22 22 22 42 42 42 70 70 70 89 81 66
55020 - 80 54 7 104 69 6 124 80 6 137 92 6
55021 -134 86 6 116 81 8 100 82 52 86 86 86
55022 - 58 58 58 30 30 30 14 14 14 6 6 6
55023 - 0 0 0 0 0 0 0 0 0 0 0 0
55024 - 0 0 0 0 0 0 0 0 0 0 0 0
55025 - 0 0 0 0 0 0 0 0 0 0 0 0
55026 - 0 0 0 0 0 0 0 0 0 0 0 0
55027 - 0 0 0 0 0 0 0 0 0 0 0 0
55028 - 0 0 0 0 0 0 0 0 0 0 0 0
55029 - 0 0 0 0 0 0 0 0 0 0 0 0
55030 - 0 0 0 0 0 0 0 0 0 0 0 0
55031 - 0 0 0 6 6 6 10 10 10 14 14 14
55032 - 18 18 18 26 26 26 38 38 38 54 54 54
55033 - 70 70 70 86 86 86 94 86 76 89 81 66
55034 - 89 81 66 86 86 86 74 74 74 50 50 50
55035 - 30 30 30 14 14 14 6 6 6 0 0 0
55036 - 0 0 0 0 0 0 0 0 0 0 0 0
55037 - 0 0 0 0 0 0 0 0 0 0 0 0
55038 - 0 0 0 0 0 0 0 0 0 0 0 0
55039 - 6 6 6 18 18 18 34 34 34 58 58 58
55040 - 82 82 82 89 81 66 89 81 66 89 81 66
55041 - 94 86 66 94 86 76 74 74 74 50 50 50
55042 - 26 26 26 14 14 14 6 6 6 0 0 0
55043 - 0 0 0 0 0 0 0 0 0 0 0 0
55044 - 0 0 0 0 0 0 0 0 0 0 0 0
55045 - 0 0 0 0 0 0 0 0 0 0 0 0
55046 - 0 0 0 0 0 0 0 0 0 0 0 0
55047 - 0 0 0 0 0 0 0 0 0 0 0 0
55048 - 0 0 0 0 0 0 0 0 0 0 0 0
55049 - 0 0 0 0 0 0 0 0 0 0 0 0
55050 - 0 0 0 0 0 0 0 0 0 0 0 0
55051 - 0 0 0 0 0 0 0 0 0 0 0 0
55052 - 6 6 6 6 6 6 14 14 14 18 18 18
55053 - 30 30 30 38 38 38 46 46 46 54 54 54
55054 - 50 50 50 42 42 42 30 30 30 18 18 18
55055 - 10 10 10 0 0 0 0 0 0 0 0 0
55056 - 0 0 0 0 0 0 0 0 0 0 0 0
55057 - 0 0 0 0 0 0 0 0 0 0 0 0
55058 - 0 0 0 0 0 0 0 0 0 0 0 0
55059 - 0 0 0 6 6 6 14 14 14 26 26 26
55060 - 38 38 38 50 50 50 58 58 58 58 58 58
55061 - 54 54 54 42 42 42 30 30 30 18 18 18
55062 - 10 10 10 0 0 0 0 0 0 0 0 0
55063 - 0 0 0 0 0 0 0 0 0 0 0 0
55064 - 0 0 0 0 0 0 0 0 0 0 0 0
55065 - 0 0 0 0 0 0 0 0 0 0 0 0
55066 - 0 0 0 0 0 0 0 0 0 0 0 0
55067 - 0 0 0 0 0 0 0 0 0 0 0 0
55068 - 0 0 0 0 0 0 0 0 0 0 0 0
55069 - 0 0 0 0 0 0 0 0 0 0 0 0
55070 - 0 0 0 0 0 0 0 0 0 0 0 0
55071 - 0 0 0 0 0 0 0 0 0 0 0 0
55072 - 0 0 0 0 0 0 0 0 0 6 6 6
55073 - 6 6 6 10 10 10 14 14 14 18 18 18
55074 - 18 18 18 14 14 14 10 10 10 6 6 6
55075 - 0 0 0 0 0 0 0 0 0 0 0 0
55076 - 0 0 0 0 0 0 0 0 0 0 0 0
55077 - 0 0 0 0 0 0 0 0 0 0 0 0
55078 - 0 0 0 0 0 0 0 0 0 0 0 0
55079 - 0 0 0 0 0 0 0 0 0 6 6 6
55080 - 14 14 14 18 18 18 22 22 22 22 22 22
55081 - 18 18 18 14 14 14 10 10 10 6 6 6
55082 - 0 0 0 0 0 0 0 0 0 0 0 0
55083 - 0 0 0 0 0 0 0 0 0 0 0 0
55084 - 0 0 0 0 0 0 0 0 0 0 0 0
55085 - 0 0 0 0 0 0 0 0 0 0 0 0
55086 - 0 0 0 0 0 0 0 0 0 0 0 0
55087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55100 +4 4 4 4 4 4
55101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55114 +4 4 4 4 4 4
55115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55128 +4 4 4 4 4 4
55129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55130 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55142 +4 4 4 4 4 4
55143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55144 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55156 +4 4 4 4 4 4
55157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55170 +4 4 4 4 4 4
55171 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55175 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
55176 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
55177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55180 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
55181 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55182 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
55183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55184 +4 4 4 4 4 4
55185 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55189 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
55190 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
55191 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55194 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
55195 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
55196 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
55197 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55198 +4 4 4 4 4 4
55199 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55203 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
55204 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
55205 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55208 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
55209 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
55210 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
55211 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
55212 +4 4 4 4 4 4
55213 +4 4 4 4 4 4 4 4 4 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 5 5 5 5 5 5 2 2 2 0 0 0
55217 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
55218 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
55219 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
55220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55221 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
55222 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
55223 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
55224 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
55225 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
55226 +4 4 4 4 4 4
55227 +4 4 4 4 4 4 4 4 4 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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
55231 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
55232 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
55233 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
55234 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55235 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
55236 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
55237 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
55238 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
55239 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
55240 +4 4 4 4 4 4
55241 +4 4 4 4 4 4 4 4 4 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 5 5 5
55244 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
55245 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
55246 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
55247 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
55248 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55249 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
55250 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
55251 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
55252 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
55253 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
55254 +4 4 4 4 4 4
55255 +4 4 4 4 4 4 4 4 4 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 5 5 5 3 3 3
55258 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
55259 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
55260 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
55261 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
55262 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
55263 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
55264 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
55265 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
55266 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
55267 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
55268 +4 4 4 4 4 4
55269 +4 4 4 4 4 4 4 4 4 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 2 2 2 0 0 0 4 0 0
55272 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
55273 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
55274 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
55275 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
55276 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
55277 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
55278 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
55279 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
55280 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
55281 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
55282 +4 4 4 4 4 4
55283 +4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
55286 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
55287 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
55288 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
55289 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
55290 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
55291 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
55292 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
55293 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
55294 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
55295 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55296 +4 4 4 4 4 4
55297 +4 4 4 4 4 4 4 4 4 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 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
55300 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
55301 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
55302 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
55303 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
55304 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
55305 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
55306 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
55307 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
55308 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
55309 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
55310 +4 4 4 4 4 4
55311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55312 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
55313 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
55314 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
55315 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
55316 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
55317 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
55318 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
55319 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
55320 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
55321 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
55322 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
55323 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
55324 +4 4 4 4 4 4
55325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55326 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
55327 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
55328 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
55329 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55330 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
55331 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
55332 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
55333 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
55334 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
55335 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
55336 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
55337 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
55338 +0 0 0 4 4 4
55339 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
55340 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
55341 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
55342 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
55343 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
55344 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
55345 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
55346 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
55347 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
55348 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
55349 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
55350 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
55351 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
55352 +2 0 0 0 0 0
55353 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
55354 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
55355 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
55356 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
55357 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
55358 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
55359 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
55360 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
55361 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
55362 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
55363 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
55364 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
55365 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
55366 +37 38 37 0 0 0
55367 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55368 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
55369 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
55370 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
55371 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
55372 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
55373 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
55374 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
55375 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
55376 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
55377 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
55378 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
55379 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
55380 +85 115 134 4 0 0
55381 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
55382 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
55383 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
55384 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
55385 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
55386 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
55387 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
55388 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
55389 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
55390 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
55391 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
55392 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
55393 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
55394 +60 73 81 4 0 0
55395 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
55396 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
55397 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
55398 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
55399 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
55400 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
55401 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
55402 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
55403 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
55404 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
55405 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
55406 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
55407 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
55408 +16 19 21 4 0 0
55409 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
55410 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
55411 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
55412 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
55413 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
55414 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
55415 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
55416 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
55417 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
55418 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
55419 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
55420 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
55421 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
55422 +4 0 0 4 3 3
55423 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
55424 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
55425 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
55426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
55427 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
55428 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
55429 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
55430 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
55431 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
55432 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
55433 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
55434 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
55435 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
55436 +3 2 2 4 4 4
55437 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
55438 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
55439 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
55440 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55441 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
55442 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
55443 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
55444 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
55445 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
55446 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
55447 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
55448 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
55449 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
55450 +4 4 4 4 4 4
55451 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
55452 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
55453 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
55454 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
55455 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
55456 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
55457 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
55458 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
55459 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
55460 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
55461 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
55462 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
55463 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
55464 +4 4 4 4 4 4
55465 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
55466 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
55467 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
55468 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
55469 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
55470 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55471 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
55472 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
55473 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55474 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55475 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55476 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55477 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55478 +5 5 5 5 5 5
55479 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55480 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55481 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55482 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55483 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55484 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55485 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55486 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55487 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55488 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55489 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55490 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55491 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55492 +5 5 5 4 4 4
55493 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55494 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55495 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55496 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55497 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55498 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55499 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55500 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55501 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55502 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55503 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55504 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55506 +4 4 4 4 4 4
55507 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55508 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55509 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55510 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55511 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55512 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55513 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55514 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55515 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55516 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55517 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55518 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
55519 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55520 +4 4 4 4 4 4
55521 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55522 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55523 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55524 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55525 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55526 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55527 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55528 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55529 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55530 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55531 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
55532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55534 +4 4 4 4 4 4
55535 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55536 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55537 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55538 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55539 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55540 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55541 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55542 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55543 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55544 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55545 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
55546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55547 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55548 +4 4 4 4 4 4
55549 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55550 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55551 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55552 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55553 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55554 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55555 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55556 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55557 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55558 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55559 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55562 +4 4 4 4 4 4
55563 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55564 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55565 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55566 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55567 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55568 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55569 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55570 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55571 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55572 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55573 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
55574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55576 +4 4 4 4 4 4
55577 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55578 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55579 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55580 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55581 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55582 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55583 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55584 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55585 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55586 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55587 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
55588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55590 +4 4 4 4 4 4
55591 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55592 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55593 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55594 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55595 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55596 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55597 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55598 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55599 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55600 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55601 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55604 +4 4 4 4 4 4
55605 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55606 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55607 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55608 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55609 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55610 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55611 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55612 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55613 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55614 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55615 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55618 +4 4 4 4 4 4
55619 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55620 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55621 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55622 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55623 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55624 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55625 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55626 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55627 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55628 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55629 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
55633 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55634 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55635 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55636 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55637 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55638 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55639 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55640 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55641 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55642 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55643 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55644 +4 4 4 4 4 4 4 4 4 4 4 4 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
55647 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55648 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55649 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55650 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55651 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55652 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55653 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55654 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55655 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55656 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55657 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55658 +4 4 4 4 4 4 4 4 4 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
55661 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55662 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55663 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55664 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55665 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55666 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55667 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55668 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55669 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55670 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55671 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55672 +4 4 4 4 4 4 4 4 4 4 4 4 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
55675 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55676 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55677 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55678 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55679 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55680 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55681 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55682 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55683 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55684 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55685 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55686 +4 4 4 4 4 4 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
55689 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55690 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55691 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55692 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55693 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55694 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55695 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55696 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55697 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55698 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55699 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55700 +4 4 4 4 4 4 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
55703 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55704 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55705 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55706 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55707 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55708 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55709 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55710 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55711 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55712 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55713 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
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
55717 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55718 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55719 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55720 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55721 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55722 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55723 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55724 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55725 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
55726 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55727 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
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
55731 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55732 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55733 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55734 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55735 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55736 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55737 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55738 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55739 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55740 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55741 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 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
55745 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55746 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55747 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55748 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55749 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55750 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55751 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55752 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55753 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55754 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55755 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 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
55759 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55760 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55761 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55762 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55763 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55764 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55765 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55766 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55767 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55768 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55769 +0 0 0 3 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
55773 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55774 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55775 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55776 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55777 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55778 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55779 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55780 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55781 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55782 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55783 +0 0 0 3 3 3 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
55787 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55788 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55789 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55790 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55791 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55792 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55793 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55794 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55795 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55796 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55797 +0 0 0 3 3 3 5 5 5 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
55801 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55802 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55803 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55804 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55805 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55806 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55807 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55808 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55809 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55810 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55811 +0 0 0 3 3 3 5 5 5 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
55815 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55816 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55817 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55818 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55819 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55820 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55821 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55822 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55823 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55824 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55825 +0 0 0 3 3 3 5 5 5 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
55829 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55830 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55831 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55832 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55833 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55834 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55835 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55836 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55837 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55838 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55839 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55842 +4 4 4 4 4 4
55843 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55844 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55845 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55846 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55847 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55848 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55849 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55850 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55851 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55852 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55853 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55856 +4 4 4 4 4 4
55857 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55858 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55859 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55860 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55861 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55862 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55863 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55864 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55865 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55866 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55867 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55870 +4 4 4 4 4 4
55871 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55872 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55873 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55874 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55875 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55876 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55877 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55878 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55879 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55880 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55881 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55884 +4 4 4 4 4 4
55885 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55886 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55887 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55888 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55889 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55890 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55891 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55892 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55893 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55894 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55895 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55898 +4 4 4 4 4 4
55899 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55900 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55901 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55902 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55903 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55904 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55905 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55906 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55907 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55908 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
55909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55912 +4 4 4 4 4 4
55913 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55914 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55915 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55916 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55917 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55918 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55919 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55920 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55921 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55922 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55925 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55926 +4 4 4 4 4 4
55927 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55928 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55929 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55930 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55931 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55932 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55933 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55934 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55935 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55936 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55939 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55940 +4 4 4 4 4 4
55941 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55942 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55943 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55944 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55945 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55946 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55947 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55948 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55949 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55950 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55953 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55954 +4 4 4 4 4 4
55955 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55956 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55957 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55958 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55959 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55960 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55961 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55962 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55963 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55968 +4 4 4 4 4 4
55969 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55970 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55971 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55972 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55973 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55974 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55975 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55976 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55977 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
55978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55982 +4 4 4 4 4 4
55983 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55984 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55985 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55986 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55987 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55988 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55989 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55990 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55991 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55996 +4 4 4 4 4 4
55997 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55998 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55999 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
56000 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
56001 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
56002 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
56003 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
56004 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
56005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56010 +4 4 4 4 4 4
56011 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
56012 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
56013 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
56014 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
56015 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
56016 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
56017 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
56018 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
56019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56024 +4 4 4 4 4 4
56025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
56026 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
56027 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56028 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
56029 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
56030 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
56031 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
56032 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
56033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56038 +4 4 4 4 4 4
56039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56040 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
56041 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
56042 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
56043 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
56044 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
56045 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
56046 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
56047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56052 +4 4 4 4 4 4
56053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56054 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
56055 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
56056 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
56057 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
56058 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
56059 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
56060 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
56061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56066 +4 4 4 4 4 4
56067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56069 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
56070 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
56071 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
56072 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
56073 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
56074 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
56075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56080 +4 4 4 4 4 4
56081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
56084 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56085 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
56086 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
56087 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
56088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56094 +4 4 4 4 4 4
56095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56098 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
56099 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
56100 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
56101 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
56102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56108 +4 4 4 4 4 4
56109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56112 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
56113 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
56114 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
56115 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
56116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56122 +4 4 4 4 4 4
56123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56126 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
56127 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
56128 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
56129 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
56130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56136 +4 4 4 4 4 4
56137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
56141 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
56142 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56143 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
56144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56150 +4 4 4 4 4 4
56151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56155 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
56156 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
56157 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
56158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56164 +4 4 4 4 4 4
56165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56169 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
56170 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
56171 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56178 +4 4 4 4 4 4
56179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56183 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
56184 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
56185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56192 +4 4 4 4 4 4
56193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56197 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
56198 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
56199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56206 +4 4 4 4 4 4
56207 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
56208 index fef20db..d28b1ab 100644
56209 --- a/drivers/xen/xenfs/xenstored.c
56210 +++ b/drivers/xen/xenfs/xenstored.c
56211 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
56212 static int xsd_kva_open(struct inode *inode, struct file *file)
56213 {
56214 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
56215 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56216 + NULL);
56217 +#else
56218 xen_store_interface);
56219 +#endif
56220 +
56221 if (!file->private_data)
56222 return -ENOMEM;
56223 return 0;
56224 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
56225 index c71e886..61d3d44b 100644
56226 --- a/fs/9p/vfs_addr.c
56227 +++ b/fs/9p/vfs_addr.c
56228 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
56229
56230 retval = v9fs_file_write_internal(inode,
56231 v9inode->writeback_fid,
56232 - (__force const char __user *)buffer,
56233 + (const char __force_user *)buffer,
56234 len, &offset, 0);
56235 if (retval > 0)
56236 retval = 0;
56237 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
56238 index 53161ec..e261d8a 100644
56239 --- a/fs/9p/vfs_inode.c
56240 +++ b/fs/9p/vfs_inode.c
56241 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56242 void
56243 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
56244 {
56245 - char *s = nd_get_link(nd);
56246 + const char *s = nd_get_link(nd);
56247
56248 p9_debug(P9_DEBUG_VFS, " %s %s\n",
56249 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
56250 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
56251 index 370b24c..ff0be7b 100644
56252 --- a/fs/Kconfig.binfmt
56253 +++ b/fs/Kconfig.binfmt
56254 @@ -103,7 +103,7 @@ config HAVE_AOUT
56255
56256 config BINFMT_AOUT
56257 tristate "Kernel support for a.out and ECOFF binaries"
56258 - depends on HAVE_AOUT
56259 + depends on HAVE_AOUT && BROKEN
56260 ---help---
56261 A.out (Assembler.OUTput) is a set of formats for libraries and
56262 executables used in the earliest versions of UNIX. Linux used
56263 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
56264 index 2946712..f737435 100644
56265 --- a/fs/afs/inode.c
56266 +++ b/fs/afs/inode.c
56267 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56268 struct afs_vnode *vnode;
56269 struct super_block *sb;
56270 struct inode *inode;
56271 - static atomic_t afs_autocell_ino;
56272 + static atomic_unchecked_t afs_autocell_ino;
56273
56274 _enter("{%x:%u},%*.*s,",
56275 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
56276 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56277 data.fid.unique = 0;
56278 data.fid.vnode = 0;
56279
56280 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
56281 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
56282 afs_iget5_autocell_test, afs_iget5_set,
56283 &data);
56284 if (!inode) {
56285 diff --git a/fs/aio.c b/fs/aio.c
56286 index e609e15..c9fcd97 100644
56287 --- a/fs/aio.c
56288 +++ b/fs/aio.c
56289 @@ -380,7 +380,7 @@ static int aio_setup_ring(struct kioctx *ctx)
56290 size += sizeof(struct io_event) * nr_events;
56291
56292 nr_pages = PFN_UP(size);
56293 - if (nr_pages < 0)
56294 + if (nr_pages <= 0)
56295 return -EINVAL;
56296
56297 file = aio_private_file(ctx, nr_pages);
56298 diff --git a/fs/attr.c b/fs/attr.c
56299 index 6530ced..4a827e2 100644
56300 --- a/fs/attr.c
56301 +++ b/fs/attr.c
56302 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
56303 unsigned long limit;
56304
56305 limit = rlimit(RLIMIT_FSIZE);
56306 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
56307 if (limit != RLIM_INFINITY && offset > limit)
56308 goto out_sig;
56309 if (offset > inode->i_sb->s_maxbytes)
56310 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
56311 index 116fd38..c04182da 100644
56312 --- a/fs/autofs4/waitq.c
56313 +++ b/fs/autofs4/waitq.c
56314 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
56315 {
56316 unsigned long sigpipe, flags;
56317 mm_segment_t fs;
56318 - const char *data = (const char *)addr;
56319 + const char __user *data = (const char __force_user *)addr;
56320 ssize_t wr = 0;
56321
56322 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
56323 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
56324 return 1;
56325 }
56326
56327 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56328 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56329 +#endif
56330 +
56331 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56332 enum autofs_notify notify)
56333 {
56334 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56335
56336 /* If this is a direct mount request create a dummy name */
56337 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56338 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56339 + /* this name does get written to userland via autofs4_write() */
56340 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56341 +#else
56342 qstr.len = sprintf(name, "%p", dentry);
56343 +#endif
56344 else {
56345 qstr.len = autofs4_getpath(sbi, dentry, &name);
56346 if (!qstr.len) {
56347 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56348 index 2722387..56059b5 100644
56349 --- a/fs/befs/endian.h
56350 +++ b/fs/befs/endian.h
56351 @@ -11,7 +11,7 @@
56352
56353 #include <asm/byteorder.h>
56354
56355 -static inline u64
56356 +static inline u64 __intentional_overflow(-1)
56357 fs64_to_cpu(const struct super_block *sb, fs64 n)
56358 {
56359 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56360 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56361 return (__force fs64)cpu_to_be64(n);
56362 }
56363
56364 -static inline u32
56365 +static inline u32 __intentional_overflow(-1)
56366 fs32_to_cpu(const struct super_block *sb, fs32 n)
56367 {
56368 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56369 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56370 return (__force fs32)cpu_to_be32(n);
56371 }
56372
56373 -static inline u16
56374 +static inline u16 __intentional_overflow(-1)
56375 fs16_to_cpu(const struct super_block *sb, fs16 n)
56376 {
56377 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56378 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56379 index ca0ba15..0fa3257 100644
56380 --- a/fs/binfmt_aout.c
56381 +++ b/fs/binfmt_aout.c
56382 @@ -16,6 +16,7 @@
56383 #include <linux/string.h>
56384 #include <linux/fs.h>
56385 #include <linux/file.h>
56386 +#include <linux/security.h>
56387 #include <linux/stat.h>
56388 #include <linux/fcntl.h>
56389 #include <linux/ptrace.h>
56390 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56391 #endif
56392 # define START_STACK(u) ((void __user *)u.start_stack)
56393
56394 + memset(&dump, 0, sizeof(dump));
56395 +
56396 fs = get_fs();
56397 set_fs(KERNEL_DS);
56398 has_dumped = 1;
56399 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56400
56401 /* If the size of the dump file exceeds the rlimit, then see what would happen
56402 if we wrote the stack, but not the data area. */
56403 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56404 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56405 dump.u_dsize = 0;
56406
56407 /* Make sure we have enough room to write the stack and data areas. */
56408 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56409 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56410 dump.u_ssize = 0;
56411
56412 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56413 rlim = rlimit(RLIMIT_DATA);
56414 if (rlim >= RLIM_INFINITY)
56415 rlim = ~0;
56416 +
56417 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56418 if (ex.a_data + ex.a_bss > rlim)
56419 return -ENOMEM;
56420
56421 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56422
56423 install_exec_creds(bprm);
56424
56425 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56426 + current->mm->pax_flags = 0UL;
56427 +#endif
56428 +
56429 +#ifdef CONFIG_PAX_PAGEEXEC
56430 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56431 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56432 +
56433 +#ifdef CONFIG_PAX_EMUTRAMP
56434 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56435 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56436 +#endif
56437 +
56438 +#ifdef CONFIG_PAX_MPROTECT
56439 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56440 + current->mm->pax_flags |= MF_PAX_MPROTECT;
56441 +#endif
56442 +
56443 + }
56444 +#endif
56445 +
56446 if (N_MAGIC(ex) == OMAGIC) {
56447 unsigned long text_addr, map_size;
56448 loff_t pos;
56449 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56450 }
56451
56452 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56453 - PROT_READ | PROT_WRITE | PROT_EXEC,
56454 + PROT_READ | PROT_WRITE,
56455 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56456 fd_offset + ex.a_text);
56457 if (error != N_DATADDR(ex)) {
56458 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56459 index aa3cb62..bc53934 100644
56460 --- a/fs/binfmt_elf.c
56461 +++ b/fs/binfmt_elf.c
56462 @@ -34,6 +34,7 @@
56463 #include <linux/utsname.h>
56464 #include <linux/coredump.h>
56465 #include <linux/sched.h>
56466 +#include <linux/xattr.h>
56467 #include <asm/uaccess.h>
56468 #include <asm/param.h>
56469 #include <asm/page.h>
56470 @@ -47,7 +48,7 @@
56471
56472 static int load_elf_binary(struct linux_binprm *bprm);
56473 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56474 - int, int, unsigned long);
56475 + int, int, unsigned long) __intentional_overflow(-1);
56476
56477 #ifdef CONFIG_USELIB
56478 static int load_elf_library(struct file *);
56479 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56480 #define elf_core_dump NULL
56481 #endif
56482
56483 +#ifdef CONFIG_PAX_MPROTECT
56484 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56485 +#endif
56486 +
56487 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56488 +static void elf_handle_mmap(struct file *file);
56489 +#endif
56490 +
56491 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56492 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56493 #else
56494 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
56495 .load_binary = load_elf_binary,
56496 .load_shlib = load_elf_library,
56497 .core_dump = elf_core_dump,
56498 +
56499 +#ifdef CONFIG_PAX_MPROTECT
56500 + .handle_mprotect= elf_handle_mprotect,
56501 +#endif
56502 +
56503 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56504 + .handle_mmap = elf_handle_mmap,
56505 +#endif
56506 +
56507 .min_coredump = ELF_EXEC_PAGESIZE,
56508 };
56509
56510 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
56511
56512 static int set_brk(unsigned long start, unsigned long end)
56513 {
56514 + unsigned long e = end;
56515 +
56516 start = ELF_PAGEALIGN(start);
56517 end = ELF_PAGEALIGN(end);
56518 if (end > start) {
56519 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
56520 if (BAD_ADDR(addr))
56521 return addr;
56522 }
56523 - current->mm->start_brk = current->mm->brk = end;
56524 + current->mm->start_brk = current->mm->brk = e;
56525 return 0;
56526 }
56527
56528 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56529 elf_addr_t __user *u_rand_bytes;
56530 const char *k_platform = ELF_PLATFORM;
56531 const char *k_base_platform = ELF_BASE_PLATFORM;
56532 - unsigned char k_rand_bytes[16];
56533 + u32 k_rand_bytes[4];
56534 int items;
56535 elf_addr_t *elf_info;
56536 int ei_index = 0;
56537 const struct cred *cred = current_cred();
56538 struct vm_area_struct *vma;
56539 + unsigned long saved_auxv[AT_VECTOR_SIZE];
56540
56541 /*
56542 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56543 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56544 * Generate 16 random bytes for userspace PRNG seeding.
56545 */
56546 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56547 - u_rand_bytes = (elf_addr_t __user *)
56548 - STACK_ALLOC(p, sizeof(k_rand_bytes));
56549 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56550 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56551 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56552 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56553 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
56554 + u_rand_bytes = (elf_addr_t __user *) p;
56555 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56556 return -EFAULT;
56557
56558 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56559 return -EFAULT;
56560 current->mm->env_end = p;
56561
56562 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56563 +
56564 /* Put the elf_info on the stack in the right place. */
56565 sp = (elf_addr_t __user *)envp + 1;
56566 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56567 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56568 return -EFAULT;
56569 return 0;
56570 }
56571 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56572 an ELF header */
56573
56574 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56575 - struct file *interpreter, unsigned long *interp_map_addr,
56576 - unsigned long no_base)
56577 + struct file *interpreter, unsigned long no_base)
56578 {
56579 struct elf_phdr *elf_phdata;
56580 struct elf_phdr *eppnt;
56581 - unsigned long load_addr = 0;
56582 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56583 int load_addr_set = 0;
56584 unsigned long last_bss = 0, elf_bss = 0;
56585 - unsigned long error = ~0UL;
56586 + unsigned long error = -EINVAL;
56587 unsigned long total_size;
56588 int retval, i, size;
56589
56590 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56591 goto out_close;
56592 }
56593
56594 +#ifdef CONFIG_PAX_SEGMEXEC
56595 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56596 + pax_task_size = SEGMEXEC_TASK_SIZE;
56597 +#endif
56598 +
56599 eppnt = elf_phdata;
56600 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56601 if (eppnt->p_type == PT_LOAD) {
56602 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56603 map_addr = elf_map(interpreter, load_addr + vaddr,
56604 eppnt, elf_prot, elf_type, total_size);
56605 total_size = 0;
56606 - if (!*interp_map_addr)
56607 - *interp_map_addr = map_addr;
56608 error = map_addr;
56609 if (BAD_ADDR(map_addr))
56610 goto out_close;
56611 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56612 k = load_addr + eppnt->p_vaddr;
56613 if (BAD_ADDR(k) ||
56614 eppnt->p_filesz > eppnt->p_memsz ||
56615 - eppnt->p_memsz > TASK_SIZE ||
56616 - TASK_SIZE - eppnt->p_memsz < k) {
56617 + eppnt->p_memsz > pax_task_size ||
56618 + pax_task_size - eppnt->p_memsz < k) {
56619 error = -ENOMEM;
56620 goto out_close;
56621 }
56622 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56623 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56624
56625 /* Map the last of the bss segment */
56626 - error = vm_brk(elf_bss, last_bss - elf_bss);
56627 - if (BAD_ADDR(error))
56628 - goto out_close;
56629 + if (last_bss > elf_bss) {
56630 + error = vm_brk(elf_bss, last_bss - elf_bss);
56631 + if (BAD_ADDR(error))
56632 + goto out_close;
56633 + }
56634 }
56635
56636 error = load_addr;
56637 @@ -543,6 +574,336 @@ out:
56638 return error;
56639 }
56640
56641 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56642 +#ifdef CONFIG_PAX_SOFTMODE
56643 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56644 +{
56645 + unsigned long pax_flags = 0UL;
56646 +
56647 +#ifdef CONFIG_PAX_PAGEEXEC
56648 + if (elf_phdata->p_flags & PF_PAGEEXEC)
56649 + pax_flags |= MF_PAX_PAGEEXEC;
56650 +#endif
56651 +
56652 +#ifdef CONFIG_PAX_SEGMEXEC
56653 + if (elf_phdata->p_flags & PF_SEGMEXEC)
56654 + pax_flags |= MF_PAX_SEGMEXEC;
56655 +#endif
56656 +
56657 +#ifdef CONFIG_PAX_EMUTRAMP
56658 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56659 + pax_flags |= MF_PAX_EMUTRAMP;
56660 +#endif
56661 +
56662 +#ifdef CONFIG_PAX_MPROTECT
56663 + if (elf_phdata->p_flags & PF_MPROTECT)
56664 + pax_flags |= MF_PAX_MPROTECT;
56665 +#endif
56666 +
56667 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56668 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56669 + pax_flags |= MF_PAX_RANDMMAP;
56670 +#endif
56671 +
56672 + return pax_flags;
56673 +}
56674 +#endif
56675 +
56676 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56677 +{
56678 + unsigned long pax_flags = 0UL;
56679 +
56680 +#ifdef CONFIG_PAX_PAGEEXEC
56681 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56682 + pax_flags |= MF_PAX_PAGEEXEC;
56683 +#endif
56684 +
56685 +#ifdef CONFIG_PAX_SEGMEXEC
56686 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56687 + pax_flags |= MF_PAX_SEGMEXEC;
56688 +#endif
56689 +
56690 +#ifdef CONFIG_PAX_EMUTRAMP
56691 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56692 + pax_flags |= MF_PAX_EMUTRAMP;
56693 +#endif
56694 +
56695 +#ifdef CONFIG_PAX_MPROTECT
56696 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56697 + pax_flags |= MF_PAX_MPROTECT;
56698 +#endif
56699 +
56700 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56701 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56702 + pax_flags |= MF_PAX_RANDMMAP;
56703 +#endif
56704 +
56705 + return pax_flags;
56706 +}
56707 +#endif
56708 +
56709 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56710 +#ifdef CONFIG_PAX_SOFTMODE
56711 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56712 +{
56713 + unsigned long pax_flags = 0UL;
56714 +
56715 +#ifdef CONFIG_PAX_PAGEEXEC
56716 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56717 + pax_flags |= MF_PAX_PAGEEXEC;
56718 +#endif
56719 +
56720 +#ifdef CONFIG_PAX_SEGMEXEC
56721 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56722 + pax_flags |= MF_PAX_SEGMEXEC;
56723 +#endif
56724 +
56725 +#ifdef CONFIG_PAX_EMUTRAMP
56726 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56727 + pax_flags |= MF_PAX_EMUTRAMP;
56728 +#endif
56729 +
56730 +#ifdef CONFIG_PAX_MPROTECT
56731 + if (pax_flags_softmode & MF_PAX_MPROTECT)
56732 + pax_flags |= MF_PAX_MPROTECT;
56733 +#endif
56734 +
56735 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56736 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56737 + pax_flags |= MF_PAX_RANDMMAP;
56738 +#endif
56739 +
56740 + return pax_flags;
56741 +}
56742 +#endif
56743 +
56744 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56745 +{
56746 + unsigned long pax_flags = 0UL;
56747 +
56748 +#ifdef CONFIG_PAX_PAGEEXEC
56749 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56750 + pax_flags |= MF_PAX_PAGEEXEC;
56751 +#endif
56752 +
56753 +#ifdef CONFIG_PAX_SEGMEXEC
56754 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56755 + pax_flags |= MF_PAX_SEGMEXEC;
56756 +#endif
56757 +
56758 +#ifdef CONFIG_PAX_EMUTRAMP
56759 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56760 + pax_flags |= MF_PAX_EMUTRAMP;
56761 +#endif
56762 +
56763 +#ifdef CONFIG_PAX_MPROTECT
56764 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56765 + pax_flags |= MF_PAX_MPROTECT;
56766 +#endif
56767 +
56768 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56769 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56770 + pax_flags |= MF_PAX_RANDMMAP;
56771 +#endif
56772 +
56773 + return pax_flags;
56774 +}
56775 +#endif
56776 +
56777 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56778 +static unsigned long pax_parse_defaults(void)
56779 +{
56780 + unsigned long pax_flags = 0UL;
56781 +
56782 +#ifdef CONFIG_PAX_SOFTMODE
56783 + if (pax_softmode)
56784 + return pax_flags;
56785 +#endif
56786 +
56787 +#ifdef CONFIG_PAX_PAGEEXEC
56788 + pax_flags |= MF_PAX_PAGEEXEC;
56789 +#endif
56790 +
56791 +#ifdef CONFIG_PAX_SEGMEXEC
56792 + pax_flags |= MF_PAX_SEGMEXEC;
56793 +#endif
56794 +
56795 +#ifdef CONFIG_PAX_MPROTECT
56796 + pax_flags |= MF_PAX_MPROTECT;
56797 +#endif
56798 +
56799 +#ifdef CONFIG_PAX_RANDMMAP
56800 + if (randomize_va_space)
56801 + pax_flags |= MF_PAX_RANDMMAP;
56802 +#endif
56803 +
56804 + return pax_flags;
56805 +}
56806 +
56807 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56808 +{
56809 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56810 +
56811 +#ifdef CONFIG_PAX_EI_PAX
56812 +
56813 +#ifdef CONFIG_PAX_SOFTMODE
56814 + if (pax_softmode)
56815 + return pax_flags;
56816 +#endif
56817 +
56818 + pax_flags = 0UL;
56819 +
56820 +#ifdef CONFIG_PAX_PAGEEXEC
56821 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56822 + pax_flags |= MF_PAX_PAGEEXEC;
56823 +#endif
56824 +
56825 +#ifdef CONFIG_PAX_SEGMEXEC
56826 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56827 + pax_flags |= MF_PAX_SEGMEXEC;
56828 +#endif
56829 +
56830 +#ifdef CONFIG_PAX_EMUTRAMP
56831 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56832 + pax_flags |= MF_PAX_EMUTRAMP;
56833 +#endif
56834 +
56835 +#ifdef CONFIG_PAX_MPROTECT
56836 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56837 + pax_flags |= MF_PAX_MPROTECT;
56838 +#endif
56839 +
56840 +#ifdef CONFIG_PAX_ASLR
56841 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56842 + pax_flags |= MF_PAX_RANDMMAP;
56843 +#endif
56844 +
56845 +#endif
56846 +
56847 + return pax_flags;
56848 +
56849 +}
56850 +
56851 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56852 +{
56853 +
56854 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56855 + unsigned long i;
56856 +
56857 + for (i = 0UL; i < elf_ex->e_phnum; i++)
56858 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56859 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56860 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56861 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56862 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56863 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56864 + return PAX_PARSE_FLAGS_FALLBACK;
56865 +
56866 +#ifdef CONFIG_PAX_SOFTMODE
56867 + if (pax_softmode)
56868 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56869 + else
56870 +#endif
56871 +
56872 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56873 + break;
56874 + }
56875 +#endif
56876 +
56877 + return PAX_PARSE_FLAGS_FALLBACK;
56878 +}
56879 +
56880 +static unsigned long pax_parse_xattr_pax(struct file * const file)
56881 +{
56882 +
56883 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56884 + ssize_t xattr_size, i;
56885 + unsigned char xattr_value[sizeof("pemrs") - 1];
56886 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56887 +
56888 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56889 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56890 + return PAX_PARSE_FLAGS_FALLBACK;
56891 +
56892 + for (i = 0; i < xattr_size; i++)
56893 + switch (xattr_value[i]) {
56894 + default:
56895 + return PAX_PARSE_FLAGS_FALLBACK;
56896 +
56897 +#define parse_flag(option1, option2, flag) \
56898 + case option1: \
56899 + if (pax_flags_hardmode & MF_PAX_##flag) \
56900 + return PAX_PARSE_FLAGS_FALLBACK;\
56901 + pax_flags_hardmode |= MF_PAX_##flag; \
56902 + break; \
56903 + case option2: \
56904 + if (pax_flags_softmode & MF_PAX_##flag) \
56905 + return PAX_PARSE_FLAGS_FALLBACK;\
56906 + pax_flags_softmode |= MF_PAX_##flag; \
56907 + break;
56908 +
56909 + parse_flag('p', 'P', PAGEEXEC);
56910 + parse_flag('e', 'E', EMUTRAMP);
56911 + parse_flag('m', 'M', MPROTECT);
56912 + parse_flag('r', 'R', RANDMMAP);
56913 + parse_flag('s', 'S', SEGMEXEC);
56914 +
56915 +#undef parse_flag
56916 + }
56917 +
56918 + if (pax_flags_hardmode & pax_flags_softmode)
56919 + return PAX_PARSE_FLAGS_FALLBACK;
56920 +
56921 +#ifdef CONFIG_PAX_SOFTMODE
56922 + if (pax_softmode)
56923 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56924 + else
56925 +#endif
56926 +
56927 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56928 +#else
56929 + return PAX_PARSE_FLAGS_FALLBACK;
56930 +#endif
56931 +
56932 +}
56933 +
56934 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56935 +{
56936 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56937 +
56938 + pax_flags = pax_parse_defaults();
56939 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
56940 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56941 + xattr_pax_flags = pax_parse_xattr_pax(file);
56942 +
56943 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56944 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56945 + pt_pax_flags != xattr_pax_flags)
56946 + return -EINVAL;
56947 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56948 + pax_flags = xattr_pax_flags;
56949 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56950 + pax_flags = pt_pax_flags;
56951 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56952 + pax_flags = ei_pax_flags;
56953 +
56954 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56955 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56956 + if ((__supported_pte_mask & _PAGE_NX))
56957 + pax_flags &= ~MF_PAX_SEGMEXEC;
56958 + else
56959 + pax_flags &= ~MF_PAX_PAGEEXEC;
56960 + }
56961 +#endif
56962 +
56963 + if (0 > pax_check_flags(&pax_flags))
56964 + return -EINVAL;
56965 +
56966 + current->mm->pax_flags = pax_flags;
56967 + return 0;
56968 +}
56969 +#endif
56970 +
56971 /*
56972 * These are the functions used to load ELF style executables and shared
56973 * libraries. There is no binary dependent code anywhere else.
56974 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56975 {
56976 unsigned int random_variable = 0;
56977
56978 +#ifdef CONFIG_PAX_RANDUSTACK
56979 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56980 + return stack_top - current->mm->delta_stack;
56981 +#endif
56982 +
56983 if ((current->flags & PF_RANDOMIZE) &&
56984 !(current->personality & ADDR_NO_RANDOMIZE)) {
56985 random_variable = get_random_int() & STACK_RND_MASK;
56986 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56987 unsigned long load_addr = 0, load_bias = 0;
56988 int load_addr_set = 0;
56989 char * elf_interpreter = NULL;
56990 - unsigned long error;
56991 + unsigned long error = 0;
56992 struct elf_phdr *elf_ppnt, *elf_phdata;
56993 unsigned long elf_bss, elf_brk;
56994 int retval, i;
56995 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56996 struct elfhdr elf_ex;
56997 struct elfhdr interp_elf_ex;
56998 } *loc;
56999 + unsigned long pax_task_size;
57000
57001 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
57002 if (!loc) {
57003 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
57004 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
57005 may depend on the personality. */
57006 SET_PERSONALITY(loc->elf_ex);
57007 +
57008 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57009 + current->mm->pax_flags = 0UL;
57010 +#endif
57011 +
57012 +#ifdef CONFIG_PAX_DLRESOLVE
57013 + current->mm->call_dl_resolve = 0UL;
57014 +#endif
57015 +
57016 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
57017 + current->mm->call_syscall = 0UL;
57018 +#endif
57019 +
57020 +#ifdef CONFIG_PAX_ASLR
57021 + current->mm->delta_mmap = 0UL;
57022 + current->mm->delta_stack = 0UL;
57023 +#endif
57024 +
57025 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57026 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
57027 + send_sig(SIGKILL, current, 0);
57028 + goto out_free_dentry;
57029 + }
57030 +#endif
57031 +
57032 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57033 + pax_set_initial_flags(bprm);
57034 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
57035 + if (pax_set_initial_flags_func)
57036 + (pax_set_initial_flags_func)(bprm);
57037 +#endif
57038 +
57039 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
57040 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
57041 + current->mm->context.user_cs_limit = PAGE_SIZE;
57042 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
57043 + }
57044 +#endif
57045 +
57046 +#ifdef CONFIG_PAX_SEGMEXEC
57047 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
57048 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
57049 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
57050 + pax_task_size = SEGMEXEC_TASK_SIZE;
57051 + current->mm->def_flags |= VM_NOHUGEPAGE;
57052 + } else
57053 +#endif
57054 +
57055 + pax_task_size = TASK_SIZE;
57056 +
57057 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
57058 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57059 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
57060 + put_cpu();
57061 + }
57062 +#endif
57063 +
57064 +#ifdef CONFIG_PAX_ASLR
57065 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57066 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
57067 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
57068 + }
57069 +#endif
57070 +
57071 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57072 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57073 + executable_stack = EXSTACK_DISABLE_X;
57074 + current->personality &= ~READ_IMPLIES_EXEC;
57075 + } else
57076 +#endif
57077 +
57078 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
57079 current->personality |= READ_IMPLIES_EXEC;
57080
57081 @@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
57082 #else
57083 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
57084 #endif
57085 +
57086 +#ifdef CONFIG_PAX_RANDMMAP
57087 + /* PaX: randomize base address at the default exe base if requested */
57088 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
57089 +#ifdef CONFIG_SPARC64
57090 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
57091 +#else
57092 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
57093 +#endif
57094 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
57095 + elf_flags |= MAP_FIXED;
57096 + }
57097 +#endif
57098 +
57099 }
57100
57101 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
57102 @@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
57103 * allowed task size. Note that p_filesz must always be
57104 * <= p_memsz so it is only necessary to check p_memsz.
57105 */
57106 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57107 - elf_ppnt->p_memsz > TASK_SIZE ||
57108 - TASK_SIZE - elf_ppnt->p_memsz < k) {
57109 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57110 + elf_ppnt->p_memsz > pax_task_size ||
57111 + pax_task_size - elf_ppnt->p_memsz < k) {
57112 /* set_brk can never work. Avoid overflows. */
57113 send_sig(SIGKILL, current, 0);
57114 retval = -EINVAL;
57115 @@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
57116 goto out_free_dentry;
57117 }
57118 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
57119 - send_sig(SIGSEGV, current, 0);
57120 - retval = -EFAULT; /* Nobody gets to see this, but.. */
57121 - goto out_free_dentry;
57122 + /*
57123 + * This bss-zeroing can fail if the ELF
57124 + * file specifies odd protections. So
57125 + * we don't check the return value
57126 + */
57127 }
57128
57129 +#ifdef CONFIG_PAX_RANDMMAP
57130 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57131 + unsigned long start, size, flags;
57132 + vm_flags_t vm_flags;
57133 +
57134 + start = ELF_PAGEALIGN(elf_brk);
57135 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
57136 + flags = MAP_FIXED | MAP_PRIVATE;
57137 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
57138 +
57139 + down_write(&current->mm->mmap_sem);
57140 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
57141 + retval = -ENOMEM;
57142 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
57143 +// if (current->personality & ADDR_NO_RANDOMIZE)
57144 +// vm_flags |= VM_READ | VM_MAYREAD;
57145 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
57146 + retval = IS_ERR_VALUE(start) ? start : 0;
57147 + }
57148 + up_write(&current->mm->mmap_sem);
57149 + if (retval == 0)
57150 + retval = set_brk(start + size, start + size + PAGE_SIZE);
57151 + if (retval < 0) {
57152 + send_sig(SIGKILL, current, 0);
57153 + goto out_free_dentry;
57154 + }
57155 + }
57156 +#endif
57157 +
57158 if (elf_interpreter) {
57159 - unsigned long interp_map_addr = 0;
57160 -
57161 elf_entry = load_elf_interp(&loc->interp_elf_ex,
57162 interpreter,
57163 - &interp_map_addr,
57164 load_bias);
57165 if (!IS_ERR((void *)elf_entry)) {
57166 /*
57167 @@ -1122,7 +1602,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
57168 * Decide what to dump of a segment, part, all or none.
57169 */
57170 static unsigned long vma_dump_size(struct vm_area_struct *vma,
57171 - unsigned long mm_flags)
57172 + unsigned long mm_flags, long signr)
57173 {
57174 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
57175
57176 @@ -1160,7 +1640,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
57177 if (vma->vm_file == NULL)
57178 return 0;
57179
57180 - if (FILTER(MAPPED_PRIVATE))
57181 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
57182 goto whole;
57183
57184 /*
57185 @@ -1367,9 +1847,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
57186 {
57187 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
57188 int i = 0;
57189 - do
57190 + do {
57191 i += 2;
57192 - while (auxv[i - 2] != AT_NULL);
57193 + } while (auxv[i - 2] != AT_NULL);
57194 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
57195 }
57196
57197 @@ -1378,7 +1858,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
57198 {
57199 mm_segment_t old_fs = get_fs();
57200 set_fs(KERNEL_DS);
57201 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
57202 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
57203 set_fs(old_fs);
57204 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
57205 }
57206 @@ -2002,14 +2482,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
57207 }
57208
57209 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
57210 - unsigned long mm_flags)
57211 + struct coredump_params *cprm)
57212 {
57213 struct vm_area_struct *vma;
57214 size_t size = 0;
57215
57216 for (vma = first_vma(current, gate_vma); vma != NULL;
57217 vma = next_vma(vma, gate_vma))
57218 - size += vma_dump_size(vma, mm_flags);
57219 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57220 return size;
57221 }
57222
57223 @@ -2100,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57224
57225 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
57226
57227 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
57228 + offset += elf_core_vma_data_size(gate_vma, cprm);
57229 offset += elf_core_extra_data_size();
57230 e_shoff = offset;
57231
57232 @@ -2128,7 +2608,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57233 phdr.p_offset = offset;
57234 phdr.p_vaddr = vma->vm_start;
57235 phdr.p_paddr = 0;
57236 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
57237 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57238 phdr.p_memsz = vma->vm_end - vma->vm_start;
57239 offset += phdr.p_filesz;
57240 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
57241 @@ -2161,7 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57242 unsigned long addr;
57243 unsigned long end;
57244
57245 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
57246 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57247
57248 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
57249 struct page *page;
57250 @@ -2202,6 +2682,167 @@ out:
57251
57252 #endif /* CONFIG_ELF_CORE */
57253
57254 +#ifdef CONFIG_PAX_MPROTECT
57255 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
57256 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
57257 + * we'll remove VM_MAYWRITE for good on RELRO segments.
57258 + *
57259 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
57260 + * basis because we want to allow the common case and not the special ones.
57261 + */
57262 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
57263 +{
57264 + struct elfhdr elf_h;
57265 + struct elf_phdr elf_p;
57266 + unsigned long i;
57267 + unsigned long oldflags;
57268 + bool is_textrel_rw, is_textrel_rx, is_relro;
57269 +
57270 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
57271 + return;
57272 +
57273 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
57274 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
57275 +
57276 +#ifdef CONFIG_PAX_ELFRELOCS
57277 + /* possible TEXTREL */
57278 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
57279 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
57280 +#else
57281 + is_textrel_rw = false;
57282 + is_textrel_rx = false;
57283 +#endif
57284 +
57285 + /* possible RELRO */
57286 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
57287 +
57288 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
57289 + return;
57290 +
57291 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57292 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57293 +
57294 +#ifdef CONFIG_PAX_ETEXECRELOCS
57295 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57296 +#else
57297 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
57298 +#endif
57299 +
57300 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57301 + !elf_check_arch(&elf_h) ||
57302 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57303 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57304 + return;
57305 +
57306 + for (i = 0UL; i < elf_h.e_phnum; i++) {
57307 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57308 + return;
57309 + switch (elf_p.p_type) {
57310 + case PT_DYNAMIC:
57311 + if (!is_textrel_rw && !is_textrel_rx)
57312 + continue;
57313 + i = 0UL;
57314 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
57315 + elf_dyn dyn;
57316 +
57317 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
57318 + break;
57319 + if (dyn.d_tag == DT_NULL)
57320 + break;
57321 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
57322 + gr_log_textrel(vma);
57323 + if (is_textrel_rw)
57324 + vma->vm_flags |= VM_MAYWRITE;
57325 + else
57326 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
57327 + vma->vm_flags &= ~VM_MAYWRITE;
57328 + break;
57329 + }
57330 + i++;
57331 + }
57332 + is_textrel_rw = false;
57333 + is_textrel_rx = false;
57334 + continue;
57335 +
57336 + case PT_GNU_RELRO:
57337 + if (!is_relro)
57338 + continue;
57339 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57340 + vma->vm_flags &= ~VM_MAYWRITE;
57341 + is_relro = false;
57342 + continue;
57343 +
57344 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
57345 + case PT_PAX_FLAGS: {
57346 + const char *msg_mprotect = "", *msg_emutramp = "";
57347 + char *buffer_lib, *buffer_exe;
57348 +
57349 + if (elf_p.p_flags & PF_NOMPROTECT)
57350 + msg_mprotect = "MPROTECT disabled";
57351 +
57352 +#ifdef CONFIG_PAX_EMUTRAMP
57353 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57354 + msg_emutramp = "EMUTRAMP enabled";
57355 +#endif
57356 +
57357 + if (!msg_mprotect[0] && !msg_emutramp[0])
57358 + continue;
57359 +
57360 + if (!printk_ratelimit())
57361 + continue;
57362 +
57363 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57364 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57365 + if (buffer_lib && buffer_exe) {
57366 + char *path_lib, *path_exe;
57367 +
57368 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57369 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57370 +
57371 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57372 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57373 +
57374 + }
57375 + free_page((unsigned long)buffer_exe);
57376 + free_page((unsigned long)buffer_lib);
57377 + continue;
57378 + }
57379 +#endif
57380 +
57381 + }
57382 + }
57383 +}
57384 +#endif
57385 +
57386 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57387 +
57388 +extern int grsec_enable_log_rwxmaps;
57389 +
57390 +static void elf_handle_mmap(struct file *file)
57391 +{
57392 + struct elfhdr elf_h;
57393 + struct elf_phdr elf_p;
57394 + unsigned long i;
57395 +
57396 + if (!grsec_enable_log_rwxmaps)
57397 + return;
57398 +
57399 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57400 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57401 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57402 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57403 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57404 + return;
57405 +
57406 + for (i = 0UL; i < elf_h.e_phnum; i++) {
57407 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57408 + return;
57409 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57410 + gr_log_ptgnustack(file);
57411 + }
57412 +}
57413 +#endif
57414 +
57415 static int __init init_elf_binfmt(void)
57416 {
57417 register_binfmt(&elf_format);
57418 diff --git a/fs/bio.c b/fs/bio.c
57419 index 6f0362b..26a7496 100644
57420 --- a/fs/bio.c
57421 +++ b/fs/bio.c
57422 @@ -1144,7 +1144,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57423 /*
57424 * Overflow, abort
57425 */
57426 - if (end < start)
57427 + if (end < start || end - start > INT_MAX - nr_pages)
57428 return ERR_PTR(-EINVAL);
57429
57430 nr_pages += end - start;
57431 @@ -1278,7 +1278,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57432 /*
57433 * Overflow, abort
57434 */
57435 - if (end < start)
57436 + if (end < start || end - start > INT_MAX - nr_pages)
57437 return ERR_PTR(-EINVAL);
57438
57439 nr_pages += end - start;
57440 @@ -1540,7 +1540,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57441 const int read = bio_data_dir(bio) == READ;
57442 struct bio_map_data *bmd = bio->bi_private;
57443 int i;
57444 - char *p = bmd->sgvecs[0].iov_base;
57445 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57446
57447 bio_for_each_segment_all(bvec, bio, i) {
57448 char *addr = page_address(bvec->bv_page);
57449 diff --git a/fs/block_dev.c b/fs/block_dev.c
57450 index 552a8d1..d51ccf3 100644
57451 --- a/fs/block_dev.c
57452 +++ b/fs/block_dev.c
57453 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57454 else if (bdev->bd_contains == bdev)
57455 return true; /* is a whole device which isn't held */
57456
57457 - else if (whole->bd_holder == bd_may_claim)
57458 + else if (whole->bd_holder == (void *)bd_may_claim)
57459 return true; /* is a partition of a device that is being partitioned */
57460 else if (whole->bd_holder != NULL)
57461 return false; /* is a partition of a held device */
57462 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57463 index 1bcfcdb..e942132 100644
57464 --- a/fs/btrfs/ctree.c
57465 +++ b/fs/btrfs/ctree.c
57466 @@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57467 free_extent_buffer(buf);
57468 add_root_to_dirty_list(root);
57469 } else {
57470 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57471 - parent_start = parent->start;
57472 - else
57473 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57474 + if (parent)
57475 + parent_start = parent->start;
57476 + else
57477 + parent_start = 0;
57478 + } else
57479 parent_start = 0;
57480
57481 WARN_ON(trans->transid != btrfs_header_generation(parent));
57482 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57483 index 33e561a..16df7ae 100644
57484 --- a/fs/btrfs/delayed-inode.c
57485 +++ b/fs/btrfs/delayed-inode.c
57486 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57487
57488 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57489 {
57490 - int seq = atomic_inc_return(&delayed_root->items_seq);
57491 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57492 if ((atomic_dec_return(&delayed_root->items) <
57493 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57494 waitqueue_active(&delayed_root->wait))
57495 @@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57496
57497 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57498 {
57499 - int val = atomic_read(&delayed_root->items_seq);
57500 + int val = atomic_read_unchecked(&delayed_root->items_seq);
57501
57502 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57503 return 1;
57504 @@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57505 int seq;
57506 int ret;
57507
57508 - seq = atomic_read(&delayed_root->items_seq);
57509 + seq = atomic_read_unchecked(&delayed_root->items_seq);
57510
57511 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57512 if (ret)
57513 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57514 index f70119f..ab5894d 100644
57515 --- a/fs/btrfs/delayed-inode.h
57516 +++ b/fs/btrfs/delayed-inode.h
57517 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57518 */
57519 struct list_head prepare_list;
57520 atomic_t items; /* for delayed items */
57521 - atomic_t items_seq; /* for delayed items */
57522 + atomic_unchecked_t items_seq; /* for delayed items */
57523 int nodes; /* for delayed nodes */
57524 wait_queue_head_t wait;
57525 };
57526 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57527 struct btrfs_delayed_root *delayed_root)
57528 {
57529 atomic_set(&delayed_root->items, 0);
57530 - atomic_set(&delayed_root->items_seq, 0);
57531 + atomic_set_unchecked(&delayed_root->items_seq, 0);
57532 delayed_root->nodes = 0;
57533 spin_lock_init(&delayed_root->lock);
57534 init_waitqueue_head(&delayed_root->wait);
57535 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57536 index 2f6d7b1..f186382 100644
57537 --- a/fs/btrfs/ioctl.c
57538 +++ b/fs/btrfs/ioctl.c
57539 @@ -3575,9 +3575,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57540 for (i = 0; i < num_types; i++) {
57541 struct btrfs_space_info *tmp;
57542
57543 + /* Don't copy in more than we allocated */
57544 if (!slot_count)
57545 break;
57546
57547 + slot_count--;
57548 +
57549 info = NULL;
57550 rcu_read_lock();
57551 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57552 @@ -3599,10 +3602,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57553 memcpy(dest, &space, sizeof(space));
57554 dest++;
57555 space_args.total_spaces++;
57556 - slot_count--;
57557 }
57558 - if (!slot_count)
57559 - break;
57560 }
57561 up_read(&info->groups_sem);
57562 }
57563 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57564 index 9601d25..2896d6c 100644
57565 --- a/fs/btrfs/super.c
57566 +++ b/fs/btrfs/super.c
57567 @@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57568 function, line, errstr);
57569 return;
57570 }
57571 - ACCESS_ONCE(trans->transaction->aborted) = errno;
57572 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57573 /* Wake up anybody who may be waiting on this transaction */
57574 wake_up(&root->fs_info->transaction_wait);
57575 wake_up(&root->fs_info->transaction_blocked_wait);
57576 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57577 index 4825cd2..b2fe768 100644
57578 --- a/fs/btrfs/sysfs.c
57579 +++ b/fs/btrfs/sysfs.c
57580 @@ -438,7 +438,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57581 for (set = 0; set < FEAT_MAX; set++) {
57582 int i;
57583 struct attribute *attrs[2];
57584 - struct attribute_group agroup = {
57585 + attribute_group_no_const agroup = {
57586 .name = "features",
57587 .attrs = attrs,
57588 };
57589 diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
57590 index e2f45fc..b036909 100644
57591 --- a/fs/btrfs/tree-log.c
57592 +++ b/fs/btrfs/tree-log.c
57593 @@ -2533,7 +2533,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57594 blk_finish_plug(&plug);
57595 btrfs_abort_transaction(trans, root, ret);
57596 btrfs_free_logged_extents(log, log_transid);
57597 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57598 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57599 trans->transid;
57600 mutex_unlock(&root->log_mutex);
57601 goto out;
57602 @@ -2577,7 +2577,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57603 list_del_init(&root_log_ctx.list);
57604
57605 blk_finish_plug(&plug);
57606 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57607 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57608 trans->transid;
57609 if (ret != -ENOSPC) {
57610 btrfs_abort_transaction(trans, root, ret);
57611 @@ -2622,7 +2622,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57612 * now that we've moved on to the tree of log tree roots,
57613 * check the full commit flag again
57614 */
57615 - if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
57616 + if (ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) ==
57617 trans->transid) {
57618 blk_finish_plug(&plug);
57619 btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
57620 @@ -2637,7 +2637,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57621 EXTENT_DIRTY | EXTENT_NEW);
57622 blk_finish_plug(&plug);
57623 if (ret) {
57624 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57625 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57626 trans->transid;
57627 btrfs_abort_transaction(trans, root, ret);
57628 btrfs_free_logged_extents(log, log_transid);
57629 @@ -2667,7 +2667,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57630 */
57631 ret = write_ctree_super(trans, root->fs_info->tree_root, 1);
57632 if (ret) {
57633 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57634 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57635 trans->transid;
57636 btrfs_abort_transaction(trans, root, ret);
57637 goto out_wake_log_root;
57638 diff --git a/fs/buffer.c b/fs/buffer.c
57639 index 9ddb9fc..7aa2487 100644
57640 --- a/fs/buffer.c
57641 +++ b/fs/buffer.c
57642 @@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57643 bh_cachep = kmem_cache_create("buffer_head",
57644 sizeof(struct buffer_head), 0,
57645 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57646 - SLAB_MEM_SPREAD),
57647 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57648 NULL);
57649
57650 /*
57651 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57652 index 5b99baf..47fffb5 100644
57653 --- a/fs/cachefiles/bind.c
57654 +++ b/fs/cachefiles/bind.c
57655 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57656 args);
57657
57658 /* start by checking things over */
57659 - ASSERT(cache->fstop_percent >= 0 &&
57660 - cache->fstop_percent < cache->fcull_percent &&
57661 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
57662 cache->fcull_percent < cache->frun_percent &&
57663 cache->frun_percent < 100);
57664
57665 - ASSERT(cache->bstop_percent >= 0 &&
57666 - cache->bstop_percent < cache->bcull_percent &&
57667 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
57668 cache->bcull_percent < cache->brun_percent &&
57669 cache->brun_percent < 100);
57670
57671 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57672 index 0a1467b..6a53245 100644
57673 --- a/fs/cachefiles/daemon.c
57674 +++ b/fs/cachefiles/daemon.c
57675 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57676 if (n > buflen)
57677 return -EMSGSIZE;
57678
57679 - if (copy_to_user(_buffer, buffer, n) != 0)
57680 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57681 return -EFAULT;
57682
57683 return n;
57684 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57685 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57686 return -EIO;
57687
57688 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
57689 + if (datalen > PAGE_SIZE - 1)
57690 return -EOPNOTSUPP;
57691
57692 /* drag the command string into the kernel so we can parse it */
57693 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57694 if (args[0] != '%' || args[1] != '\0')
57695 return -EINVAL;
57696
57697 - if (fstop < 0 || fstop >= cache->fcull_percent)
57698 + if (fstop >= cache->fcull_percent)
57699 return cachefiles_daemon_range_error(cache, args);
57700
57701 cache->fstop_percent = fstop;
57702 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57703 if (args[0] != '%' || args[1] != '\0')
57704 return -EINVAL;
57705
57706 - if (bstop < 0 || bstop >= cache->bcull_percent)
57707 + if (bstop >= cache->bcull_percent)
57708 return cachefiles_daemon_range_error(cache, args);
57709
57710 cache->bstop_percent = bstop;
57711 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57712 index 5349473..d6c0b93 100644
57713 --- a/fs/cachefiles/internal.h
57714 +++ b/fs/cachefiles/internal.h
57715 @@ -59,7 +59,7 @@ struct cachefiles_cache {
57716 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57717 struct rb_root active_nodes; /* active nodes (can't be culled) */
57718 rwlock_t active_lock; /* lock for active_nodes */
57719 - atomic_t gravecounter; /* graveyard uniquifier */
57720 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57721 unsigned frun_percent; /* when to stop culling (% files) */
57722 unsigned fcull_percent; /* when to start culling (% files) */
57723 unsigned fstop_percent; /* when to stop allocating (% files) */
57724 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57725 * proc.c
57726 */
57727 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57728 -extern atomic_t cachefiles_lookup_histogram[HZ];
57729 -extern atomic_t cachefiles_mkdir_histogram[HZ];
57730 -extern atomic_t cachefiles_create_histogram[HZ];
57731 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57732 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57733 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57734
57735 extern int __init cachefiles_proc_init(void);
57736 extern void cachefiles_proc_cleanup(void);
57737 static inline
57738 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57739 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57740 {
57741 unsigned long jif = jiffies - start_jif;
57742 if (jif >= HZ)
57743 jif = HZ - 1;
57744 - atomic_inc(&histogram[jif]);
57745 + atomic_inc_unchecked(&histogram[jif]);
57746 }
57747
57748 #else
57749 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57750 index c0a6817..ea811166 100644
57751 --- a/fs/cachefiles/namei.c
57752 +++ b/fs/cachefiles/namei.c
57753 @@ -317,7 +317,7 @@ try_again:
57754 /* first step is to make up a grave dentry in the graveyard */
57755 sprintf(nbuffer, "%08x%08x",
57756 (uint32_t) get_seconds(),
57757 - (uint32_t) atomic_inc_return(&cache->gravecounter));
57758 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57759
57760 /* do the multiway lock magic */
57761 trap = lock_rename(cache->graveyard, dir);
57762 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57763 index eccd339..4c1d995 100644
57764 --- a/fs/cachefiles/proc.c
57765 +++ b/fs/cachefiles/proc.c
57766 @@ -14,9 +14,9 @@
57767 #include <linux/seq_file.h>
57768 #include "internal.h"
57769
57770 -atomic_t cachefiles_lookup_histogram[HZ];
57771 -atomic_t cachefiles_mkdir_histogram[HZ];
57772 -atomic_t cachefiles_create_histogram[HZ];
57773 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57774 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57775 +atomic_unchecked_t cachefiles_create_histogram[HZ];
57776
57777 /*
57778 * display the latency histogram
57779 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57780 return 0;
57781 default:
57782 index = (unsigned long) v - 3;
57783 - x = atomic_read(&cachefiles_lookup_histogram[index]);
57784 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
57785 - z = atomic_read(&cachefiles_create_histogram[index]);
57786 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57787 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57788 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57789 if (x == 0 && y == 0 && z == 0)
57790 return 0;
57791
57792 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57793 index 4b1fb5c..0d2a699 100644
57794 --- a/fs/cachefiles/rdwr.c
57795 +++ b/fs/cachefiles/rdwr.c
57796 @@ -943,7 +943,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57797 old_fs = get_fs();
57798 set_fs(KERNEL_DS);
57799 ret = file->f_op->write(
57800 - file, (const void __user *) data, len, &pos);
57801 + file, (const void __force_user *) data, len, &pos);
57802 set_fs(old_fs);
57803 kunmap(page);
57804 file_end_write(file);
57805 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57806 index c29d6ae..a56c4ae 100644
57807 --- a/fs/ceph/dir.c
57808 +++ b/fs/ceph/dir.c
57809 @@ -250,7 +250,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57810 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57811 struct ceph_mds_client *mdsc = fsc->mdsc;
57812 unsigned frag = fpos_frag(ctx->pos);
57813 - int off = fpos_off(ctx->pos);
57814 + unsigned int off = fpos_off(ctx->pos);
57815 int err;
57816 u32 ftype;
57817 struct ceph_mds_reply_info_parsed *rinfo;
57818 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57819 index 06150fd..192061b 100644
57820 --- a/fs/ceph/super.c
57821 +++ b/fs/ceph/super.c
57822 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57823 /*
57824 * construct our own bdi so we can control readahead, etc.
57825 */
57826 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57827 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57828
57829 static int ceph_register_bdi(struct super_block *sb,
57830 struct ceph_fs_client *fsc)
57831 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57832 default_backing_dev_info.ra_pages;
57833
57834 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57835 - atomic_long_inc_return(&bdi_seq));
57836 + atomic_long_inc_return_unchecked(&bdi_seq));
57837 if (!err)
57838 sb->s_bdi = &fsc->backing_dev_info;
57839 return err;
57840 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57841 index f3ac415..3d2420c 100644
57842 --- a/fs/cifs/cifs_debug.c
57843 +++ b/fs/cifs/cifs_debug.c
57844 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57845
57846 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57847 #ifdef CONFIG_CIFS_STATS2
57848 - atomic_set(&totBufAllocCount, 0);
57849 - atomic_set(&totSmBufAllocCount, 0);
57850 + atomic_set_unchecked(&totBufAllocCount, 0);
57851 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57852 #endif /* CONFIG_CIFS_STATS2 */
57853 spin_lock(&cifs_tcp_ses_lock);
57854 list_for_each(tmp1, &cifs_tcp_ses_list) {
57855 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57856 tcon = list_entry(tmp3,
57857 struct cifs_tcon,
57858 tcon_list);
57859 - atomic_set(&tcon->num_smbs_sent, 0);
57860 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57861 if (server->ops->clear_stats)
57862 server->ops->clear_stats(tcon);
57863 }
57864 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57865 smBufAllocCount.counter, cifs_min_small);
57866 #ifdef CONFIG_CIFS_STATS2
57867 seq_printf(m, "Total Large %d Small %d Allocations\n",
57868 - atomic_read(&totBufAllocCount),
57869 - atomic_read(&totSmBufAllocCount));
57870 + atomic_read_unchecked(&totBufAllocCount),
57871 + atomic_read_unchecked(&totSmBufAllocCount));
57872 #endif /* CONFIG_CIFS_STATS2 */
57873
57874 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57875 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57876 if (tcon->need_reconnect)
57877 seq_puts(m, "\tDISCONNECTED ");
57878 seq_printf(m, "\nSMBs: %d",
57879 - atomic_read(&tcon->num_smbs_sent));
57880 + atomic_read_unchecked(&tcon->num_smbs_sent));
57881 if (server->ops->print_stats)
57882 server->ops->print_stats(m, tcon);
57883 }
57884 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57885 index 5be1f997..fa1015a1 100644
57886 --- a/fs/cifs/cifsfs.c
57887 +++ b/fs/cifs/cifsfs.c
57888 @@ -1068,7 +1068,7 @@ cifs_init_request_bufs(void)
57889 */
57890 cifs_req_cachep = kmem_cache_create("cifs_request",
57891 CIFSMaxBufSize + max_hdr_size, 0,
57892 - SLAB_HWCACHE_ALIGN, NULL);
57893 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57894 if (cifs_req_cachep == NULL)
57895 return -ENOMEM;
57896
57897 @@ -1095,7 +1095,7 @@ cifs_init_request_bufs(void)
57898 efficient to alloc 1 per page off the slab compared to 17K (5page)
57899 alloc of large cifs buffers even when page debugging is on */
57900 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57901 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57902 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57903 NULL);
57904 if (cifs_sm_req_cachep == NULL) {
57905 mempool_destroy(cifs_req_poolp);
57906 @@ -1180,8 +1180,8 @@ init_cifs(void)
57907 atomic_set(&bufAllocCount, 0);
57908 atomic_set(&smBufAllocCount, 0);
57909 #ifdef CONFIG_CIFS_STATS2
57910 - atomic_set(&totBufAllocCount, 0);
57911 - atomic_set(&totSmBufAllocCount, 0);
57912 + atomic_set_unchecked(&totBufAllocCount, 0);
57913 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57914 #endif /* CONFIG_CIFS_STATS2 */
57915
57916 atomic_set(&midCount, 0);
57917 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57918 index 30f6e92..e915ba5 100644
57919 --- a/fs/cifs/cifsglob.h
57920 +++ b/fs/cifs/cifsglob.h
57921 @@ -806,35 +806,35 @@ struct cifs_tcon {
57922 __u16 Flags; /* optional support bits */
57923 enum statusEnum tidStatus;
57924 #ifdef CONFIG_CIFS_STATS
57925 - atomic_t num_smbs_sent;
57926 + atomic_unchecked_t num_smbs_sent;
57927 union {
57928 struct {
57929 - atomic_t num_writes;
57930 - atomic_t num_reads;
57931 - atomic_t num_flushes;
57932 - atomic_t num_oplock_brks;
57933 - atomic_t num_opens;
57934 - atomic_t num_closes;
57935 - atomic_t num_deletes;
57936 - atomic_t num_mkdirs;
57937 - atomic_t num_posixopens;
57938 - atomic_t num_posixmkdirs;
57939 - atomic_t num_rmdirs;
57940 - atomic_t num_renames;
57941 - atomic_t num_t2renames;
57942 - atomic_t num_ffirst;
57943 - atomic_t num_fnext;
57944 - atomic_t num_fclose;
57945 - atomic_t num_hardlinks;
57946 - atomic_t num_symlinks;
57947 - atomic_t num_locks;
57948 - atomic_t num_acl_get;
57949 - atomic_t num_acl_set;
57950 + atomic_unchecked_t num_writes;
57951 + atomic_unchecked_t num_reads;
57952 + atomic_unchecked_t num_flushes;
57953 + atomic_unchecked_t num_oplock_brks;
57954 + atomic_unchecked_t num_opens;
57955 + atomic_unchecked_t num_closes;
57956 + atomic_unchecked_t num_deletes;
57957 + atomic_unchecked_t num_mkdirs;
57958 + atomic_unchecked_t num_posixopens;
57959 + atomic_unchecked_t num_posixmkdirs;
57960 + atomic_unchecked_t num_rmdirs;
57961 + atomic_unchecked_t num_renames;
57962 + atomic_unchecked_t num_t2renames;
57963 + atomic_unchecked_t num_ffirst;
57964 + atomic_unchecked_t num_fnext;
57965 + atomic_unchecked_t num_fclose;
57966 + atomic_unchecked_t num_hardlinks;
57967 + atomic_unchecked_t num_symlinks;
57968 + atomic_unchecked_t num_locks;
57969 + atomic_unchecked_t num_acl_get;
57970 + atomic_unchecked_t num_acl_set;
57971 } cifs_stats;
57972 #ifdef CONFIG_CIFS_SMB2
57973 struct {
57974 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57975 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57976 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57977 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57978 } smb2_stats;
57979 #endif /* CONFIG_CIFS_SMB2 */
57980 } stats;
57981 @@ -1170,7 +1170,7 @@ convert_delimiter(char *path, char delim)
57982 }
57983
57984 #ifdef CONFIG_CIFS_STATS
57985 -#define cifs_stats_inc atomic_inc
57986 +#define cifs_stats_inc atomic_inc_unchecked
57987
57988 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57989 unsigned int bytes)
57990 @@ -1536,8 +1536,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57991 /* Various Debug counters */
57992 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57993 #ifdef CONFIG_CIFS_STATS2
57994 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57995 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57996 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57997 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57998 #endif
57999 GLOBAL_EXTERN atomic_t smBufAllocCount;
58000 GLOBAL_EXTERN atomic_t midCount;
58001 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
58002 index 5ed03e0..e9a3a6c 100644
58003 --- a/fs/cifs/file.c
58004 +++ b/fs/cifs/file.c
58005 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
58006 index = mapping->writeback_index; /* Start from prev offset */
58007 end = -1;
58008 } else {
58009 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
58010 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
58011 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
58012 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
58013 range_whole = true;
58014 + index = 0;
58015 + end = ULONG_MAX;
58016 + } else {
58017 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
58018 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
58019 + }
58020 scanned = true;
58021 }
58022 retry:
58023 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
58024 index 3b0c62e..f7d090c 100644
58025 --- a/fs/cifs/misc.c
58026 +++ b/fs/cifs/misc.c
58027 @@ -170,7 +170,7 @@ cifs_buf_get(void)
58028 memset(ret_buf, 0, buf_size + 3);
58029 atomic_inc(&bufAllocCount);
58030 #ifdef CONFIG_CIFS_STATS2
58031 - atomic_inc(&totBufAllocCount);
58032 + atomic_inc_unchecked(&totBufAllocCount);
58033 #endif /* CONFIG_CIFS_STATS2 */
58034 }
58035
58036 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
58037 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
58038 atomic_inc(&smBufAllocCount);
58039 #ifdef CONFIG_CIFS_STATS2
58040 - atomic_inc(&totSmBufAllocCount);
58041 + atomic_inc_unchecked(&totSmBufAllocCount);
58042 #endif /* CONFIG_CIFS_STATS2 */
58043
58044 }
58045 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
58046 index d1fdfa8..94558f8 100644
58047 --- a/fs/cifs/smb1ops.c
58048 +++ b/fs/cifs/smb1ops.c
58049 @@ -626,27 +626,27 @@ static void
58050 cifs_clear_stats(struct cifs_tcon *tcon)
58051 {
58052 #ifdef CONFIG_CIFS_STATS
58053 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
58054 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
58055 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
58056 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58057 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
58058 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
58059 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58060 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
58061 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
58062 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
58063 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
58064 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
58065 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
58066 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
58067 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
58068 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
58069 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
58070 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
58071 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
58072 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
58073 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
58074 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
58075 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
58076 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
58077 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58078 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
58079 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
58080 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58081 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
58082 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
58083 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
58084 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
58085 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
58086 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
58087 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
58088 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
58089 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
58090 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
58091 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
58092 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
58093 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
58094 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
58095 #endif
58096 }
58097
58098 @@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58099 {
58100 #ifdef CONFIG_CIFS_STATS
58101 seq_printf(m, " Oplocks breaks: %d",
58102 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
58103 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
58104 seq_printf(m, "\nReads: %d Bytes: %llu",
58105 - atomic_read(&tcon->stats.cifs_stats.num_reads),
58106 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
58107 (long long)(tcon->bytes_read));
58108 seq_printf(m, "\nWrites: %d Bytes: %llu",
58109 - atomic_read(&tcon->stats.cifs_stats.num_writes),
58110 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
58111 (long long)(tcon->bytes_written));
58112 seq_printf(m, "\nFlushes: %d",
58113 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
58114 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
58115 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
58116 - atomic_read(&tcon->stats.cifs_stats.num_locks),
58117 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
58118 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
58119 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
58120 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
58121 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
58122 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
58123 - atomic_read(&tcon->stats.cifs_stats.num_opens),
58124 - atomic_read(&tcon->stats.cifs_stats.num_closes),
58125 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
58126 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
58127 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
58128 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
58129 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
58130 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
58131 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
58132 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
58133 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
58134 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
58135 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
58136 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
58137 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
58138 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
58139 seq_printf(m, "\nRenames: %d T2 Renames %d",
58140 - atomic_read(&tcon->stats.cifs_stats.num_renames),
58141 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
58142 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
58143 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
58144 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
58145 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
58146 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
58147 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
58148 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
58149 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
58150 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
58151 #endif
58152 }
58153
58154 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
58155 index 35ddc3e..563e809 100644
58156 --- a/fs/cifs/smb2ops.c
58157 +++ b/fs/cifs/smb2ops.c
58158 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
58159 #ifdef CONFIG_CIFS_STATS
58160 int i;
58161 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
58162 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58163 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58164 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58165 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58166 }
58167 #endif
58168 }
58169 @@ -405,65 +405,65 @@ static void
58170 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58171 {
58172 #ifdef CONFIG_CIFS_STATS
58173 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58174 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58175 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58176 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58177 seq_printf(m, "\nNegotiates: %d sent %d failed",
58178 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
58179 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
58180 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
58181 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
58182 seq_printf(m, "\nSessionSetups: %d sent %d failed",
58183 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
58184 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
58185 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
58186 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
58187 seq_printf(m, "\nLogoffs: %d sent %d failed",
58188 - atomic_read(&sent[SMB2_LOGOFF_HE]),
58189 - atomic_read(&failed[SMB2_LOGOFF_HE]));
58190 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
58191 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
58192 seq_printf(m, "\nTreeConnects: %d sent %d failed",
58193 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
58194 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
58195 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
58196 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
58197 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
58198 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
58199 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
58200 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
58201 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
58202 seq_printf(m, "\nCreates: %d sent %d failed",
58203 - atomic_read(&sent[SMB2_CREATE_HE]),
58204 - atomic_read(&failed[SMB2_CREATE_HE]));
58205 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
58206 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
58207 seq_printf(m, "\nCloses: %d sent %d failed",
58208 - atomic_read(&sent[SMB2_CLOSE_HE]),
58209 - atomic_read(&failed[SMB2_CLOSE_HE]));
58210 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
58211 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
58212 seq_printf(m, "\nFlushes: %d sent %d failed",
58213 - atomic_read(&sent[SMB2_FLUSH_HE]),
58214 - atomic_read(&failed[SMB2_FLUSH_HE]));
58215 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
58216 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
58217 seq_printf(m, "\nReads: %d sent %d failed",
58218 - atomic_read(&sent[SMB2_READ_HE]),
58219 - atomic_read(&failed[SMB2_READ_HE]));
58220 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
58221 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
58222 seq_printf(m, "\nWrites: %d sent %d failed",
58223 - atomic_read(&sent[SMB2_WRITE_HE]),
58224 - atomic_read(&failed[SMB2_WRITE_HE]));
58225 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
58226 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
58227 seq_printf(m, "\nLocks: %d sent %d failed",
58228 - atomic_read(&sent[SMB2_LOCK_HE]),
58229 - atomic_read(&failed[SMB2_LOCK_HE]));
58230 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
58231 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
58232 seq_printf(m, "\nIOCTLs: %d sent %d failed",
58233 - atomic_read(&sent[SMB2_IOCTL_HE]),
58234 - atomic_read(&failed[SMB2_IOCTL_HE]));
58235 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
58236 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
58237 seq_printf(m, "\nCancels: %d sent %d failed",
58238 - atomic_read(&sent[SMB2_CANCEL_HE]),
58239 - atomic_read(&failed[SMB2_CANCEL_HE]));
58240 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
58241 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
58242 seq_printf(m, "\nEchos: %d sent %d failed",
58243 - atomic_read(&sent[SMB2_ECHO_HE]),
58244 - atomic_read(&failed[SMB2_ECHO_HE]));
58245 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
58246 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
58247 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
58248 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
58249 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
58250 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
58251 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
58252 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
58253 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
58254 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
58255 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
58256 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
58257 seq_printf(m, "\nQueryInfos: %d sent %d failed",
58258 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
58259 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
58260 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
58261 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
58262 seq_printf(m, "\nSetInfos: %d sent %d failed",
58263 - atomic_read(&sent[SMB2_SET_INFO_HE]),
58264 - atomic_read(&failed[SMB2_SET_INFO_HE]));
58265 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
58266 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
58267 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
58268 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
58269 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
58270 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
58271 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
58272 #endif
58273 }
58274
58275 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
58276 index 1fb6ad2..758e171 100644
58277 --- a/fs/cifs/smb2pdu.c
58278 +++ b/fs/cifs/smb2pdu.c
58279 @@ -2097,8 +2097,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
58280 default:
58281 cifs_dbg(VFS, "info level %u isn't supported\n",
58282 srch_inf->info_level);
58283 - rc = -EINVAL;
58284 - goto qdir_exit;
58285 + return -EINVAL;
58286 }
58287
58288 req->FileIndex = cpu_to_le32(index);
58289 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
58290 index 1da168c..8bc7ff6 100644
58291 --- a/fs/coda/cache.c
58292 +++ b/fs/coda/cache.c
58293 @@ -24,7 +24,7 @@
58294 #include "coda_linux.h"
58295 #include "coda_cache.h"
58296
58297 -static atomic_t permission_epoch = ATOMIC_INIT(0);
58298 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
58299
58300 /* replace or extend an acl cache hit */
58301 void coda_cache_enter(struct inode *inode, int mask)
58302 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
58303 struct coda_inode_info *cii = ITOC(inode);
58304
58305 spin_lock(&cii->c_lock);
58306 - cii->c_cached_epoch = atomic_read(&permission_epoch);
58307 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
58308 if (!uid_eq(cii->c_uid, current_fsuid())) {
58309 cii->c_uid = current_fsuid();
58310 cii->c_cached_perm = mask;
58311 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
58312 {
58313 struct coda_inode_info *cii = ITOC(inode);
58314 spin_lock(&cii->c_lock);
58315 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
58316 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
58317 spin_unlock(&cii->c_lock);
58318 }
58319
58320 /* remove all acl caches */
58321 void coda_cache_clear_all(struct super_block *sb)
58322 {
58323 - atomic_inc(&permission_epoch);
58324 + atomic_inc_unchecked(&permission_epoch);
58325 }
58326
58327
58328 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58329 spin_lock(&cii->c_lock);
58330 hit = (mask & cii->c_cached_perm) == mask &&
58331 uid_eq(cii->c_uid, current_fsuid()) &&
58332 - cii->c_cached_epoch == atomic_read(&permission_epoch);
58333 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58334 spin_unlock(&cii->c_lock);
58335
58336 return hit;
58337 diff --git a/fs/compat.c b/fs/compat.c
58338 index 66d3d3c..9c10175 100644
58339 --- a/fs/compat.c
58340 +++ b/fs/compat.c
58341 @@ -54,7 +54,7 @@
58342 #include <asm/ioctls.h>
58343 #include "internal.h"
58344
58345 -int compat_log = 1;
58346 +int compat_log = 0;
58347
58348 int compat_printk(const char *fmt, ...)
58349 {
58350 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
58351
58352 set_fs(KERNEL_DS);
58353 /* The __user pointer cast is valid because of the set_fs() */
58354 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58355 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58356 set_fs(oldfs);
58357 /* truncating is ok because it's a user address */
58358 if (!ret)
58359 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58360 goto out;
58361
58362 ret = -EINVAL;
58363 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58364 + if (nr_segs > UIO_MAXIOV)
58365 goto out;
58366 if (nr_segs > fast_segs) {
58367 ret = -ENOMEM;
58368 @@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
58369 struct compat_readdir_callback {
58370 struct dir_context ctx;
58371 struct compat_old_linux_dirent __user *dirent;
58372 + struct file * file;
58373 int result;
58374 };
58375
58376 @@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58377 buf->result = -EOVERFLOW;
58378 return -EOVERFLOW;
58379 }
58380 +
58381 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58382 + return 0;
58383 +
58384 buf->result++;
58385 dirent = buf->dirent;
58386 if (!access_ok(VERIFY_WRITE, dirent,
58387 @@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
58388 if (!f.file)
58389 return -EBADF;
58390
58391 + buf.file = f.file;
58392 error = iterate_dir(f.file, &buf.ctx);
58393 if (buf.result)
58394 error = buf.result;
58395 @@ -917,6 +923,7 @@ struct compat_getdents_callback {
58396 struct dir_context ctx;
58397 struct compat_linux_dirent __user *current_dir;
58398 struct compat_linux_dirent __user *previous;
58399 + struct file * file;
58400 int count;
58401 int error;
58402 };
58403 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58404 buf->error = -EOVERFLOW;
58405 return -EOVERFLOW;
58406 }
58407 +
58408 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58409 + return 0;
58410 +
58411 dirent = buf->previous;
58412 if (dirent) {
58413 if (__put_user(offset, &dirent->d_off))
58414 @@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
58415 if (!f.file)
58416 return -EBADF;
58417
58418 + buf.file = f.file;
58419 error = iterate_dir(f.file, &buf.ctx);
58420 if (error >= 0)
58421 error = buf.error;
58422 @@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
58423 struct dir_context ctx;
58424 struct linux_dirent64 __user *current_dir;
58425 struct linux_dirent64 __user *previous;
58426 + struct file * file;
58427 int count;
58428 int error;
58429 };
58430 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58431 buf->error = -EINVAL; /* only used if we fail.. */
58432 if (reclen > buf->count)
58433 return -EINVAL;
58434 +
58435 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58436 + return 0;
58437 +
58438 dirent = buf->previous;
58439
58440 if (dirent) {
58441 @@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
58442 if (!f.file)
58443 return -EBADF;
58444
58445 + buf.file = f.file;
58446 error = iterate_dir(f.file, &buf.ctx);
58447 if (error >= 0)
58448 error = buf.error;
58449 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58450 index 4d24d17..4f8c09e 100644
58451 --- a/fs/compat_binfmt_elf.c
58452 +++ b/fs/compat_binfmt_elf.c
58453 @@ -30,11 +30,13 @@
58454 #undef elf_phdr
58455 #undef elf_shdr
58456 #undef elf_note
58457 +#undef elf_dyn
58458 #undef elf_addr_t
58459 #define elfhdr elf32_hdr
58460 #define elf_phdr elf32_phdr
58461 #define elf_shdr elf32_shdr
58462 #define elf_note elf32_note
58463 +#define elf_dyn Elf32_Dyn
58464 #define elf_addr_t Elf32_Addr
58465
58466 /*
58467 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58468 index e822890..59374d5 100644
58469 --- a/fs/compat_ioctl.c
58470 +++ b/fs/compat_ioctl.c
58471 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58472 return -EFAULT;
58473 if (__get_user(udata, &ss32->iomem_base))
58474 return -EFAULT;
58475 - ss.iomem_base = compat_ptr(udata);
58476 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58477 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58478 __get_user(ss.port_high, &ss32->port_high))
58479 return -EFAULT;
58480 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58481 for (i = 0; i < nmsgs; i++) {
58482 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58483 return -EFAULT;
58484 - if (get_user(datap, &umsgs[i].buf) ||
58485 - put_user(compat_ptr(datap), &tmsgs[i].buf))
58486 + if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58487 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58488 return -EFAULT;
58489 }
58490 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58491 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58492 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58493 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58494 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58495 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58496 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58497 return -EFAULT;
58498
58499 return ioctl_preallocate(file, p);
58500 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
58501 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58502 {
58503 unsigned int a, b;
58504 - a = *(unsigned int *)p;
58505 - b = *(unsigned int *)q;
58506 + a = *(const unsigned int *)p;
58507 + b = *(const unsigned int *)q;
58508 if (a > b)
58509 return 1;
58510 if (a < b)
58511 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58512 index e081acb..911df21 100644
58513 --- a/fs/configfs/dir.c
58514 +++ b/fs/configfs/dir.c
58515 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58516 }
58517 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58518 struct configfs_dirent *next;
58519 - const char *name;
58520 + const unsigned char * name;
58521 + char d_name[sizeof(next->s_dentry->d_iname)];
58522 int len;
58523 struct inode *inode = NULL;
58524
58525 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58526 continue;
58527
58528 name = configfs_get_name(next);
58529 - len = strlen(name);
58530 + if (next->s_dentry && name == next->s_dentry->d_iname) {
58531 + len = next->s_dentry->d_name.len;
58532 + memcpy(d_name, name, len);
58533 + name = d_name;
58534 + } else
58535 + len = strlen(name);
58536
58537 /*
58538 * We'll have a dentry and an inode for
58539 diff --git a/fs/coredump.c b/fs/coredump.c
58540 index 0b2528f..836c55f 100644
58541 --- a/fs/coredump.c
58542 +++ b/fs/coredump.c
58543 @@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58544 struct pipe_inode_info *pipe = file->private_data;
58545
58546 pipe_lock(pipe);
58547 - pipe->readers++;
58548 - pipe->writers--;
58549 + atomic_inc(&pipe->readers);
58550 + atomic_dec(&pipe->writers);
58551 wake_up_interruptible_sync(&pipe->wait);
58552 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58553 pipe_unlock(pipe);
58554 @@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58555 * We actually want wait_event_freezable() but then we need
58556 * to clear TIF_SIGPENDING and improve dump_interrupted().
58557 */
58558 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
58559 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58560
58561 pipe_lock(pipe);
58562 - pipe->readers--;
58563 - pipe->writers++;
58564 + atomic_dec(&pipe->readers);
58565 + atomic_inc(&pipe->writers);
58566 pipe_unlock(pipe);
58567 }
58568
58569 @@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58570 struct files_struct *displaced;
58571 bool need_nonrelative = false;
58572 bool core_dumped = false;
58573 - static atomic_t core_dump_count = ATOMIC_INIT(0);
58574 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58575 + long signr = siginfo->si_signo;
58576 + int dumpable;
58577 struct coredump_params cprm = {
58578 .siginfo = siginfo,
58579 .regs = signal_pt_regs(),
58580 @@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58581 .mm_flags = mm->flags,
58582 };
58583
58584 - audit_core_dumps(siginfo->si_signo);
58585 + audit_core_dumps(signr);
58586 +
58587 + dumpable = __get_dumpable(cprm.mm_flags);
58588 +
58589 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58590 + gr_handle_brute_attach(dumpable);
58591
58592 binfmt = mm->binfmt;
58593 if (!binfmt || !binfmt->core_dump)
58594 goto fail;
58595 - if (!__get_dumpable(cprm.mm_flags))
58596 + if (!dumpable)
58597 goto fail;
58598
58599 cred = prepare_creds();
58600 @@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58601 need_nonrelative = true;
58602 }
58603
58604 - retval = coredump_wait(siginfo->si_signo, &core_state);
58605 + retval = coredump_wait(signr, &core_state);
58606 if (retval < 0)
58607 goto fail_creds;
58608
58609 @@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58610 }
58611 cprm.limit = RLIM_INFINITY;
58612
58613 - dump_count = atomic_inc_return(&core_dump_count);
58614 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
58615 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58616 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58617 task_tgid_vnr(current), current->comm);
58618 @@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58619 } else {
58620 struct inode *inode;
58621
58622 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58623 +
58624 if (cprm.limit < binfmt->min_coredump)
58625 goto fail_unlock;
58626
58627 @@ -673,7 +682,7 @@ close_fail:
58628 filp_close(cprm.file, NULL);
58629 fail_dropcount:
58630 if (ispipe)
58631 - atomic_dec(&core_dump_count);
58632 + atomic_dec_unchecked(&core_dump_count);
58633 fail_unlock:
58634 kfree(cn.corename);
58635 coredump_finish(mm, core_dumped);
58636 @@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58637 struct file *file = cprm->file;
58638 loff_t pos = file->f_pos;
58639 ssize_t n;
58640 +
58641 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58642 if (cprm->written + nr > cprm->limit)
58643 return 0;
58644 while (nr) {
58645 diff --git a/fs/dcache.c b/fs/dcache.c
58646 index e99c6f5..2838bf58 100644
58647 --- a/fs/dcache.c
58648 +++ b/fs/dcache.c
58649 @@ -1445,7 +1445,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58650 */
58651 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58652 if (name->len > DNAME_INLINE_LEN-1) {
58653 - dname = kmalloc(name->len + 1, GFP_KERNEL);
58654 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58655 if (!dname) {
58656 kmem_cache_free(dentry_cache, dentry);
58657 return NULL;
58658 @@ -3413,7 +3413,8 @@ void __init vfs_caches_init(unsigned long mempages)
58659 mempages -= reserve;
58660
58661 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58662 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58663 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58664 + SLAB_NO_SANITIZE, NULL);
58665
58666 dcache_init();
58667 inode_init();
58668 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58669 index 8c41b52..145b1b9 100644
58670 --- a/fs/debugfs/inode.c
58671 +++ b/fs/debugfs/inode.c
58672 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58673 */
58674 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58675 {
58676 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58677 + return __create_file(name, S_IFDIR | S_IRWXU,
58678 +#else
58679 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58680 +#endif
58681 parent, NULL, NULL);
58682 }
58683 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58684 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58685 index d4a9431..77f9b2e 100644
58686 --- a/fs/ecryptfs/inode.c
58687 +++ b/fs/ecryptfs/inode.c
58688 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58689 old_fs = get_fs();
58690 set_fs(get_ds());
58691 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58692 - (char __user *)lower_buf,
58693 + (char __force_user *)lower_buf,
58694 PATH_MAX);
58695 set_fs(old_fs);
58696 if (rc < 0)
58697 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58698 index e4141f2..d8263e8 100644
58699 --- a/fs/ecryptfs/miscdev.c
58700 +++ b/fs/ecryptfs/miscdev.c
58701 @@ -304,7 +304,7 @@ check_list:
58702 goto out_unlock_msg_ctx;
58703 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58704 if (msg_ctx->msg) {
58705 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
58706 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58707 goto out_unlock_msg_ctx;
58708 i += packet_length_size;
58709 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58710 diff --git a/fs/exec.c b/fs/exec.c
58711 index 238b7aa..a421d91 100644
58712 --- a/fs/exec.c
58713 +++ b/fs/exec.c
58714 @@ -56,8 +56,20 @@
58715 #include <linux/pipe_fs_i.h>
58716 #include <linux/oom.h>
58717 #include <linux/compat.h>
58718 +#include <linux/random.h>
58719 +#include <linux/seq_file.h>
58720 +#include <linux/coredump.h>
58721 +#include <linux/mman.h>
58722 +
58723 +#ifdef CONFIG_PAX_REFCOUNT
58724 +#include <linux/kallsyms.h>
58725 +#include <linux/kdebug.h>
58726 +#endif
58727 +
58728 +#include <trace/events/fs.h>
58729
58730 #include <asm/uaccess.h>
58731 +#include <asm/sections.h>
58732 #include <asm/mmu_context.h>
58733 #include <asm/tlb.h>
58734
58735 @@ -66,19 +78,34 @@
58736
58737 #include <trace/events/sched.h>
58738
58739 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58740 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58741 +{
58742 + 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");
58743 +}
58744 +#endif
58745 +
58746 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58747 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58748 +EXPORT_SYMBOL(pax_set_initial_flags_func);
58749 +#endif
58750 +
58751 int suid_dumpable = 0;
58752
58753 static LIST_HEAD(formats);
58754 static DEFINE_RWLOCK(binfmt_lock);
58755
58756 +extern int gr_process_kernel_exec_ban(void);
58757 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58758 +
58759 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58760 {
58761 BUG_ON(!fmt);
58762 if (WARN_ON(!fmt->load_binary))
58763 return;
58764 write_lock(&binfmt_lock);
58765 - insert ? list_add(&fmt->lh, &formats) :
58766 - list_add_tail(&fmt->lh, &formats);
58767 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58768 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58769 write_unlock(&binfmt_lock);
58770 }
58771
58772 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58773 void unregister_binfmt(struct linux_binfmt * fmt)
58774 {
58775 write_lock(&binfmt_lock);
58776 - list_del(&fmt->lh);
58777 + pax_list_del((struct list_head *)&fmt->lh);
58778 write_unlock(&binfmt_lock);
58779 }
58780
58781 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58782 int write)
58783 {
58784 struct page *page;
58785 - int ret;
58786
58787 -#ifdef CONFIG_STACK_GROWSUP
58788 - if (write) {
58789 - ret = expand_downwards(bprm->vma, pos);
58790 - if (ret < 0)
58791 - return NULL;
58792 - }
58793 -#endif
58794 - ret = get_user_pages(current, bprm->mm, pos,
58795 - 1, write, 1, &page, NULL);
58796 - if (ret <= 0)
58797 + if (0 > expand_downwards(bprm->vma, pos))
58798 + return NULL;
58799 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58800 return NULL;
58801
58802 if (write) {
58803 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58804 if (size <= ARG_MAX)
58805 return page;
58806
58807 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58808 + // only allow 512KB for argv+env on suid/sgid binaries
58809 + // to prevent easy ASLR exhaustion
58810 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58811 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
58812 + (size > (512 * 1024))) {
58813 + put_page(page);
58814 + return NULL;
58815 + }
58816 +#endif
58817 +
58818 /*
58819 * Limit to 1/4-th the stack size for the argv+env strings.
58820 * This ensures that:
58821 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58822 vma->vm_end = STACK_TOP_MAX;
58823 vma->vm_start = vma->vm_end - PAGE_SIZE;
58824 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58825 +
58826 +#ifdef CONFIG_PAX_SEGMEXEC
58827 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58828 +#endif
58829 +
58830 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58831 INIT_LIST_HEAD(&vma->anon_vma_chain);
58832
58833 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58834 mm->stack_vm = mm->total_vm = 1;
58835 up_write(&mm->mmap_sem);
58836 bprm->p = vma->vm_end - sizeof(void *);
58837 +
58838 +#ifdef CONFIG_PAX_RANDUSTACK
58839 + if (randomize_va_space)
58840 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
58841 +#endif
58842 +
58843 return 0;
58844 err:
58845 up_write(&mm->mmap_sem);
58846 @@ -399,7 +440,7 @@ struct user_arg_ptr {
58847 } ptr;
58848 };
58849
58850 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58851 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58852 {
58853 const char __user *native;
58854
58855 @@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58856 compat_uptr_t compat;
58857
58858 if (get_user(compat, argv.ptr.compat + nr))
58859 - return ERR_PTR(-EFAULT);
58860 + return (const char __force_user *)ERR_PTR(-EFAULT);
58861
58862 return compat_ptr(compat);
58863 }
58864 #endif
58865
58866 if (get_user(native, argv.ptr.native + nr))
58867 - return ERR_PTR(-EFAULT);
58868 + return (const char __force_user *)ERR_PTR(-EFAULT);
58869
58870 return native;
58871 }
58872 @@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
58873 if (!p)
58874 break;
58875
58876 - if (IS_ERR(p))
58877 + if (IS_ERR((const char __force_kernel *)p))
58878 return -EFAULT;
58879
58880 if (i >= max)
58881 @@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58882
58883 ret = -EFAULT;
58884 str = get_user_arg_ptr(argv, argc);
58885 - if (IS_ERR(str))
58886 + if (IS_ERR((const char __force_kernel *)str))
58887 goto out;
58888
58889 len = strnlen_user(str, MAX_ARG_STRLEN);
58890 @@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58891 int r;
58892 mm_segment_t oldfs = get_fs();
58893 struct user_arg_ptr argv = {
58894 - .ptr.native = (const char __user *const __user *)__argv,
58895 + .ptr.native = (const char __user * const __force_user *)__argv,
58896 };
58897
58898 set_fs(KERNEL_DS);
58899 @@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58900 unsigned long new_end = old_end - shift;
58901 struct mmu_gather tlb;
58902
58903 - BUG_ON(new_start > new_end);
58904 + if (new_start >= new_end || new_start < mmap_min_addr)
58905 + return -ENOMEM;
58906
58907 /*
58908 * ensure there are no vmas between where we want to go
58909 @@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58910 if (vma != find_vma(mm, new_start))
58911 return -EFAULT;
58912
58913 +#ifdef CONFIG_PAX_SEGMEXEC
58914 + BUG_ON(pax_find_mirror_vma(vma));
58915 +#endif
58916 +
58917 /*
58918 * cover the whole range: [new_start, old_end)
58919 */
58920 @@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58921 stack_top = arch_align_stack(stack_top);
58922 stack_top = PAGE_ALIGN(stack_top);
58923
58924 - if (unlikely(stack_top < mmap_min_addr) ||
58925 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58926 - return -ENOMEM;
58927 -
58928 stack_shift = vma->vm_end - stack_top;
58929
58930 bprm->p -= stack_shift;
58931 @@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58932 bprm->exec -= stack_shift;
58933
58934 down_write(&mm->mmap_sem);
58935 +
58936 + /* Move stack pages down in memory. */
58937 + if (stack_shift) {
58938 + ret = shift_arg_pages(vma, stack_shift);
58939 + if (ret)
58940 + goto out_unlock;
58941 + }
58942 +
58943 vm_flags = VM_STACK_FLAGS;
58944
58945 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58946 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58947 + vm_flags &= ~VM_EXEC;
58948 +
58949 +#ifdef CONFIG_PAX_MPROTECT
58950 + if (mm->pax_flags & MF_PAX_MPROTECT)
58951 + vm_flags &= ~VM_MAYEXEC;
58952 +#endif
58953 +
58954 + }
58955 +#endif
58956 +
58957 /*
58958 * Adjust stack execute permissions; explicitly enable for
58959 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58960 @@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58961 goto out_unlock;
58962 BUG_ON(prev != vma);
58963
58964 - /* Move stack pages down in memory. */
58965 - if (stack_shift) {
58966 - ret = shift_arg_pages(vma, stack_shift);
58967 - if (ret)
58968 - goto out_unlock;
58969 - }
58970 -
58971 /* mprotect_fixup is overkill to remove the temporary stack flags */
58972 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58973
58974 @@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58975 #endif
58976 current->mm->start_stack = bprm->p;
58977 ret = expand_stack(vma, stack_base);
58978 +
58979 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58980 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58981 + unsigned long size;
58982 + vm_flags_t vm_flags;
58983 +
58984 + size = STACK_TOP - vma->vm_end;
58985 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58986 +
58987 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58988 +
58989 +#ifdef CONFIG_X86
58990 + if (!ret) {
58991 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58992 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58993 + }
58994 +#endif
58995 +
58996 + }
58997 +#endif
58998 +
58999 if (ret)
59000 ret = -EFAULT;
59001
59002 @@ -775,6 +851,8 @@ static struct file *do_open_exec(struct filename *name)
59003
59004 fsnotify_open(file);
59005
59006 + trace_open_exec(name->name);
59007 +
59008 err = deny_write_access(file);
59009 if (err)
59010 goto exit;
59011 @@ -804,7 +882,7 @@ int kernel_read(struct file *file, loff_t offset,
59012 old_fs = get_fs();
59013 set_fs(get_ds());
59014 /* The cast to a user pointer is valid due to the set_fs() */
59015 - result = vfs_read(file, (void __user *)addr, count, &pos);
59016 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
59017 set_fs(old_fs);
59018 return result;
59019 }
59020 @@ -849,6 +927,7 @@ static int exec_mmap(struct mm_struct *mm)
59021 tsk->mm = mm;
59022 tsk->active_mm = mm;
59023 activate_mm(active_mm, mm);
59024 + populate_stack();
59025 tsk->mm->vmacache_seqnum = 0;
59026 vmacache_flush(tsk);
59027 task_unlock(tsk);
59028 @@ -1246,7 +1325,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
59029 }
59030 rcu_read_unlock();
59031
59032 - if (p->fs->users > n_fs)
59033 + if (atomic_read(&p->fs->users) > n_fs)
59034 bprm->unsafe |= LSM_UNSAFE_SHARE;
59035 else
59036 p->fs->in_exec = 1;
59037 @@ -1422,6 +1501,31 @@ static int exec_binprm(struct linux_binprm *bprm)
59038 return ret;
59039 }
59040
59041 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59042 +static DEFINE_PER_CPU(u64, exec_counter);
59043 +static int __init init_exec_counters(void)
59044 +{
59045 + unsigned int cpu;
59046 +
59047 + for_each_possible_cpu(cpu) {
59048 + per_cpu(exec_counter, cpu) = (u64)cpu;
59049 + }
59050 +
59051 + return 0;
59052 +}
59053 +early_initcall(init_exec_counters);
59054 +static inline void increment_exec_counter(void)
59055 +{
59056 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
59057 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
59058 +}
59059 +#else
59060 +static inline void increment_exec_counter(void) {}
59061 +#endif
59062 +
59063 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
59064 + struct user_arg_ptr argv);
59065 +
59066 /*
59067 * sys_execve() executes a new program.
59068 */
59069 @@ -1429,6 +1533,11 @@ static int do_execve_common(struct filename *filename,
59070 struct user_arg_ptr argv,
59071 struct user_arg_ptr envp)
59072 {
59073 +#ifdef CONFIG_GRKERNSEC
59074 + struct file *old_exec_file;
59075 + struct acl_subject_label *old_acl;
59076 + struct rlimit old_rlim[RLIM_NLIMITS];
59077 +#endif
59078 struct linux_binprm *bprm;
59079 struct file *file;
59080 struct files_struct *displaced;
59081 @@ -1437,6 +1546,8 @@ static int do_execve_common(struct filename *filename,
59082 if (IS_ERR(filename))
59083 return PTR_ERR(filename);
59084
59085 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
59086 +
59087 /*
59088 * We move the actual failure in case of RLIMIT_NPROC excess from
59089 * set*uid() to execve() because too many poorly written programs
59090 @@ -1474,11 +1585,21 @@ static int do_execve_common(struct filename *filename,
59091 if (IS_ERR(file))
59092 goto out_unmark;
59093
59094 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
59095 + retval = -EPERM;
59096 + goto out_unmark;
59097 + }
59098 +
59099 sched_exec();
59100
59101 bprm->file = file;
59102 bprm->filename = bprm->interp = filename->name;
59103
59104 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
59105 + retval = -EACCES;
59106 + goto out_unmark;
59107 + }
59108 +
59109 retval = bprm_mm_init(bprm);
59110 if (retval)
59111 goto out_unmark;
59112 @@ -1495,24 +1616,70 @@ static int do_execve_common(struct filename *filename,
59113 if (retval < 0)
59114 goto out;
59115
59116 +#ifdef CONFIG_GRKERNSEC
59117 + old_acl = current->acl;
59118 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
59119 + old_exec_file = current->exec_file;
59120 + get_file(file);
59121 + current->exec_file = file;
59122 +#endif
59123 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59124 + /* limit suid stack to 8MB
59125 + * we saved the old limits above and will restore them if this exec fails
59126 + */
59127 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
59128 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
59129 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
59130 +#endif
59131 +
59132 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
59133 + retval = -EPERM;
59134 + goto out_fail;
59135 + }
59136 +
59137 + if (!gr_tpe_allow(file)) {
59138 + retval = -EACCES;
59139 + goto out_fail;
59140 + }
59141 +
59142 + if (gr_check_crash_exec(file)) {
59143 + retval = -EACCES;
59144 + goto out_fail;
59145 + }
59146 +
59147 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
59148 + bprm->unsafe);
59149 + if (retval < 0)
59150 + goto out_fail;
59151 +
59152 retval = copy_strings_kernel(1, &bprm->filename, bprm);
59153 if (retval < 0)
59154 - goto out;
59155 + goto out_fail;
59156
59157 bprm->exec = bprm->p;
59158 retval = copy_strings(bprm->envc, envp, bprm);
59159 if (retval < 0)
59160 - goto out;
59161 + goto out_fail;
59162
59163 retval = copy_strings(bprm->argc, argv, bprm);
59164 if (retval < 0)
59165 - goto out;
59166 + goto out_fail;
59167 +
59168 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
59169 +
59170 + gr_handle_exec_args(bprm, argv);
59171
59172 retval = exec_binprm(bprm);
59173 if (retval < 0)
59174 - goto out;
59175 + goto out_fail;
59176 +#ifdef CONFIG_GRKERNSEC
59177 + if (old_exec_file)
59178 + fput(old_exec_file);
59179 +#endif
59180
59181 /* execve succeeded */
59182 +
59183 + increment_exec_counter();
59184 current->fs->in_exec = 0;
59185 current->in_execve = 0;
59186 acct_update_integrals(current);
59187 @@ -1523,6 +1690,14 @@ static int do_execve_common(struct filename *filename,
59188 put_files_struct(displaced);
59189 return retval;
59190
59191 +out_fail:
59192 +#ifdef CONFIG_GRKERNSEC
59193 + current->acl = old_acl;
59194 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
59195 + fput(current->exec_file);
59196 + current->exec_file = old_exec_file;
59197 +#endif
59198 +
59199 out:
59200 if (bprm->mm) {
59201 acct_arg_size(bprm, 0);
59202 @@ -1614,3 +1789,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
59203 return compat_do_execve(getname(filename), argv, envp);
59204 }
59205 #endif
59206 +
59207 +int pax_check_flags(unsigned long *flags)
59208 +{
59209 + int retval = 0;
59210 +
59211 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
59212 + if (*flags & MF_PAX_SEGMEXEC)
59213 + {
59214 + *flags &= ~MF_PAX_SEGMEXEC;
59215 + retval = -EINVAL;
59216 + }
59217 +#endif
59218 +
59219 + if ((*flags & MF_PAX_PAGEEXEC)
59220 +
59221 +#ifdef CONFIG_PAX_PAGEEXEC
59222 + && (*flags & MF_PAX_SEGMEXEC)
59223 +#endif
59224 +
59225 + )
59226 + {
59227 + *flags &= ~MF_PAX_PAGEEXEC;
59228 + retval = -EINVAL;
59229 + }
59230 +
59231 + if ((*flags & MF_PAX_MPROTECT)
59232 +
59233 +#ifdef CONFIG_PAX_MPROTECT
59234 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59235 +#endif
59236 +
59237 + )
59238 + {
59239 + *flags &= ~MF_PAX_MPROTECT;
59240 + retval = -EINVAL;
59241 + }
59242 +
59243 + if ((*flags & MF_PAX_EMUTRAMP)
59244 +
59245 +#ifdef CONFIG_PAX_EMUTRAMP
59246 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59247 +#endif
59248 +
59249 + )
59250 + {
59251 + *flags &= ~MF_PAX_EMUTRAMP;
59252 + retval = -EINVAL;
59253 + }
59254 +
59255 + return retval;
59256 +}
59257 +
59258 +EXPORT_SYMBOL(pax_check_flags);
59259 +
59260 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59261 +char *pax_get_path(const struct path *path, char *buf, int buflen)
59262 +{
59263 + char *pathname = d_path(path, buf, buflen);
59264 +
59265 + if (IS_ERR(pathname))
59266 + goto toolong;
59267 +
59268 + pathname = mangle_path(buf, pathname, "\t\n\\");
59269 + if (!pathname)
59270 + goto toolong;
59271 +
59272 + *pathname = 0;
59273 + return buf;
59274 +
59275 +toolong:
59276 + return "<path too long>";
59277 +}
59278 +EXPORT_SYMBOL(pax_get_path);
59279 +
59280 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
59281 +{
59282 + struct task_struct *tsk = current;
59283 + struct mm_struct *mm = current->mm;
59284 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
59285 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
59286 + char *path_exec = NULL;
59287 + char *path_fault = NULL;
59288 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
59289 + siginfo_t info = { };
59290 +
59291 + if (buffer_exec && buffer_fault) {
59292 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
59293 +
59294 + down_read(&mm->mmap_sem);
59295 + vma = mm->mmap;
59296 + while (vma && (!vma_exec || !vma_fault)) {
59297 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
59298 + vma_exec = vma;
59299 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
59300 + vma_fault = vma;
59301 + vma = vma->vm_next;
59302 + }
59303 + if (vma_exec)
59304 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
59305 + if (vma_fault) {
59306 + start = vma_fault->vm_start;
59307 + end = vma_fault->vm_end;
59308 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
59309 + if (vma_fault->vm_file)
59310 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
59311 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
59312 + path_fault = "<heap>";
59313 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
59314 + path_fault = "<stack>";
59315 + else
59316 + path_fault = "<anonymous mapping>";
59317 + }
59318 + up_read(&mm->mmap_sem);
59319 + }
59320 + if (tsk->signal->curr_ip)
59321 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
59322 + else
59323 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
59324 + 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),
59325 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
59326 + free_page((unsigned long)buffer_exec);
59327 + free_page((unsigned long)buffer_fault);
59328 + pax_report_insns(regs, pc, sp);
59329 + info.si_signo = SIGKILL;
59330 + info.si_errno = 0;
59331 + info.si_code = SI_KERNEL;
59332 + info.si_pid = 0;
59333 + info.si_uid = 0;
59334 + do_coredump(&info);
59335 +}
59336 +#endif
59337 +
59338 +#ifdef CONFIG_PAX_REFCOUNT
59339 +void pax_report_refcount_overflow(struct pt_regs *regs)
59340 +{
59341 + if (current->signal->curr_ip)
59342 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59343 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
59344 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59345 + else
59346 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59347 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59348 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59349 + preempt_disable();
59350 + show_regs(regs);
59351 + preempt_enable();
59352 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59353 +}
59354 +#endif
59355 +
59356 +#ifdef CONFIG_PAX_USERCOPY
59357 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59358 +static noinline int check_stack_object(const void *obj, unsigned long len)
59359 +{
59360 + const void * const stack = task_stack_page(current);
59361 + const void * const stackend = stack + THREAD_SIZE;
59362 +
59363 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59364 + const void *frame = NULL;
59365 + const void *oldframe;
59366 +#endif
59367 +
59368 + if (obj + len < obj)
59369 + return -1;
59370 +
59371 + if (obj + len <= stack || stackend <= obj)
59372 + return 0;
59373 +
59374 + if (obj < stack || stackend < obj + len)
59375 + return -1;
59376 +
59377 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59378 + oldframe = __builtin_frame_address(1);
59379 + if (oldframe)
59380 + frame = __builtin_frame_address(2);
59381 + /*
59382 + low ----------------------------------------------> high
59383 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
59384 + ^----------------^
59385 + allow copies only within here
59386 + */
59387 + while (stack <= frame && frame < stackend) {
59388 + /* if obj + len extends past the last frame, this
59389 + check won't pass and the next frame will be 0,
59390 + causing us to bail out and correctly report
59391 + the copy as invalid
59392 + */
59393 + if (obj + len <= frame)
59394 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59395 + oldframe = frame;
59396 + frame = *(const void * const *)frame;
59397 + }
59398 + return -1;
59399 +#else
59400 + return 1;
59401 +#endif
59402 +}
59403 +
59404 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59405 +{
59406 + if (current->signal->curr_ip)
59407 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59408 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59409 + else
59410 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59411 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59412 + dump_stack();
59413 + gr_handle_kernel_exploit();
59414 + do_group_exit(SIGKILL);
59415 +}
59416 +#endif
59417 +
59418 +#ifdef CONFIG_PAX_USERCOPY
59419 +
59420 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59421 +{
59422 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59423 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
59424 +#ifdef CONFIG_MODULES
59425 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59426 +#else
59427 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59428 +#endif
59429 +
59430 +#else
59431 + unsigned long textlow = (unsigned long)_stext;
59432 + unsigned long texthigh = (unsigned long)_etext;
59433 +
59434 +#ifdef CONFIG_X86_64
59435 + /* check against linear mapping as well */
59436 + if (high > (unsigned long)__va(__pa(textlow)) &&
59437 + low < (unsigned long)__va(__pa(texthigh)))
59438 + return true;
59439 +#endif
59440 +
59441 +#endif
59442 +
59443 + if (high <= textlow || low >= texthigh)
59444 + return false;
59445 + else
59446 + return true;
59447 +}
59448 +#endif
59449 +
59450 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
59451 +{
59452 +#ifdef CONFIG_PAX_USERCOPY
59453 + const char *type;
59454 +#endif
59455 +
59456 +#ifndef CONFIG_STACK_GROWSUP
59457 + unsigned long stackstart = (unsigned long)task_stack_page(current);
59458 + unsigned long currentsp = (unsigned long)&stackstart;
59459 + if (unlikely((currentsp < stackstart + 512 ||
59460 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
59461 + BUG();
59462 +#endif
59463 +
59464 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
59465 + if (const_size)
59466 + return;
59467 +#endif
59468 +
59469 +#ifdef CONFIG_PAX_USERCOPY
59470 + if (!n)
59471 + return;
59472 +
59473 + type = check_heap_object(ptr, n);
59474 + if (!type) {
59475 + int ret = check_stack_object(ptr, n);
59476 + if (ret == 1 || ret == 2)
59477 + return;
59478 + if (ret == 0) {
59479 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59480 + type = "<kernel text>";
59481 + else
59482 + return;
59483 + } else
59484 + type = "<process stack>";
59485 + }
59486 +
59487 + pax_report_usercopy(ptr, n, to_user, type);
59488 +#endif
59489 +
59490 +}
59491 +EXPORT_SYMBOL(__check_object_size);
59492 +
59493 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59494 +void pax_track_stack(void)
59495 +{
59496 + unsigned long sp = (unsigned long)&sp;
59497 + if (sp < current_thread_info()->lowest_stack &&
59498 + sp > (unsigned long)task_stack_page(current))
59499 + current_thread_info()->lowest_stack = sp;
59500 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
59501 + BUG();
59502 +}
59503 +EXPORT_SYMBOL(pax_track_stack);
59504 +#endif
59505 +
59506 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
59507 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59508 +{
59509 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59510 + dump_stack();
59511 + do_group_exit(SIGKILL);
59512 +}
59513 +EXPORT_SYMBOL(report_size_overflow);
59514 +#endif
59515 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59516 index 9f9992b..8b59411 100644
59517 --- a/fs/ext2/balloc.c
59518 +++ b/fs/ext2/balloc.c
59519 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59520
59521 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59522 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59523 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59524 + if (free_blocks < root_blocks + 1 &&
59525 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59526 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59527 - !in_group_p (sbi->s_resgid))) {
59528 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59529 return 0;
59530 }
59531 return 1;
59532 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59533 index 9142614..97484fa 100644
59534 --- a/fs/ext2/xattr.c
59535 +++ b/fs/ext2/xattr.c
59536 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59537 struct buffer_head *bh = NULL;
59538 struct ext2_xattr_entry *entry;
59539 char *end;
59540 - size_t rest = buffer_size;
59541 + size_t rest = buffer_size, total_size = 0;
59542 int error;
59543
59544 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59545 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59546 buffer += size;
59547 }
59548 rest -= size;
59549 + total_size += size;
59550 }
59551 }
59552 - error = buffer_size - rest; /* total size */
59553 + error = total_size;
59554
59555 cleanup:
59556 brelse(bh);
59557 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59558 index 158b5d4..2432610 100644
59559 --- a/fs/ext3/balloc.c
59560 +++ b/fs/ext3/balloc.c
59561 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59562
59563 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59564 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59565 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59566 + if (free_blocks < root_blocks + 1 &&
59567 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59568 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59569 - !in_group_p (sbi->s_resgid))) {
59570 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59571 return 0;
59572 }
59573 return 1;
59574 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59575 index c6874be..f8a6ae8 100644
59576 --- a/fs/ext3/xattr.c
59577 +++ b/fs/ext3/xattr.c
59578 @@ -330,7 +330,7 @@ static int
59579 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59580 char *buffer, size_t buffer_size)
59581 {
59582 - size_t rest = buffer_size;
59583 + size_t rest = buffer_size, total_size = 0;
59584
59585 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59586 const struct xattr_handler *handler =
59587 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59588 buffer += size;
59589 }
59590 rest -= size;
59591 + total_size += size;
59592 }
59593 }
59594 - return buffer_size - rest;
59595 + return total_size;
59596 }
59597
59598 static int
59599 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59600 index 5c56785..77698a2 100644
59601 --- a/fs/ext4/balloc.c
59602 +++ b/fs/ext4/balloc.c
59603 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59604 /* Hm, nope. Are (enough) root reserved clusters available? */
59605 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59606 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59607 - capable(CAP_SYS_RESOURCE) ||
59608 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59609 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59610 + capable_nolog(CAP_SYS_RESOURCE)) {
59611
59612 if (free_clusters >= (nclusters + dirty_clusters +
59613 resv_clusters))
59614 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59615 index f542e48..c0275f5 100644
59616 --- a/fs/ext4/ext4.h
59617 +++ b/fs/ext4/ext4.h
59618 @@ -1274,19 +1274,19 @@ struct ext4_sb_info {
59619 unsigned long s_mb_last_start;
59620
59621 /* stats for buddy allocator */
59622 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59623 - atomic_t s_bal_success; /* we found long enough chunks */
59624 - atomic_t s_bal_allocated; /* in blocks */
59625 - atomic_t s_bal_ex_scanned; /* total extents scanned */
59626 - atomic_t s_bal_goals; /* goal hits */
59627 - atomic_t s_bal_breaks; /* too long searches */
59628 - atomic_t s_bal_2orders; /* 2^order hits */
59629 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59630 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59631 + atomic_unchecked_t s_bal_allocated; /* in blocks */
59632 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59633 + atomic_unchecked_t s_bal_goals; /* goal hits */
59634 + atomic_unchecked_t s_bal_breaks; /* too long searches */
59635 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59636 spinlock_t s_bal_lock;
59637 unsigned long s_mb_buddies_generated;
59638 unsigned long long s_mb_generation_time;
59639 - atomic_t s_mb_lost_chunks;
59640 - atomic_t s_mb_preallocated;
59641 - atomic_t s_mb_discarded;
59642 + atomic_unchecked_t s_mb_lost_chunks;
59643 + atomic_unchecked_t s_mb_preallocated;
59644 + atomic_unchecked_t s_mb_discarded;
59645 atomic_t s_lock_busy;
59646
59647 /* locality groups */
59648 diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
59649 index e6574d7..c30cbe2 100644
59650 --- a/fs/ext4/indirect.c
59651 +++ b/fs/ext4/indirect.c
59652 @@ -1345,8 +1345,8 @@ static int free_hole_blocks(handle_t *handle, struct inode *inode,
59653 if (level == 0 ||
59654 (bh && all_zeroes((__le32 *)bh->b_data,
59655 (__le32 *)bh->b_data + addr_per_block))) {
59656 - ext4_free_data(handle, inode, parent_bh, &blk, &blk+1);
59657 - *i_data = 0;
59658 + ext4_free_data(handle, inode, parent_bh,
59659 + i_data, i_data + 1);
59660 }
59661 brelse(bh);
59662 bh = NULL;
59663 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59664 index 2735a72..d083044 100644
59665 --- a/fs/ext4/mballoc.c
59666 +++ b/fs/ext4/mballoc.c
59667 @@ -1889,7 +1889,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59668 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59669
59670 if (EXT4_SB(sb)->s_mb_stats)
59671 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59672 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59673
59674 break;
59675 }
59676 @@ -2199,7 +2199,7 @@ repeat:
59677 ac->ac_status = AC_STATUS_CONTINUE;
59678 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59679 cr = 3;
59680 - atomic_inc(&sbi->s_mb_lost_chunks);
59681 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59682 goto repeat;
59683 }
59684 }
59685 @@ -2707,25 +2707,25 @@ int ext4_mb_release(struct super_block *sb)
59686 if (sbi->s_mb_stats) {
59687 ext4_msg(sb, KERN_INFO,
59688 "mballoc: %u blocks %u reqs (%u success)",
59689 - atomic_read(&sbi->s_bal_allocated),
59690 - atomic_read(&sbi->s_bal_reqs),
59691 - atomic_read(&sbi->s_bal_success));
59692 + atomic_read_unchecked(&sbi->s_bal_allocated),
59693 + atomic_read_unchecked(&sbi->s_bal_reqs),
59694 + atomic_read_unchecked(&sbi->s_bal_success));
59695 ext4_msg(sb, KERN_INFO,
59696 "mballoc: %u extents scanned, %u goal hits, "
59697 "%u 2^N hits, %u breaks, %u lost",
59698 - atomic_read(&sbi->s_bal_ex_scanned),
59699 - atomic_read(&sbi->s_bal_goals),
59700 - atomic_read(&sbi->s_bal_2orders),
59701 - atomic_read(&sbi->s_bal_breaks),
59702 - atomic_read(&sbi->s_mb_lost_chunks));
59703 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59704 + atomic_read_unchecked(&sbi->s_bal_goals),
59705 + atomic_read_unchecked(&sbi->s_bal_2orders),
59706 + atomic_read_unchecked(&sbi->s_bal_breaks),
59707 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59708 ext4_msg(sb, KERN_INFO,
59709 "mballoc: %lu generated and it took %Lu",
59710 sbi->s_mb_buddies_generated,
59711 sbi->s_mb_generation_time);
59712 ext4_msg(sb, KERN_INFO,
59713 "mballoc: %u preallocated, %u discarded",
59714 - atomic_read(&sbi->s_mb_preallocated),
59715 - atomic_read(&sbi->s_mb_discarded));
59716 + atomic_read_unchecked(&sbi->s_mb_preallocated),
59717 + atomic_read_unchecked(&sbi->s_mb_discarded));
59718 }
59719
59720 free_percpu(sbi->s_locality_groups);
59721 @@ -3179,16 +3179,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59722 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59723
59724 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59725 - atomic_inc(&sbi->s_bal_reqs);
59726 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59727 + atomic_inc_unchecked(&sbi->s_bal_reqs);
59728 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59729 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59730 - atomic_inc(&sbi->s_bal_success);
59731 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59732 + atomic_inc_unchecked(&sbi->s_bal_success);
59733 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59734 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59735 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59736 - atomic_inc(&sbi->s_bal_goals);
59737 + atomic_inc_unchecked(&sbi->s_bal_goals);
59738 if (ac->ac_found > sbi->s_mb_max_to_scan)
59739 - atomic_inc(&sbi->s_bal_breaks);
59740 + atomic_inc_unchecked(&sbi->s_bal_breaks);
59741 }
59742
59743 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59744 @@ -3593,7 +3593,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59745 trace_ext4_mb_new_inode_pa(ac, pa);
59746
59747 ext4_mb_use_inode_pa(ac, pa);
59748 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59749 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59750
59751 ei = EXT4_I(ac->ac_inode);
59752 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59753 @@ -3653,7 +3653,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59754 trace_ext4_mb_new_group_pa(ac, pa);
59755
59756 ext4_mb_use_group_pa(ac, pa);
59757 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59758 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59759
59760 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59761 lg = ac->ac_lg;
59762 @@ -3742,7 +3742,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59763 * from the bitmap and continue.
59764 */
59765 }
59766 - atomic_add(free, &sbi->s_mb_discarded);
59767 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
59768
59769 return err;
59770 }
59771 @@ -3760,7 +3760,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59772 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59773 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59774 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59775 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59776 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59777 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59778
59779 return 0;
59780 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59781 index 04434ad..6404663 100644
59782 --- a/fs/ext4/mmp.c
59783 +++ b/fs/ext4/mmp.c
59784 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59785 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59786 const char *function, unsigned int line, const char *msg)
59787 {
59788 - __ext4_warning(sb, function, line, msg);
59789 + __ext4_warning(sb, function, line, "%s", msg);
59790 __ext4_warning(sb, function, line,
59791 "MMP failure info: last update time: %llu, last update "
59792 "node: %s, last update device: %s\n",
59793 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59794 index 29a403c..f58dbdb 100644
59795 --- a/fs/ext4/super.c
59796 +++ b/fs/ext4/super.c
59797 @@ -1275,7 +1275,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59798 }
59799
59800 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59801 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59802 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59803 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59804
59805 #ifdef CONFIG_QUOTA
59806 @@ -2453,7 +2453,7 @@ struct ext4_attr {
59807 int offset;
59808 int deprecated_val;
59809 } u;
59810 -};
59811 +} __do_const;
59812
59813 static int parse_strtoull(const char *buf,
59814 unsigned long long max, unsigned long long *value)
59815 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59816 index 4eec399..1d9444c 100644
59817 --- a/fs/ext4/xattr.c
59818 +++ b/fs/ext4/xattr.c
59819 @@ -383,7 +383,7 @@ static int
59820 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59821 char *buffer, size_t buffer_size)
59822 {
59823 - size_t rest = buffer_size;
59824 + size_t rest = buffer_size, total_size = 0;
59825
59826 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59827 const struct xattr_handler *handler =
59828 @@ -400,9 +400,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59829 buffer += size;
59830 }
59831 rest -= size;
59832 + total_size += size;
59833 }
59834 }
59835 - return buffer_size - rest;
59836 + return total_size;
59837 }
59838
59839 static int
59840 diff --git a/fs/fcntl.c b/fs/fcntl.c
59841 index 72c82f6..a18b263 100644
59842 --- a/fs/fcntl.c
59843 +++ b/fs/fcntl.c
59844 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59845 if (err)
59846 return err;
59847
59848 + if (gr_handle_chroot_fowner(pid, type))
59849 + return -ENOENT;
59850 + if (gr_check_protected_task_fowner(pid, type))
59851 + return -EACCES;
59852 +
59853 f_modown(filp, pid, type, force);
59854 return 0;
59855 }
59856 diff --git a/fs/fhandle.c b/fs/fhandle.c
59857 index 999ff5c..ac037c9 100644
59858 --- a/fs/fhandle.c
59859 +++ b/fs/fhandle.c
59860 @@ -8,6 +8,7 @@
59861 #include <linux/fs_struct.h>
59862 #include <linux/fsnotify.h>
59863 #include <linux/personality.h>
59864 +#include <linux/grsecurity.h>
59865 #include <asm/uaccess.h>
59866 #include "internal.h"
59867 #include "mount.h"
59868 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
59869 } else
59870 retval = 0;
59871 /* copy the mount id */
59872 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59873 - sizeof(*mnt_id)) ||
59874 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59875 copy_to_user(ufh, handle,
59876 sizeof(struct file_handle) + handle_bytes))
59877 retval = -EFAULT;
59878 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
59879 * the directory. Ideally we would like CAP_DAC_SEARCH.
59880 * But we don't have that
59881 */
59882 - if (!capable(CAP_DAC_READ_SEARCH)) {
59883 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
59884 retval = -EPERM;
59885 goto out_err;
59886 }
59887 diff --git a/fs/file.c b/fs/file.c
59888 index 8f294cf..d0f3872 100644
59889 --- a/fs/file.c
59890 +++ b/fs/file.c
59891 @@ -16,6 +16,7 @@
59892 #include <linux/slab.h>
59893 #include <linux/vmalloc.h>
59894 #include <linux/file.h>
59895 +#include <linux/security.h>
59896 #include <linux/fdtable.h>
59897 #include <linux/bitops.h>
59898 #include <linux/interrupt.h>
59899 @@ -144,7 +145,7 @@ out:
59900 * Return <0 error code on error; 1 on successful completion.
59901 * The files->file_lock should be held on entry, and will be held on exit.
59902 */
59903 -static int expand_fdtable(struct files_struct *files, int nr)
59904 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
59905 __releases(files->file_lock)
59906 __acquires(files->file_lock)
59907 {
59908 @@ -189,7 +190,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59909 * expanded and execution may have blocked.
59910 * The files->file_lock should be held on entry, and will be held on exit.
59911 */
59912 -static int expand_files(struct files_struct *files, int nr)
59913 +static int expand_files(struct files_struct *files, unsigned int nr)
59914 {
59915 struct fdtable *fdt;
59916
59917 @@ -804,6 +805,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59918 if (!file)
59919 return __close_fd(files, fd);
59920
59921 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59922 if (fd >= rlimit(RLIMIT_NOFILE))
59923 return -EBADF;
59924
59925 @@ -830,6 +832,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59926 if (unlikely(oldfd == newfd))
59927 return -EINVAL;
59928
59929 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59930 if (newfd >= rlimit(RLIMIT_NOFILE))
59931 return -EBADF;
59932
59933 @@ -885,6 +888,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59934 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59935 {
59936 int err;
59937 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59938 if (from >= rlimit(RLIMIT_NOFILE))
59939 return -EINVAL;
59940 err = alloc_fd(from, flags);
59941 diff --git a/fs/filesystems.c b/fs/filesystems.c
59942 index 5797d45..7d7d79a 100644
59943 --- a/fs/filesystems.c
59944 +++ b/fs/filesystems.c
59945 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
59946 int len = dot ? dot - name : strlen(name);
59947
59948 fs = __get_fs_type(name, len);
59949 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
59950 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59951 +#else
59952 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59953 +#endif
59954 fs = __get_fs_type(name, len);
59955
59956 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59957 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59958 index 7dca743..543d620 100644
59959 --- a/fs/fs_struct.c
59960 +++ b/fs/fs_struct.c
59961 @@ -4,6 +4,7 @@
59962 #include <linux/path.h>
59963 #include <linux/slab.h>
59964 #include <linux/fs_struct.h>
59965 +#include <linux/grsecurity.h>
59966 #include "internal.h"
59967
59968 /*
59969 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59970 write_seqcount_begin(&fs->seq);
59971 old_root = fs->root;
59972 fs->root = *path;
59973 + gr_set_chroot_entries(current, path);
59974 write_seqcount_end(&fs->seq);
59975 spin_unlock(&fs->lock);
59976 if (old_root.dentry)
59977 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59978 int hits = 0;
59979 spin_lock(&fs->lock);
59980 write_seqcount_begin(&fs->seq);
59981 + /* this root replacement is only done by pivot_root,
59982 + leave grsec's chroot tagging alone for this task
59983 + so that a pivoted root isn't treated as a chroot
59984 + */
59985 hits += replace_path(&fs->root, old_root, new_root);
59986 hits += replace_path(&fs->pwd, old_root, new_root);
59987 write_seqcount_end(&fs->seq);
59988 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59989 task_lock(tsk);
59990 spin_lock(&fs->lock);
59991 tsk->fs = NULL;
59992 - kill = !--fs->users;
59993 + gr_clear_chroot_entries(tsk);
59994 + kill = !atomic_dec_return(&fs->users);
59995 spin_unlock(&fs->lock);
59996 task_unlock(tsk);
59997 if (kill)
59998 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59999 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
60000 /* We don't need to lock fs - think why ;-) */
60001 if (fs) {
60002 - fs->users = 1;
60003 + atomic_set(&fs->users, 1);
60004 fs->in_exec = 0;
60005 spin_lock_init(&fs->lock);
60006 seqcount_init(&fs->seq);
60007 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60008 spin_lock(&old->lock);
60009 fs->root = old->root;
60010 path_get(&fs->root);
60011 + /* instead of calling gr_set_chroot_entries here,
60012 + we call it from every caller of this function
60013 + */
60014 fs->pwd = old->pwd;
60015 path_get(&fs->pwd);
60016 spin_unlock(&old->lock);
60017 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
60018
60019 task_lock(current);
60020 spin_lock(&fs->lock);
60021 - kill = !--fs->users;
60022 + kill = !atomic_dec_return(&fs->users);
60023 current->fs = new_fs;
60024 + gr_set_chroot_entries(current, &new_fs->root);
60025 spin_unlock(&fs->lock);
60026 task_unlock(current);
60027
60028 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
60029
60030 int current_umask(void)
60031 {
60032 - return current->fs->umask;
60033 + return current->fs->umask | gr_acl_umask();
60034 }
60035 EXPORT_SYMBOL(current_umask);
60036
60037 /* to be mentioned only in INIT_TASK */
60038 struct fs_struct init_fs = {
60039 - .users = 1,
60040 + .users = ATOMIC_INIT(1),
60041 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
60042 .seq = SEQCNT_ZERO(init_fs.seq),
60043 .umask = 0022,
60044 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
60045 index 29d7feb..303644d 100644
60046 --- a/fs/fscache/cookie.c
60047 +++ b/fs/fscache/cookie.c
60048 @@ -19,7 +19,7 @@
60049
60050 struct kmem_cache *fscache_cookie_jar;
60051
60052 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
60053 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
60054
60055 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
60056 static int fscache_alloc_object(struct fscache_cache *cache,
60057 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
60058 parent ? (char *) parent->def->name : "<no-parent>",
60059 def->name, netfs_data, enable);
60060
60061 - fscache_stat(&fscache_n_acquires);
60062 + fscache_stat_unchecked(&fscache_n_acquires);
60063
60064 /* if there's no parent cookie, then we don't create one here either */
60065 if (!parent) {
60066 - fscache_stat(&fscache_n_acquires_null);
60067 + fscache_stat_unchecked(&fscache_n_acquires_null);
60068 _leave(" [no parent]");
60069 return NULL;
60070 }
60071 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60072 /* allocate and initialise a cookie */
60073 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
60074 if (!cookie) {
60075 - fscache_stat(&fscache_n_acquires_oom);
60076 + fscache_stat_unchecked(&fscache_n_acquires_oom);
60077 _leave(" [ENOMEM]");
60078 return NULL;
60079 }
60080 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
60081
60082 switch (cookie->def->type) {
60083 case FSCACHE_COOKIE_TYPE_INDEX:
60084 - fscache_stat(&fscache_n_cookie_index);
60085 + fscache_stat_unchecked(&fscache_n_cookie_index);
60086 break;
60087 case FSCACHE_COOKIE_TYPE_DATAFILE:
60088 - fscache_stat(&fscache_n_cookie_data);
60089 + fscache_stat_unchecked(&fscache_n_cookie_data);
60090 break;
60091 default:
60092 - fscache_stat(&fscache_n_cookie_special);
60093 + fscache_stat_unchecked(&fscache_n_cookie_special);
60094 break;
60095 }
60096
60097 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60098 } else {
60099 atomic_dec(&parent->n_children);
60100 __fscache_cookie_put(cookie);
60101 - fscache_stat(&fscache_n_acquires_nobufs);
60102 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
60103 _leave(" = NULL");
60104 return NULL;
60105 }
60106 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60107 }
60108 }
60109
60110 - fscache_stat(&fscache_n_acquires_ok);
60111 + fscache_stat_unchecked(&fscache_n_acquires_ok);
60112 _leave(" = %p", cookie);
60113 return cookie;
60114 }
60115 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
60116 cache = fscache_select_cache_for_object(cookie->parent);
60117 if (!cache) {
60118 up_read(&fscache_addremove_sem);
60119 - fscache_stat(&fscache_n_acquires_no_cache);
60120 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
60121 _leave(" = -ENOMEDIUM [no cache]");
60122 return -ENOMEDIUM;
60123 }
60124 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
60125 object = cache->ops->alloc_object(cache, cookie);
60126 fscache_stat_d(&fscache_n_cop_alloc_object);
60127 if (IS_ERR(object)) {
60128 - fscache_stat(&fscache_n_object_no_alloc);
60129 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
60130 ret = PTR_ERR(object);
60131 goto error;
60132 }
60133
60134 - fscache_stat(&fscache_n_object_alloc);
60135 + fscache_stat_unchecked(&fscache_n_object_alloc);
60136
60137 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
60138 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
60139
60140 _debug("ALLOC OBJ%x: %s {%lx}",
60141 object->debug_id, cookie->def->name, object->events);
60142 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
60143
60144 _enter("{%s}", cookie->def->name);
60145
60146 - fscache_stat(&fscache_n_invalidates);
60147 + fscache_stat_unchecked(&fscache_n_invalidates);
60148
60149 /* Only permit invalidation of data files. Invalidating an index will
60150 * require the caller to release all its attachments to the tree rooted
60151 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
60152 {
60153 struct fscache_object *object;
60154
60155 - fscache_stat(&fscache_n_updates);
60156 + fscache_stat_unchecked(&fscache_n_updates);
60157
60158 if (!cookie) {
60159 - fscache_stat(&fscache_n_updates_null);
60160 + fscache_stat_unchecked(&fscache_n_updates_null);
60161 _leave(" [no cookie]");
60162 return;
60163 }
60164 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
60165 */
60166 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
60167 {
60168 - fscache_stat(&fscache_n_relinquishes);
60169 + fscache_stat_unchecked(&fscache_n_relinquishes);
60170 if (retire)
60171 - fscache_stat(&fscache_n_relinquishes_retire);
60172 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
60173
60174 if (!cookie) {
60175 - fscache_stat(&fscache_n_relinquishes_null);
60176 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
60177 _leave(" [no cookie]");
60178 return;
60179 }
60180 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
60181 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
60182 goto inconsistent;
60183
60184 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60185 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60186
60187 __fscache_use_cookie(cookie);
60188 if (fscache_submit_op(object, op) < 0)
60189 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
60190 index 4226f66..0fb3f45 100644
60191 --- a/fs/fscache/internal.h
60192 +++ b/fs/fscache/internal.h
60193 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
60194 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
60195 extern int fscache_wait_for_operation_activation(struct fscache_object *,
60196 struct fscache_operation *,
60197 - atomic_t *,
60198 - atomic_t *,
60199 + atomic_unchecked_t *,
60200 + atomic_unchecked_t *,
60201 void (*)(struct fscache_operation *));
60202 extern void fscache_invalidate_writes(struct fscache_cookie *);
60203
60204 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
60205 * stats.c
60206 */
60207 #ifdef CONFIG_FSCACHE_STATS
60208 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60209 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60210 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60211 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60212
60213 -extern atomic_t fscache_n_op_pend;
60214 -extern atomic_t fscache_n_op_run;
60215 -extern atomic_t fscache_n_op_enqueue;
60216 -extern atomic_t fscache_n_op_deferred_release;
60217 -extern atomic_t fscache_n_op_release;
60218 -extern atomic_t fscache_n_op_gc;
60219 -extern atomic_t fscache_n_op_cancelled;
60220 -extern atomic_t fscache_n_op_rejected;
60221 +extern atomic_unchecked_t fscache_n_op_pend;
60222 +extern atomic_unchecked_t fscache_n_op_run;
60223 +extern atomic_unchecked_t fscache_n_op_enqueue;
60224 +extern atomic_unchecked_t fscache_n_op_deferred_release;
60225 +extern atomic_unchecked_t fscache_n_op_release;
60226 +extern atomic_unchecked_t fscache_n_op_gc;
60227 +extern atomic_unchecked_t fscache_n_op_cancelled;
60228 +extern atomic_unchecked_t fscache_n_op_rejected;
60229
60230 -extern atomic_t fscache_n_attr_changed;
60231 -extern atomic_t fscache_n_attr_changed_ok;
60232 -extern atomic_t fscache_n_attr_changed_nobufs;
60233 -extern atomic_t fscache_n_attr_changed_nomem;
60234 -extern atomic_t fscache_n_attr_changed_calls;
60235 +extern atomic_unchecked_t fscache_n_attr_changed;
60236 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
60237 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
60238 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
60239 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
60240
60241 -extern atomic_t fscache_n_allocs;
60242 -extern atomic_t fscache_n_allocs_ok;
60243 -extern atomic_t fscache_n_allocs_wait;
60244 -extern atomic_t fscache_n_allocs_nobufs;
60245 -extern atomic_t fscache_n_allocs_intr;
60246 -extern atomic_t fscache_n_allocs_object_dead;
60247 -extern atomic_t fscache_n_alloc_ops;
60248 -extern atomic_t fscache_n_alloc_op_waits;
60249 +extern atomic_unchecked_t fscache_n_allocs;
60250 +extern atomic_unchecked_t fscache_n_allocs_ok;
60251 +extern atomic_unchecked_t fscache_n_allocs_wait;
60252 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
60253 +extern atomic_unchecked_t fscache_n_allocs_intr;
60254 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
60255 +extern atomic_unchecked_t fscache_n_alloc_ops;
60256 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
60257
60258 -extern atomic_t fscache_n_retrievals;
60259 -extern atomic_t fscache_n_retrievals_ok;
60260 -extern atomic_t fscache_n_retrievals_wait;
60261 -extern atomic_t fscache_n_retrievals_nodata;
60262 -extern atomic_t fscache_n_retrievals_nobufs;
60263 -extern atomic_t fscache_n_retrievals_intr;
60264 -extern atomic_t fscache_n_retrievals_nomem;
60265 -extern atomic_t fscache_n_retrievals_object_dead;
60266 -extern atomic_t fscache_n_retrieval_ops;
60267 -extern atomic_t fscache_n_retrieval_op_waits;
60268 +extern atomic_unchecked_t fscache_n_retrievals;
60269 +extern atomic_unchecked_t fscache_n_retrievals_ok;
60270 +extern atomic_unchecked_t fscache_n_retrievals_wait;
60271 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
60272 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
60273 +extern atomic_unchecked_t fscache_n_retrievals_intr;
60274 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
60275 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
60276 +extern atomic_unchecked_t fscache_n_retrieval_ops;
60277 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
60278
60279 -extern atomic_t fscache_n_stores;
60280 -extern atomic_t fscache_n_stores_ok;
60281 -extern atomic_t fscache_n_stores_again;
60282 -extern atomic_t fscache_n_stores_nobufs;
60283 -extern atomic_t fscache_n_stores_oom;
60284 -extern atomic_t fscache_n_store_ops;
60285 -extern atomic_t fscache_n_store_calls;
60286 -extern atomic_t fscache_n_store_pages;
60287 -extern atomic_t fscache_n_store_radix_deletes;
60288 -extern atomic_t fscache_n_store_pages_over_limit;
60289 +extern atomic_unchecked_t fscache_n_stores;
60290 +extern atomic_unchecked_t fscache_n_stores_ok;
60291 +extern atomic_unchecked_t fscache_n_stores_again;
60292 +extern atomic_unchecked_t fscache_n_stores_nobufs;
60293 +extern atomic_unchecked_t fscache_n_stores_oom;
60294 +extern atomic_unchecked_t fscache_n_store_ops;
60295 +extern atomic_unchecked_t fscache_n_store_calls;
60296 +extern atomic_unchecked_t fscache_n_store_pages;
60297 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
60298 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
60299
60300 -extern atomic_t fscache_n_store_vmscan_not_storing;
60301 -extern atomic_t fscache_n_store_vmscan_gone;
60302 -extern atomic_t fscache_n_store_vmscan_busy;
60303 -extern atomic_t fscache_n_store_vmscan_cancelled;
60304 -extern atomic_t fscache_n_store_vmscan_wait;
60305 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60306 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
60307 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
60308 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60309 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
60310
60311 -extern atomic_t fscache_n_marks;
60312 -extern atomic_t fscache_n_uncaches;
60313 +extern atomic_unchecked_t fscache_n_marks;
60314 +extern atomic_unchecked_t fscache_n_uncaches;
60315
60316 -extern atomic_t fscache_n_acquires;
60317 -extern atomic_t fscache_n_acquires_null;
60318 -extern atomic_t fscache_n_acquires_no_cache;
60319 -extern atomic_t fscache_n_acquires_ok;
60320 -extern atomic_t fscache_n_acquires_nobufs;
60321 -extern atomic_t fscache_n_acquires_oom;
60322 +extern atomic_unchecked_t fscache_n_acquires;
60323 +extern atomic_unchecked_t fscache_n_acquires_null;
60324 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
60325 +extern atomic_unchecked_t fscache_n_acquires_ok;
60326 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
60327 +extern atomic_unchecked_t fscache_n_acquires_oom;
60328
60329 -extern atomic_t fscache_n_invalidates;
60330 -extern atomic_t fscache_n_invalidates_run;
60331 +extern atomic_unchecked_t fscache_n_invalidates;
60332 +extern atomic_unchecked_t fscache_n_invalidates_run;
60333
60334 -extern atomic_t fscache_n_updates;
60335 -extern atomic_t fscache_n_updates_null;
60336 -extern atomic_t fscache_n_updates_run;
60337 +extern atomic_unchecked_t fscache_n_updates;
60338 +extern atomic_unchecked_t fscache_n_updates_null;
60339 +extern atomic_unchecked_t fscache_n_updates_run;
60340
60341 -extern atomic_t fscache_n_relinquishes;
60342 -extern atomic_t fscache_n_relinquishes_null;
60343 -extern atomic_t fscache_n_relinquishes_waitcrt;
60344 -extern atomic_t fscache_n_relinquishes_retire;
60345 +extern atomic_unchecked_t fscache_n_relinquishes;
60346 +extern atomic_unchecked_t fscache_n_relinquishes_null;
60347 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60348 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
60349
60350 -extern atomic_t fscache_n_cookie_index;
60351 -extern atomic_t fscache_n_cookie_data;
60352 -extern atomic_t fscache_n_cookie_special;
60353 +extern atomic_unchecked_t fscache_n_cookie_index;
60354 +extern atomic_unchecked_t fscache_n_cookie_data;
60355 +extern atomic_unchecked_t fscache_n_cookie_special;
60356
60357 -extern atomic_t fscache_n_object_alloc;
60358 -extern atomic_t fscache_n_object_no_alloc;
60359 -extern atomic_t fscache_n_object_lookups;
60360 -extern atomic_t fscache_n_object_lookups_negative;
60361 -extern atomic_t fscache_n_object_lookups_positive;
60362 -extern atomic_t fscache_n_object_lookups_timed_out;
60363 -extern atomic_t fscache_n_object_created;
60364 -extern atomic_t fscache_n_object_avail;
60365 -extern atomic_t fscache_n_object_dead;
60366 +extern atomic_unchecked_t fscache_n_object_alloc;
60367 +extern atomic_unchecked_t fscache_n_object_no_alloc;
60368 +extern atomic_unchecked_t fscache_n_object_lookups;
60369 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
60370 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
60371 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60372 +extern atomic_unchecked_t fscache_n_object_created;
60373 +extern atomic_unchecked_t fscache_n_object_avail;
60374 +extern atomic_unchecked_t fscache_n_object_dead;
60375
60376 -extern atomic_t fscache_n_checkaux_none;
60377 -extern atomic_t fscache_n_checkaux_okay;
60378 -extern atomic_t fscache_n_checkaux_update;
60379 -extern atomic_t fscache_n_checkaux_obsolete;
60380 +extern atomic_unchecked_t fscache_n_checkaux_none;
60381 +extern atomic_unchecked_t fscache_n_checkaux_okay;
60382 +extern atomic_unchecked_t fscache_n_checkaux_update;
60383 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60384
60385 extern atomic_t fscache_n_cop_alloc_object;
60386 extern atomic_t fscache_n_cop_lookup_object;
60387 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60388 atomic_inc(stat);
60389 }
60390
60391 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60392 +{
60393 + atomic_inc_unchecked(stat);
60394 +}
60395 +
60396 static inline void fscache_stat_d(atomic_t *stat)
60397 {
60398 atomic_dec(stat);
60399 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60400
60401 #define __fscache_stat(stat) (NULL)
60402 #define fscache_stat(stat) do {} while (0)
60403 +#define fscache_stat_unchecked(stat) do {} while (0)
60404 #define fscache_stat_d(stat) do {} while (0)
60405 #endif
60406
60407 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60408 index d3b4539..ed0c659 100644
60409 --- a/fs/fscache/object.c
60410 +++ b/fs/fscache/object.c
60411 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60412 _debug("LOOKUP \"%s\" in \"%s\"",
60413 cookie->def->name, object->cache->tag->name);
60414
60415 - fscache_stat(&fscache_n_object_lookups);
60416 + fscache_stat_unchecked(&fscache_n_object_lookups);
60417 fscache_stat(&fscache_n_cop_lookup_object);
60418 ret = object->cache->ops->lookup_object(object);
60419 fscache_stat_d(&fscache_n_cop_lookup_object);
60420 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60421 if (ret == -ETIMEDOUT) {
60422 /* probably stuck behind another object, so move this one to
60423 * the back of the queue */
60424 - fscache_stat(&fscache_n_object_lookups_timed_out);
60425 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60426 _leave(" [timeout]");
60427 return NO_TRANSIT;
60428 }
60429 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60430 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60431
60432 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60433 - fscache_stat(&fscache_n_object_lookups_negative);
60434 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60435
60436 /* Allow write requests to begin stacking up and read requests to begin
60437 * returning ENODATA.
60438 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60439 /* if we were still looking up, then we must have a positive lookup
60440 * result, in which case there may be data available */
60441 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60442 - fscache_stat(&fscache_n_object_lookups_positive);
60443 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60444
60445 /* We do (presumably) have data */
60446 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60447 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60448 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60449 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60450 } else {
60451 - fscache_stat(&fscache_n_object_created);
60452 + fscache_stat_unchecked(&fscache_n_object_created);
60453 }
60454
60455 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60456 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60457 fscache_stat_d(&fscache_n_cop_lookup_complete);
60458
60459 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60460 - fscache_stat(&fscache_n_object_avail);
60461 + fscache_stat_unchecked(&fscache_n_object_avail);
60462
60463 _leave("");
60464 return transit_to(JUMPSTART_DEPS);
60465 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60466
60467 /* this just shifts the object release to the work processor */
60468 fscache_put_object(object);
60469 - fscache_stat(&fscache_n_object_dead);
60470 + fscache_stat_unchecked(&fscache_n_object_dead);
60471
60472 _leave("");
60473 return transit_to(OBJECT_DEAD);
60474 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60475 enum fscache_checkaux result;
60476
60477 if (!object->cookie->def->check_aux) {
60478 - fscache_stat(&fscache_n_checkaux_none);
60479 + fscache_stat_unchecked(&fscache_n_checkaux_none);
60480 return FSCACHE_CHECKAUX_OKAY;
60481 }
60482
60483 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60484 switch (result) {
60485 /* entry okay as is */
60486 case FSCACHE_CHECKAUX_OKAY:
60487 - fscache_stat(&fscache_n_checkaux_okay);
60488 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
60489 break;
60490
60491 /* entry requires update */
60492 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60493 - fscache_stat(&fscache_n_checkaux_update);
60494 + fscache_stat_unchecked(&fscache_n_checkaux_update);
60495 break;
60496
60497 /* entry requires deletion */
60498 case FSCACHE_CHECKAUX_OBSOLETE:
60499 - fscache_stat(&fscache_n_checkaux_obsolete);
60500 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60501 break;
60502
60503 default:
60504 @@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60505 {
60506 const struct fscache_state *s;
60507
60508 - fscache_stat(&fscache_n_invalidates_run);
60509 + fscache_stat_unchecked(&fscache_n_invalidates_run);
60510 fscache_stat(&fscache_n_cop_invalidate_object);
60511 s = _fscache_invalidate_object(object, event);
60512 fscache_stat_d(&fscache_n_cop_invalidate_object);
60513 @@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60514 {
60515 _enter("{OBJ%x},%d", object->debug_id, event);
60516
60517 - fscache_stat(&fscache_n_updates_run);
60518 + fscache_stat_unchecked(&fscache_n_updates_run);
60519 fscache_stat(&fscache_n_cop_update_object);
60520 object->cache->ops->update_object(object);
60521 fscache_stat_d(&fscache_n_cop_update_object);
60522 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60523 index 318071a..379938b 100644
60524 --- a/fs/fscache/operation.c
60525 +++ b/fs/fscache/operation.c
60526 @@ -17,7 +17,7 @@
60527 #include <linux/slab.h>
60528 #include "internal.h"
60529
60530 -atomic_t fscache_op_debug_id;
60531 +atomic_unchecked_t fscache_op_debug_id;
60532 EXPORT_SYMBOL(fscache_op_debug_id);
60533
60534 /**
60535 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60536 ASSERTCMP(atomic_read(&op->usage), >, 0);
60537 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60538
60539 - fscache_stat(&fscache_n_op_enqueue);
60540 + fscache_stat_unchecked(&fscache_n_op_enqueue);
60541 switch (op->flags & FSCACHE_OP_TYPE) {
60542 case FSCACHE_OP_ASYNC:
60543 _debug("queue async");
60544 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60545 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60546 if (op->processor)
60547 fscache_enqueue_operation(op);
60548 - fscache_stat(&fscache_n_op_run);
60549 + fscache_stat_unchecked(&fscache_n_op_run);
60550 }
60551
60552 /*
60553 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60554 if (object->n_in_progress > 0) {
60555 atomic_inc(&op->usage);
60556 list_add_tail(&op->pend_link, &object->pending_ops);
60557 - fscache_stat(&fscache_n_op_pend);
60558 + fscache_stat_unchecked(&fscache_n_op_pend);
60559 } else if (!list_empty(&object->pending_ops)) {
60560 atomic_inc(&op->usage);
60561 list_add_tail(&op->pend_link, &object->pending_ops);
60562 - fscache_stat(&fscache_n_op_pend);
60563 + fscache_stat_unchecked(&fscache_n_op_pend);
60564 fscache_start_operations(object);
60565 } else {
60566 ASSERTCMP(object->n_in_progress, ==, 0);
60567 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60568 object->n_exclusive++; /* reads and writes must wait */
60569 atomic_inc(&op->usage);
60570 list_add_tail(&op->pend_link, &object->pending_ops);
60571 - fscache_stat(&fscache_n_op_pend);
60572 + fscache_stat_unchecked(&fscache_n_op_pend);
60573 ret = 0;
60574 } else {
60575 /* If we're in any other state, there must have been an I/O
60576 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60577 if (object->n_exclusive > 0) {
60578 atomic_inc(&op->usage);
60579 list_add_tail(&op->pend_link, &object->pending_ops);
60580 - fscache_stat(&fscache_n_op_pend);
60581 + fscache_stat_unchecked(&fscache_n_op_pend);
60582 } else if (!list_empty(&object->pending_ops)) {
60583 atomic_inc(&op->usage);
60584 list_add_tail(&op->pend_link, &object->pending_ops);
60585 - fscache_stat(&fscache_n_op_pend);
60586 + fscache_stat_unchecked(&fscache_n_op_pend);
60587 fscache_start_operations(object);
60588 } else {
60589 ASSERTCMP(object->n_exclusive, ==, 0);
60590 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60591 object->n_ops++;
60592 atomic_inc(&op->usage);
60593 list_add_tail(&op->pend_link, &object->pending_ops);
60594 - fscache_stat(&fscache_n_op_pend);
60595 + fscache_stat_unchecked(&fscache_n_op_pend);
60596 ret = 0;
60597 } else if (fscache_object_is_dying(object)) {
60598 - fscache_stat(&fscache_n_op_rejected);
60599 + fscache_stat_unchecked(&fscache_n_op_rejected);
60600 op->state = FSCACHE_OP_ST_CANCELLED;
60601 ret = -ENOBUFS;
60602 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60603 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60604 ret = -EBUSY;
60605 if (op->state == FSCACHE_OP_ST_PENDING) {
60606 ASSERT(!list_empty(&op->pend_link));
60607 - fscache_stat(&fscache_n_op_cancelled);
60608 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60609 list_del_init(&op->pend_link);
60610 if (do_cancel)
60611 do_cancel(op);
60612 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60613 while (!list_empty(&object->pending_ops)) {
60614 op = list_entry(object->pending_ops.next,
60615 struct fscache_operation, pend_link);
60616 - fscache_stat(&fscache_n_op_cancelled);
60617 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60618 list_del_init(&op->pend_link);
60619
60620 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60621 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60622 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60623 op->state = FSCACHE_OP_ST_DEAD;
60624
60625 - fscache_stat(&fscache_n_op_release);
60626 + fscache_stat_unchecked(&fscache_n_op_release);
60627
60628 if (op->release) {
60629 op->release(op);
60630 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60631 * lock, and defer it otherwise */
60632 if (!spin_trylock(&object->lock)) {
60633 _debug("defer put");
60634 - fscache_stat(&fscache_n_op_deferred_release);
60635 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
60636
60637 cache = object->cache;
60638 spin_lock(&cache->op_gc_list_lock);
60639 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60640
60641 _debug("GC DEFERRED REL OBJ%x OP%x",
60642 object->debug_id, op->debug_id);
60643 - fscache_stat(&fscache_n_op_gc);
60644 + fscache_stat_unchecked(&fscache_n_op_gc);
60645
60646 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60647 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60648 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60649 index 7f5c658..6c1e164 100644
60650 --- a/fs/fscache/page.c
60651 +++ b/fs/fscache/page.c
60652 @@ -61,7 +61,7 @@ try_again:
60653 val = radix_tree_lookup(&cookie->stores, page->index);
60654 if (!val) {
60655 rcu_read_unlock();
60656 - fscache_stat(&fscache_n_store_vmscan_not_storing);
60657 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60658 __fscache_uncache_page(cookie, page);
60659 return true;
60660 }
60661 @@ -91,11 +91,11 @@ try_again:
60662 spin_unlock(&cookie->stores_lock);
60663
60664 if (xpage) {
60665 - fscache_stat(&fscache_n_store_vmscan_cancelled);
60666 - fscache_stat(&fscache_n_store_radix_deletes);
60667 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60668 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60669 ASSERTCMP(xpage, ==, page);
60670 } else {
60671 - fscache_stat(&fscache_n_store_vmscan_gone);
60672 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60673 }
60674
60675 wake_up_bit(&cookie->flags, 0);
60676 @@ -110,11 +110,11 @@ page_busy:
60677 * sleeping on memory allocation, so we may need to impose a timeout
60678 * too. */
60679 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60680 - fscache_stat(&fscache_n_store_vmscan_busy);
60681 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60682 return false;
60683 }
60684
60685 - fscache_stat(&fscache_n_store_vmscan_wait);
60686 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60687 __fscache_wait_on_page_write(cookie, page);
60688 gfp &= ~__GFP_WAIT;
60689 goto try_again;
60690 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60691 FSCACHE_COOKIE_STORING_TAG);
60692 if (!radix_tree_tag_get(&cookie->stores, page->index,
60693 FSCACHE_COOKIE_PENDING_TAG)) {
60694 - fscache_stat(&fscache_n_store_radix_deletes);
60695 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60696 xpage = radix_tree_delete(&cookie->stores, page->index);
60697 }
60698 spin_unlock(&cookie->stores_lock);
60699 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60700
60701 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60702
60703 - fscache_stat(&fscache_n_attr_changed_calls);
60704 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60705
60706 if (fscache_object_is_active(object)) {
60707 fscache_stat(&fscache_n_cop_attr_changed);
60708 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60709
60710 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60711
60712 - fscache_stat(&fscache_n_attr_changed);
60713 + fscache_stat_unchecked(&fscache_n_attr_changed);
60714
60715 op = kzalloc(sizeof(*op), GFP_KERNEL);
60716 if (!op) {
60717 - fscache_stat(&fscache_n_attr_changed_nomem);
60718 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60719 _leave(" = -ENOMEM");
60720 return -ENOMEM;
60721 }
60722 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60723 if (fscache_submit_exclusive_op(object, op) < 0)
60724 goto nobufs;
60725 spin_unlock(&cookie->lock);
60726 - fscache_stat(&fscache_n_attr_changed_ok);
60727 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60728 fscache_put_operation(op);
60729 _leave(" = 0");
60730 return 0;
60731 @@ -225,7 +225,7 @@ nobufs:
60732 kfree(op);
60733 if (wake_cookie)
60734 __fscache_wake_unused_cookie(cookie);
60735 - fscache_stat(&fscache_n_attr_changed_nobufs);
60736 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60737 _leave(" = %d", -ENOBUFS);
60738 return -ENOBUFS;
60739 }
60740 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60741 /* allocate a retrieval operation and attempt to submit it */
60742 op = kzalloc(sizeof(*op), GFP_NOIO);
60743 if (!op) {
60744 - fscache_stat(&fscache_n_retrievals_nomem);
60745 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60746 return NULL;
60747 }
60748
60749 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60750 return 0;
60751 }
60752
60753 - fscache_stat(&fscache_n_retrievals_wait);
60754 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
60755
60756 jif = jiffies;
60757 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60758 fscache_wait_bit_interruptible,
60759 TASK_INTERRUPTIBLE) != 0) {
60760 - fscache_stat(&fscache_n_retrievals_intr);
60761 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60762 _leave(" = -ERESTARTSYS");
60763 return -ERESTARTSYS;
60764 }
60765 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60766 */
60767 int fscache_wait_for_operation_activation(struct fscache_object *object,
60768 struct fscache_operation *op,
60769 - atomic_t *stat_op_waits,
60770 - atomic_t *stat_object_dead,
60771 + atomic_unchecked_t *stat_op_waits,
60772 + atomic_unchecked_t *stat_object_dead,
60773 void (*do_cancel)(struct fscache_operation *))
60774 {
60775 int ret;
60776 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60777
60778 _debug(">>> WT");
60779 if (stat_op_waits)
60780 - fscache_stat(stat_op_waits);
60781 + fscache_stat_unchecked(stat_op_waits);
60782 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60783 fscache_wait_bit_interruptible,
60784 TASK_INTERRUPTIBLE) != 0) {
60785 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60786 check_if_dead:
60787 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60788 if (stat_object_dead)
60789 - fscache_stat(stat_object_dead);
60790 + fscache_stat_unchecked(stat_object_dead);
60791 _leave(" = -ENOBUFS [cancelled]");
60792 return -ENOBUFS;
60793 }
60794 @@ -366,7 +366,7 @@ check_if_dead:
60795 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60796 fscache_cancel_op(op, do_cancel);
60797 if (stat_object_dead)
60798 - fscache_stat(stat_object_dead);
60799 + fscache_stat_unchecked(stat_object_dead);
60800 return -ENOBUFS;
60801 }
60802 return 0;
60803 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60804
60805 _enter("%p,%p,,,", cookie, page);
60806
60807 - fscache_stat(&fscache_n_retrievals);
60808 + fscache_stat_unchecked(&fscache_n_retrievals);
60809
60810 if (hlist_empty(&cookie->backing_objects))
60811 goto nobufs;
60812 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60813 goto nobufs_unlock_dec;
60814 spin_unlock(&cookie->lock);
60815
60816 - fscache_stat(&fscache_n_retrieval_ops);
60817 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60818
60819 /* pin the netfs read context in case we need to do the actual netfs
60820 * read because we've encountered a cache read failure */
60821 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60822
60823 error:
60824 if (ret == -ENOMEM)
60825 - fscache_stat(&fscache_n_retrievals_nomem);
60826 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60827 else if (ret == -ERESTARTSYS)
60828 - fscache_stat(&fscache_n_retrievals_intr);
60829 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60830 else if (ret == -ENODATA)
60831 - fscache_stat(&fscache_n_retrievals_nodata);
60832 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60833 else if (ret < 0)
60834 - fscache_stat(&fscache_n_retrievals_nobufs);
60835 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60836 else
60837 - fscache_stat(&fscache_n_retrievals_ok);
60838 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60839
60840 fscache_put_retrieval(op);
60841 _leave(" = %d", ret);
60842 @@ -490,7 +490,7 @@ nobufs_unlock:
60843 __fscache_wake_unused_cookie(cookie);
60844 kfree(op);
60845 nobufs:
60846 - fscache_stat(&fscache_n_retrievals_nobufs);
60847 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60848 _leave(" = -ENOBUFS");
60849 return -ENOBUFS;
60850 }
60851 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60852
60853 _enter("%p,,%d,,,", cookie, *nr_pages);
60854
60855 - fscache_stat(&fscache_n_retrievals);
60856 + fscache_stat_unchecked(&fscache_n_retrievals);
60857
60858 if (hlist_empty(&cookie->backing_objects))
60859 goto nobufs;
60860 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60861 goto nobufs_unlock_dec;
60862 spin_unlock(&cookie->lock);
60863
60864 - fscache_stat(&fscache_n_retrieval_ops);
60865 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60866
60867 /* pin the netfs read context in case we need to do the actual netfs
60868 * read because we've encountered a cache read failure */
60869 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60870
60871 error:
60872 if (ret == -ENOMEM)
60873 - fscache_stat(&fscache_n_retrievals_nomem);
60874 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60875 else if (ret == -ERESTARTSYS)
60876 - fscache_stat(&fscache_n_retrievals_intr);
60877 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60878 else if (ret == -ENODATA)
60879 - fscache_stat(&fscache_n_retrievals_nodata);
60880 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60881 else if (ret < 0)
60882 - fscache_stat(&fscache_n_retrievals_nobufs);
60883 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60884 else
60885 - fscache_stat(&fscache_n_retrievals_ok);
60886 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60887
60888 fscache_put_retrieval(op);
60889 _leave(" = %d", ret);
60890 @@ -621,7 +621,7 @@ nobufs_unlock:
60891 if (wake_cookie)
60892 __fscache_wake_unused_cookie(cookie);
60893 nobufs:
60894 - fscache_stat(&fscache_n_retrievals_nobufs);
60895 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60896 _leave(" = -ENOBUFS");
60897 return -ENOBUFS;
60898 }
60899 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60900
60901 _enter("%p,%p,,,", cookie, page);
60902
60903 - fscache_stat(&fscache_n_allocs);
60904 + fscache_stat_unchecked(&fscache_n_allocs);
60905
60906 if (hlist_empty(&cookie->backing_objects))
60907 goto nobufs;
60908 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60909 goto nobufs_unlock_dec;
60910 spin_unlock(&cookie->lock);
60911
60912 - fscache_stat(&fscache_n_alloc_ops);
60913 + fscache_stat_unchecked(&fscache_n_alloc_ops);
60914
60915 ret = fscache_wait_for_operation_activation(
60916 object, &op->op,
60917 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60918
60919 error:
60920 if (ret == -ERESTARTSYS)
60921 - fscache_stat(&fscache_n_allocs_intr);
60922 + fscache_stat_unchecked(&fscache_n_allocs_intr);
60923 else if (ret < 0)
60924 - fscache_stat(&fscache_n_allocs_nobufs);
60925 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60926 else
60927 - fscache_stat(&fscache_n_allocs_ok);
60928 + fscache_stat_unchecked(&fscache_n_allocs_ok);
60929
60930 fscache_put_retrieval(op);
60931 _leave(" = %d", ret);
60932 @@ -715,7 +715,7 @@ nobufs_unlock:
60933 if (wake_cookie)
60934 __fscache_wake_unused_cookie(cookie);
60935 nobufs:
60936 - fscache_stat(&fscache_n_allocs_nobufs);
60937 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60938 _leave(" = -ENOBUFS");
60939 return -ENOBUFS;
60940 }
60941 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60942
60943 spin_lock(&cookie->stores_lock);
60944
60945 - fscache_stat(&fscache_n_store_calls);
60946 + fscache_stat_unchecked(&fscache_n_store_calls);
60947
60948 /* find a page to store */
60949 page = NULL;
60950 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60951 page = results[0];
60952 _debug("gang %d [%lx]", n, page->index);
60953 if (page->index > op->store_limit) {
60954 - fscache_stat(&fscache_n_store_pages_over_limit);
60955 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60956 goto superseded;
60957 }
60958
60959 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60960 spin_unlock(&cookie->stores_lock);
60961 spin_unlock(&object->lock);
60962
60963 - fscache_stat(&fscache_n_store_pages);
60964 + fscache_stat_unchecked(&fscache_n_store_pages);
60965 fscache_stat(&fscache_n_cop_write_page);
60966 ret = object->cache->ops->write_page(op, page);
60967 fscache_stat_d(&fscache_n_cop_write_page);
60968 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60969 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60970 ASSERT(PageFsCache(page));
60971
60972 - fscache_stat(&fscache_n_stores);
60973 + fscache_stat_unchecked(&fscache_n_stores);
60974
60975 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60976 _leave(" = -ENOBUFS [invalidating]");
60977 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60978 spin_unlock(&cookie->stores_lock);
60979 spin_unlock(&object->lock);
60980
60981 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60982 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60983 op->store_limit = object->store_limit;
60984
60985 __fscache_use_cookie(cookie);
60986 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60987
60988 spin_unlock(&cookie->lock);
60989 radix_tree_preload_end();
60990 - fscache_stat(&fscache_n_store_ops);
60991 - fscache_stat(&fscache_n_stores_ok);
60992 + fscache_stat_unchecked(&fscache_n_store_ops);
60993 + fscache_stat_unchecked(&fscache_n_stores_ok);
60994
60995 /* the work queue now carries its own ref on the object */
60996 fscache_put_operation(&op->op);
60997 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60998 return 0;
60999
61000 already_queued:
61001 - fscache_stat(&fscache_n_stores_again);
61002 + fscache_stat_unchecked(&fscache_n_stores_again);
61003 already_pending:
61004 spin_unlock(&cookie->stores_lock);
61005 spin_unlock(&object->lock);
61006 spin_unlock(&cookie->lock);
61007 radix_tree_preload_end();
61008 kfree(op);
61009 - fscache_stat(&fscache_n_stores_ok);
61010 + fscache_stat_unchecked(&fscache_n_stores_ok);
61011 _leave(" = 0");
61012 return 0;
61013
61014 @@ -1024,14 +1024,14 @@ nobufs:
61015 kfree(op);
61016 if (wake_cookie)
61017 __fscache_wake_unused_cookie(cookie);
61018 - fscache_stat(&fscache_n_stores_nobufs);
61019 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
61020 _leave(" = -ENOBUFS");
61021 return -ENOBUFS;
61022
61023 nomem_free:
61024 kfree(op);
61025 nomem:
61026 - fscache_stat(&fscache_n_stores_oom);
61027 + fscache_stat_unchecked(&fscache_n_stores_oom);
61028 _leave(" = -ENOMEM");
61029 return -ENOMEM;
61030 }
61031 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
61032 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61033 ASSERTCMP(page, !=, NULL);
61034
61035 - fscache_stat(&fscache_n_uncaches);
61036 + fscache_stat_unchecked(&fscache_n_uncaches);
61037
61038 /* cache withdrawal may beat us to it */
61039 if (!PageFsCache(page))
61040 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
61041 struct fscache_cookie *cookie = op->op.object->cookie;
61042
61043 #ifdef CONFIG_FSCACHE_STATS
61044 - atomic_inc(&fscache_n_marks);
61045 + atomic_inc_unchecked(&fscache_n_marks);
61046 #endif
61047
61048 _debug("- mark %p{%lx}", page, page->index);
61049 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
61050 index 40d13c7..ddf52b9 100644
61051 --- a/fs/fscache/stats.c
61052 +++ b/fs/fscache/stats.c
61053 @@ -18,99 +18,99 @@
61054 /*
61055 * operation counters
61056 */
61057 -atomic_t fscache_n_op_pend;
61058 -atomic_t fscache_n_op_run;
61059 -atomic_t fscache_n_op_enqueue;
61060 -atomic_t fscache_n_op_requeue;
61061 -atomic_t fscache_n_op_deferred_release;
61062 -atomic_t fscache_n_op_release;
61063 -atomic_t fscache_n_op_gc;
61064 -atomic_t fscache_n_op_cancelled;
61065 -atomic_t fscache_n_op_rejected;
61066 +atomic_unchecked_t fscache_n_op_pend;
61067 +atomic_unchecked_t fscache_n_op_run;
61068 +atomic_unchecked_t fscache_n_op_enqueue;
61069 +atomic_unchecked_t fscache_n_op_requeue;
61070 +atomic_unchecked_t fscache_n_op_deferred_release;
61071 +atomic_unchecked_t fscache_n_op_release;
61072 +atomic_unchecked_t fscache_n_op_gc;
61073 +atomic_unchecked_t fscache_n_op_cancelled;
61074 +atomic_unchecked_t fscache_n_op_rejected;
61075
61076 -atomic_t fscache_n_attr_changed;
61077 -atomic_t fscache_n_attr_changed_ok;
61078 -atomic_t fscache_n_attr_changed_nobufs;
61079 -atomic_t fscache_n_attr_changed_nomem;
61080 -atomic_t fscache_n_attr_changed_calls;
61081 +atomic_unchecked_t fscache_n_attr_changed;
61082 +atomic_unchecked_t fscache_n_attr_changed_ok;
61083 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
61084 +atomic_unchecked_t fscache_n_attr_changed_nomem;
61085 +atomic_unchecked_t fscache_n_attr_changed_calls;
61086
61087 -atomic_t fscache_n_allocs;
61088 -atomic_t fscache_n_allocs_ok;
61089 -atomic_t fscache_n_allocs_wait;
61090 -atomic_t fscache_n_allocs_nobufs;
61091 -atomic_t fscache_n_allocs_intr;
61092 -atomic_t fscache_n_allocs_object_dead;
61093 -atomic_t fscache_n_alloc_ops;
61094 -atomic_t fscache_n_alloc_op_waits;
61095 +atomic_unchecked_t fscache_n_allocs;
61096 +atomic_unchecked_t fscache_n_allocs_ok;
61097 +atomic_unchecked_t fscache_n_allocs_wait;
61098 +atomic_unchecked_t fscache_n_allocs_nobufs;
61099 +atomic_unchecked_t fscache_n_allocs_intr;
61100 +atomic_unchecked_t fscache_n_allocs_object_dead;
61101 +atomic_unchecked_t fscache_n_alloc_ops;
61102 +atomic_unchecked_t fscache_n_alloc_op_waits;
61103
61104 -atomic_t fscache_n_retrievals;
61105 -atomic_t fscache_n_retrievals_ok;
61106 -atomic_t fscache_n_retrievals_wait;
61107 -atomic_t fscache_n_retrievals_nodata;
61108 -atomic_t fscache_n_retrievals_nobufs;
61109 -atomic_t fscache_n_retrievals_intr;
61110 -atomic_t fscache_n_retrievals_nomem;
61111 -atomic_t fscache_n_retrievals_object_dead;
61112 -atomic_t fscache_n_retrieval_ops;
61113 -atomic_t fscache_n_retrieval_op_waits;
61114 +atomic_unchecked_t fscache_n_retrievals;
61115 +atomic_unchecked_t fscache_n_retrievals_ok;
61116 +atomic_unchecked_t fscache_n_retrievals_wait;
61117 +atomic_unchecked_t fscache_n_retrievals_nodata;
61118 +atomic_unchecked_t fscache_n_retrievals_nobufs;
61119 +atomic_unchecked_t fscache_n_retrievals_intr;
61120 +atomic_unchecked_t fscache_n_retrievals_nomem;
61121 +atomic_unchecked_t fscache_n_retrievals_object_dead;
61122 +atomic_unchecked_t fscache_n_retrieval_ops;
61123 +atomic_unchecked_t fscache_n_retrieval_op_waits;
61124
61125 -atomic_t fscache_n_stores;
61126 -atomic_t fscache_n_stores_ok;
61127 -atomic_t fscache_n_stores_again;
61128 -atomic_t fscache_n_stores_nobufs;
61129 -atomic_t fscache_n_stores_oom;
61130 -atomic_t fscache_n_store_ops;
61131 -atomic_t fscache_n_store_calls;
61132 -atomic_t fscache_n_store_pages;
61133 -atomic_t fscache_n_store_radix_deletes;
61134 -atomic_t fscache_n_store_pages_over_limit;
61135 +atomic_unchecked_t fscache_n_stores;
61136 +atomic_unchecked_t fscache_n_stores_ok;
61137 +atomic_unchecked_t fscache_n_stores_again;
61138 +atomic_unchecked_t fscache_n_stores_nobufs;
61139 +atomic_unchecked_t fscache_n_stores_oom;
61140 +atomic_unchecked_t fscache_n_store_ops;
61141 +atomic_unchecked_t fscache_n_store_calls;
61142 +atomic_unchecked_t fscache_n_store_pages;
61143 +atomic_unchecked_t fscache_n_store_radix_deletes;
61144 +atomic_unchecked_t fscache_n_store_pages_over_limit;
61145
61146 -atomic_t fscache_n_store_vmscan_not_storing;
61147 -atomic_t fscache_n_store_vmscan_gone;
61148 -atomic_t fscache_n_store_vmscan_busy;
61149 -atomic_t fscache_n_store_vmscan_cancelled;
61150 -atomic_t fscache_n_store_vmscan_wait;
61151 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
61152 +atomic_unchecked_t fscache_n_store_vmscan_gone;
61153 +atomic_unchecked_t fscache_n_store_vmscan_busy;
61154 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
61155 +atomic_unchecked_t fscache_n_store_vmscan_wait;
61156
61157 -atomic_t fscache_n_marks;
61158 -atomic_t fscache_n_uncaches;
61159 +atomic_unchecked_t fscache_n_marks;
61160 +atomic_unchecked_t fscache_n_uncaches;
61161
61162 -atomic_t fscache_n_acquires;
61163 -atomic_t fscache_n_acquires_null;
61164 -atomic_t fscache_n_acquires_no_cache;
61165 -atomic_t fscache_n_acquires_ok;
61166 -atomic_t fscache_n_acquires_nobufs;
61167 -atomic_t fscache_n_acquires_oom;
61168 +atomic_unchecked_t fscache_n_acquires;
61169 +atomic_unchecked_t fscache_n_acquires_null;
61170 +atomic_unchecked_t fscache_n_acquires_no_cache;
61171 +atomic_unchecked_t fscache_n_acquires_ok;
61172 +atomic_unchecked_t fscache_n_acquires_nobufs;
61173 +atomic_unchecked_t fscache_n_acquires_oom;
61174
61175 -atomic_t fscache_n_invalidates;
61176 -atomic_t fscache_n_invalidates_run;
61177 +atomic_unchecked_t fscache_n_invalidates;
61178 +atomic_unchecked_t fscache_n_invalidates_run;
61179
61180 -atomic_t fscache_n_updates;
61181 -atomic_t fscache_n_updates_null;
61182 -atomic_t fscache_n_updates_run;
61183 +atomic_unchecked_t fscache_n_updates;
61184 +atomic_unchecked_t fscache_n_updates_null;
61185 +atomic_unchecked_t fscache_n_updates_run;
61186
61187 -atomic_t fscache_n_relinquishes;
61188 -atomic_t fscache_n_relinquishes_null;
61189 -atomic_t fscache_n_relinquishes_waitcrt;
61190 -atomic_t fscache_n_relinquishes_retire;
61191 +atomic_unchecked_t fscache_n_relinquishes;
61192 +atomic_unchecked_t fscache_n_relinquishes_null;
61193 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
61194 +atomic_unchecked_t fscache_n_relinquishes_retire;
61195
61196 -atomic_t fscache_n_cookie_index;
61197 -atomic_t fscache_n_cookie_data;
61198 -atomic_t fscache_n_cookie_special;
61199 +atomic_unchecked_t fscache_n_cookie_index;
61200 +atomic_unchecked_t fscache_n_cookie_data;
61201 +atomic_unchecked_t fscache_n_cookie_special;
61202
61203 -atomic_t fscache_n_object_alloc;
61204 -atomic_t fscache_n_object_no_alloc;
61205 -atomic_t fscache_n_object_lookups;
61206 -atomic_t fscache_n_object_lookups_negative;
61207 -atomic_t fscache_n_object_lookups_positive;
61208 -atomic_t fscache_n_object_lookups_timed_out;
61209 -atomic_t fscache_n_object_created;
61210 -atomic_t fscache_n_object_avail;
61211 -atomic_t fscache_n_object_dead;
61212 +atomic_unchecked_t fscache_n_object_alloc;
61213 +atomic_unchecked_t fscache_n_object_no_alloc;
61214 +atomic_unchecked_t fscache_n_object_lookups;
61215 +atomic_unchecked_t fscache_n_object_lookups_negative;
61216 +atomic_unchecked_t fscache_n_object_lookups_positive;
61217 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
61218 +atomic_unchecked_t fscache_n_object_created;
61219 +atomic_unchecked_t fscache_n_object_avail;
61220 +atomic_unchecked_t fscache_n_object_dead;
61221
61222 -atomic_t fscache_n_checkaux_none;
61223 -atomic_t fscache_n_checkaux_okay;
61224 -atomic_t fscache_n_checkaux_update;
61225 -atomic_t fscache_n_checkaux_obsolete;
61226 +atomic_unchecked_t fscache_n_checkaux_none;
61227 +atomic_unchecked_t fscache_n_checkaux_okay;
61228 +atomic_unchecked_t fscache_n_checkaux_update;
61229 +atomic_unchecked_t fscache_n_checkaux_obsolete;
61230
61231 atomic_t fscache_n_cop_alloc_object;
61232 atomic_t fscache_n_cop_lookup_object;
61233 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
61234 seq_puts(m, "FS-Cache statistics\n");
61235
61236 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
61237 - atomic_read(&fscache_n_cookie_index),
61238 - atomic_read(&fscache_n_cookie_data),
61239 - atomic_read(&fscache_n_cookie_special));
61240 + atomic_read_unchecked(&fscache_n_cookie_index),
61241 + atomic_read_unchecked(&fscache_n_cookie_data),
61242 + atomic_read_unchecked(&fscache_n_cookie_special));
61243
61244 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
61245 - atomic_read(&fscache_n_object_alloc),
61246 - atomic_read(&fscache_n_object_no_alloc),
61247 - atomic_read(&fscache_n_object_avail),
61248 - atomic_read(&fscache_n_object_dead));
61249 + atomic_read_unchecked(&fscache_n_object_alloc),
61250 + atomic_read_unchecked(&fscache_n_object_no_alloc),
61251 + atomic_read_unchecked(&fscache_n_object_avail),
61252 + atomic_read_unchecked(&fscache_n_object_dead));
61253 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
61254 - atomic_read(&fscache_n_checkaux_none),
61255 - atomic_read(&fscache_n_checkaux_okay),
61256 - atomic_read(&fscache_n_checkaux_update),
61257 - atomic_read(&fscache_n_checkaux_obsolete));
61258 + atomic_read_unchecked(&fscache_n_checkaux_none),
61259 + atomic_read_unchecked(&fscache_n_checkaux_okay),
61260 + atomic_read_unchecked(&fscache_n_checkaux_update),
61261 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
61262
61263 seq_printf(m, "Pages : mrk=%u unc=%u\n",
61264 - atomic_read(&fscache_n_marks),
61265 - atomic_read(&fscache_n_uncaches));
61266 + atomic_read_unchecked(&fscache_n_marks),
61267 + atomic_read_unchecked(&fscache_n_uncaches));
61268
61269 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
61270 " oom=%u\n",
61271 - atomic_read(&fscache_n_acquires),
61272 - atomic_read(&fscache_n_acquires_null),
61273 - atomic_read(&fscache_n_acquires_no_cache),
61274 - atomic_read(&fscache_n_acquires_ok),
61275 - atomic_read(&fscache_n_acquires_nobufs),
61276 - atomic_read(&fscache_n_acquires_oom));
61277 + atomic_read_unchecked(&fscache_n_acquires),
61278 + atomic_read_unchecked(&fscache_n_acquires_null),
61279 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
61280 + atomic_read_unchecked(&fscache_n_acquires_ok),
61281 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
61282 + atomic_read_unchecked(&fscache_n_acquires_oom));
61283
61284 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
61285 - atomic_read(&fscache_n_object_lookups),
61286 - atomic_read(&fscache_n_object_lookups_negative),
61287 - atomic_read(&fscache_n_object_lookups_positive),
61288 - atomic_read(&fscache_n_object_created),
61289 - atomic_read(&fscache_n_object_lookups_timed_out));
61290 + atomic_read_unchecked(&fscache_n_object_lookups),
61291 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
61292 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
61293 + atomic_read_unchecked(&fscache_n_object_created),
61294 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
61295
61296 seq_printf(m, "Invals : n=%u run=%u\n",
61297 - atomic_read(&fscache_n_invalidates),
61298 - atomic_read(&fscache_n_invalidates_run));
61299 + atomic_read_unchecked(&fscache_n_invalidates),
61300 + atomic_read_unchecked(&fscache_n_invalidates_run));
61301
61302 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
61303 - atomic_read(&fscache_n_updates),
61304 - atomic_read(&fscache_n_updates_null),
61305 - atomic_read(&fscache_n_updates_run));
61306 + atomic_read_unchecked(&fscache_n_updates),
61307 + atomic_read_unchecked(&fscache_n_updates_null),
61308 + atomic_read_unchecked(&fscache_n_updates_run));
61309
61310 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
61311 - atomic_read(&fscache_n_relinquishes),
61312 - atomic_read(&fscache_n_relinquishes_null),
61313 - atomic_read(&fscache_n_relinquishes_waitcrt),
61314 - atomic_read(&fscache_n_relinquishes_retire));
61315 + atomic_read_unchecked(&fscache_n_relinquishes),
61316 + atomic_read_unchecked(&fscache_n_relinquishes_null),
61317 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
61318 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
61319
61320 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
61321 - atomic_read(&fscache_n_attr_changed),
61322 - atomic_read(&fscache_n_attr_changed_ok),
61323 - atomic_read(&fscache_n_attr_changed_nobufs),
61324 - atomic_read(&fscache_n_attr_changed_nomem),
61325 - atomic_read(&fscache_n_attr_changed_calls));
61326 + atomic_read_unchecked(&fscache_n_attr_changed),
61327 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
61328 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
61329 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
61330 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
61331
61332 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61333 - atomic_read(&fscache_n_allocs),
61334 - atomic_read(&fscache_n_allocs_ok),
61335 - atomic_read(&fscache_n_allocs_wait),
61336 - atomic_read(&fscache_n_allocs_nobufs),
61337 - atomic_read(&fscache_n_allocs_intr));
61338 + atomic_read_unchecked(&fscache_n_allocs),
61339 + atomic_read_unchecked(&fscache_n_allocs_ok),
61340 + atomic_read_unchecked(&fscache_n_allocs_wait),
61341 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
61342 + atomic_read_unchecked(&fscache_n_allocs_intr));
61343 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61344 - atomic_read(&fscache_n_alloc_ops),
61345 - atomic_read(&fscache_n_alloc_op_waits),
61346 - atomic_read(&fscache_n_allocs_object_dead));
61347 + atomic_read_unchecked(&fscache_n_alloc_ops),
61348 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
61349 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
61350
61351 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61352 " int=%u oom=%u\n",
61353 - atomic_read(&fscache_n_retrievals),
61354 - atomic_read(&fscache_n_retrievals_ok),
61355 - atomic_read(&fscache_n_retrievals_wait),
61356 - atomic_read(&fscache_n_retrievals_nodata),
61357 - atomic_read(&fscache_n_retrievals_nobufs),
61358 - atomic_read(&fscache_n_retrievals_intr),
61359 - atomic_read(&fscache_n_retrievals_nomem));
61360 + atomic_read_unchecked(&fscache_n_retrievals),
61361 + atomic_read_unchecked(&fscache_n_retrievals_ok),
61362 + atomic_read_unchecked(&fscache_n_retrievals_wait),
61363 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
61364 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61365 + atomic_read_unchecked(&fscache_n_retrievals_intr),
61366 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
61367 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61368 - atomic_read(&fscache_n_retrieval_ops),
61369 - atomic_read(&fscache_n_retrieval_op_waits),
61370 - atomic_read(&fscache_n_retrievals_object_dead));
61371 + atomic_read_unchecked(&fscache_n_retrieval_ops),
61372 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61373 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61374
61375 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61376 - atomic_read(&fscache_n_stores),
61377 - atomic_read(&fscache_n_stores_ok),
61378 - atomic_read(&fscache_n_stores_again),
61379 - atomic_read(&fscache_n_stores_nobufs),
61380 - atomic_read(&fscache_n_stores_oom));
61381 + atomic_read_unchecked(&fscache_n_stores),
61382 + atomic_read_unchecked(&fscache_n_stores_ok),
61383 + atomic_read_unchecked(&fscache_n_stores_again),
61384 + atomic_read_unchecked(&fscache_n_stores_nobufs),
61385 + atomic_read_unchecked(&fscache_n_stores_oom));
61386 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61387 - atomic_read(&fscache_n_store_ops),
61388 - atomic_read(&fscache_n_store_calls),
61389 - atomic_read(&fscache_n_store_pages),
61390 - atomic_read(&fscache_n_store_radix_deletes),
61391 - atomic_read(&fscache_n_store_pages_over_limit));
61392 + atomic_read_unchecked(&fscache_n_store_ops),
61393 + atomic_read_unchecked(&fscache_n_store_calls),
61394 + atomic_read_unchecked(&fscache_n_store_pages),
61395 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
61396 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61397
61398 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61399 - atomic_read(&fscache_n_store_vmscan_not_storing),
61400 - atomic_read(&fscache_n_store_vmscan_gone),
61401 - atomic_read(&fscache_n_store_vmscan_busy),
61402 - atomic_read(&fscache_n_store_vmscan_cancelled),
61403 - atomic_read(&fscache_n_store_vmscan_wait));
61404 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61405 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61406 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61407 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61408 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61409
61410 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61411 - atomic_read(&fscache_n_op_pend),
61412 - atomic_read(&fscache_n_op_run),
61413 - atomic_read(&fscache_n_op_enqueue),
61414 - atomic_read(&fscache_n_op_cancelled),
61415 - atomic_read(&fscache_n_op_rejected));
61416 + atomic_read_unchecked(&fscache_n_op_pend),
61417 + atomic_read_unchecked(&fscache_n_op_run),
61418 + atomic_read_unchecked(&fscache_n_op_enqueue),
61419 + atomic_read_unchecked(&fscache_n_op_cancelled),
61420 + atomic_read_unchecked(&fscache_n_op_rejected));
61421 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61422 - atomic_read(&fscache_n_op_deferred_release),
61423 - atomic_read(&fscache_n_op_release),
61424 - atomic_read(&fscache_n_op_gc));
61425 + atomic_read_unchecked(&fscache_n_op_deferred_release),
61426 + atomic_read_unchecked(&fscache_n_op_release),
61427 + atomic_read_unchecked(&fscache_n_op_gc));
61428
61429 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61430 atomic_read(&fscache_n_cop_alloc_object),
61431 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61432 index 13b691a..1ffca5ae 100644
61433 --- a/fs/fuse/cuse.c
61434 +++ b/fs/fuse/cuse.c
61435 @@ -607,10 +607,12 @@ static int __init cuse_init(void)
61436 INIT_LIST_HEAD(&cuse_conntbl[i]);
61437
61438 /* inherit and extend fuse_dev_operations */
61439 - cuse_channel_fops = fuse_dev_operations;
61440 - cuse_channel_fops.owner = THIS_MODULE;
61441 - cuse_channel_fops.open = cuse_channel_open;
61442 - cuse_channel_fops.release = cuse_channel_release;
61443 + pax_open_kernel();
61444 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61445 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61446 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
61447 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
61448 + pax_close_kernel();
61449
61450 cuse_class = class_create(THIS_MODULE, "cuse");
61451 if (IS_ERR(cuse_class))
61452 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61453 index aac71ce..fcd6a1b 100644
61454 --- a/fs/fuse/dev.c
61455 +++ b/fs/fuse/dev.c
61456 @@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61457 ret = 0;
61458 pipe_lock(pipe);
61459
61460 - if (!pipe->readers) {
61461 + if (!atomic_read(&pipe->readers)) {
61462 send_sig(SIGPIPE, current, 0);
61463 if (!ret)
61464 ret = -EPIPE;
61465 @@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61466 page_nr++;
61467 ret += buf->len;
61468
61469 - if (pipe->files)
61470 + if (atomic_read(&pipe->files))
61471 do_wakeup = 1;
61472 }
61473
61474 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61475 index 4219835..3473b7e 100644
61476 --- a/fs/fuse/dir.c
61477 +++ b/fs/fuse/dir.c
61478 @@ -1478,7 +1478,7 @@ static char *read_link(struct dentry *dentry)
61479 return link;
61480 }
61481
61482 -static void free_link(char *link)
61483 +static void free_link(const char *link)
61484 {
61485 if (!IS_ERR(link))
61486 free_page((unsigned long) link);
61487 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61488 index 9c470fd..aae410e 100644
61489 --- a/fs/hostfs/hostfs_kern.c
61490 +++ b/fs/hostfs/hostfs_kern.c
61491 @@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61492
61493 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61494 {
61495 - char *s = nd_get_link(nd);
61496 + const char *s = nd_get_link(nd);
61497 if (!IS_ERR(s))
61498 __putname(s);
61499 }
61500 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61501 index e19d4c0..8a357a9 100644
61502 --- a/fs/hugetlbfs/inode.c
61503 +++ b/fs/hugetlbfs/inode.c
61504 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61505 struct mm_struct *mm = current->mm;
61506 struct vm_area_struct *vma;
61507 struct hstate *h = hstate_file(file);
61508 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61509 struct vm_unmapped_area_info info;
61510
61511 if (len & ~huge_page_mask(h))
61512 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61513 return addr;
61514 }
61515
61516 +#ifdef CONFIG_PAX_RANDMMAP
61517 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61518 +#endif
61519 +
61520 if (addr) {
61521 addr = ALIGN(addr, huge_page_size(h));
61522 vma = find_vma(mm, addr);
61523 - if (TASK_SIZE - len >= addr &&
61524 - (!vma || addr + len <= vma->vm_start))
61525 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61526 return addr;
61527 }
61528
61529 info.flags = 0;
61530 info.length = len;
61531 info.low_limit = TASK_UNMAPPED_BASE;
61532 +
61533 +#ifdef CONFIG_PAX_RANDMMAP
61534 + if (mm->pax_flags & MF_PAX_RANDMMAP)
61535 + info.low_limit += mm->delta_mmap;
61536 +#endif
61537 +
61538 info.high_limit = TASK_SIZE;
61539 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61540 info.align_offset = 0;
61541 @@ -921,7 +931,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61542 };
61543 MODULE_ALIAS_FS("hugetlbfs");
61544
61545 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61546 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61547
61548 static int can_do_hugetlb_shm(void)
61549 {
61550 diff --git a/fs/inode.c b/fs/inode.c
61551 index d2fb2f2..a6444b0 100644
61552 --- a/fs/inode.c
61553 +++ b/fs/inode.c
61554 @@ -839,16 +839,20 @@ unsigned int get_next_ino(void)
61555 unsigned int *p = &get_cpu_var(last_ino);
61556 unsigned int res = *p;
61557
61558 +start:
61559 +
61560 #ifdef CONFIG_SMP
61561 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61562 - static atomic_t shared_last_ino;
61563 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61564 + static atomic_unchecked_t shared_last_ino;
61565 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61566
61567 res = next - LAST_INO_BATCH;
61568 }
61569 #endif
61570
61571 - *p = ++res;
61572 + if (unlikely(!++res))
61573 + goto start; /* never zero */
61574 + *p = res;
61575 put_cpu_var(last_ino);
61576 return res;
61577 }
61578 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61579 index 4a6cf28..d3a29d3 100644
61580 --- a/fs/jffs2/erase.c
61581 +++ b/fs/jffs2/erase.c
61582 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61583 struct jffs2_unknown_node marker = {
61584 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61585 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61586 - .totlen = cpu_to_je32(c->cleanmarker_size)
61587 + .totlen = cpu_to_je32(c->cleanmarker_size),
61588 + .hdr_crc = cpu_to_je32(0)
61589 };
61590
61591 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61592 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61593 index a6597d6..41b30ec 100644
61594 --- a/fs/jffs2/wbuf.c
61595 +++ b/fs/jffs2/wbuf.c
61596 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61597 {
61598 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61599 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61600 - .totlen = constant_cpu_to_je32(8)
61601 + .totlen = constant_cpu_to_je32(8),
61602 + .hdr_crc = constant_cpu_to_je32(0)
61603 };
61604
61605 /*
61606 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61607 index 97f7fda..09bd33d 100644
61608 --- a/fs/jfs/super.c
61609 +++ b/fs/jfs/super.c
61610 @@ -885,7 +885,7 @@ static int __init init_jfs_fs(void)
61611
61612 jfs_inode_cachep =
61613 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61614 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61615 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61616 init_once);
61617 if (jfs_inode_cachep == NULL)
61618 return -ENOMEM;
61619 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61620 index a693f5b..82276a1 100644
61621 --- a/fs/kernfs/dir.c
61622 +++ b/fs/kernfs/dir.c
61623 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
61624 *
61625 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61626 */
61627 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
61628 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61629 {
61630 unsigned long hash = init_name_hash();
61631 unsigned int len = strlen(name);
61632 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61633 index 5e9a80c..3853a24 100644
61634 --- a/fs/kernfs/file.c
61635 +++ b/fs/kernfs/file.c
61636 @@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61637
61638 struct kernfs_open_node {
61639 atomic_t refcnt;
61640 - atomic_t event;
61641 + atomic_unchecked_t event;
61642 wait_queue_head_t poll;
61643 struct list_head files; /* goes through kernfs_open_file.list */
61644 };
61645 @@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61646 {
61647 struct kernfs_open_file *of = sf->private;
61648
61649 - of->event = atomic_read(&of->kn->attr.open->event);
61650 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61651
61652 return of->kn->attr.ops->seq_show(sf, v);
61653 }
61654 @@ -361,12 +361,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61655 return ret;
61656 }
61657
61658 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61659 - void *buf, int len, int write)
61660 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61661 + void *buf, size_t len, int write)
61662 {
61663 struct file *file = vma->vm_file;
61664 struct kernfs_open_file *of = kernfs_of(file);
61665 - int ret;
61666 + ssize_t ret;
61667
61668 if (!of->vm_ops)
61669 return -EINVAL;
61670 @@ -567,7 +567,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61671 return -ENOMEM;
61672
61673 atomic_set(&new_on->refcnt, 0);
61674 - atomic_set(&new_on->event, 1);
61675 + atomic_set_unchecked(&new_on->event, 1);
61676 init_waitqueue_head(&new_on->poll);
61677 INIT_LIST_HEAD(&new_on->files);
61678 goto retry;
61679 @@ -773,7 +773,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61680
61681 kernfs_put_active(kn);
61682
61683 - if (of->event != atomic_read(&on->event))
61684 + if (of->event != atomic_read_unchecked(&on->event))
61685 goto trigger;
61686
61687 return DEFAULT_POLLMASK;
61688 @@ -798,7 +798,7 @@ void kernfs_notify(struct kernfs_node *kn)
61689 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61690 on = kn->attr.open;
61691 if (on) {
61692 - atomic_inc(&on->event);
61693 + atomic_inc_unchecked(&on->event);
61694 wake_up_interruptible(&on->poll);
61695 }
61696 }
61697 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61698 index 8a19889..4c3069a 100644
61699 --- a/fs/kernfs/symlink.c
61700 +++ b/fs/kernfs/symlink.c
61701 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61702 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61703 void *cookie)
61704 {
61705 - char *page = nd_get_link(nd);
61706 + const char *page = nd_get_link(nd);
61707 if (!IS_ERR(page))
61708 free_page((unsigned long)page);
61709 }
61710 diff --git a/fs/libfs.c b/fs/libfs.c
61711 index a184424..944ddce 100644
61712 --- a/fs/libfs.c
61713 +++ b/fs/libfs.c
61714 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61715
61716 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61717 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61718 + char d_name[sizeof(next->d_iname)];
61719 + const unsigned char *name;
61720 +
61721 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61722 if (!simple_positive(next)) {
61723 spin_unlock(&next->d_lock);
61724 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61725
61726 spin_unlock(&next->d_lock);
61727 spin_unlock(&dentry->d_lock);
61728 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61729 + name = next->d_name.name;
61730 + if (name == next->d_iname) {
61731 + memcpy(d_name, name, next->d_name.len);
61732 + name = d_name;
61733 + }
61734 + if (!dir_emit(ctx, name, next->d_name.len,
61735 next->d_inode->i_ino, dt_type(next->d_inode)))
61736 return 0;
61737 spin_lock(&dentry->d_lock);
61738 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61739 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61740 void *cookie)
61741 {
61742 - char *s = nd_get_link(nd);
61743 + const char *s = nd_get_link(nd);
61744 if (!IS_ERR(s))
61745 kfree(s);
61746 }
61747 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61748 index acd3947..1f896e2 100644
61749 --- a/fs/lockd/clntproc.c
61750 +++ b/fs/lockd/clntproc.c
61751 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61752 /*
61753 * Cookie counter for NLM requests
61754 */
61755 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61756 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61757
61758 void nlmclnt_next_cookie(struct nlm_cookie *c)
61759 {
61760 - u32 cookie = atomic_inc_return(&nlm_cookie);
61761 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61762
61763 memcpy(c->data, &cookie, 4);
61764 c->len=4;
61765 diff --git a/fs/locks.c b/fs/locks.c
61766 index e390bd9..c79870e 100644
61767 --- a/fs/locks.c
61768 +++ b/fs/locks.c
61769 @@ -2315,16 +2315,16 @@ void locks_remove_file(struct file *filp)
61770 locks_remove_posix(filp, (fl_owner_t)filp);
61771
61772 if (filp->f_op->flock) {
61773 - struct file_lock fl = {
61774 + struct file_lock flock = {
61775 .fl_pid = current->tgid,
61776 .fl_file = filp,
61777 .fl_flags = FL_FLOCK,
61778 .fl_type = F_UNLCK,
61779 .fl_end = OFFSET_MAX,
61780 };
61781 - filp->f_op->flock(filp, F_SETLKW, &fl);
61782 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
61783 - fl.fl_ops->fl_release_private(&fl);
61784 + filp->f_op->flock(filp, F_SETLKW, &flock);
61785 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
61786 + flock.fl_ops->fl_release_private(&flock);
61787 }
61788
61789 spin_lock(&inode->i_lock);
61790 diff --git a/fs/mount.h b/fs/mount.h
61791 index d55297f..f5b28c5 100644
61792 --- a/fs/mount.h
61793 +++ b/fs/mount.h
61794 @@ -11,7 +11,7 @@ struct mnt_namespace {
61795 u64 seq; /* Sequence number to prevent loops */
61796 wait_queue_head_t poll;
61797 u64 event;
61798 -};
61799 +} __randomize_layout;
61800
61801 struct mnt_pcp {
61802 int mnt_count;
61803 @@ -57,7 +57,7 @@ struct mount {
61804 int mnt_expiry_mark; /* true if marked for expiry */
61805 int mnt_pinned;
61806 struct path mnt_ex_mountpoint;
61807 -};
61808 +} __randomize_layout;
61809
61810 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61811
61812 diff --git a/fs/namei.c b/fs/namei.c
61813 index 985c6f3..5f520b67 100644
61814 --- a/fs/namei.c
61815 +++ b/fs/namei.c
61816 @@ -330,17 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61817 if (ret != -EACCES)
61818 return ret;
61819
61820 +#ifdef CONFIG_GRKERNSEC
61821 + /* we'll block if we have to log due to a denied capability use */
61822 + if (mask & MAY_NOT_BLOCK)
61823 + return -ECHILD;
61824 +#endif
61825 +
61826 if (S_ISDIR(inode->i_mode)) {
61827 /* DACs are overridable for directories */
61828 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61829 - return 0;
61830 if (!(mask & MAY_WRITE))
61831 - if (capable_wrt_inode_uidgid(inode,
61832 - CAP_DAC_READ_SEARCH))
61833 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61834 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61835 return 0;
61836 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61837 + return 0;
61838 return -EACCES;
61839 }
61840 /*
61841 + * Searching includes executable on directories, else just read.
61842 + */
61843 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61844 + if (mask == MAY_READ)
61845 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61846 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61847 + return 0;
61848 +
61849 + /*
61850 * Read/write DACs are always overridable.
61851 * Executable DACs are overridable when there is
61852 * at least one exec bit set.
61853 @@ -349,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61854 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61855 return 0;
61856
61857 - /*
61858 - * Searching includes executable on directories, else just read.
61859 - */
61860 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61861 - if (mask == MAY_READ)
61862 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61863 - return 0;
61864 -
61865 return -EACCES;
61866 }
61867 EXPORT_SYMBOL(generic_permission);
61868 @@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61869 {
61870 struct dentry *dentry = link->dentry;
61871 int error;
61872 - char *s;
61873 + const char *s;
61874
61875 BUG_ON(nd->flags & LOOKUP_RCU);
61876
61877 @@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61878 if (error)
61879 goto out_put_nd_path;
61880
61881 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
61882 + dentry->d_inode, dentry, nd->path.mnt)) {
61883 + error = -EACCES;
61884 + goto out_put_nd_path;
61885 + }
61886 +
61887 nd->last_type = LAST_BIND;
61888 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61889 error = PTR_ERR(*p);
61890 @@ -1596,6 +1609,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61891 if (res)
61892 break;
61893 res = walk_component(nd, path, LOOKUP_FOLLOW);
61894 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61895 + res = -EACCES;
61896 put_link(nd, &link, cookie);
61897 } while (res > 0);
61898
61899 @@ -1669,7 +1684,7 @@ EXPORT_SYMBOL(full_name_hash);
61900 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61901 {
61902 unsigned long a, b, adata, bdata, mask, hash, len;
61903 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61904 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61905
61906 hash = a = 0;
61907 len = -sizeof(unsigned long);
61908 @@ -1953,6 +1968,8 @@ static int path_lookupat(int dfd, const char *name,
61909 if (err)
61910 break;
61911 err = lookup_last(nd, &path);
61912 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
61913 + err = -EACCES;
61914 put_link(nd, &link, cookie);
61915 }
61916 }
61917 @@ -1960,6 +1977,13 @@ static int path_lookupat(int dfd, const char *name,
61918 if (!err)
61919 err = complete_walk(nd);
61920
61921 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
61922 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61923 + path_put(&nd->path);
61924 + err = -ENOENT;
61925 + }
61926 + }
61927 +
61928 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61929 if (!d_can_lookup(nd->path.dentry)) {
61930 path_put(&nd->path);
61931 @@ -1987,8 +2011,15 @@ static int filename_lookup(int dfd, struct filename *name,
61932 retval = path_lookupat(dfd, name->name,
61933 flags | LOOKUP_REVAL, nd);
61934
61935 - if (likely(!retval))
61936 + if (likely(!retval)) {
61937 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61938 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61939 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61940 + path_put(&nd->path);
61941 + return -ENOENT;
61942 + }
61943 + }
61944 + }
61945 return retval;
61946 }
61947
61948 @@ -2256,9 +2287,10 @@ done:
61949 goto out;
61950 }
61951 path->dentry = dentry;
61952 - path->mnt = mntget(nd->path.mnt);
61953 + path->mnt = nd->path.mnt;
61954 if (should_follow_link(dentry, nd->flags & LOOKUP_FOLLOW))
61955 return 1;
61956 + mntget(path->mnt);
61957 follow_mount(path);
61958 error = 0;
61959 out:
61960 @@ -2569,6 +2601,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61961 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61962 return -EPERM;
61963
61964 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61965 + return -EPERM;
61966 + if (gr_handle_rawio(inode))
61967 + return -EPERM;
61968 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61969 + return -EACCES;
61970 +
61971 return 0;
61972 }
61973
61974 @@ -2800,7 +2839,7 @@ looked_up:
61975 * cleared otherwise prior to returning.
61976 */
61977 static int lookup_open(struct nameidata *nd, struct path *path,
61978 - struct file *file,
61979 + struct path *link, struct file *file,
61980 const struct open_flags *op,
61981 bool got_write, int *opened)
61982 {
61983 @@ -2835,6 +2874,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61984 /* Negative dentry, just create the file */
61985 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61986 umode_t mode = op->mode;
61987 +
61988 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61989 + error = -EACCES;
61990 + goto out_dput;
61991 + }
61992 +
61993 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61994 + error = -EACCES;
61995 + goto out_dput;
61996 + }
61997 +
61998 if (!IS_POSIXACL(dir->d_inode))
61999 mode &= ~current_umask();
62000 /*
62001 @@ -2856,6 +2906,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62002 nd->flags & LOOKUP_EXCL);
62003 if (error)
62004 goto out_dput;
62005 + else
62006 + gr_handle_create(dentry, nd->path.mnt);
62007 }
62008 out_no_open:
62009 path->dentry = dentry;
62010 @@ -2870,7 +2922,7 @@ out_dput:
62011 /*
62012 * Handle the last step of open()
62013 */
62014 -static int do_last(struct nameidata *nd, struct path *path,
62015 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
62016 struct file *file, const struct open_flags *op,
62017 int *opened, struct filename *name)
62018 {
62019 @@ -2920,6 +2972,15 @@ static int do_last(struct nameidata *nd, struct path *path,
62020 if (error)
62021 return error;
62022
62023 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
62024 + error = -ENOENT;
62025 + goto out;
62026 + }
62027 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
62028 + error = -EACCES;
62029 + goto out;
62030 + }
62031 +
62032 audit_inode(name, dir, LOOKUP_PARENT);
62033 error = -EISDIR;
62034 /* trailing slashes? */
62035 @@ -2939,7 +3000,7 @@ retry_lookup:
62036 */
62037 }
62038 mutex_lock(&dir->d_inode->i_mutex);
62039 - error = lookup_open(nd, path, file, op, got_write, opened);
62040 + error = lookup_open(nd, path, link, file, op, got_write, opened);
62041 mutex_unlock(&dir->d_inode->i_mutex);
62042
62043 if (error <= 0) {
62044 @@ -2963,11 +3024,28 @@ retry_lookup:
62045 goto finish_open_created;
62046 }
62047
62048 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
62049 + error = -ENOENT;
62050 + goto exit_dput;
62051 + }
62052 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
62053 + error = -EACCES;
62054 + goto exit_dput;
62055 + }
62056 +
62057 /*
62058 * create/update audit record if it already exists.
62059 */
62060 - if (d_is_positive(path->dentry))
62061 + if (d_is_positive(path->dentry)) {
62062 + /* only check if O_CREAT is specified, all other checks need to go
62063 + into may_open */
62064 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
62065 + error = -EACCES;
62066 + goto exit_dput;
62067 + }
62068 +
62069 audit_inode(name, path->dentry, 0);
62070 + }
62071
62072 /*
62073 * If atomic_open() acquired write access it is dropped now due to
62074 @@ -3008,6 +3086,11 @@ finish_lookup:
62075 }
62076 }
62077 BUG_ON(inode != path->dentry->d_inode);
62078 + /* if we're resolving a symlink to another symlink */
62079 + if (link && gr_handle_symlink_owner(link, inode)) {
62080 + error = -EACCES;
62081 + goto out;
62082 + }
62083 return 1;
62084 }
62085
62086 @@ -3017,7 +3100,6 @@ finish_lookup:
62087 save_parent.dentry = nd->path.dentry;
62088 save_parent.mnt = mntget(path->mnt);
62089 nd->path.dentry = path->dentry;
62090 -
62091 }
62092 nd->inode = inode;
62093 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
62094 @@ -3027,7 +3109,18 @@ finish_open:
62095 path_put(&save_parent);
62096 return error;
62097 }
62098 +
62099 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62100 + error = -ENOENT;
62101 + goto out;
62102 + }
62103 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
62104 + error = -EACCES;
62105 + goto out;
62106 + }
62107 +
62108 audit_inode(name, nd->path.dentry, 0);
62109 +
62110 error = -EISDIR;
62111 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
62112 goto out;
62113 @@ -3190,7 +3283,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62114 if (unlikely(error))
62115 goto out;
62116
62117 - error = do_last(nd, &path, file, op, &opened, pathname);
62118 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
62119 while (unlikely(error > 0)) { /* trailing symlink */
62120 struct path link = path;
62121 void *cookie;
62122 @@ -3208,7 +3301,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62123 error = follow_link(&link, nd, &cookie);
62124 if (unlikely(error))
62125 break;
62126 - error = do_last(nd, &path, file, op, &opened, pathname);
62127 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
62128 put_link(nd, &link, cookie);
62129 }
62130 out:
62131 @@ -3308,9 +3401,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
62132 goto unlock;
62133
62134 error = -EEXIST;
62135 - if (d_is_positive(dentry))
62136 + if (d_is_positive(dentry)) {
62137 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
62138 + error = -ENOENT;
62139 goto fail;
62140 -
62141 + }
62142 /*
62143 * Special case - lookup gave negative, but... we had foo/bar/
62144 * From the vfs_mknod() POV we just have a negative dentry -
62145 @@ -3362,6 +3457,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
62146 }
62147 EXPORT_SYMBOL(user_path_create);
62148
62149 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
62150 +{
62151 + struct filename *tmp = getname(pathname);
62152 + struct dentry *res;
62153 + if (IS_ERR(tmp))
62154 + return ERR_CAST(tmp);
62155 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
62156 + if (IS_ERR(res))
62157 + putname(tmp);
62158 + else
62159 + *to = tmp;
62160 + return res;
62161 +}
62162 +
62163 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
62164 {
62165 int error = may_create(dir, dentry);
62166 @@ -3425,6 +3534,17 @@ retry:
62167
62168 if (!IS_POSIXACL(path.dentry->d_inode))
62169 mode &= ~current_umask();
62170 +
62171 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
62172 + error = -EPERM;
62173 + goto out;
62174 + }
62175 +
62176 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
62177 + error = -EACCES;
62178 + goto out;
62179 + }
62180 +
62181 error = security_path_mknod(&path, dentry, mode, dev);
62182 if (error)
62183 goto out;
62184 @@ -3441,6 +3561,8 @@ retry:
62185 break;
62186 }
62187 out:
62188 + if (!error)
62189 + gr_handle_create(dentry, path.mnt);
62190 done_path_create(&path, dentry);
62191 if (retry_estale(error, lookup_flags)) {
62192 lookup_flags |= LOOKUP_REVAL;
62193 @@ -3494,9 +3616,16 @@ retry:
62194
62195 if (!IS_POSIXACL(path.dentry->d_inode))
62196 mode &= ~current_umask();
62197 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
62198 + error = -EACCES;
62199 + goto out;
62200 + }
62201 error = security_path_mkdir(&path, dentry, mode);
62202 if (!error)
62203 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
62204 + if (!error)
62205 + gr_handle_create(dentry, path.mnt);
62206 +out:
62207 done_path_create(&path, dentry);
62208 if (retry_estale(error, lookup_flags)) {
62209 lookup_flags |= LOOKUP_REVAL;
62210 @@ -3579,6 +3708,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
62211 struct filename *name;
62212 struct dentry *dentry;
62213 struct nameidata nd;
62214 + ino_t saved_ino = 0;
62215 + dev_t saved_dev = 0;
62216 unsigned int lookup_flags = 0;
62217 retry:
62218 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62219 @@ -3611,10 +3742,21 @@ retry:
62220 error = -ENOENT;
62221 goto exit3;
62222 }
62223 +
62224 + saved_ino = dentry->d_inode->i_ino;
62225 + saved_dev = gr_get_dev_from_dentry(dentry);
62226 +
62227 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
62228 + error = -EACCES;
62229 + goto exit3;
62230 + }
62231 +
62232 error = security_path_rmdir(&nd.path, dentry);
62233 if (error)
62234 goto exit3;
62235 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
62236 + if (!error && (saved_dev || saved_ino))
62237 + gr_handle_delete(saved_ino, saved_dev);
62238 exit3:
62239 dput(dentry);
62240 exit2:
62241 @@ -3705,6 +3847,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
62242 struct nameidata nd;
62243 struct inode *inode = NULL;
62244 struct inode *delegated_inode = NULL;
62245 + ino_t saved_ino = 0;
62246 + dev_t saved_dev = 0;
62247 unsigned int lookup_flags = 0;
62248 retry:
62249 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62250 @@ -3731,10 +3875,22 @@ retry_deleg:
62251 if (d_is_negative(dentry))
62252 goto slashes;
62253 ihold(inode);
62254 +
62255 + if (inode->i_nlink <= 1) {
62256 + saved_ino = inode->i_ino;
62257 + saved_dev = gr_get_dev_from_dentry(dentry);
62258 + }
62259 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
62260 + error = -EACCES;
62261 + goto exit2;
62262 + }
62263 +
62264 error = security_path_unlink(&nd.path, dentry);
62265 if (error)
62266 goto exit2;
62267 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
62268 + if (!error && (saved_ino || saved_dev))
62269 + gr_handle_delete(saved_ino, saved_dev);
62270 exit2:
62271 dput(dentry);
62272 }
62273 @@ -3823,9 +3979,17 @@ retry:
62274 if (IS_ERR(dentry))
62275 goto out_putname;
62276
62277 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
62278 + error = -EACCES;
62279 + goto out;
62280 + }
62281 +
62282 error = security_path_symlink(&path, dentry, from->name);
62283 if (!error)
62284 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
62285 + if (!error)
62286 + gr_handle_create(dentry, path.mnt);
62287 +out:
62288 done_path_create(&path, dentry);
62289 if (retry_estale(error, lookup_flags)) {
62290 lookup_flags |= LOOKUP_REVAL;
62291 @@ -3929,6 +4093,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
62292 struct dentry *new_dentry;
62293 struct path old_path, new_path;
62294 struct inode *delegated_inode = NULL;
62295 + struct filename *to = NULL;
62296 int how = 0;
62297 int error;
62298
62299 @@ -3952,7 +4117,7 @@ retry:
62300 if (error)
62301 return error;
62302
62303 - new_dentry = user_path_create(newdfd, newname, &new_path,
62304 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
62305 (how & LOOKUP_REVAL));
62306 error = PTR_ERR(new_dentry);
62307 if (IS_ERR(new_dentry))
62308 @@ -3964,11 +4129,28 @@ retry:
62309 error = may_linkat(&old_path);
62310 if (unlikely(error))
62311 goto out_dput;
62312 +
62313 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
62314 + old_path.dentry->d_inode,
62315 + old_path.dentry->d_inode->i_mode, to)) {
62316 + error = -EACCES;
62317 + goto out_dput;
62318 + }
62319 +
62320 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
62321 + old_path.dentry, old_path.mnt, to)) {
62322 + error = -EACCES;
62323 + goto out_dput;
62324 + }
62325 +
62326 error = security_path_link(old_path.dentry, &new_path, new_dentry);
62327 if (error)
62328 goto out_dput;
62329 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
62330 + if (!error)
62331 + gr_handle_create(new_dentry, new_path.mnt);
62332 out_dput:
62333 + putname(to);
62334 done_path_create(&new_path, new_dentry);
62335 if (delegated_inode) {
62336 error = break_deleg_wait(&delegated_inode);
62337 @@ -4278,6 +4460,12 @@ retry_deleg:
62338 if (new_dentry == trap)
62339 goto exit5;
62340
62341 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
62342 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
62343 + to, flags);
62344 + if (error)
62345 + goto exit5;
62346 +
62347 error = security_path_rename(&oldnd.path, old_dentry,
62348 &newnd.path, new_dentry, flags);
62349 if (error)
62350 @@ -4285,6 +4473,9 @@ retry_deleg:
62351 error = vfs_rename(old_dir->d_inode, old_dentry,
62352 new_dir->d_inode, new_dentry,
62353 &delegated_inode, flags);
62354 + if (!error)
62355 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62356 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
62357 exit5:
62358 dput(new_dentry);
62359 exit4:
62360 @@ -4327,14 +4518,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62361
62362 int readlink_copy(char __user *buffer, int buflen, const char *link)
62363 {
62364 + char tmpbuf[64];
62365 + const char *newlink;
62366 int len = PTR_ERR(link);
62367 +
62368 if (IS_ERR(link))
62369 goto out;
62370
62371 len = strlen(link);
62372 if (len > (unsigned) buflen)
62373 len = buflen;
62374 - if (copy_to_user(buffer, link, len))
62375 +
62376 + if (len < sizeof(tmpbuf)) {
62377 + memcpy(tmpbuf, link, len);
62378 + newlink = tmpbuf;
62379 + } else
62380 + newlink = link;
62381 +
62382 + if (copy_to_user(buffer, newlink, len))
62383 len = -EFAULT;
62384 out:
62385 return len;
62386 diff --git a/fs/namespace.c b/fs/namespace.c
62387 index 182bc41..72e3cf1 100644
62388 --- a/fs/namespace.c
62389 +++ b/fs/namespace.c
62390 @@ -1348,6 +1348,9 @@ static int do_umount(struct mount *mnt, int flags)
62391 if (!(sb->s_flags & MS_RDONLY))
62392 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62393 up_write(&sb->s_umount);
62394 +
62395 + gr_log_remount(mnt->mnt_devname, retval);
62396 +
62397 return retval;
62398 }
62399
62400 @@ -1370,6 +1373,9 @@ static int do_umount(struct mount *mnt, int flags)
62401 }
62402 unlock_mount_hash();
62403 namespace_unlock();
62404 +
62405 + gr_log_unmount(mnt->mnt_devname, retval);
62406 +
62407 return retval;
62408 }
62409
62410 @@ -1389,7 +1395,7 @@ static inline bool may_mount(void)
62411 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62412 */
62413
62414 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62415 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62416 {
62417 struct path path;
62418 struct mount *mnt;
62419 @@ -1431,7 +1437,7 @@ out:
62420 /*
62421 * The 2.0 compatible umount. No flags.
62422 */
62423 -SYSCALL_DEFINE1(oldumount, char __user *, name)
62424 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
62425 {
62426 return sys_umount(name, 0);
62427 }
62428 @@ -2440,6 +2446,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62429 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62430 MS_STRICTATIME);
62431
62432 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62433 + retval = -EPERM;
62434 + goto dput_out;
62435 + }
62436 +
62437 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62438 + retval = -EPERM;
62439 + goto dput_out;
62440 + }
62441 +
62442 if (flags & MS_REMOUNT)
62443 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62444 data_page);
62445 @@ -2454,6 +2470,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62446 dev_name, data_page);
62447 dput_out:
62448 path_put(&path);
62449 +
62450 + gr_log_mount(dev_name, dir_name, retval);
62451 +
62452 return retval;
62453 }
62454
62455 @@ -2471,7 +2490,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62456 * number incrementing at 10Ghz will take 12,427 years to wrap which
62457 * is effectively never, so we can ignore the possibility.
62458 */
62459 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62460 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62461
62462 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62463 {
62464 @@ -2486,7 +2505,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62465 kfree(new_ns);
62466 return ERR_PTR(ret);
62467 }
62468 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62469 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62470 atomic_set(&new_ns->count, 1);
62471 new_ns->root = NULL;
62472 INIT_LIST_HEAD(&new_ns->list);
62473 @@ -2496,7 +2515,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62474 return new_ns;
62475 }
62476
62477 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62478 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62479 struct user_namespace *user_ns, struct fs_struct *new_fs)
62480 {
62481 struct mnt_namespace *new_ns;
62482 @@ -2617,8 +2636,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62483 }
62484 EXPORT_SYMBOL(mount_subtree);
62485
62486 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62487 - char __user *, type, unsigned long, flags, void __user *, data)
62488 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62489 + const char __user *, type, unsigned long, flags, void __user *, data)
62490 {
62491 int ret;
62492 char *kernel_type;
62493 @@ -2731,6 +2750,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62494 if (error)
62495 goto out2;
62496
62497 + if (gr_handle_chroot_pivot()) {
62498 + error = -EPERM;
62499 + goto out2;
62500 + }
62501 +
62502 get_fs_root(current->fs, &root);
62503 old_mp = lock_mount(&old);
62504 error = PTR_ERR(old_mp);
62505 @@ -2999,7 +3023,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62506 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62507 return -EPERM;
62508
62509 - if (fs->users != 1)
62510 + if (atomic_read(&fs->users) != 1)
62511 return -EINVAL;
62512
62513 get_mnt_ns(mnt_ns);
62514 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62515 index f4ccfe6..a5cf064 100644
62516 --- a/fs/nfs/callback_xdr.c
62517 +++ b/fs/nfs/callback_xdr.c
62518 @@ -51,7 +51,7 @@ struct callback_op {
62519 callback_decode_arg_t decode_args;
62520 callback_encode_res_t encode_res;
62521 long res_maxsize;
62522 -};
62523 +} __do_const;
62524
62525 static struct callback_op callback_ops[];
62526
62527 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62528 index c79f3e7..d61d671 100644
62529 --- a/fs/nfs/inode.c
62530 +++ b/fs/nfs/inode.c
62531 @@ -1209,16 +1209,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62532 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62533 }
62534
62535 -static atomic_long_t nfs_attr_generation_counter;
62536 +static atomic_long_unchecked_t nfs_attr_generation_counter;
62537
62538 static unsigned long nfs_read_attr_generation_counter(void)
62539 {
62540 - return atomic_long_read(&nfs_attr_generation_counter);
62541 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62542 }
62543
62544 unsigned long nfs_inc_attr_generation_counter(void)
62545 {
62546 - return atomic_long_inc_return(&nfs_attr_generation_counter);
62547 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62548 }
62549
62550 void nfs_fattr_init(struct nfs_fattr *fattr)
62551 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62552 index 95e3720..46c23fa 100644
62553 --- a/fs/nfsd/nfs4proc.c
62554 +++ b/fs/nfsd/nfs4proc.c
62555 @@ -1169,7 +1169,7 @@ struct nfsd4_operation {
62556 nfsd4op_rsize op_rsize_bop;
62557 stateid_getter op_get_currentstateid;
62558 stateid_setter op_set_currentstateid;
62559 -};
62560 +} __do_const;
62561
62562 static struct nfsd4_operation nfsd4_ops[];
62563
62564 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62565 index 3297158..7bb8436 100644
62566 --- a/fs/nfsd/nfs4xdr.c
62567 +++ b/fs/nfsd/nfs4xdr.c
62568 @@ -1541,7 +1541,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62569
62570 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62571
62572 -static nfsd4_dec nfsd4_dec_ops[] = {
62573 +static const nfsd4_dec nfsd4_dec_ops[] = {
62574 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62575 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62576 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62577 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62578 index f8f060f..c4ba09a 100644
62579 --- a/fs/nfsd/nfscache.c
62580 +++ b/fs/nfsd/nfscache.c
62581 @@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62582 {
62583 struct svc_cacherep *rp = rqstp->rq_cacherep;
62584 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62585 - int len;
62586 + long len;
62587 size_t bufsize = 0;
62588
62589 if (!rp)
62590 return;
62591
62592 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62593 - len >>= 2;
62594 + if (statp) {
62595 + len = (char*)statp - (char*)resv->iov_base;
62596 + len = resv->iov_len - len;
62597 + len >>= 2;
62598 + }
62599
62600 /* Don't cache excessive amounts of data and XDR failures */
62601 if (!statp || len > (256 >> 2)) {
62602 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62603 index 16f0673..1c2c30ab 100644
62604 --- a/fs/nfsd/vfs.c
62605 +++ b/fs/nfsd/vfs.c
62606 @@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62607 } else {
62608 oldfs = get_fs();
62609 set_fs(KERNEL_DS);
62610 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62611 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62612 set_fs(oldfs);
62613 }
62614
62615 @@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62616
62617 /* Write the data. */
62618 oldfs = get_fs(); set_fs(KERNEL_DS);
62619 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62620 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62621 set_fs(oldfs);
62622 if (host_err < 0)
62623 goto out_nfserr;
62624 @@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62625 */
62626
62627 oldfs = get_fs(); set_fs(KERNEL_DS);
62628 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62629 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62630 set_fs(oldfs);
62631
62632 if (host_err < 0)
62633 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62634 index 52ccd34..43a53b1 100644
62635 --- a/fs/nls/nls_base.c
62636 +++ b/fs/nls/nls_base.c
62637 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62638
62639 int __register_nls(struct nls_table *nls, struct module *owner)
62640 {
62641 - struct nls_table ** tmp = &tables;
62642 + struct nls_table *tmp = tables;
62643
62644 if (nls->next)
62645 return -EBUSY;
62646
62647 - nls->owner = owner;
62648 + pax_open_kernel();
62649 + *(void **)&nls->owner = owner;
62650 + pax_close_kernel();
62651 spin_lock(&nls_lock);
62652 - while (*tmp) {
62653 - if (nls == *tmp) {
62654 + while (tmp) {
62655 + if (nls == tmp) {
62656 spin_unlock(&nls_lock);
62657 return -EBUSY;
62658 }
62659 - tmp = &(*tmp)->next;
62660 + tmp = tmp->next;
62661 }
62662 - nls->next = tables;
62663 + pax_open_kernel();
62664 + *(struct nls_table **)&nls->next = tables;
62665 + pax_close_kernel();
62666 tables = nls;
62667 spin_unlock(&nls_lock);
62668 return 0;
62669 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62670
62671 int unregister_nls(struct nls_table * nls)
62672 {
62673 - struct nls_table ** tmp = &tables;
62674 + struct nls_table * const * tmp = &tables;
62675
62676 spin_lock(&nls_lock);
62677 while (*tmp) {
62678 if (nls == *tmp) {
62679 - *tmp = nls->next;
62680 + pax_open_kernel();
62681 + *(struct nls_table **)tmp = nls->next;
62682 + pax_close_kernel();
62683 spin_unlock(&nls_lock);
62684 return 0;
62685 }
62686 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62687 index 162b3f1..6076a7c 100644
62688 --- a/fs/nls/nls_euc-jp.c
62689 +++ b/fs/nls/nls_euc-jp.c
62690 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62691 p_nls = load_nls("cp932");
62692
62693 if (p_nls) {
62694 - table.charset2upper = p_nls->charset2upper;
62695 - table.charset2lower = p_nls->charset2lower;
62696 + pax_open_kernel();
62697 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62698 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62699 + pax_close_kernel();
62700 return register_nls(&table);
62701 }
62702
62703 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62704 index a80a741..7b96e1b 100644
62705 --- a/fs/nls/nls_koi8-ru.c
62706 +++ b/fs/nls/nls_koi8-ru.c
62707 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62708 p_nls = load_nls("koi8-u");
62709
62710 if (p_nls) {
62711 - table.charset2upper = p_nls->charset2upper;
62712 - table.charset2lower = p_nls->charset2lower;
62713 + pax_open_kernel();
62714 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62715 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62716 + pax_close_kernel();
62717 return register_nls(&table);
62718 }
62719
62720 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62721 index 732648b..d3b017f 100644
62722 --- a/fs/notify/fanotify/fanotify_user.c
62723 +++ b/fs/notify/fanotify/fanotify_user.c
62724 @@ -203,8 +203,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62725
62726 fd = fanotify_event_metadata.fd;
62727 ret = -EFAULT;
62728 - if (copy_to_user(buf, &fanotify_event_metadata,
62729 - fanotify_event_metadata.event_len))
62730 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62731 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62732 goto out_close_fd;
62733
62734 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62735 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62736 index 1e58402..bb2d6f4 100644
62737 --- a/fs/notify/notification.c
62738 +++ b/fs/notify/notification.c
62739 @@ -48,7 +48,7 @@
62740 #include <linux/fsnotify_backend.h>
62741 #include "fsnotify.h"
62742
62743 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62744 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62745
62746 /**
62747 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62748 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62749 */
62750 u32 fsnotify_get_cookie(void)
62751 {
62752 - return atomic_inc_return(&fsnotify_sync_cookie);
62753 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62754 }
62755 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62756
62757 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62758 index 9e38daf..5727cae 100644
62759 --- a/fs/ntfs/dir.c
62760 +++ b/fs/ntfs/dir.c
62761 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
62762 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62763 ~(s64)(ndir->itype.index.block_size - 1)));
62764 /* Bounds checks. */
62765 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62766 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62767 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62768 "inode 0x%lx or driver bug.", vdir->i_ino);
62769 goto err_out;
62770 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62771 index db9bd8a..8338fb6 100644
62772 --- a/fs/ntfs/file.c
62773 +++ b/fs/ntfs/file.c
62774 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62775 char *addr;
62776 size_t total = 0;
62777 unsigned len;
62778 - int left;
62779 + unsigned left;
62780
62781 do {
62782 len = PAGE_CACHE_SIZE - ofs;
62783 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62784 index 9de2491..3306095 100644
62785 --- a/fs/ntfs/super.c
62786 +++ b/fs/ntfs/super.c
62787 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62788 if (!silent)
62789 ntfs_error(sb, "Primary boot sector is invalid.");
62790 } else if (!silent)
62791 - ntfs_error(sb, read_err_str, "primary");
62792 + ntfs_error(sb, read_err_str, "%s", "primary");
62793 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62794 if (bh_primary)
62795 brelse(bh_primary);
62796 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62797 goto hotfix_primary_boot_sector;
62798 brelse(bh_backup);
62799 } else if (!silent)
62800 - ntfs_error(sb, read_err_str, "backup");
62801 + ntfs_error(sb, read_err_str, "%s", "backup");
62802 /* Try to read NT3.51- backup boot sector. */
62803 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62804 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62805 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62806 "sector.");
62807 brelse(bh_backup);
62808 } else if (!silent)
62809 - ntfs_error(sb, read_err_str, "backup");
62810 + ntfs_error(sb, read_err_str, "%s", "backup");
62811 /* We failed. Cleanup and return. */
62812 if (bh_primary)
62813 brelse(bh_primary);
62814 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62815 index 0440134..d52c93a 100644
62816 --- a/fs/ocfs2/localalloc.c
62817 +++ b/fs/ocfs2/localalloc.c
62818 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62819 goto bail;
62820 }
62821
62822 - atomic_inc(&osb->alloc_stats.moves);
62823 + atomic_inc_unchecked(&osb->alloc_stats.moves);
62824
62825 bail:
62826 if (handle)
62827 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62828 index 8d64a97..c37665d 100644
62829 --- a/fs/ocfs2/ocfs2.h
62830 +++ b/fs/ocfs2/ocfs2.h
62831 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
62832
62833 struct ocfs2_alloc_stats
62834 {
62835 - atomic_t moves;
62836 - atomic_t local_data;
62837 - atomic_t bitmap_data;
62838 - atomic_t bg_allocs;
62839 - atomic_t bg_extends;
62840 + atomic_unchecked_t moves;
62841 + atomic_unchecked_t local_data;
62842 + atomic_unchecked_t bitmap_data;
62843 + atomic_unchecked_t bg_allocs;
62844 + atomic_unchecked_t bg_extends;
62845 };
62846
62847 enum ocfs2_local_alloc_state
62848 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62849 index 0cb889a..6a26b24 100644
62850 --- a/fs/ocfs2/suballoc.c
62851 +++ b/fs/ocfs2/suballoc.c
62852 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62853 mlog_errno(status);
62854 goto bail;
62855 }
62856 - atomic_inc(&osb->alloc_stats.bg_extends);
62857 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62858
62859 /* You should never ask for this much metadata */
62860 BUG_ON(bits_wanted >
62861 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62862 mlog_errno(status);
62863 goto bail;
62864 }
62865 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62866 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62867
62868 *suballoc_loc = res.sr_bg_blkno;
62869 *suballoc_bit_start = res.sr_bit_offset;
62870 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62871 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62872 res->sr_bits);
62873
62874 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62875 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62876
62877 BUG_ON(res->sr_bits != 1);
62878
62879 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62880 mlog_errno(status);
62881 goto bail;
62882 }
62883 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62884 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62885
62886 BUG_ON(res.sr_bits != 1);
62887
62888 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62889 cluster_start,
62890 num_clusters);
62891 if (!status)
62892 - atomic_inc(&osb->alloc_stats.local_data);
62893 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
62894 } else {
62895 if (min_clusters > (osb->bitmap_cpg - 1)) {
62896 /* The only paths asking for contiguousness
62897 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62898 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62899 res.sr_bg_blkno,
62900 res.sr_bit_offset);
62901 - atomic_inc(&osb->alloc_stats.bitmap_data);
62902 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62903 *num_clusters = res.sr_bits;
62904 }
62905 }
62906 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62907 index a7cdd56..c583144 100644
62908 --- a/fs/ocfs2/super.c
62909 +++ b/fs/ocfs2/super.c
62910 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62911 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62912 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62913 "Stats",
62914 - atomic_read(&osb->alloc_stats.bitmap_data),
62915 - atomic_read(&osb->alloc_stats.local_data),
62916 - atomic_read(&osb->alloc_stats.bg_allocs),
62917 - atomic_read(&osb->alloc_stats.moves),
62918 - atomic_read(&osb->alloc_stats.bg_extends));
62919 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62920 + atomic_read_unchecked(&osb->alloc_stats.local_data),
62921 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62922 + atomic_read_unchecked(&osb->alloc_stats.moves),
62923 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62924
62925 out += snprintf(buf + out, len - out,
62926 "%10s => State: %u Descriptor: %llu Size: %u bits "
62927 @@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62928
62929 mutex_init(&osb->system_file_mutex);
62930
62931 - atomic_set(&osb->alloc_stats.moves, 0);
62932 - atomic_set(&osb->alloc_stats.local_data, 0);
62933 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
62934 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
62935 - atomic_set(&osb->alloc_stats.bg_extends, 0);
62936 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62937 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62938 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62939 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62940 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62941
62942 /* Copy the blockcheck stats from the superblock probe */
62943 osb->osb_ecc_stats = *stats;
62944 diff --git a/fs/open.c b/fs/open.c
62945 index 9d64679..75f925c 100644
62946 --- a/fs/open.c
62947 +++ b/fs/open.c
62948 @@ -32,6 +32,8 @@
62949 #include <linux/dnotify.h>
62950 #include <linux/compat.h>
62951
62952 +#define CREATE_TRACE_POINTS
62953 +#include <trace/events/fs.h>
62954 #include "internal.h"
62955
62956 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62957 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62958 error = locks_verify_truncate(inode, NULL, length);
62959 if (!error)
62960 error = security_path_truncate(path);
62961 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62962 + error = -EACCES;
62963 if (!error)
62964 error = do_truncate(path->dentry, length, 0, NULL);
62965
62966 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62967 error = locks_verify_truncate(inode, f.file, length);
62968 if (!error)
62969 error = security_path_truncate(&f.file->f_path);
62970 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62971 + error = -EACCES;
62972 if (!error)
62973 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62974 sb_end_write(inode->i_sb);
62975 @@ -381,6 +387,9 @@ retry:
62976 if (__mnt_is_readonly(path.mnt))
62977 res = -EROFS;
62978
62979 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62980 + res = -EACCES;
62981 +
62982 out_path_release:
62983 path_put(&path);
62984 if (retry_estale(res, lookup_flags)) {
62985 @@ -412,6 +421,8 @@ retry:
62986 if (error)
62987 goto dput_and_out;
62988
62989 + gr_log_chdir(path.dentry, path.mnt);
62990 +
62991 set_fs_pwd(current->fs, &path);
62992
62993 dput_and_out:
62994 @@ -441,6 +452,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62995 goto out_putf;
62996
62997 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62998 +
62999 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
63000 + error = -EPERM;
63001 +
63002 + if (!error)
63003 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
63004 +
63005 if (!error)
63006 set_fs_pwd(current->fs, &f.file->f_path);
63007 out_putf:
63008 @@ -470,7 +488,13 @@ retry:
63009 if (error)
63010 goto dput_and_out;
63011
63012 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
63013 + goto dput_and_out;
63014 +
63015 set_fs_root(current->fs, &path);
63016 +
63017 + gr_handle_chroot_chdir(&path);
63018 +
63019 error = 0;
63020 dput_and_out:
63021 path_put(&path);
63022 @@ -494,6 +518,16 @@ static int chmod_common(struct path *path, umode_t mode)
63023 return error;
63024 retry_deleg:
63025 mutex_lock(&inode->i_mutex);
63026 +
63027 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
63028 + error = -EACCES;
63029 + goto out_unlock;
63030 + }
63031 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
63032 + error = -EACCES;
63033 + goto out_unlock;
63034 + }
63035 +
63036 error = security_path_chmod(path, mode);
63037 if (error)
63038 goto out_unlock;
63039 @@ -559,6 +593,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
63040 uid = make_kuid(current_user_ns(), user);
63041 gid = make_kgid(current_user_ns(), group);
63042
63043 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
63044 + return -EACCES;
63045 +
63046 newattrs.ia_valid = ATTR_CTIME;
63047 if (user != (uid_t) -1) {
63048 if (!uid_valid(uid))
63049 @@ -978,6 +1015,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
63050 } else {
63051 fsnotify_open(f);
63052 fd_install(fd, f);
63053 + trace_do_sys_open(tmp->name, flags, mode);
63054 }
63055 }
63056 putname(tmp);
63057 diff --git a/fs/pipe.c b/fs/pipe.c
63058 index 034bffa..6c6b522 100644
63059 --- a/fs/pipe.c
63060 +++ b/fs/pipe.c
63061 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
63062
63063 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
63064 {
63065 - if (pipe->files)
63066 + if (atomic_read(&pipe->files))
63067 mutex_lock_nested(&pipe->mutex, subclass);
63068 }
63069
63070 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
63071
63072 void pipe_unlock(struct pipe_inode_info *pipe)
63073 {
63074 - if (pipe->files)
63075 + if (atomic_read(&pipe->files))
63076 mutex_unlock(&pipe->mutex);
63077 }
63078 EXPORT_SYMBOL(pipe_unlock);
63079 @@ -342,9 +342,9 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
63080 }
63081 if (bufs) /* More to do? */
63082 continue;
63083 - if (!pipe->writers)
63084 + if (!atomic_read(&pipe->writers))
63085 break;
63086 - if (!pipe->waiting_writers) {
63087 + if (!atomic_read(&pipe->waiting_writers)) {
63088 /* syscall merging: Usually we must not sleep
63089 * if O_NONBLOCK is set, or if we got some data.
63090 * But if a writer sleeps in kernel space, then
63091 @@ -406,7 +406,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
63092 ret = 0;
63093 __pipe_lock(pipe);
63094
63095 - if (!pipe->readers) {
63096 + if (!atomic_read(&pipe->readers)) {
63097 send_sig(SIGPIPE, current, 0);
63098 ret = -EPIPE;
63099 goto out;
63100 @@ -461,7 +461,7 @@ redo1:
63101 for (;;) {
63102 int bufs;
63103
63104 - if (!pipe->readers) {
63105 + if (!atomic_read(&pipe->readers)) {
63106 send_sig(SIGPIPE, current, 0);
63107 if (!ret)
63108 ret = -EPIPE;
63109 @@ -552,9 +552,9 @@ redo2:
63110 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63111 do_wakeup = 0;
63112 }
63113 - pipe->waiting_writers++;
63114 + atomic_inc(&pipe->waiting_writers);
63115 pipe_wait(pipe);
63116 - pipe->waiting_writers--;
63117 + atomic_dec(&pipe->waiting_writers);
63118 }
63119 out:
63120 __pipe_unlock(pipe);
63121 @@ -609,7 +609,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63122 mask = 0;
63123 if (filp->f_mode & FMODE_READ) {
63124 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
63125 - if (!pipe->writers && filp->f_version != pipe->w_counter)
63126 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
63127 mask |= POLLHUP;
63128 }
63129
63130 @@ -619,7 +619,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63131 * Most Unices do not set POLLERR for FIFOs but on Linux they
63132 * behave exactly like pipes for poll().
63133 */
63134 - if (!pipe->readers)
63135 + if (!atomic_read(&pipe->readers))
63136 mask |= POLLERR;
63137 }
63138
63139 @@ -631,7 +631,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
63140 int kill = 0;
63141
63142 spin_lock(&inode->i_lock);
63143 - if (!--pipe->files) {
63144 + if (atomic_dec_and_test(&pipe->files)) {
63145 inode->i_pipe = NULL;
63146 kill = 1;
63147 }
63148 @@ -648,11 +648,11 @@ pipe_release(struct inode *inode, struct file *file)
63149
63150 __pipe_lock(pipe);
63151 if (file->f_mode & FMODE_READ)
63152 - pipe->readers--;
63153 + atomic_dec(&pipe->readers);
63154 if (file->f_mode & FMODE_WRITE)
63155 - pipe->writers--;
63156 + atomic_dec(&pipe->writers);
63157
63158 - if (pipe->readers || pipe->writers) {
63159 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
63160 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
63161 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63162 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
63163 @@ -717,7 +717,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
63164 kfree(pipe);
63165 }
63166
63167 -static struct vfsmount *pipe_mnt __read_mostly;
63168 +struct vfsmount *pipe_mnt __read_mostly;
63169
63170 /*
63171 * pipefs_dname() is called from d_path().
63172 @@ -747,8 +747,9 @@ static struct inode * get_pipe_inode(void)
63173 goto fail_iput;
63174
63175 inode->i_pipe = pipe;
63176 - pipe->files = 2;
63177 - pipe->readers = pipe->writers = 1;
63178 + atomic_set(&pipe->files, 2);
63179 + atomic_set(&pipe->readers, 1);
63180 + atomic_set(&pipe->writers, 1);
63181 inode->i_fop = &pipefifo_fops;
63182
63183 /*
63184 @@ -927,17 +928,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
63185 spin_lock(&inode->i_lock);
63186 if (inode->i_pipe) {
63187 pipe = inode->i_pipe;
63188 - pipe->files++;
63189 + atomic_inc(&pipe->files);
63190 spin_unlock(&inode->i_lock);
63191 } else {
63192 spin_unlock(&inode->i_lock);
63193 pipe = alloc_pipe_info();
63194 if (!pipe)
63195 return -ENOMEM;
63196 - pipe->files = 1;
63197 + atomic_set(&pipe->files, 1);
63198 spin_lock(&inode->i_lock);
63199 if (unlikely(inode->i_pipe)) {
63200 - inode->i_pipe->files++;
63201 + atomic_inc(&inode->i_pipe->files);
63202 spin_unlock(&inode->i_lock);
63203 free_pipe_info(pipe);
63204 pipe = inode->i_pipe;
63205 @@ -962,10 +963,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
63206 * opened, even when there is no process writing the FIFO.
63207 */
63208 pipe->r_counter++;
63209 - if (pipe->readers++ == 0)
63210 + if (atomic_inc_return(&pipe->readers) == 1)
63211 wake_up_partner(pipe);
63212
63213 - if (!is_pipe && !pipe->writers) {
63214 + if (!is_pipe && !atomic_read(&pipe->writers)) {
63215 if ((filp->f_flags & O_NONBLOCK)) {
63216 /* suppress POLLHUP until we have
63217 * seen a writer */
63218 @@ -984,14 +985,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
63219 * errno=ENXIO when there is no process reading the FIFO.
63220 */
63221 ret = -ENXIO;
63222 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
63223 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
63224 goto err;
63225
63226 pipe->w_counter++;
63227 - if (!pipe->writers++)
63228 + if (atomic_inc_return(&pipe->writers) == 1)
63229 wake_up_partner(pipe);
63230
63231 - if (!is_pipe && !pipe->readers) {
63232 + if (!is_pipe && !atomic_read(&pipe->readers)) {
63233 if (wait_for_partner(pipe, &pipe->r_counter))
63234 goto err_wr;
63235 }
63236 @@ -1005,11 +1006,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
63237 * the process can at least talk to itself.
63238 */
63239
63240 - pipe->readers++;
63241 - pipe->writers++;
63242 + atomic_inc(&pipe->readers);
63243 + atomic_inc(&pipe->writers);
63244 pipe->r_counter++;
63245 pipe->w_counter++;
63246 - if (pipe->readers == 1 || pipe->writers == 1)
63247 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
63248 wake_up_partner(pipe);
63249 break;
63250
63251 @@ -1023,13 +1024,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
63252 return 0;
63253
63254 err_rd:
63255 - if (!--pipe->readers)
63256 + if (atomic_dec_and_test(&pipe->readers))
63257 wake_up_interruptible(&pipe->wait);
63258 ret = -ERESTARTSYS;
63259 goto err;
63260
63261 err_wr:
63262 - if (!--pipe->writers)
63263 + if (atomic_dec_and_test(&pipe->writers))
63264 wake_up_interruptible(&pipe->wait);
63265 ret = -ERESTARTSYS;
63266 goto err;
63267 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
63268 index 0855f77..6787d50 100644
63269 --- a/fs/posix_acl.c
63270 +++ b/fs/posix_acl.c
63271 @@ -20,6 +20,7 @@
63272 #include <linux/xattr.h>
63273 #include <linux/export.h>
63274 #include <linux/user_namespace.h>
63275 +#include <linux/grsecurity.h>
63276
63277 struct posix_acl **acl_by_type(struct inode *inode, int type)
63278 {
63279 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
63280 }
63281 }
63282 if (mode_p)
63283 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63284 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63285 return not_equiv;
63286 }
63287 EXPORT_SYMBOL(posix_acl_equiv_mode);
63288 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
63289 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
63290 }
63291
63292 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63293 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63294 return not_equiv;
63295 }
63296
63297 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
63298 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
63299 int err = -ENOMEM;
63300 if (clone) {
63301 + *mode_p &= ~gr_acl_umask();
63302 +
63303 err = posix_acl_create_masq(clone, mode_p);
63304 if (err < 0) {
63305 posix_acl_release(clone);
63306 @@ -659,11 +662,12 @@ struct posix_acl *
63307 posix_acl_from_xattr(struct user_namespace *user_ns,
63308 const void *value, size_t size)
63309 {
63310 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63311 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63312 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63313 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63314 int count;
63315 struct posix_acl *acl;
63316 struct posix_acl_entry *acl_e;
63317 + umode_t umask = gr_acl_umask();
63318
63319 if (!value)
63320 return NULL;
63321 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63322
63323 switch(acl_e->e_tag) {
63324 case ACL_USER_OBJ:
63325 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63326 + break;
63327 case ACL_GROUP_OBJ:
63328 case ACL_MASK:
63329 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63330 + break;
63331 case ACL_OTHER:
63332 + acl_e->e_perm &= ~(umask & S_IRWXO);
63333 break;
63334
63335 case ACL_USER:
63336 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63337 acl_e->e_uid =
63338 make_kuid(user_ns,
63339 le32_to_cpu(entry->e_id));
63340 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63341 goto fail;
63342 break;
63343 case ACL_GROUP:
63344 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63345 acl_e->e_gid =
63346 make_kgid(user_ns,
63347 le32_to_cpu(entry->e_id));
63348 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63349 index 2183fcf..3c32a98 100644
63350 --- a/fs/proc/Kconfig
63351 +++ b/fs/proc/Kconfig
63352 @@ -30,7 +30,7 @@ config PROC_FS
63353
63354 config PROC_KCORE
63355 bool "/proc/kcore support" if !ARM
63356 - depends on PROC_FS && MMU
63357 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63358 help
63359 Provides a virtual ELF core file of the live kernel. This can
63360 be read with gdb and other ELF tools. No modifications can be
63361 @@ -38,8 +38,8 @@ config PROC_KCORE
63362
63363 config PROC_VMCORE
63364 bool "/proc/vmcore support"
63365 - depends on PROC_FS && CRASH_DUMP
63366 - default y
63367 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63368 + default n
63369 help
63370 Exports the dump image of crashed kernel in ELF format.
63371
63372 @@ -63,8 +63,8 @@ config PROC_SYSCTL
63373 limited in memory.
63374
63375 config PROC_PAGE_MONITOR
63376 - default y
63377 - depends on PROC_FS && MMU
63378 + default n
63379 + depends on PROC_FS && MMU && !GRKERNSEC
63380 bool "Enable /proc page monitoring" if EXPERT
63381 help
63382 Various /proc files exist to monitor process memory utilization:
63383 diff --git a/fs/proc/array.c b/fs/proc/array.c
63384 index 64db2bc..a8185d6 100644
63385 --- a/fs/proc/array.c
63386 +++ b/fs/proc/array.c
63387 @@ -60,6 +60,7 @@
63388 #include <linux/tty.h>
63389 #include <linux/string.h>
63390 #include <linux/mman.h>
63391 +#include <linux/grsecurity.h>
63392 #include <linux/proc_fs.h>
63393 #include <linux/ioport.h>
63394 #include <linux/uaccess.h>
63395 @@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63396 seq_putc(m, '\n');
63397 }
63398
63399 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63400 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
63401 +{
63402 + if (p->mm)
63403 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63404 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63405 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63406 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63407 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63408 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63409 + else
63410 + seq_printf(m, "PaX:\t-----\n");
63411 +}
63412 +#endif
63413 +
63414 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63415 struct pid *pid, struct task_struct *task)
63416 {
63417 @@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63418 task_cpus_allowed(m, task);
63419 cpuset_task_status_allowed(m, task);
63420 task_context_switch_counts(m, task);
63421 +
63422 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63423 + task_pax(m, task);
63424 +#endif
63425 +
63426 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63427 + task_grsec_rbac(m, task);
63428 +#endif
63429 +
63430 return 0;
63431 }
63432
63433 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63434 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63435 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63436 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63437 +#endif
63438 +
63439 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63440 struct pid *pid, struct task_struct *task, int whole)
63441 {
63442 @@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63443 char tcomm[sizeof(task->comm)];
63444 unsigned long flags;
63445
63446 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63447 + if (current->exec_id != m->exec_id) {
63448 + gr_log_badprocpid("stat");
63449 + return 0;
63450 + }
63451 +#endif
63452 +
63453 state = *get_task_state(task);
63454 vsize = eip = esp = 0;
63455 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63456 @@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63457 gtime = task_gtime(task);
63458 }
63459
63460 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63461 + if (PAX_RAND_FLAGS(mm)) {
63462 + eip = 0;
63463 + esp = 0;
63464 + wchan = 0;
63465 + }
63466 +#endif
63467 +#ifdef CONFIG_GRKERNSEC_HIDESYM
63468 + wchan = 0;
63469 + eip =0;
63470 + esp =0;
63471 +#endif
63472 +
63473 /* scale priority and nice values from timeslices to -20..20 */
63474 /* to make it look like a "normal" Unix priority/nice value */
63475 priority = task_prio(task);
63476 @@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63477 seq_put_decimal_ull(m, ' ', vsize);
63478 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63479 seq_put_decimal_ull(m, ' ', rsslim);
63480 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63481 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63482 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63483 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63484 +#else
63485 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63486 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63487 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63488 +#endif
63489 seq_put_decimal_ull(m, ' ', esp);
63490 seq_put_decimal_ull(m, ' ', eip);
63491 /* The signal information here is obsolete.
63492 @@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63493 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63494 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63495
63496 - if (mm && permitted) {
63497 + if (mm && permitted
63498 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63499 + && !PAX_RAND_FLAGS(mm)
63500 +#endif
63501 + ) {
63502 seq_put_decimal_ull(m, ' ', mm->start_data);
63503 seq_put_decimal_ull(m, ' ', mm->end_data);
63504 seq_put_decimal_ull(m, ' ', mm->start_brk);
63505 @@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63506 struct pid *pid, struct task_struct *task)
63507 {
63508 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63509 - struct mm_struct *mm = get_task_mm(task);
63510 + struct mm_struct *mm;
63511
63512 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63513 + if (current->exec_id != m->exec_id) {
63514 + gr_log_badprocpid("statm");
63515 + return 0;
63516 + }
63517 +#endif
63518 + mm = get_task_mm(task);
63519 if (mm) {
63520 size = task_statm(mm, &shared, &text, &data, &resident);
63521 mmput(mm);
63522 @@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63523 return 0;
63524 }
63525
63526 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63527 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63528 +{
63529 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63530 +}
63531 +#endif
63532 +
63533 #ifdef CONFIG_CHECKPOINT_RESTORE
63534 static struct pid *
63535 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63536 diff --git a/fs/proc/base.c b/fs/proc/base.c
63537 index 2d696b0..b9da447 100644
63538 --- a/fs/proc/base.c
63539 +++ b/fs/proc/base.c
63540 @@ -113,6 +113,14 @@ struct pid_entry {
63541 union proc_op op;
63542 };
63543
63544 +struct getdents_callback {
63545 + struct linux_dirent __user * current_dir;
63546 + struct linux_dirent __user * previous;
63547 + struct file * file;
63548 + int count;
63549 + int error;
63550 +};
63551 +
63552 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63553 .name = (NAME), \
63554 .len = sizeof(NAME) - 1, \
63555 @@ -205,12 +213,28 @@ static int proc_pid_cmdline(struct task_struct *task, char *buffer)
63556 return get_cmdline(task, buffer, PAGE_SIZE);
63557 }
63558
63559 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63560 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63561 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63562 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63563 +#endif
63564 +
63565 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63566 {
63567 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63568 int res = PTR_ERR(mm);
63569 if (mm && !IS_ERR(mm)) {
63570 unsigned int nwords = 0;
63571 +
63572 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63573 + /* allow if we're currently ptracing this task */
63574 + if (PAX_RAND_FLAGS(mm) &&
63575 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63576 + mmput(mm);
63577 + return 0;
63578 + }
63579 +#endif
63580 +
63581 do {
63582 nwords += 2;
63583 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63584 @@ -224,7 +248,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63585 }
63586
63587
63588 -#ifdef CONFIG_KALLSYMS
63589 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63590 /*
63591 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63592 * Returns the resolved symbol. If that fails, simply return the address.
63593 @@ -263,7 +287,7 @@ static void unlock_trace(struct task_struct *task)
63594 mutex_unlock(&task->signal->cred_guard_mutex);
63595 }
63596
63597 -#ifdef CONFIG_STACKTRACE
63598 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63599
63600 #define MAX_STACK_TRACE_DEPTH 64
63601
63602 @@ -486,7 +510,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63603 return count;
63604 }
63605
63606 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63607 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63608 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63609 {
63610 long nr;
63611 @@ -515,7 +539,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63612 /************************************************************************/
63613
63614 /* permission checks */
63615 -static int proc_fd_access_allowed(struct inode *inode)
63616 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63617 {
63618 struct task_struct *task;
63619 int allowed = 0;
63620 @@ -525,7 +549,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63621 */
63622 task = get_proc_task(inode);
63623 if (task) {
63624 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63625 + if (log)
63626 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63627 + else
63628 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63629 put_task_struct(task);
63630 }
63631 return allowed;
63632 @@ -556,10 +583,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63633 struct task_struct *task,
63634 int hide_pid_min)
63635 {
63636 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63637 + return false;
63638 +
63639 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63640 + rcu_read_lock();
63641 + {
63642 + const struct cred *tmpcred = current_cred();
63643 + const struct cred *cred = __task_cred(task);
63644 +
63645 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63646 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63647 + || in_group_p(grsec_proc_gid)
63648 +#endif
63649 + ) {
63650 + rcu_read_unlock();
63651 + return true;
63652 + }
63653 + }
63654 + rcu_read_unlock();
63655 +
63656 + if (!pid->hide_pid)
63657 + return false;
63658 +#endif
63659 +
63660 if (pid->hide_pid < hide_pid_min)
63661 return true;
63662 if (in_group_p(pid->pid_gid))
63663 return true;
63664 +
63665 return ptrace_may_access(task, PTRACE_MODE_READ);
63666 }
63667
63668 @@ -577,7 +629,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63669 put_task_struct(task);
63670
63671 if (!has_perms) {
63672 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63673 + {
63674 +#else
63675 if (pid->hide_pid == 2) {
63676 +#endif
63677 /*
63678 * Let's make getdents(), stat(), and open()
63679 * consistent with each other. If a process
63680 @@ -675,6 +731,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63681 if (!task)
63682 return -ESRCH;
63683
63684 + if (gr_acl_handle_procpidmem(task)) {
63685 + put_task_struct(task);
63686 + return -EPERM;
63687 + }
63688 +
63689 mm = mm_access(task, mode);
63690 put_task_struct(task);
63691
63692 @@ -690,6 +751,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63693
63694 file->private_data = mm;
63695
63696 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63697 + file->f_version = current->exec_id;
63698 +#endif
63699 +
63700 return 0;
63701 }
63702
63703 @@ -711,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63704 ssize_t copied;
63705 char *page;
63706
63707 +#ifdef CONFIG_GRKERNSEC
63708 + if (write)
63709 + return -EPERM;
63710 +#endif
63711 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63712 + if (file->f_version != current->exec_id) {
63713 + gr_log_badprocpid("mem");
63714 + return 0;
63715 + }
63716 +#endif
63717 +
63718 if (!mm)
63719 return 0;
63720
63721 @@ -723,7 +799,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63722 goto free;
63723
63724 while (count > 0) {
63725 - int this_len = min_t(int, count, PAGE_SIZE);
63726 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63727
63728 if (write && copy_from_user(page, buf, this_len)) {
63729 copied = -EFAULT;
63730 @@ -815,6 +891,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63731 if (!mm)
63732 return 0;
63733
63734 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63735 + if (file->f_version != current->exec_id) {
63736 + gr_log_badprocpid("environ");
63737 + return 0;
63738 + }
63739 +#endif
63740 +
63741 page = (char *)__get_free_page(GFP_TEMPORARY);
63742 if (!page)
63743 return -ENOMEM;
63744 @@ -824,7 +907,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63745 goto free;
63746 while (count > 0) {
63747 size_t this_len, max_len;
63748 - int retval;
63749 + ssize_t retval;
63750
63751 if (src >= (mm->env_end - mm->env_start))
63752 break;
63753 @@ -1438,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63754 int error = -EACCES;
63755
63756 /* Are we allowed to snoop on the tasks file descriptors? */
63757 - if (!proc_fd_access_allowed(inode))
63758 + if (!proc_fd_access_allowed(inode, 0))
63759 goto out;
63760
63761 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63762 @@ -1482,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63763 struct path path;
63764
63765 /* Are we allowed to snoop on the tasks file descriptors? */
63766 - if (!proc_fd_access_allowed(inode))
63767 - goto out;
63768 + /* logging this is needed for learning on chromium to work properly,
63769 + but we don't want to flood the logs from 'ps' which does a readlink
63770 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63771 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
63772 + */
63773 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63774 + if (!proc_fd_access_allowed(inode,0))
63775 + goto out;
63776 + } else {
63777 + if (!proc_fd_access_allowed(inode,1))
63778 + goto out;
63779 + }
63780
63781 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63782 if (error)
63783 @@ -1533,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63784 rcu_read_lock();
63785 cred = __task_cred(task);
63786 inode->i_uid = cred->euid;
63787 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63788 + inode->i_gid = grsec_proc_gid;
63789 +#else
63790 inode->i_gid = cred->egid;
63791 +#endif
63792 rcu_read_unlock();
63793 }
63794 security_task_to_inode(task, inode);
63795 @@ -1569,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63796 return -ENOENT;
63797 }
63798 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63799 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63800 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63801 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63802 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63803 +#endif
63804 task_dumpable(task)) {
63805 cred = __task_cred(task);
63806 stat->uid = cred->euid;
63807 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63808 + stat->gid = grsec_proc_gid;
63809 +#else
63810 stat->gid = cred->egid;
63811 +#endif
63812 }
63813 }
63814 rcu_read_unlock();
63815 @@ -1610,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63816
63817 if (task) {
63818 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63819 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63820 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63821 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63822 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63823 +#endif
63824 task_dumpable(task)) {
63825 rcu_read_lock();
63826 cred = __task_cred(task);
63827 inode->i_uid = cred->euid;
63828 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63829 + inode->i_gid = grsec_proc_gid;
63830 +#else
63831 inode->i_gid = cred->egid;
63832 +#endif
63833 rcu_read_unlock();
63834 } else {
63835 inode->i_uid = GLOBAL_ROOT_UID;
63836 @@ -2149,6 +2264,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63837 if (!task)
63838 goto out_no_task;
63839
63840 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63841 + goto out;
63842 +
63843 /*
63844 * Yes, it does not scale. And it should not. Don't add
63845 * new entries into /proc/<tgid>/ without very good reasons.
63846 @@ -2179,6 +2297,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63847 if (!task)
63848 return -ENOENT;
63849
63850 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63851 + goto out;
63852 +
63853 if (!dir_emit_dots(file, ctx))
63854 goto out;
63855
63856 @@ -2568,7 +2689,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63857 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63858 #endif
63859 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63860 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63861 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63862 INF("syscall", S_IRUSR, proc_pid_syscall),
63863 #endif
63864 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63865 @@ -2593,10 +2714,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63866 #ifdef CONFIG_SECURITY
63867 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63868 #endif
63869 -#ifdef CONFIG_KALLSYMS
63870 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63871 INF("wchan", S_IRUGO, proc_pid_wchan),
63872 #endif
63873 -#ifdef CONFIG_STACKTRACE
63874 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63875 ONE("stack", S_IRUSR, proc_pid_stack),
63876 #endif
63877 #ifdef CONFIG_SCHEDSTATS
63878 @@ -2630,6 +2751,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63879 #ifdef CONFIG_HARDWALL
63880 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63881 #endif
63882 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63883 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63884 +#endif
63885 #ifdef CONFIG_USER_NS
63886 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63887 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63888 @@ -2760,7 +2884,14 @@ static int proc_pid_instantiate(struct inode *dir,
63889 if (!inode)
63890 goto out;
63891
63892 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63893 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63894 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63895 + inode->i_gid = grsec_proc_gid;
63896 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63897 +#else
63898 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63899 +#endif
63900 inode->i_op = &proc_tgid_base_inode_operations;
63901 inode->i_fop = &proc_tgid_base_operations;
63902 inode->i_flags|=S_IMMUTABLE;
63903 @@ -2798,7 +2929,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63904 if (!task)
63905 goto out;
63906
63907 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63908 + goto out_put_task;
63909 +
63910 result = proc_pid_instantiate(dir, dentry, task, NULL);
63911 +out_put_task:
63912 put_task_struct(task);
63913 out:
63914 return ERR_PTR(result);
63915 @@ -2904,7 +3039,7 @@ static const struct pid_entry tid_base_stuff[] = {
63916 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63917 #endif
63918 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63919 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63920 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63921 INF("syscall", S_IRUSR, proc_pid_syscall),
63922 #endif
63923 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63924 @@ -2931,10 +3066,10 @@ static const struct pid_entry tid_base_stuff[] = {
63925 #ifdef CONFIG_SECURITY
63926 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63927 #endif
63928 -#ifdef CONFIG_KALLSYMS
63929 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63930 INF("wchan", S_IRUGO, proc_pid_wchan),
63931 #endif
63932 -#ifdef CONFIG_STACKTRACE
63933 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63934 ONE("stack", S_IRUSR, proc_pid_stack),
63935 #endif
63936 #ifdef CONFIG_SCHEDSTATS
63937 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63938 index cbd82df..c0407d2 100644
63939 --- a/fs/proc/cmdline.c
63940 +++ b/fs/proc/cmdline.c
63941 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63942
63943 static int __init proc_cmdline_init(void)
63944 {
63945 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63946 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63947 +#else
63948 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63949 +#endif
63950 return 0;
63951 }
63952 fs_initcall(proc_cmdline_init);
63953 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63954 index 50493ed..248166b 100644
63955 --- a/fs/proc/devices.c
63956 +++ b/fs/proc/devices.c
63957 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63958
63959 static int __init proc_devices_init(void)
63960 {
63961 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63962 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63963 +#else
63964 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63965 +#endif
63966 return 0;
63967 }
63968 fs_initcall(proc_devices_init);
63969 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63970 index 0788d09..9cc1385 100644
63971 --- a/fs/proc/fd.c
63972 +++ b/fs/proc/fd.c
63973 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
63974 if (!task)
63975 return -ENOENT;
63976
63977 - files = get_files_struct(task);
63978 + if (!gr_acl_handle_procpidmem(task))
63979 + files = get_files_struct(task);
63980 put_task_struct(task);
63981
63982 if (files) {
63983 @@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63984 */
63985 int proc_fd_permission(struct inode *inode, int mask)
63986 {
63987 + struct task_struct *task;
63988 int rv = generic_permission(inode, mask);
63989 - if (rv == 0)
63990 - return 0;
63991 +
63992 if (task_tgid(current) == proc_pid(inode))
63993 rv = 0;
63994 +
63995 + task = get_proc_task(inode);
63996 + if (task == NULL)
63997 + return rv;
63998 +
63999 + if (gr_acl_handle_procpidmem(task))
64000 + rv = -EACCES;
64001 +
64002 + put_task_struct(task);
64003 +
64004 return rv;
64005 }
64006
64007 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
64008 index b7f268e..3bea6b7 100644
64009 --- a/fs/proc/generic.c
64010 +++ b/fs/proc/generic.c
64011 @@ -23,6 +23,7 @@
64012 #include <linux/bitops.h>
64013 #include <linux/spinlock.h>
64014 #include <linux/completion.h>
64015 +#include <linux/grsecurity.h>
64016 #include <asm/uaccess.h>
64017
64018 #include "internal.h"
64019 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
64020 return proc_lookup_de(PDE(dir), dir, dentry);
64021 }
64022
64023 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
64024 + unsigned int flags)
64025 +{
64026 + if (gr_proc_is_restricted())
64027 + return ERR_PTR(-EACCES);
64028 +
64029 + return proc_lookup_de(PDE(dir), dir, dentry);
64030 +}
64031 +
64032 /*
64033 * This returns non-zero if at EOF, so that the /proc
64034 * root directory can use this and check if it should
64035 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
64036 return proc_readdir_de(PDE(inode), file, ctx);
64037 }
64038
64039 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
64040 +{
64041 + struct inode *inode = file_inode(file);
64042 +
64043 + if (gr_proc_is_restricted())
64044 + return -EACCES;
64045 +
64046 + return proc_readdir_de(PDE(inode), file, ctx);
64047 +}
64048 +
64049 /*
64050 * These are the generic /proc directory operations. They
64051 * use the in-memory "struct proc_dir_entry" tree to parse
64052 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
64053 .iterate = proc_readdir,
64054 };
64055
64056 +static const struct file_operations proc_dir_restricted_operations = {
64057 + .llseek = generic_file_llseek,
64058 + .read = generic_read_dir,
64059 + .iterate = proc_readdir_restrict,
64060 +};
64061 +
64062 /*
64063 * proc directories can do almost nothing..
64064 */
64065 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
64066 .setattr = proc_notify_change,
64067 };
64068
64069 +static const struct inode_operations proc_dir_restricted_inode_operations = {
64070 + .lookup = proc_lookup_restrict,
64071 + .getattr = proc_getattr,
64072 + .setattr = proc_notify_change,
64073 +};
64074 +
64075 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
64076 {
64077 struct proc_dir_entry *tmp;
64078 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
64079 return ret;
64080
64081 if (S_ISDIR(dp->mode)) {
64082 - dp->proc_fops = &proc_dir_operations;
64083 - dp->proc_iops = &proc_dir_inode_operations;
64084 + if (dp->restricted) {
64085 + dp->proc_fops = &proc_dir_restricted_operations;
64086 + dp->proc_iops = &proc_dir_restricted_inode_operations;
64087 + } else {
64088 + dp->proc_fops = &proc_dir_operations;
64089 + dp->proc_iops = &proc_dir_inode_operations;
64090 + }
64091 dir->nlink++;
64092 } else if (S_ISLNK(dp->mode)) {
64093 dp->proc_iops = &proc_link_inode_operations;
64094 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
64095 }
64096 EXPORT_SYMBOL_GPL(proc_mkdir_data);
64097
64098 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
64099 + struct proc_dir_entry *parent, void *data)
64100 +{
64101 + struct proc_dir_entry *ent;
64102 +
64103 + if (mode == 0)
64104 + mode = S_IRUGO | S_IXUGO;
64105 +
64106 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
64107 + if (ent) {
64108 + ent->data = data;
64109 + ent->restricted = 1;
64110 + if (proc_register(parent, ent) < 0) {
64111 + kfree(ent);
64112 + ent = NULL;
64113 + }
64114 + }
64115 + return ent;
64116 +}
64117 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
64118 +
64119 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
64120 struct proc_dir_entry *parent)
64121 {
64122 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
64123 }
64124 EXPORT_SYMBOL(proc_mkdir);
64125
64126 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
64127 + struct proc_dir_entry *parent)
64128 +{
64129 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
64130 +}
64131 +EXPORT_SYMBOL(proc_mkdir_restrict);
64132 +
64133 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
64134 struct proc_dir_entry *parent,
64135 const struct file_operations *proc_fops,
64136 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
64137 index 0adbc02..bee4d0b 100644
64138 --- a/fs/proc/inode.c
64139 +++ b/fs/proc/inode.c
64140 @@ -23,11 +23,17 @@
64141 #include <linux/slab.h>
64142 #include <linux/mount.h>
64143 #include <linux/magic.h>
64144 +#include <linux/grsecurity.h>
64145
64146 #include <asm/uaccess.h>
64147
64148 #include "internal.h"
64149
64150 +#ifdef CONFIG_PROC_SYSCTL
64151 +extern const struct inode_operations proc_sys_inode_operations;
64152 +extern const struct inode_operations proc_sys_dir_operations;
64153 +#endif
64154 +
64155 static void proc_evict_inode(struct inode *inode)
64156 {
64157 struct proc_dir_entry *de;
64158 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
64159 ns = PROC_I(inode)->ns.ns;
64160 if (ns_ops && ns)
64161 ns_ops->put(ns);
64162 +
64163 +#ifdef CONFIG_PROC_SYSCTL
64164 + if (inode->i_op == &proc_sys_inode_operations ||
64165 + inode->i_op == &proc_sys_dir_operations)
64166 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
64167 +#endif
64168 +
64169 }
64170
64171 static struct kmem_cache * proc_inode_cachep;
64172 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
64173 if (de->mode) {
64174 inode->i_mode = de->mode;
64175 inode->i_uid = de->uid;
64176 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64177 + inode->i_gid = grsec_proc_gid;
64178 +#else
64179 inode->i_gid = de->gid;
64180 +#endif
64181 }
64182 if (de->size)
64183 inode->i_size = de->size;
64184 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
64185 index 3ab6d14..b26174e 100644
64186 --- a/fs/proc/internal.h
64187 +++ b/fs/proc/internal.h
64188 @@ -46,9 +46,10 @@ struct proc_dir_entry {
64189 struct completion *pde_unload_completion;
64190 struct list_head pde_openers; /* who did ->open, but not ->release */
64191 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
64192 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
64193 u8 namelen;
64194 char name[];
64195 -};
64196 +} __randomize_layout;
64197
64198 union proc_op {
64199 int (*proc_get_link)(struct dentry *, struct path *);
64200 @@ -67,7 +68,7 @@ struct proc_inode {
64201 struct ctl_table *sysctl_entry;
64202 struct proc_ns ns;
64203 struct inode vfs_inode;
64204 -};
64205 +} __randomize_layout;
64206
64207 /*
64208 * General functions
64209 @@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
64210 struct pid *, struct task_struct *);
64211 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
64212 struct pid *, struct task_struct *);
64213 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64214 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
64215 +#endif
64216
64217 /*
64218 * base.c
64219 @@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
64220 extern spinlock_t proc_subdir_lock;
64221
64222 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
64223 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
64224 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
64225 struct dentry *);
64226 extern int proc_readdir(struct file *, struct dir_context *);
64227 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
64228 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
64229
64230 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
64231 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
64232 index a352d57..cb94a5c 100644
64233 --- a/fs/proc/interrupts.c
64234 +++ b/fs/proc/interrupts.c
64235 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
64236
64237 static int __init proc_interrupts_init(void)
64238 {
64239 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64240 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
64241 +#else
64242 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
64243 +#endif
64244 return 0;
64245 }
64246 fs_initcall(proc_interrupts_init);
64247 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
64248 index 39e6ef3..2f9cb5e 100644
64249 --- a/fs/proc/kcore.c
64250 +++ b/fs/proc/kcore.c
64251 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64252 * the addresses in the elf_phdr on our list.
64253 */
64254 start = kc_offset_to_vaddr(*fpos - elf_buflen);
64255 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
64256 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
64257 + if (tsz > buflen)
64258 tsz = buflen;
64259 -
64260 +
64261 while (buflen) {
64262 struct kcore_list *m;
64263
64264 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64265 kfree(elf_buf);
64266 } else {
64267 if (kern_addr_valid(start)) {
64268 - unsigned long n;
64269 + char *elf_buf;
64270 + mm_segment_t oldfs;
64271
64272 - n = copy_to_user(buffer, (char *)start, tsz);
64273 - /*
64274 - * We cannot distinguish between fault on source
64275 - * and fault on destination. When this happens
64276 - * we clear too and hope it will trigger the
64277 - * EFAULT again.
64278 - */
64279 - if (n) {
64280 - if (clear_user(buffer + tsz - n,
64281 - n))
64282 + elf_buf = kmalloc(tsz, GFP_KERNEL);
64283 + if (!elf_buf)
64284 + return -ENOMEM;
64285 + oldfs = get_fs();
64286 + set_fs(KERNEL_DS);
64287 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
64288 + set_fs(oldfs);
64289 + if (copy_to_user(buffer, elf_buf, tsz)) {
64290 + kfree(elf_buf);
64291 return -EFAULT;
64292 + }
64293 }
64294 + set_fs(oldfs);
64295 + kfree(elf_buf);
64296 } else {
64297 if (clear_user(buffer, tsz))
64298 return -EFAULT;
64299 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64300
64301 static int open_kcore(struct inode *inode, struct file *filp)
64302 {
64303 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64304 + return -EPERM;
64305 +#endif
64306 if (!capable(CAP_SYS_RAWIO))
64307 return -EPERM;
64308 if (kcore_need_update)
64309 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
64310 index 7445af0..7c5113c 100644
64311 --- a/fs/proc/meminfo.c
64312 +++ b/fs/proc/meminfo.c
64313 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
64314 vmi.used >> 10,
64315 vmi.largest_chunk >> 10
64316 #ifdef CONFIG_MEMORY_FAILURE
64317 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64318 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64319 #endif
64320 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64321 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
64322 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
64323 index d4a3574..b421ce9 100644
64324 --- a/fs/proc/nommu.c
64325 +++ b/fs/proc/nommu.c
64326 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
64327
64328 if (file) {
64329 seq_pad(m, ' ');
64330 - seq_path(m, &file->f_path, "");
64331 + seq_path(m, &file->f_path, "\n\\");
64332 }
64333
64334 seq_putc(m, '\n');
64335 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
64336 index 4677bb7..dad3045 100644
64337 --- a/fs/proc/proc_net.c
64338 +++ b/fs/proc/proc_net.c
64339 @@ -23,9 +23,27 @@
64340 #include <linux/nsproxy.h>
64341 #include <net/net_namespace.h>
64342 #include <linux/seq_file.h>
64343 +#include <linux/grsecurity.h>
64344
64345 #include "internal.h"
64346
64347 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
64348 +static struct seq_operations *ipv6_seq_ops_addr;
64349 +
64350 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
64351 +{
64352 + ipv6_seq_ops_addr = addr;
64353 +}
64354 +
64355 +void unregister_ipv6_seq_ops_addr(void)
64356 +{
64357 + ipv6_seq_ops_addr = NULL;
64358 +}
64359 +
64360 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
64361 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
64362 +#endif
64363 +
64364 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
64365 {
64366 return pde->parent->data;
64367 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
64368 return maybe_get_net(PDE_NET(PDE(inode)));
64369 }
64370
64371 +extern const struct seq_operations dev_seq_ops;
64372 +
64373 int seq_open_net(struct inode *ino, struct file *f,
64374 const struct seq_operations *ops, int size)
64375 {
64376 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
64377
64378 BUG_ON(size < sizeof(*p));
64379
64380 + /* only permit access to /proc/net/dev */
64381 + if (
64382 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
64383 + ops != ipv6_seq_ops_addr &&
64384 +#endif
64385 + ops != &dev_seq_ops && gr_proc_is_restricted())
64386 + return -EACCES;
64387 +
64388 net = get_proc_net(ino);
64389 if (net == NULL)
64390 return -ENXIO;
64391 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
64392 int err;
64393 struct net *net;
64394
64395 + if (gr_proc_is_restricted())
64396 + return -EACCES;
64397 +
64398 err = -ENXIO;
64399 net = get_proc_net(inode);
64400 if (net == NULL)
64401 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64402 index 7129046..6914844 100644
64403 --- a/fs/proc/proc_sysctl.c
64404 +++ b/fs/proc/proc_sysctl.c
64405 @@ -11,13 +11,21 @@
64406 #include <linux/namei.h>
64407 #include <linux/mm.h>
64408 #include <linux/module.h>
64409 +#include <linux/nsproxy.h>
64410 +#ifdef CONFIG_GRKERNSEC
64411 +#include <net/net_namespace.h>
64412 +#endif
64413 #include "internal.h"
64414
64415 +extern int gr_handle_chroot_sysctl(const int op);
64416 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64417 + const int op);
64418 +
64419 static const struct dentry_operations proc_sys_dentry_operations;
64420 static const struct file_operations proc_sys_file_operations;
64421 -static const struct inode_operations proc_sys_inode_operations;
64422 +const struct inode_operations proc_sys_inode_operations;
64423 static const struct file_operations proc_sys_dir_file_operations;
64424 -static const struct inode_operations proc_sys_dir_operations;
64425 +const struct inode_operations proc_sys_dir_operations;
64426
64427 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64428 {
64429 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64430
64431 err = NULL;
64432 d_set_d_op(dentry, &proc_sys_dentry_operations);
64433 +
64434 + gr_handle_proc_create(dentry, inode);
64435 +
64436 d_add(dentry, inode);
64437
64438 out:
64439 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64440 struct inode *inode = file_inode(filp);
64441 struct ctl_table_header *head = grab_header(inode);
64442 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64443 + int op = write ? MAY_WRITE : MAY_READ;
64444 ssize_t error;
64445 size_t res;
64446
64447 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64448 * and won't be until we finish.
64449 */
64450 error = -EPERM;
64451 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64452 + if (sysctl_perm(head, table, op))
64453 goto out;
64454
64455 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64456 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64457 if (!table->proc_handler)
64458 goto out;
64459
64460 +#ifdef CONFIG_GRKERNSEC
64461 + error = -EPERM;
64462 + if (gr_handle_chroot_sysctl(op))
64463 + goto out;
64464 + dget(filp->f_path.dentry);
64465 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64466 + dput(filp->f_path.dentry);
64467 + goto out;
64468 + }
64469 + dput(filp->f_path.dentry);
64470 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64471 + goto out;
64472 + if (write) {
64473 + if (current->nsproxy->net_ns != table->extra2) {
64474 + if (!capable(CAP_SYS_ADMIN))
64475 + goto out;
64476 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64477 + goto out;
64478 + }
64479 +#endif
64480 +
64481 /* careful: calling conventions are nasty here */
64482 res = count;
64483 error = table->proc_handler(table, write, buf, &res, ppos);
64484 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64485 return false;
64486 } else {
64487 d_set_d_op(child, &proc_sys_dentry_operations);
64488 +
64489 + gr_handle_proc_create(child, inode);
64490 +
64491 d_add(child, inode);
64492 }
64493 } else {
64494 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64495 if ((*pos)++ < ctx->pos)
64496 return true;
64497
64498 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64499 + return 0;
64500 +
64501 if (unlikely(S_ISLNK(table->mode)))
64502 res = proc_sys_link_fill_cache(file, ctx, head, table);
64503 else
64504 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64505 if (IS_ERR(head))
64506 return PTR_ERR(head);
64507
64508 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64509 + return -ENOENT;
64510 +
64511 generic_fillattr(inode, stat);
64512 if (table)
64513 stat->mode = (stat->mode & S_IFMT) | table->mode;
64514 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64515 .llseek = generic_file_llseek,
64516 };
64517
64518 -static const struct inode_operations proc_sys_inode_operations = {
64519 +const struct inode_operations proc_sys_inode_operations = {
64520 .permission = proc_sys_permission,
64521 .setattr = proc_sys_setattr,
64522 .getattr = proc_sys_getattr,
64523 };
64524
64525 -static const struct inode_operations proc_sys_dir_operations = {
64526 +const struct inode_operations proc_sys_dir_operations = {
64527 .lookup = proc_sys_lookup,
64528 .permission = proc_sys_permission,
64529 .setattr = proc_sys_setattr,
64530 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64531 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64532 const char *name, int namelen)
64533 {
64534 - struct ctl_table *table;
64535 + ctl_table_no_const *table;
64536 struct ctl_dir *new;
64537 struct ctl_node *node;
64538 char *new_name;
64539 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64540 return NULL;
64541
64542 node = (struct ctl_node *)(new + 1);
64543 - table = (struct ctl_table *)(node + 1);
64544 + table = (ctl_table_no_const *)(node + 1);
64545 new_name = (char *)(table + 2);
64546 memcpy(new_name, name, namelen);
64547 new_name[namelen] = '\0';
64548 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64549 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64550 struct ctl_table_root *link_root)
64551 {
64552 - struct ctl_table *link_table, *entry, *link;
64553 + ctl_table_no_const *link_table, *link;
64554 + struct ctl_table *entry;
64555 struct ctl_table_header *links;
64556 struct ctl_node *node;
64557 char *link_name;
64558 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64559 return NULL;
64560
64561 node = (struct ctl_node *)(links + 1);
64562 - link_table = (struct ctl_table *)(node + nr_entries);
64563 + link_table = (ctl_table_no_const *)(node + nr_entries);
64564 link_name = (char *)&link_table[nr_entries + 1];
64565
64566 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64567 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64568 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64569 struct ctl_table *table)
64570 {
64571 - struct ctl_table *ctl_table_arg = NULL;
64572 - struct ctl_table *entry, *files;
64573 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64574 + struct ctl_table *entry;
64575 int nr_files = 0;
64576 int nr_dirs = 0;
64577 int err = -ENOMEM;
64578 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64579 nr_files++;
64580 }
64581
64582 - files = table;
64583 /* If there are mixed files and directories we need a new table */
64584 if (nr_dirs && nr_files) {
64585 - struct ctl_table *new;
64586 + ctl_table_no_const *new;
64587 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64588 GFP_KERNEL);
64589 if (!files)
64590 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64591 /* Register everything except a directory full of subdirectories */
64592 if (nr_files || !nr_dirs) {
64593 struct ctl_table_header *header;
64594 - header = __register_sysctl_table(set, path, files);
64595 + header = __register_sysctl_table(set, path, files ? files : table);
64596 if (!header) {
64597 kfree(ctl_table_arg);
64598 goto out;
64599 diff --git a/fs/proc/root.c b/fs/proc/root.c
64600 index 5dbadec..473af2f 100644
64601 --- a/fs/proc/root.c
64602 +++ b/fs/proc/root.c
64603 @@ -185,7 +185,15 @@ void __init proc_root_init(void)
64604 proc_mkdir("openprom", NULL);
64605 #endif
64606 proc_tty_init();
64607 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64608 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64609 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64610 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64611 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64612 +#endif
64613 +#else
64614 proc_mkdir("bus", NULL);
64615 +#endif
64616 proc_sys_init();
64617 }
64618
64619 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64620 index 9d231e9..2e1b51a 100644
64621 --- a/fs/proc/stat.c
64622 +++ b/fs/proc/stat.c
64623 @@ -11,6 +11,7 @@
64624 #include <linux/irqnr.h>
64625 #include <linux/cputime.h>
64626 #include <linux/tick.h>
64627 +#include <linux/grsecurity.h>
64628
64629 #ifndef arch_irq_stat_cpu
64630 #define arch_irq_stat_cpu(cpu) 0
64631 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64632 u64 sum_softirq = 0;
64633 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64634 struct timespec boottime;
64635 + int unrestricted = 1;
64636 +
64637 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64638 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64639 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64640 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64641 + && !in_group_p(grsec_proc_gid)
64642 +#endif
64643 + )
64644 + unrestricted = 0;
64645 +#endif
64646 +#endif
64647
64648 user = nice = system = idle = iowait =
64649 irq = softirq = steal = 0;
64650 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64651 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64652 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64653 idle += get_idle_time(i);
64654 - iowait += get_iowait_time(i);
64655 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64656 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64657 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64658 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64659 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64660 - sum += kstat_cpu_irqs_sum(i);
64661 - sum += arch_irq_stat_cpu(i);
64662 + if (unrestricted) {
64663 + iowait += get_iowait_time(i);
64664 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64665 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64666 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64667 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64668 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64669 + sum += kstat_cpu_irqs_sum(i);
64670 + sum += arch_irq_stat_cpu(i);
64671 + for (j = 0; j < NR_SOFTIRQS; j++) {
64672 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64673
64674 - for (j = 0; j < NR_SOFTIRQS; j++) {
64675 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64676 -
64677 - per_softirq_sums[j] += softirq_stat;
64678 - sum_softirq += softirq_stat;
64679 + per_softirq_sums[j] += softirq_stat;
64680 + sum_softirq += softirq_stat;
64681 + }
64682 }
64683 }
64684 - sum += arch_irq_stat();
64685 + if (unrestricted)
64686 + sum += arch_irq_stat();
64687
64688 seq_puts(p, "cpu ");
64689 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64690 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64691 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64692 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64693 idle = get_idle_time(i);
64694 - iowait = get_iowait_time(i);
64695 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64696 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64697 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64698 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64699 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64700 + if (unrestricted) {
64701 + iowait = get_iowait_time(i);
64702 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64703 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64704 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64705 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64706 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64707 + }
64708 seq_printf(p, "cpu%d", i);
64709 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64710 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64711 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64712
64713 /* sum again ? it could be updated? */
64714 for_each_irq_nr(j)
64715 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64716 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64717
64718 seq_printf(p,
64719 "\nctxt %llu\n"
64720 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64721 "processes %lu\n"
64722 "procs_running %lu\n"
64723 "procs_blocked %lu\n",
64724 - nr_context_switches(),
64725 + unrestricted ? nr_context_switches() : 0ULL,
64726 (unsigned long)jif,
64727 - total_forks,
64728 - nr_running(),
64729 - nr_iowait());
64730 + unrestricted ? total_forks : 0UL,
64731 + unrestricted ? nr_running() : 0UL,
64732 + unrestricted ? nr_iowait() : 0UL);
64733
64734 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64735
64736 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64737 index c4b2646..84f0d7b 100644
64738 --- a/fs/proc/task_mmu.c
64739 +++ b/fs/proc/task_mmu.c
64740 @@ -13,12 +13,19 @@
64741 #include <linux/swap.h>
64742 #include <linux/swapops.h>
64743 #include <linux/mmu_notifier.h>
64744 +#include <linux/grsecurity.h>
64745
64746 #include <asm/elf.h>
64747 #include <asm/uaccess.h>
64748 #include <asm/tlbflush.h>
64749 #include "internal.h"
64750
64751 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64752 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64753 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
64754 + _mm->pax_flags & MF_PAX_SEGMEXEC))
64755 +#endif
64756 +
64757 void task_mem(struct seq_file *m, struct mm_struct *mm)
64758 {
64759 unsigned long data, text, lib, swap;
64760 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64761 "VmExe:\t%8lu kB\n"
64762 "VmLib:\t%8lu kB\n"
64763 "VmPTE:\t%8lu kB\n"
64764 - "VmSwap:\t%8lu kB\n",
64765 - hiwater_vm << (PAGE_SHIFT-10),
64766 + "VmSwap:\t%8lu kB\n"
64767 +
64768 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64769 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64770 +#endif
64771 +
64772 + ,hiwater_vm << (PAGE_SHIFT-10),
64773 total_vm << (PAGE_SHIFT-10),
64774 mm->locked_vm << (PAGE_SHIFT-10),
64775 mm->pinned_vm << (PAGE_SHIFT-10),
64776 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64777 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64778 (PTRS_PER_PTE * sizeof(pte_t) *
64779 atomic_long_read(&mm->nr_ptes)) >> 10,
64780 - swap << (PAGE_SHIFT-10));
64781 + swap << (PAGE_SHIFT-10)
64782 +
64783 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64784 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64785 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64786 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64787 +#else
64788 + , mm->context.user_cs_base
64789 + , mm->context.user_cs_limit
64790 +#endif
64791 +#endif
64792 +
64793 + );
64794 }
64795
64796 unsigned long task_vsize(struct mm_struct *mm)
64797 @@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64798 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64799 }
64800
64801 - /* We don't show the stack guard page in /proc/maps */
64802 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64803 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64804 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64805 +#else
64806 start = vma->vm_start;
64807 - if (stack_guard_page_start(vma, start))
64808 - start += PAGE_SIZE;
64809 end = vma->vm_end;
64810 - if (stack_guard_page_end(vma, end))
64811 - end -= PAGE_SIZE;
64812 +#endif
64813
64814 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64815 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64816 @@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64817 flags & VM_WRITE ? 'w' : '-',
64818 flags & VM_EXEC ? 'x' : '-',
64819 flags & VM_MAYSHARE ? 's' : 'p',
64820 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64821 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64822 +#else
64823 pgoff,
64824 +#endif
64825 MAJOR(dev), MINOR(dev), ino);
64826
64827 /*
64828 @@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64829 */
64830 if (file) {
64831 seq_pad(m, ' ');
64832 - seq_path(m, &file->f_path, "\n");
64833 + seq_path(m, &file->f_path, "\n\\");
64834 goto done;
64835 }
64836
64837 @@ -322,8 +350,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64838 * Thread stack in /proc/PID/task/TID/maps or
64839 * the main process stack.
64840 */
64841 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
64842 - vma->vm_end >= mm->start_stack)) {
64843 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64844 + (vma->vm_start <= mm->start_stack &&
64845 + vma->vm_end >= mm->start_stack)) {
64846 name = "[stack]";
64847 } else {
64848 /* Thread stack in /proc/PID/maps */
64849 @@ -347,6 +376,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64850 struct proc_maps_private *priv = m->private;
64851 struct task_struct *task = priv->task;
64852
64853 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64854 + if (current->exec_id != m->exec_id) {
64855 + gr_log_badprocpid("maps");
64856 + return 0;
64857 + }
64858 +#endif
64859 +
64860 show_map_vma(m, vma, is_pid);
64861
64862 if (m->count < m->size) /* vma is copied successfully */
64863 @@ -587,12 +623,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64864 .private = &mss,
64865 };
64866
64867 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64868 + if (current->exec_id != m->exec_id) {
64869 + gr_log_badprocpid("smaps");
64870 + return 0;
64871 + }
64872 +#endif
64873 memset(&mss, 0, sizeof mss);
64874 - mss.vma = vma;
64875 - /* mmap_sem is held in m_start */
64876 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64877 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64878 -
64879 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64880 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64881 +#endif
64882 + mss.vma = vma;
64883 + /* mmap_sem is held in m_start */
64884 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64885 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64886 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64887 + }
64888 +#endif
64889 show_map_vma(m, vma, is_pid);
64890
64891 seq_printf(m,
64892 @@ -610,7 +657,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64893 "KernelPageSize: %8lu kB\n"
64894 "MMUPageSize: %8lu kB\n"
64895 "Locked: %8lu kB\n",
64896 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64897 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64898 +#else
64899 (vma->vm_end - vma->vm_start) >> 10,
64900 +#endif
64901 mss.resident >> 10,
64902 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64903 mss.shared_clean >> 10,
64904 @@ -1388,6 +1439,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64905 char buffer[64];
64906 int nid;
64907
64908 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64909 + if (current->exec_id != m->exec_id) {
64910 + gr_log_badprocpid("numa_maps");
64911 + return 0;
64912 + }
64913 +#endif
64914 +
64915 if (!mm)
64916 return 0;
64917
64918 @@ -1405,11 +1463,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64919 mpol_to_str(buffer, sizeof(buffer), pol);
64920 mpol_cond_put(pol);
64921
64922 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64923 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64924 +#else
64925 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64926 +#endif
64927
64928 if (file) {
64929 seq_printf(m, " file=");
64930 - seq_path(m, &file->f_path, "\n\t= ");
64931 + seq_path(m, &file->f_path, "\n\t\\= ");
64932 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64933 seq_printf(m, " heap");
64934 } else {
64935 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64936 index 678455d..ebd3245 100644
64937 --- a/fs/proc/task_nommu.c
64938 +++ b/fs/proc/task_nommu.c
64939 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64940 else
64941 bytes += kobjsize(mm);
64942
64943 - if (current->fs && current->fs->users > 1)
64944 + if (current->fs && atomic_read(&current->fs->users) > 1)
64945 sbytes += kobjsize(current->fs);
64946 else
64947 bytes += kobjsize(current->fs);
64948 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64949
64950 if (file) {
64951 seq_pad(m, ' ');
64952 - seq_path(m, &file->f_path, "");
64953 + seq_path(m, &file->f_path, "\n\\");
64954 } else if (mm) {
64955 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64956
64957 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64958 index 6a8e785..41f2a6c 100644
64959 --- a/fs/proc/vmcore.c
64960 +++ b/fs/proc/vmcore.c
64961 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64962 nr_bytes = count;
64963
64964 /* If pfn is not ram, return zeros for sparse dump files */
64965 - if (pfn_is_ram(pfn) == 0)
64966 - memset(buf, 0, nr_bytes);
64967 - else {
64968 + if (pfn_is_ram(pfn) == 0) {
64969 + if (userbuf) {
64970 + if (clear_user((char __force_user *)buf, nr_bytes))
64971 + return -EFAULT;
64972 + } else
64973 + memset(buf, 0, nr_bytes);
64974 + } else {
64975 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64976 offset, userbuf);
64977 if (tmp < 0)
64978 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64979 static int copy_to(void *target, void *src, size_t size, int userbuf)
64980 {
64981 if (userbuf) {
64982 - if (copy_to_user((char __user *) target, src, size))
64983 + if (copy_to_user((char __force_user *) target, src, size))
64984 return -EFAULT;
64985 } else {
64986 memcpy(target, src, size);
64987 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64988 if (*fpos < m->offset + m->size) {
64989 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64990 start = m->paddr + *fpos - m->offset;
64991 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64992 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64993 if (tmp < 0)
64994 return tmp;
64995 buflen -= tsz;
64996 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64997 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64998 size_t buflen, loff_t *fpos)
64999 {
65000 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
65001 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
65002 }
65003
65004 /*
65005 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
65006 index b00fcc9..e0c6381 100644
65007 --- a/fs/qnx6/qnx6.h
65008 +++ b/fs/qnx6/qnx6.h
65009 @@ -74,7 +74,7 @@ enum {
65010 BYTESEX_BE,
65011 };
65012
65013 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65014 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65015 {
65016 if (sbi->s_bytesex == BYTESEX_LE)
65017 return le64_to_cpu((__force __le64)n);
65018 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
65019 return (__force __fs64)cpu_to_be64(n);
65020 }
65021
65022 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65023 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65024 {
65025 if (sbi->s_bytesex == BYTESEX_LE)
65026 return le32_to_cpu((__force __le32)n);
65027 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
65028 index 72d2917..c917c12 100644
65029 --- a/fs/quota/netlink.c
65030 +++ b/fs/quota/netlink.c
65031 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
65032 void quota_send_warning(struct kqid qid, dev_t dev,
65033 const char warntype)
65034 {
65035 - static atomic_t seq;
65036 + static atomic_unchecked_t seq;
65037 struct sk_buff *skb;
65038 void *msg_head;
65039 int ret;
65040 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
65041 "VFS: Not enough memory to send quota warning.\n");
65042 return;
65043 }
65044 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
65045 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
65046 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
65047 if (!msg_head) {
65048 printk(KERN_ERR
65049 diff --git a/fs/read_write.c b/fs/read_write.c
65050 index 31c6efa..a068805 100644
65051 --- a/fs/read_write.c
65052 +++ b/fs/read_write.c
65053 @@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
65054
65055 old_fs = get_fs();
65056 set_fs(get_ds());
65057 - p = (__force const char __user *)buf;
65058 + p = (const char __force_user *)buf;
65059 if (count > MAX_RW_COUNT)
65060 count = MAX_RW_COUNT;
65061 if (file->f_op->write)
65062 diff --git a/fs/readdir.c b/fs/readdir.c
65063 index 5b53d99..a6c3049 100644
65064 --- a/fs/readdir.c
65065 +++ b/fs/readdir.c
65066 @@ -17,6 +17,7 @@
65067 #include <linux/security.h>
65068 #include <linux/syscalls.h>
65069 #include <linux/unistd.h>
65070 +#include <linux/namei.h>
65071
65072 #include <asm/uaccess.h>
65073
65074 @@ -69,6 +70,7 @@ struct old_linux_dirent {
65075 struct readdir_callback {
65076 struct dir_context ctx;
65077 struct old_linux_dirent __user * dirent;
65078 + struct file * file;
65079 int result;
65080 };
65081
65082 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
65083 buf->result = -EOVERFLOW;
65084 return -EOVERFLOW;
65085 }
65086 +
65087 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65088 + return 0;
65089 +
65090 buf->result++;
65091 dirent = buf->dirent;
65092 if (!access_ok(VERIFY_WRITE, dirent,
65093 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
65094 if (!f.file)
65095 return -EBADF;
65096
65097 + buf.file = f.file;
65098 error = iterate_dir(f.file, &buf.ctx);
65099 if (buf.result)
65100 error = buf.result;
65101 @@ -142,6 +149,7 @@ struct getdents_callback {
65102 struct dir_context ctx;
65103 struct linux_dirent __user * current_dir;
65104 struct linux_dirent __user * previous;
65105 + struct file * file;
65106 int count;
65107 int error;
65108 };
65109 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
65110 buf->error = -EOVERFLOW;
65111 return -EOVERFLOW;
65112 }
65113 +
65114 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65115 + return 0;
65116 +
65117 dirent = buf->previous;
65118 if (dirent) {
65119 if (__put_user(offset, &dirent->d_off))
65120 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
65121 if (!f.file)
65122 return -EBADF;
65123
65124 + buf.file = f.file;
65125 error = iterate_dir(f.file, &buf.ctx);
65126 if (error >= 0)
65127 error = buf.error;
65128 @@ -226,6 +239,7 @@ struct getdents_callback64 {
65129 struct dir_context ctx;
65130 struct linux_dirent64 __user * current_dir;
65131 struct linux_dirent64 __user * previous;
65132 + struct file *file;
65133 int count;
65134 int error;
65135 };
65136 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
65137 buf->error = -EINVAL; /* only used if we fail.. */
65138 if (reclen > buf->count)
65139 return -EINVAL;
65140 +
65141 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65142 + return 0;
65143 +
65144 dirent = buf->previous;
65145 if (dirent) {
65146 if (__put_user(offset, &dirent->d_off))
65147 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
65148 if (!f.file)
65149 return -EBADF;
65150
65151 + buf.file = f.file;
65152 error = iterate_dir(f.file, &buf.ctx);
65153 if (error >= 0)
65154 error = buf.error;
65155 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
65156 index 9a3c68c..767933e 100644
65157 --- a/fs/reiserfs/do_balan.c
65158 +++ b/fs/reiserfs/do_balan.c
65159 @@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
65160 return;
65161 }
65162
65163 - atomic_inc(&(fs_generation(tb->tb_sb)));
65164 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
65165 do_balance_starts(tb);
65166
65167 /* balance leaf returns 0 except if combining L R and S into
65168 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
65169 index ee382ef..f4eb6eb5 100644
65170 --- a/fs/reiserfs/item_ops.c
65171 +++ b/fs/reiserfs/item_ops.c
65172 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
65173 }
65174
65175 static struct item_operations errcatch_ops = {
65176 - errcatch_bytes_number,
65177 - errcatch_decrement_key,
65178 - errcatch_is_left_mergeable,
65179 - errcatch_print_item,
65180 - errcatch_check_item,
65181 + .bytes_number = errcatch_bytes_number,
65182 + .decrement_key = errcatch_decrement_key,
65183 + .is_left_mergeable = errcatch_is_left_mergeable,
65184 + .print_item = errcatch_print_item,
65185 + .check_item = errcatch_check_item,
65186
65187 - errcatch_create_vi,
65188 - errcatch_check_left,
65189 - errcatch_check_right,
65190 - errcatch_part_size,
65191 - errcatch_unit_num,
65192 - errcatch_print_vi
65193 + .create_vi = errcatch_create_vi,
65194 + .check_left = errcatch_check_left,
65195 + .check_right = errcatch_check_right,
65196 + .part_size = errcatch_part_size,
65197 + .unit_num = errcatch_unit_num,
65198 + .print_vi = errcatch_print_vi
65199 };
65200
65201 //////////////////////////////////////////////////////////////////////////////
65202 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
65203 index 02b0b7d..c85018b 100644
65204 --- a/fs/reiserfs/procfs.c
65205 +++ b/fs/reiserfs/procfs.c
65206 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
65207 "SMALL_TAILS " : "NO_TAILS ",
65208 replay_only(sb) ? "REPLAY_ONLY " : "",
65209 convert_reiserfs(sb) ? "CONV " : "",
65210 - atomic_read(&r->s_generation_counter),
65211 + atomic_read_unchecked(&r->s_generation_counter),
65212 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
65213 SF(s_do_balance), SF(s_unneeded_left_neighbor),
65214 SF(s_good_search_by_key_reada), SF(s_bmaps),
65215 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
65216 index 83d4eac..04e39a7 100644
65217 --- a/fs/reiserfs/reiserfs.h
65218 +++ b/fs/reiserfs/reiserfs.h
65219 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
65220 /* Comment? -Hans */
65221 wait_queue_head_t s_wait;
65222 /* To be obsoleted soon by per buffer seals.. -Hans */
65223 - atomic_t s_generation_counter; // increased by one every time the
65224 + atomic_unchecked_t s_generation_counter; // increased by one every time the
65225 // tree gets re-balanced
65226 unsigned long s_properties; /* File system properties. Currently holds
65227 on-disk FS format */
65228 @@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
65229 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
65230
65231 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
65232 -#define get_generation(s) atomic_read (&fs_generation(s))
65233 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
65234 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
65235 #define __fs_changed(gen,s) (gen != get_generation (s))
65236 #define fs_changed(gen,s) \
65237 diff --git a/fs/select.c b/fs/select.c
65238 index 467bb1c..cf9d65a 100644
65239 --- a/fs/select.c
65240 +++ b/fs/select.c
65241 @@ -20,6 +20,7 @@
65242 #include <linux/export.h>
65243 #include <linux/slab.h>
65244 #include <linux/poll.h>
65245 +#include <linux/security.h>
65246 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
65247 #include <linux/file.h>
65248 #include <linux/fdtable.h>
65249 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
65250 struct poll_list *walk = head;
65251 unsigned long todo = nfds;
65252
65253 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
65254 if (nfds > rlimit(RLIMIT_NOFILE))
65255 return -EINVAL;
65256
65257 diff --git a/fs/seq_file.c b/fs/seq_file.c
65258 index 1d641bb..c2f4743 100644
65259 --- a/fs/seq_file.c
65260 +++ b/fs/seq_file.c
65261 @@ -10,6 +10,8 @@
65262 #include <linux/seq_file.h>
65263 #include <linux/slab.h>
65264 #include <linux/cred.h>
65265 +#include <linux/sched.h>
65266 +#include <linux/grsecurity.h>
65267
65268 #include <asm/uaccess.h>
65269 #include <asm/page.h>
65270 @@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
65271 #ifdef CONFIG_USER_NS
65272 p->user_ns = file->f_cred->user_ns;
65273 #endif
65274 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65275 + p->exec_id = current->exec_id;
65276 +#endif
65277
65278 /*
65279 * Wrappers around seq_open(e.g. swaps_open) need to be
65280 @@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
65281 }
65282 EXPORT_SYMBOL(seq_open);
65283
65284 +
65285 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
65286 +{
65287 + if (gr_proc_is_restricted())
65288 + return -EACCES;
65289 +
65290 + return seq_open(file, op);
65291 +}
65292 +EXPORT_SYMBOL(seq_open_restrict);
65293 +
65294 static int traverse(struct seq_file *m, loff_t offset)
65295 {
65296 loff_t pos = 0, index;
65297 @@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
65298 return 0;
65299 }
65300 if (!m->buf) {
65301 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65302 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65303 if (!m->buf)
65304 return -ENOMEM;
65305 }
65306 @@ -137,7 +152,7 @@ Eoverflow:
65307 m->op->stop(m, p);
65308 kfree(m->buf);
65309 m->count = 0;
65310 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65311 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65312 return !m->buf ? -ENOMEM : -EAGAIN;
65313 }
65314
65315 @@ -153,7 +168,7 @@ Eoverflow:
65316 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65317 {
65318 struct seq_file *m = file->private_data;
65319 - size_t copied = 0;
65320 + ssize_t copied = 0;
65321 loff_t pos;
65322 size_t n;
65323 void *p;
65324 @@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65325
65326 /* grab buffer if we didn't have one */
65327 if (!m->buf) {
65328 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65329 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65330 if (!m->buf)
65331 goto Enomem;
65332 }
65333 @@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65334 m->op->stop(m, p);
65335 kfree(m->buf);
65336 m->count = 0;
65337 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65338 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65339 if (!m->buf)
65340 goto Enomem;
65341 m->version = 0;
65342 @@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
65343 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
65344 void *data)
65345 {
65346 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
65347 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
65348 int res = -ENOMEM;
65349
65350 if (op) {
65351 @@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
65352 }
65353 EXPORT_SYMBOL(single_open_size);
65354
65355 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
65356 + void *data)
65357 +{
65358 + if (gr_proc_is_restricted())
65359 + return -EACCES;
65360 +
65361 + return single_open(file, show, data);
65362 +}
65363 +EXPORT_SYMBOL(single_open_restrict);
65364 +
65365 +
65366 int single_release(struct inode *inode, struct file *file)
65367 {
65368 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65369 diff --git a/fs/splice.c b/fs/splice.c
65370 index e246954..bd4f5b5 100644
65371 --- a/fs/splice.c
65372 +++ b/fs/splice.c
65373 @@ -192,7 +192,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65374 pipe_lock(pipe);
65375
65376 for (;;) {
65377 - if (!pipe->readers) {
65378 + if (!atomic_read(&pipe->readers)) {
65379 send_sig(SIGPIPE, current, 0);
65380 if (!ret)
65381 ret = -EPIPE;
65382 @@ -215,7 +215,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65383 page_nr++;
65384 ret += buf->len;
65385
65386 - if (pipe->files)
65387 + if (atomic_read(&pipe->files))
65388 do_wakeup = 1;
65389
65390 if (!--spd->nr_pages)
65391 @@ -246,9 +246,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65392 do_wakeup = 0;
65393 }
65394
65395 - pipe->waiting_writers++;
65396 + atomic_inc(&pipe->waiting_writers);
65397 pipe_wait(pipe);
65398 - pipe->waiting_writers--;
65399 + atomic_dec(&pipe->waiting_writers);
65400 }
65401
65402 pipe_unlock(pipe);
65403 @@ -575,7 +575,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65404 old_fs = get_fs();
65405 set_fs(get_ds());
65406 /* The cast to a user pointer is valid due to the set_fs() */
65407 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65408 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65409 set_fs(old_fs);
65410
65411 return res;
65412 @@ -590,7 +590,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65413 old_fs = get_fs();
65414 set_fs(get_ds());
65415 /* The cast to a user pointer is valid due to the set_fs() */
65416 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65417 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65418 set_fs(old_fs);
65419
65420 return res;
65421 @@ -643,7 +643,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65422 goto err;
65423
65424 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65425 - vec[i].iov_base = (void __user *) page_address(page);
65426 + vec[i].iov_base = (void __force_user *) page_address(page);
65427 vec[i].iov_len = this_len;
65428 spd.pages[i] = page;
65429 spd.nr_pages++;
65430 @@ -839,7 +839,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65431 ops->release(pipe, buf);
65432 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65433 pipe->nrbufs--;
65434 - if (pipe->files)
65435 + if (atomic_read(&pipe->files))
65436 sd->need_wakeup = true;
65437 }
65438
65439 @@ -864,10 +864,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65440 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65441 {
65442 while (!pipe->nrbufs) {
65443 - if (!pipe->writers)
65444 + if (!atomic_read(&pipe->writers))
65445 return 0;
65446
65447 - if (!pipe->waiting_writers && sd->num_spliced)
65448 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65449 return 0;
65450
65451 if (sd->flags & SPLICE_F_NONBLOCK)
65452 @@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65453 * out of the pipe right after the splice_to_pipe(). So set
65454 * PIPE_READERS appropriately.
65455 */
65456 - pipe->readers = 1;
65457 + atomic_set(&pipe->readers, 1);
65458
65459 current->splice_pipe = pipe;
65460 }
65461 @@ -1485,6 +1485,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65462
65463 partial[buffers].offset = off;
65464 partial[buffers].len = plen;
65465 + partial[buffers].private = 0;
65466
65467 off = 0;
65468 len -= plen;
65469 @@ -1721,9 +1722,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65470 ret = -ERESTARTSYS;
65471 break;
65472 }
65473 - if (!pipe->writers)
65474 + if (!atomic_read(&pipe->writers))
65475 break;
65476 - if (!pipe->waiting_writers) {
65477 + if (!atomic_read(&pipe->waiting_writers)) {
65478 if (flags & SPLICE_F_NONBLOCK) {
65479 ret = -EAGAIN;
65480 break;
65481 @@ -1755,7 +1756,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65482 pipe_lock(pipe);
65483
65484 while (pipe->nrbufs >= pipe->buffers) {
65485 - if (!pipe->readers) {
65486 + if (!atomic_read(&pipe->readers)) {
65487 send_sig(SIGPIPE, current, 0);
65488 ret = -EPIPE;
65489 break;
65490 @@ -1768,9 +1769,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65491 ret = -ERESTARTSYS;
65492 break;
65493 }
65494 - pipe->waiting_writers++;
65495 + atomic_inc(&pipe->waiting_writers);
65496 pipe_wait(pipe);
65497 - pipe->waiting_writers--;
65498 + atomic_dec(&pipe->waiting_writers);
65499 }
65500
65501 pipe_unlock(pipe);
65502 @@ -1806,14 +1807,14 @@ retry:
65503 pipe_double_lock(ipipe, opipe);
65504
65505 do {
65506 - if (!opipe->readers) {
65507 + if (!atomic_read(&opipe->readers)) {
65508 send_sig(SIGPIPE, current, 0);
65509 if (!ret)
65510 ret = -EPIPE;
65511 break;
65512 }
65513
65514 - if (!ipipe->nrbufs && !ipipe->writers)
65515 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65516 break;
65517
65518 /*
65519 @@ -1910,7 +1911,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65520 pipe_double_lock(ipipe, opipe);
65521
65522 do {
65523 - if (!opipe->readers) {
65524 + if (!atomic_read(&opipe->readers)) {
65525 send_sig(SIGPIPE, current, 0);
65526 if (!ret)
65527 ret = -EPIPE;
65528 @@ -1955,7 +1956,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65529 * return EAGAIN if we have the potential of some data in the
65530 * future, otherwise just return 0
65531 */
65532 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65533 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65534 ret = -EAGAIN;
65535
65536 pipe_unlock(ipipe);
65537 diff --git a/fs/stat.c b/fs/stat.c
65538 index ae0c3ce..9ee641c 100644
65539 --- a/fs/stat.c
65540 +++ b/fs/stat.c
65541 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65542 stat->gid = inode->i_gid;
65543 stat->rdev = inode->i_rdev;
65544 stat->size = i_size_read(inode);
65545 - stat->atime = inode->i_atime;
65546 - stat->mtime = inode->i_mtime;
65547 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65548 + stat->atime = inode->i_ctime;
65549 + stat->mtime = inode->i_ctime;
65550 + } else {
65551 + stat->atime = inode->i_atime;
65552 + stat->mtime = inode->i_mtime;
65553 + }
65554 stat->ctime = inode->i_ctime;
65555 stat->blksize = (1 << inode->i_blkbits);
65556 stat->blocks = inode->i_blocks;
65557 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65558 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65559 {
65560 struct inode *inode = path->dentry->d_inode;
65561 + int retval;
65562
65563 - if (inode->i_op->getattr)
65564 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
65565 + if (inode->i_op->getattr) {
65566 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65567 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65568 + stat->atime = stat->ctime;
65569 + stat->mtime = stat->ctime;
65570 + }
65571 + return retval;
65572 + }
65573
65574 generic_fillattr(inode, stat);
65575 return 0;
65576 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65577 index 0b45ff4..847de5b 100644
65578 --- a/fs/sysfs/dir.c
65579 +++ b/fs/sysfs/dir.c
65580 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65581 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65582 {
65583 struct kernfs_node *parent, *kn;
65584 + const char *name;
65585 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65586 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65587 + const char *parent_name;
65588 +#endif
65589
65590 BUG_ON(!kobj);
65591
65592 + name = kobject_name(kobj);
65593 +
65594 if (kobj->parent)
65595 parent = kobj->parent->sd;
65596 else
65597 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65598 if (!parent)
65599 return -ENOENT;
65600
65601 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65602 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65603 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65604 + parent_name = parent->name;
65605 + mode = S_IRWXU;
65606 +
65607 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65608 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65609 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65610 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65611 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
65612 +#endif
65613 +
65614 + kn = kernfs_create_dir_ns(parent, name,
65615 + mode, kobj, ns);
65616 if (IS_ERR(kn)) {
65617 if (PTR_ERR(kn) == -EEXIST)
65618 - sysfs_warn_dup(parent, kobject_name(kobj));
65619 + sysfs_warn_dup(parent, name);
65620 return PTR_ERR(kn);
65621 }
65622
65623 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65624 index 69d4889..a810bd4 100644
65625 --- a/fs/sysv/sysv.h
65626 +++ b/fs/sysv/sysv.h
65627 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65628 #endif
65629 }
65630
65631 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65632 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65633 {
65634 if (sbi->s_bytesex == BYTESEX_PDP)
65635 return PDP_swab((__force __u32)n);
65636 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65637 index e18b988..f1d4ad0f 100644
65638 --- a/fs/ubifs/io.c
65639 +++ b/fs/ubifs/io.c
65640 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65641 return err;
65642 }
65643
65644 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65645 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65646 {
65647 int err;
65648
65649 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65650 index c175b4d..8f36a16 100644
65651 --- a/fs/udf/misc.c
65652 +++ b/fs/udf/misc.c
65653 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65654
65655 u8 udf_tag_checksum(const struct tag *t)
65656 {
65657 - u8 *data = (u8 *)t;
65658 + const u8 *data = (const u8 *)t;
65659 u8 checksum = 0;
65660 int i;
65661 for (i = 0; i < sizeof(struct tag); ++i)
65662 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65663 index 8d974c4..b82f6ec 100644
65664 --- a/fs/ufs/swab.h
65665 +++ b/fs/ufs/swab.h
65666 @@ -22,7 +22,7 @@ enum {
65667 BYTESEX_BE
65668 };
65669
65670 -static inline u64
65671 +static inline u64 __intentional_overflow(-1)
65672 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65673 {
65674 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65675 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65676 return (__force __fs64)cpu_to_be64(n);
65677 }
65678
65679 -static inline u32
65680 +static inline u32 __intentional_overflow(-1)
65681 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65682 {
65683 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65684 diff --git a/fs/utimes.c b/fs/utimes.c
65685 index aa138d6..5f3a811 100644
65686 --- a/fs/utimes.c
65687 +++ b/fs/utimes.c
65688 @@ -1,6 +1,7 @@
65689 #include <linux/compiler.h>
65690 #include <linux/file.h>
65691 #include <linux/fs.h>
65692 +#include <linux/security.h>
65693 #include <linux/linkage.h>
65694 #include <linux/mount.h>
65695 #include <linux/namei.h>
65696 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65697 }
65698 }
65699 retry_deleg:
65700 +
65701 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65702 + error = -EACCES;
65703 + goto mnt_drop_write_and_out;
65704 + }
65705 +
65706 mutex_lock(&inode->i_mutex);
65707 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65708 mutex_unlock(&inode->i_mutex);
65709 diff --git a/fs/xattr.c b/fs/xattr.c
65710 index 3377dff..f394815 100644
65711 --- a/fs/xattr.c
65712 +++ b/fs/xattr.c
65713 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65714 return rc;
65715 }
65716
65717 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65718 +ssize_t
65719 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
65720 +{
65721 + struct inode *inode = dentry->d_inode;
65722 + ssize_t error;
65723 +
65724 + error = inode_permission(inode, MAY_EXEC);
65725 + if (error)
65726 + return error;
65727 +
65728 + if (inode->i_op->getxattr)
65729 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65730 + else
65731 + error = -EOPNOTSUPP;
65732 +
65733 + return error;
65734 +}
65735 +EXPORT_SYMBOL(pax_getxattr);
65736 +#endif
65737 +
65738 ssize_t
65739 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65740 {
65741 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65742 * Extended attribute SET operations
65743 */
65744 static long
65745 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
65746 +setxattr(struct path *path, const char __user *name, const void __user *value,
65747 size_t size, int flags)
65748 {
65749 int error;
65750 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65751 posix_acl_fix_xattr_from_user(kvalue, size);
65752 }
65753
65754 - error = vfs_setxattr(d, kname, kvalue, size, flags);
65755 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65756 + error = -EACCES;
65757 + goto out;
65758 + }
65759 +
65760 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65761 out:
65762 if (vvalue)
65763 vfree(vvalue);
65764 @@ -377,7 +403,7 @@ retry:
65765 return error;
65766 error = mnt_want_write(path.mnt);
65767 if (!error) {
65768 - error = setxattr(path.dentry, name, value, size, flags);
65769 + error = setxattr(&path, name, value, size, flags);
65770 mnt_drop_write(path.mnt);
65771 }
65772 path_put(&path);
65773 @@ -401,7 +427,7 @@ retry:
65774 return error;
65775 error = mnt_want_write(path.mnt);
65776 if (!error) {
65777 - error = setxattr(path.dentry, name, value, size, flags);
65778 + error = setxattr(&path, name, value, size, flags);
65779 mnt_drop_write(path.mnt);
65780 }
65781 path_put(&path);
65782 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65783 const void __user *,value, size_t, size, int, flags)
65784 {
65785 struct fd f = fdget(fd);
65786 - struct dentry *dentry;
65787 int error = -EBADF;
65788
65789 if (!f.file)
65790 return error;
65791 - dentry = f.file->f_path.dentry;
65792 - audit_inode(NULL, dentry, 0);
65793 + audit_inode(NULL, f.file->f_path.dentry, 0);
65794 error = mnt_want_write_file(f.file);
65795 if (!error) {
65796 - error = setxattr(dentry, name, value, size, flags);
65797 + error = setxattr(&f.file->f_path, name, value, size, flags);
65798 mnt_drop_write_file(f.file);
65799 }
65800 fdput(f);
65801 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65802 * Extended attribute REMOVE operations
65803 */
65804 static long
65805 -removexattr(struct dentry *d, const char __user *name)
65806 +removexattr(struct path *path, const char __user *name)
65807 {
65808 int error;
65809 char kname[XATTR_NAME_MAX + 1];
65810 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65811 if (error < 0)
65812 return error;
65813
65814 - return vfs_removexattr(d, kname);
65815 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65816 + return -EACCES;
65817 +
65818 + return vfs_removexattr(path->dentry, kname);
65819 }
65820
65821 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65822 @@ -652,7 +679,7 @@ retry:
65823 return error;
65824 error = mnt_want_write(path.mnt);
65825 if (!error) {
65826 - error = removexattr(path.dentry, name);
65827 + error = removexattr(&path, name);
65828 mnt_drop_write(path.mnt);
65829 }
65830 path_put(&path);
65831 @@ -675,7 +702,7 @@ retry:
65832 return error;
65833 error = mnt_want_write(path.mnt);
65834 if (!error) {
65835 - error = removexattr(path.dentry, name);
65836 + error = removexattr(&path, name);
65837 mnt_drop_write(path.mnt);
65838 }
65839 path_put(&path);
65840 @@ -689,16 +716,16 @@ retry:
65841 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65842 {
65843 struct fd f = fdget(fd);
65844 - struct dentry *dentry;
65845 + struct path *path;
65846 int error = -EBADF;
65847
65848 if (!f.file)
65849 return error;
65850 - dentry = f.file->f_path.dentry;
65851 - audit_inode(NULL, dentry, 0);
65852 + path = &f.file->f_path;
65853 + audit_inode(NULL, path->dentry, 0);
65854 error = mnt_want_write_file(f.file);
65855 if (!error) {
65856 - error = removexattr(dentry, name);
65857 + error = removexattr(path, name);
65858 mnt_drop_write_file(f.file);
65859 }
65860 fdput(f);
65861 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65862 index f0efc7e..ba72910 100644
65863 --- a/fs/xfs/xfs_bmap.c
65864 +++ b/fs/xfs/xfs_bmap.c
65865 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65866
65867 #else
65868 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65869 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65870 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65871 #endif /* DEBUG */
65872
65873 /*
65874 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65875 index aead369..0dfecfd 100644
65876 --- a/fs/xfs/xfs_dir2_readdir.c
65877 +++ b/fs/xfs/xfs_dir2_readdir.c
65878 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65879 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65880 filetype = dp->d_ops->sf_get_ftype(sfep);
65881 ctx->pos = off & 0x7fffffff;
65882 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65883 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65884 + char name[sfep->namelen];
65885 + memcpy(name, sfep->name, sfep->namelen);
65886 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65887 + return 0;
65888 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65889 xfs_dir3_get_dtype(mp, filetype)))
65890 return 0;
65891 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65892 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65893 index 6152cbe..f0f9eaa 100644
65894 --- a/fs/xfs/xfs_ioctl.c
65895 +++ b/fs/xfs/xfs_ioctl.c
65896 @@ -122,7 +122,7 @@ xfs_find_handle(
65897 }
65898
65899 error = -EFAULT;
65900 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65901 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65902 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65903 goto out_put;
65904
65905 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65906 new file mode 100644
65907 index 0000000..bfd482c
65908 --- /dev/null
65909 +++ b/grsecurity/Kconfig
65910 @@ -0,0 +1,1176 @@
65911 +#
65912 +# grecurity configuration
65913 +#
65914 +menu "Memory Protections"
65915 +depends on GRKERNSEC
65916 +
65917 +config GRKERNSEC_KMEM
65918 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65919 + default y if GRKERNSEC_CONFIG_AUTO
65920 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65921 + help
65922 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65923 + be written to or read from to modify or leak the contents of the running
65924 + kernel. /dev/port will also not be allowed to be opened, writing to
65925 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65926 + If you have module support disabled, enabling this will close up several
65927 + ways that are currently used to insert malicious code into the running
65928 + kernel.
65929 +
65930 + Even with this feature enabled, we still highly recommend that
65931 + you use the RBAC system, as it is still possible for an attacker to
65932 + modify the running kernel through other more obscure methods.
65933 +
65934 + It is highly recommended that you say Y here if you meet all the
65935 + conditions above.
65936 +
65937 +config GRKERNSEC_VM86
65938 + bool "Restrict VM86 mode"
65939 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65940 + depends on X86_32
65941 +
65942 + help
65943 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65944 + make use of a special execution mode on 32bit x86 processors called
65945 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65946 + video cards and will still work with this option enabled. The purpose
65947 + of the option is to prevent exploitation of emulation errors in
65948 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
65949 + Nearly all users should be able to enable this option.
65950 +
65951 +config GRKERNSEC_IO
65952 + bool "Disable privileged I/O"
65953 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65954 + depends on X86
65955 + select RTC_CLASS
65956 + select RTC_INTF_DEV
65957 + select RTC_DRV_CMOS
65958 +
65959 + help
65960 + If you say Y here, all ioperm and iopl calls will return an error.
65961 + Ioperm and iopl can be used to modify the running kernel.
65962 + Unfortunately, some programs need this access to operate properly,
65963 + the most notable of which are XFree86 and hwclock. hwclock can be
65964 + remedied by having RTC support in the kernel, so real-time
65965 + clock support is enabled if this option is enabled, to ensure
65966 + that hwclock operates correctly. If hwclock still does not work,
65967 + either update udev or symlink /dev/rtc to /dev/rtc0.
65968 +
65969 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
65970 + you may not be able to boot into a graphical environment with this
65971 + option enabled. In this case, you should use the RBAC system instead.
65972 +
65973 +config GRKERNSEC_JIT_HARDEN
65974 + bool "Harden BPF JIT against spray attacks"
65975 + default y if GRKERNSEC_CONFIG_AUTO
65976 + depends on BPF_JIT && X86
65977 + help
65978 + If you say Y here, the native code generated by the kernel's Berkeley
65979 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65980 + attacks that attempt to fit attacker-beneficial instructions in
65981 + 32bit immediate fields of JIT-generated native instructions. The
65982 + attacker will generally aim to cause an unintended instruction sequence
65983 + of JIT-generated native code to execute by jumping into the middle of
65984 + a generated instruction. This feature effectively randomizes the 32bit
65985 + immediate constants present in the generated code to thwart such attacks.
65986 +
65987 + If you're using KERNEXEC, it's recommended that you enable this option
65988 + to supplement the hardening of the kernel.
65989 +
65990 +config GRKERNSEC_PERF_HARDEN
65991 + bool "Disable unprivileged PERF_EVENTS usage by default"
65992 + default y if GRKERNSEC_CONFIG_AUTO
65993 + depends on PERF_EVENTS
65994 + help
65995 + If you say Y here, the range of acceptable values for the
65996 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65997 + default to a new value: 3. When the sysctl is set to this value, no
65998 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65999 +
66000 + Though PERF_EVENTS can be used legitimately for performance monitoring
66001 + and low-level application profiling, it is forced on regardless of
66002 + configuration, has been at fault for several vulnerabilities, and
66003 + creates new opportunities for side channels and other information leaks.
66004 +
66005 + This feature puts PERF_EVENTS into a secure default state and permits
66006 + the administrator to change out of it temporarily if unprivileged
66007 + application profiling is needed.
66008 +
66009 +config GRKERNSEC_RAND_THREADSTACK
66010 + bool "Insert random gaps between thread stacks"
66011 + default y if GRKERNSEC_CONFIG_AUTO
66012 + depends on PAX_RANDMMAP && !PPC
66013 + help
66014 + If you say Y here, a random-sized gap will be enforced between allocated
66015 + thread stacks. Glibc's NPTL and other threading libraries that
66016 + pass MAP_STACK to the kernel for thread stack allocation are supported.
66017 + The implementation currently provides 8 bits of entropy for the gap.
66018 +
66019 + Many distributions do not compile threaded remote services with the
66020 + -fstack-check argument to GCC, causing the variable-sized stack-based
66021 + allocator, alloca(), to not probe the stack on allocation. This
66022 + permits an unbounded alloca() to skip over any guard page and potentially
66023 + modify another thread's stack reliably. An enforced random gap
66024 + reduces the reliability of such an attack and increases the chance
66025 + that such a read/write to another thread's stack instead lands in
66026 + an unmapped area, causing a crash and triggering grsecurity's
66027 + anti-bruteforcing logic.
66028 +
66029 +config GRKERNSEC_PROC_MEMMAP
66030 + bool "Harden ASLR against information leaks and entropy reduction"
66031 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
66032 + depends on PAX_NOEXEC || PAX_ASLR
66033 + help
66034 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
66035 + give no information about the addresses of its mappings if
66036 + PaX features that rely on random addresses are enabled on the task.
66037 + In addition to sanitizing this information and disabling other
66038 + dangerous sources of information, this option causes reads of sensitive
66039 + /proc/<pid> entries where the file descriptor was opened in a different
66040 + task than the one performing the read. Such attempts are logged.
66041 + This option also limits argv/env strings for suid/sgid binaries
66042 + to 512KB to prevent a complete exhaustion of the stack entropy provided
66043 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
66044 + binaries to prevent alternative mmap layouts from being abused.
66045 +
66046 + If you use PaX it is essential that you say Y here as it closes up
66047 + several holes that make full ASLR useless locally.
66048 +
66049 +
66050 +config GRKERNSEC_KSTACKOVERFLOW
66051 + bool "Prevent kernel stack overflows"
66052 + default y if GRKERNSEC_CONFIG_AUTO
66053 + depends on !IA64 && 64BIT
66054 + help
66055 + If you say Y here, the kernel's process stacks will be allocated
66056 + with vmalloc instead of the kernel's default allocator. This
66057 + introduces guard pages that in combination with the alloca checking
66058 + of the STACKLEAK feature prevents all forms of kernel process stack
66059 + overflow abuse. Note that this is different from kernel stack
66060 + buffer overflows.
66061 +
66062 +config GRKERNSEC_BRUTE
66063 + bool "Deter exploit bruteforcing"
66064 + default y if GRKERNSEC_CONFIG_AUTO
66065 + help
66066 + If you say Y here, attempts to bruteforce exploits against forking
66067 + daemons such as apache or sshd, as well as against suid/sgid binaries
66068 + will be deterred. When a child of a forking daemon is killed by PaX
66069 + or crashes due to an illegal instruction or other suspicious signal,
66070 + the parent process will be delayed 30 seconds upon every subsequent
66071 + fork until the administrator is able to assess the situation and
66072 + restart the daemon.
66073 + In the suid/sgid case, the attempt is logged, the user has all their
66074 + existing instances of the suid/sgid binary terminated and will
66075 + be unable to execute any suid/sgid binaries for 15 minutes.
66076 +
66077 + It is recommended that you also enable signal logging in the auditing
66078 + section so that logs are generated when a process triggers a suspicious
66079 + signal.
66080 + If the sysctl option is enabled, a sysctl option with name
66081 + "deter_bruteforce" is created.
66082 +
66083 +config GRKERNSEC_MODHARDEN
66084 + bool "Harden module auto-loading"
66085 + default y if GRKERNSEC_CONFIG_AUTO
66086 + depends on MODULES
66087 + help
66088 + If you say Y here, module auto-loading in response to use of some
66089 + feature implemented by an unloaded module will be restricted to
66090 + root users. Enabling this option helps defend against attacks
66091 + by unprivileged users who abuse the auto-loading behavior to
66092 + cause a vulnerable module to load that is then exploited.
66093 +
66094 + If this option prevents a legitimate use of auto-loading for a
66095 + non-root user, the administrator can execute modprobe manually
66096 + with the exact name of the module mentioned in the alert log.
66097 + Alternatively, the administrator can add the module to the list
66098 + of modules loaded at boot by modifying init scripts.
66099 +
66100 + Modification of init scripts will most likely be needed on
66101 + Ubuntu servers with encrypted home directory support enabled,
66102 + as the first non-root user logging in will cause the ecb(aes),
66103 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
66104 +
66105 +config GRKERNSEC_HIDESYM
66106 + bool "Hide kernel symbols"
66107 + default y if GRKERNSEC_CONFIG_AUTO
66108 + select PAX_USERCOPY_SLABS
66109 + help
66110 + If you say Y here, getting information on loaded modules, and
66111 + displaying all kernel symbols through a syscall will be restricted
66112 + to users with CAP_SYS_MODULE. For software compatibility reasons,
66113 + /proc/kallsyms will be restricted to the root user. The RBAC
66114 + system can hide that entry even from root.
66115 +
66116 + This option also prevents leaking of kernel addresses through
66117 + several /proc entries.
66118 +
66119 + Note that this option is only effective provided the following
66120 + conditions are met:
66121 + 1) The kernel using grsecurity is not precompiled by some distribution
66122 + 2) You have also enabled GRKERNSEC_DMESG
66123 + 3) You are using the RBAC system and hiding other files such as your
66124 + kernel image and System.map. Alternatively, enabling this option
66125 + causes the permissions on /boot, /lib/modules, and the kernel
66126 + source directory to change at compile time to prevent
66127 + reading by non-root users.
66128 + If the above conditions are met, this option will aid in providing a
66129 + useful protection against local kernel exploitation of overflows
66130 + and arbitrary read/write vulnerabilities.
66131 +
66132 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
66133 + in addition to this feature.
66134 +
66135 +config GRKERNSEC_RANDSTRUCT
66136 + bool "Randomize layout of sensitive kernel structures"
66137 + default y if GRKERNSEC_CONFIG_AUTO
66138 + select GRKERNSEC_HIDESYM
66139 + select MODVERSIONS if MODULES
66140 + help
66141 + If you say Y here, the layouts of a number of sensitive kernel
66142 + structures (task, fs, cred, etc) and all structures composed entirely
66143 + of function pointers (aka "ops" structs) will be randomized at compile-time.
66144 + This can introduce the requirement of an additional infoleak
66145 + vulnerability for exploits targeting these structure types.
66146 +
66147 + Enabling this feature will introduce some performance impact, slightly
66148 + increase memory usage, and prevent the use of forensic tools like
66149 + Volatility against the system (unless the kernel source tree isn't
66150 + cleaned after kernel installation).
66151 +
66152 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
66153 + It remains after a make clean to allow for external modules to be compiled
66154 + with the existing seed and will be removed by a make mrproper or
66155 + make distclean.
66156 +
66157 + Note that the implementation requires gcc 4.6.4. or newer. You may need
66158 + to install the supporting headers explicitly in addition to the normal
66159 + gcc package.
66160 +
66161 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
66162 + bool "Use cacheline-aware structure randomization"
66163 + depends on GRKERNSEC_RANDSTRUCT
66164 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
66165 + help
66166 + If you say Y here, the RANDSTRUCT randomization will make a best effort
66167 + at restricting randomization to cacheline-sized groups of elements. It
66168 + will further not randomize bitfields in structures. This reduces the
66169 + performance hit of RANDSTRUCT at the cost of weakened randomization.
66170 +
66171 +config GRKERNSEC_KERN_LOCKOUT
66172 + bool "Active kernel exploit response"
66173 + default y if GRKERNSEC_CONFIG_AUTO
66174 + depends on X86 || ARM || PPC || SPARC
66175 + help
66176 + If you say Y here, when a PaX alert is triggered due to suspicious
66177 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
66178 + or an OOPS occurs due to bad memory accesses, instead of just
66179 + terminating the offending process (and potentially allowing
66180 + a subsequent exploit from the same user), we will take one of two
66181 + actions:
66182 + If the user was root, we will panic the system
66183 + If the user was non-root, we will log the attempt, terminate
66184 + all processes owned by the user, then prevent them from creating
66185 + any new processes until the system is restarted
66186 + This deters repeated kernel exploitation/bruteforcing attempts
66187 + and is useful for later forensics.
66188 +
66189 +config GRKERNSEC_OLD_ARM_USERLAND
66190 + bool "Old ARM userland compatibility"
66191 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
66192 + help
66193 + If you say Y here, stubs of executable code to perform such operations
66194 + as "compare-exchange" will be placed at fixed locations in the ARM vector
66195 + table. This is unfortunately needed for old ARM userland meant to run
66196 + across a wide range of processors. Without this option enabled,
66197 + the get_tls and data memory barrier stubs will be emulated by the kernel,
66198 + which is enough for Linaro userlands or other userlands designed for v6
66199 + and newer ARM CPUs. It's recommended that you try without this option enabled
66200 + first, and only enable it if your userland does not boot (it will likely fail
66201 + at init time).
66202 +
66203 +endmenu
66204 +menu "Role Based Access Control Options"
66205 +depends on GRKERNSEC
66206 +
66207 +config GRKERNSEC_RBAC_DEBUG
66208 + bool
66209 +
66210 +config GRKERNSEC_NO_RBAC
66211 + bool "Disable RBAC system"
66212 + help
66213 + If you say Y here, the /dev/grsec device will be removed from the kernel,
66214 + preventing the RBAC system from being enabled. You should only say Y
66215 + here if you have no intention of using the RBAC system, so as to prevent
66216 + an attacker with root access from misusing the RBAC system to hide files
66217 + and processes when loadable module support and /dev/[k]mem have been
66218 + locked down.
66219 +
66220 +config GRKERNSEC_ACL_HIDEKERN
66221 + bool "Hide kernel processes"
66222 + help
66223 + If you say Y here, all kernel threads will be hidden to all
66224 + processes but those whose subject has the "view hidden processes"
66225 + flag.
66226 +
66227 +config GRKERNSEC_ACL_MAXTRIES
66228 + int "Maximum tries before password lockout"
66229 + default 3
66230 + help
66231 + This option enforces the maximum number of times a user can attempt
66232 + to authorize themselves with the grsecurity RBAC system before being
66233 + denied the ability to attempt authorization again for a specified time.
66234 + The lower the number, the harder it will be to brute-force a password.
66235 +
66236 +config GRKERNSEC_ACL_TIMEOUT
66237 + int "Time to wait after max password tries, in seconds"
66238 + default 30
66239 + help
66240 + This option specifies the time the user must wait after attempting to
66241 + authorize to the RBAC system with the maximum number of invalid
66242 + passwords. The higher the number, the harder it will be to brute-force
66243 + a password.
66244 +
66245 +endmenu
66246 +menu "Filesystem Protections"
66247 +depends on GRKERNSEC
66248 +
66249 +config GRKERNSEC_PROC
66250 + bool "Proc restrictions"
66251 + default y if GRKERNSEC_CONFIG_AUTO
66252 + help
66253 + If you say Y here, the permissions of the /proc filesystem
66254 + will be altered to enhance system security and privacy. You MUST
66255 + choose either a user only restriction or a user and group restriction.
66256 + Depending upon the option you choose, you can either restrict users to
66257 + see only the processes they themselves run, or choose a group that can
66258 + view all processes and files normally restricted to root if you choose
66259 + the "restrict to user only" option. NOTE: If you're running identd or
66260 + ntpd as a non-root user, you will have to run it as the group you
66261 + specify here.
66262 +
66263 +config GRKERNSEC_PROC_USER
66264 + bool "Restrict /proc to user only"
66265 + depends on GRKERNSEC_PROC
66266 + help
66267 + If you say Y here, non-root users will only be able to view their own
66268 + processes, and restricts them from viewing network-related information,
66269 + and viewing kernel symbol and module information.
66270 +
66271 +config GRKERNSEC_PROC_USERGROUP
66272 + bool "Allow special group"
66273 + default y if GRKERNSEC_CONFIG_AUTO
66274 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
66275 + help
66276 + If you say Y here, you will be able to select a group that will be
66277 + able to view all processes and network-related information. If you've
66278 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
66279 + remain hidden. This option is useful if you want to run identd as
66280 + a non-root user. The group you select may also be chosen at boot time
66281 + via "grsec_proc_gid=" on the kernel commandline.
66282 +
66283 +config GRKERNSEC_PROC_GID
66284 + int "GID for special group"
66285 + depends on GRKERNSEC_PROC_USERGROUP
66286 + default 1001
66287 +
66288 +config GRKERNSEC_PROC_ADD
66289 + bool "Additional restrictions"
66290 + default y if GRKERNSEC_CONFIG_AUTO
66291 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
66292 + help
66293 + If you say Y here, additional restrictions will be placed on
66294 + /proc that keep normal users from viewing device information and
66295 + slabinfo information that could be useful for exploits.
66296 +
66297 +config GRKERNSEC_LINK
66298 + bool "Linking restrictions"
66299 + default y if GRKERNSEC_CONFIG_AUTO
66300 + help
66301 + If you say Y here, /tmp race exploits will be prevented, since users
66302 + will no longer be able to follow symlinks owned by other users in
66303 + world-writable +t directories (e.g. /tmp), unless the owner of the
66304 + symlink is the owner of the directory. users will also not be
66305 + able to hardlink to files they do not own. If the sysctl option is
66306 + enabled, a sysctl option with name "linking_restrictions" is created.
66307 +
66308 +config GRKERNSEC_SYMLINKOWN
66309 + bool "Kernel-enforced SymlinksIfOwnerMatch"
66310 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66311 + help
66312 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
66313 + that prevents it from being used as a security feature. As Apache
66314 + verifies the symlink by performing a stat() against the target of
66315 + the symlink before it is followed, an attacker can setup a symlink
66316 + to point to a same-owned file, then replace the symlink with one
66317 + that targets another user's file just after Apache "validates" the
66318 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
66319 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
66320 + will be in place for the group you specify. If the sysctl option
66321 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
66322 + created.
66323 +
66324 +config GRKERNSEC_SYMLINKOWN_GID
66325 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
66326 + depends on GRKERNSEC_SYMLINKOWN
66327 + default 1006
66328 + help
66329 + Setting this GID determines what group kernel-enforced
66330 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
66331 + is enabled, a sysctl option with name "symlinkown_gid" is created.
66332 +
66333 +config GRKERNSEC_FIFO
66334 + bool "FIFO restrictions"
66335 + default y if GRKERNSEC_CONFIG_AUTO
66336 + help
66337 + If you say Y here, users will not be able to write to FIFOs they don't
66338 + own in world-writable +t directories (e.g. /tmp), unless the owner of
66339 + the FIFO is the same owner of the directory it's held in. If the sysctl
66340 + option is enabled, a sysctl option with name "fifo_restrictions" is
66341 + created.
66342 +
66343 +config GRKERNSEC_SYSFS_RESTRICT
66344 + bool "Sysfs/debugfs restriction"
66345 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66346 + depends on SYSFS
66347 + help
66348 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
66349 + any filesystem normally mounted under it (e.g. debugfs) will be
66350 + mostly accessible only by root. These filesystems generally provide access
66351 + to hardware and debug information that isn't appropriate for unprivileged
66352 + users of the system. Sysfs and debugfs have also become a large source
66353 + of new vulnerabilities, ranging from infoleaks to local compromise.
66354 + There has been very little oversight with an eye toward security involved
66355 + in adding new exporters of information to these filesystems, so their
66356 + use is discouraged.
66357 + For reasons of compatibility, a few directories have been whitelisted
66358 + for access by non-root users:
66359 + /sys/fs/selinux
66360 + /sys/fs/fuse
66361 + /sys/devices/system/cpu
66362 +
66363 +config GRKERNSEC_ROFS
66364 + bool "Runtime read-only mount protection"
66365 + depends on SYSCTL
66366 + help
66367 + If you say Y here, a sysctl option with name "romount_protect" will
66368 + be created. By setting this option to 1 at runtime, filesystems
66369 + will be protected in the following ways:
66370 + * No new writable mounts will be allowed
66371 + * Existing read-only mounts won't be able to be remounted read/write
66372 + * Write operations will be denied on all block devices
66373 + This option acts independently of grsec_lock: once it is set to 1,
66374 + it cannot be turned off. Therefore, please be mindful of the resulting
66375 + behavior if this option is enabled in an init script on a read-only
66376 + filesystem.
66377 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66378 + and GRKERNSEC_IO should be enabled and module loading disabled via
66379 + config or at runtime.
66380 + This feature is mainly intended for secure embedded systems.
66381 +
66382 +
66383 +config GRKERNSEC_DEVICE_SIDECHANNEL
66384 + bool "Eliminate stat/notify-based device sidechannels"
66385 + default y if GRKERNSEC_CONFIG_AUTO
66386 + help
66387 + If you say Y here, timing analyses on block or character
66388 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66389 + will be thwarted for unprivileged users. If a process without
66390 + CAP_MKNOD stats such a device, the last access and last modify times
66391 + will match the device's create time. No access or modify events
66392 + will be triggered through inotify/dnotify/fanotify for such devices.
66393 + This feature will prevent attacks that may at a minimum
66394 + allow an attacker to determine the administrator's password length.
66395 +
66396 +config GRKERNSEC_CHROOT
66397 + bool "Chroot jail restrictions"
66398 + default y if GRKERNSEC_CONFIG_AUTO
66399 + help
66400 + If you say Y here, you will be able to choose several options that will
66401 + make breaking out of a chrooted jail much more difficult. If you
66402 + encounter no software incompatibilities with the following options, it
66403 + is recommended that you enable each one.
66404 +
66405 + Note that the chroot restrictions are not intended to apply to "chroots"
66406 + to directories that are simple bind mounts of the global root filesystem.
66407 + For several other reasons, a user shouldn't expect any significant
66408 + security by performing such a chroot.
66409 +
66410 +config GRKERNSEC_CHROOT_MOUNT
66411 + bool "Deny mounts"
66412 + default y if GRKERNSEC_CONFIG_AUTO
66413 + depends on GRKERNSEC_CHROOT
66414 + help
66415 + If you say Y here, processes inside a chroot will not be able to
66416 + mount or remount filesystems. If the sysctl option is enabled, a
66417 + sysctl option with name "chroot_deny_mount" is created.
66418 +
66419 +config GRKERNSEC_CHROOT_DOUBLE
66420 + bool "Deny double-chroots"
66421 + default y if GRKERNSEC_CONFIG_AUTO
66422 + depends on GRKERNSEC_CHROOT
66423 + help
66424 + If you say Y here, processes inside a chroot will not be able to chroot
66425 + again outside the chroot. This is a widely used method of breaking
66426 + out of a chroot jail and should not be allowed. If the sysctl
66427 + option is enabled, a sysctl option with name
66428 + "chroot_deny_chroot" is created.
66429 +
66430 +config GRKERNSEC_CHROOT_PIVOT
66431 + bool "Deny pivot_root in chroot"
66432 + default y if GRKERNSEC_CONFIG_AUTO
66433 + depends on GRKERNSEC_CHROOT
66434 + help
66435 + If you say Y here, processes inside a chroot will not be able to use
66436 + a function called pivot_root() that was introduced in Linux 2.3.41. It
66437 + works similar to chroot in that it changes the root filesystem. This
66438 + function could be misused in a chrooted process to attempt to break out
66439 + of the chroot, and therefore should not be allowed. If the sysctl
66440 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
66441 + created.
66442 +
66443 +config GRKERNSEC_CHROOT_CHDIR
66444 + bool "Enforce chdir(\"/\") on all chroots"
66445 + default y if GRKERNSEC_CONFIG_AUTO
66446 + depends on GRKERNSEC_CHROOT
66447 + help
66448 + If you say Y here, the current working directory of all newly-chrooted
66449 + applications will be set to the the root directory of the chroot.
66450 + The man page on chroot(2) states:
66451 + Note that this call does not change the current working
66452 + directory, so that `.' can be outside the tree rooted at
66453 + `/'. In particular, the super-user can escape from a
66454 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66455 +
66456 + It is recommended that you say Y here, since it's not known to break
66457 + any software. If the sysctl option is enabled, a sysctl option with
66458 + name "chroot_enforce_chdir" is created.
66459 +
66460 +config GRKERNSEC_CHROOT_CHMOD
66461 + bool "Deny (f)chmod +s"
66462 + default y if GRKERNSEC_CONFIG_AUTO
66463 + depends on GRKERNSEC_CHROOT
66464 + help
66465 + If you say Y here, processes inside a chroot will not be able to chmod
66466 + or fchmod files to make them have suid or sgid bits. This protects
66467 + against another published method of breaking a chroot. If the sysctl
66468 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
66469 + created.
66470 +
66471 +config GRKERNSEC_CHROOT_FCHDIR
66472 + bool "Deny fchdir and fhandle out of chroot"
66473 + default y if GRKERNSEC_CONFIG_AUTO
66474 + depends on GRKERNSEC_CHROOT
66475 + help
66476 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
66477 + to a file descriptor of the chrooting process that points to a directory
66478 + outside the filesystem will be stopped. Additionally, this option prevents
66479 + use of the recently-created syscall for opening files by a guessable "file
66480 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
66481 + with name "chroot_deny_fchdir" is created.
66482 +
66483 +config GRKERNSEC_CHROOT_MKNOD
66484 + bool "Deny mknod"
66485 + default y if GRKERNSEC_CONFIG_AUTO
66486 + depends on GRKERNSEC_CHROOT
66487 + help
66488 + If you say Y here, processes inside a chroot will not be allowed to
66489 + mknod. The problem with using mknod inside a chroot is that it
66490 + would allow an attacker to create a device entry that is the same
66491 + as one on the physical root of your system, which could range from
66492 + anything from the console device to a device for your harddrive (which
66493 + they could then use to wipe the drive or steal data). It is recommended
66494 + that you say Y here, unless you run into software incompatibilities.
66495 + If the sysctl option is enabled, a sysctl option with name
66496 + "chroot_deny_mknod" is created.
66497 +
66498 +config GRKERNSEC_CHROOT_SHMAT
66499 + bool "Deny shmat() out of chroot"
66500 + default y if GRKERNSEC_CONFIG_AUTO
66501 + depends on GRKERNSEC_CHROOT
66502 + help
66503 + If you say Y here, processes inside a chroot will not be able to attach
66504 + to shared memory segments that were created outside of the chroot jail.
66505 + It is recommended that you say Y here. If the sysctl option is enabled,
66506 + a sysctl option with name "chroot_deny_shmat" is created.
66507 +
66508 +config GRKERNSEC_CHROOT_UNIX
66509 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
66510 + default y if GRKERNSEC_CONFIG_AUTO
66511 + depends on GRKERNSEC_CHROOT
66512 + help
66513 + If you say Y here, processes inside a chroot will not be able to
66514 + connect to abstract (meaning not belonging to a filesystem) Unix
66515 + domain sockets that were bound outside of a chroot. It is recommended
66516 + that you say Y here. If the sysctl option is enabled, a sysctl option
66517 + with name "chroot_deny_unix" is created.
66518 +
66519 +config GRKERNSEC_CHROOT_FINDTASK
66520 + bool "Protect outside processes"
66521 + default y if GRKERNSEC_CONFIG_AUTO
66522 + depends on GRKERNSEC_CHROOT
66523 + help
66524 + If you say Y here, processes inside a chroot will not be able to
66525 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66526 + getsid, or view any process outside of the chroot. If the sysctl
66527 + option is enabled, a sysctl option with name "chroot_findtask" is
66528 + created.
66529 +
66530 +config GRKERNSEC_CHROOT_NICE
66531 + bool "Restrict priority changes"
66532 + default y if GRKERNSEC_CONFIG_AUTO
66533 + depends on GRKERNSEC_CHROOT
66534 + help
66535 + If you say Y here, processes inside a chroot will not be able to raise
66536 + the priority of processes in the chroot, or alter the priority of
66537 + processes outside the chroot. This provides more security than simply
66538 + removing CAP_SYS_NICE from the process' capability set. If the
66539 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66540 + is created.
66541 +
66542 +config GRKERNSEC_CHROOT_SYSCTL
66543 + bool "Deny sysctl writes"
66544 + default y if GRKERNSEC_CONFIG_AUTO
66545 + depends on GRKERNSEC_CHROOT
66546 + help
66547 + If you say Y here, an attacker in a chroot will not be able to
66548 + write to sysctl entries, either by sysctl(2) or through a /proc
66549 + interface. It is strongly recommended that you say Y here. If the
66550 + sysctl option is enabled, a sysctl option with name
66551 + "chroot_deny_sysctl" is created.
66552 +
66553 +config GRKERNSEC_CHROOT_CAPS
66554 + bool "Capability restrictions"
66555 + default y if GRKERNSEC_CONFIG_AUTO
66556 + depends on GRKERNSEC_CHROOT
66557 + help
66558 + If you say Y here, the capabilities on all processes within a
66559 + chroot jail will be lowered to stop module insertion, raw i/o,
66560 + system and net admin tasks, rebooting the system, modifying immutable
66561 + files, modifying IPC owned by another, and changing the system time.
66562 + This is left an option because it can break some apps. Disable this
66563 + if your chrooted apps are having problems performing those kinds of
66564 + tasks. If the sysctl option is enabled, a sysctl option with
66565 + name "chroot_caps" is created.
66566 +
66567 +config GRKERNSEC_CHROOT_INITRD
66568 + bool "Exempt initrd tasks from restrictions"
66569 + default y if GRKERNSEC_CONFIG_AUTO
66570 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66571 + help
66572 + If you say Y here, tasks started prior to init will be exempted from
66573 + grsecurity's chroot restrictions. This option is mainly meant to
66574 + resolve Plymouth's performing privileged operations unnecessarily
66575 + in a chroot.
66576 +
66577 +endmenu
66578 +menu "Kernel Auditing"
66579 +depends on GRKERNSEC
66580 +
66581 +config GRKERNSEC_AUDIT_GROUP
66582 + bool "Single group for auditing"
66583 + help
66584 + If you say Y here, the exec and chdir logging features will only operate
66585 + on a group you specify. This option is recommended if you only want to
66586 + watch certain users instead of having a large amount of logs from the
66587 + entire system. If the sysctl option is enabled, a sysctl option with
66588 + name "audit_group" is created.
66589 +
66590 +config GRKERNSEC_AUDIT_GID
66591 + int "GID for auditing"
66592 + depends on GRKERNSEC_AUDIT_GROUP
66593 + default 1007
66594 +
66595 +config GRKERNSEC_EXECLOG
66596 + bool "Exec logging"
66597 + help
66598 + If you say Y here, all execve() calls will be logged (since the
66599 + other exec*() calls are frontends to execve(), all execution
66600 + will be logged). Useful for shell-servers that like to keep track
66601 + of their users. If the sysctl option is enabled, a sysctl option with
66602 + name "exec_logging" is created.
66603 + WARNING: This option when enabled will produce a LOT of logs, especially
66604 + on an active system.
66605 +
66606 +config GRKERNSEC_RESLOG
66607 + bool "Resource logging"
66608 + default y if GRKERNSEC_CONFIG_AUTO
66609 + help
66610 + If you say Y here, all attempts to overstep resource limits will
66611 + be logged with the resource name, the requested size, and the current
66612 + limit. It is highly recommended that you say Y here. If the sysctl
66613 + option is enabled, a sysctl option with name "resource_logging" is
66614 + created. If the RBAC system is enabled, the sysctl value is ignored.
66615 +
66616 +config GRKERNSEC_CHROOT_EXECLOG
66617 + bool "Log execs within chroot"
66618 + help
66619 + If you say Y here, all executions inside a chroot jail will be logged
66620 + to syslog. This can cause a large amount of logs if certain
66621 + applications (eg. djb's daemontools) are installed on the system, and
66622 + is therefore left as an option. If the sysctl option is enabled, a
66623 + sysctl option with name "chroot_execlog" is created.
66624 +
66625 +config GRKERNSEC_AUDIT_PTRACE
66626 + bool "Ptrace logging"
66627 + help
66628 + If you say Y here, all attempts to attach to a process via ptrace
66629 + will be logged. If the sysctl option is enabled, a sysctl option
66630 + with name "audit_ptrace" is created.
66631 +
66632 +config GRKERNSEC_AUDIT_CHDIR
66633 + bool "Chdir logging"
66634 + help
66635 + If you say Y here, all chdir() calls will be logged. If the sysctl
66636 + option is enabled, a sysctl option with name "audit_chdir" is created.
66637 +
66638 +config GRKERNSEC_AUDIT_MOUNT
66639 + bool "(Un)Mount logging"
66640 + help
66641 + If you say Y here, all mounts and unmounts will be logged. If the
66642 + sysctl option is enabled, a sysctl option with name "audit_mount" is
66643 + created.
66644 +
66645 +config GRKERNSEC_SIGNAL
66646 + bool "Signal logging"
66647 + default y if GRKERNSEC_CONFIG_AUTO
66648 + help
66649 + If you say Y here, certain important signals will be logged, such as
66650 + SIGSEGV, which will as a result inform you of when a error in a program
66651 + occurred, which in some cases could mean a possible exploit attempt.
66652 + If the sysctl option is enabled, a sysctl option with name
66653 + "signal_logging" is created.
66654 +
66655 +config GRKERNSEC_FORKFAIL
66656 + bool "Fork failure logging"
66657 + help
66658 + If you say Y here, all failed fork() attempts will be logged.
66659 + This could suggest a fork bomb, or someone attempting to overstep
66660 + their process limit. If the sysctl option is enabled, a sysctl option
66661 + with name "forkfail_logging" is created.
66662 +
66663 +config GRKERNSEC_TIME
66664 + bool "Time change logging"
66665 + default y if GRKERNSEC_CONFIG_AUTO
66666 + help
66667 + If you say Y here, any changes of the system clock will be logged.
66668 + If the sysctl option is enabled, a sysctl option with name
66669 + "timechange_logging" is created.
66670 +
66671 +config GRKERNSEC_PROC_IPADDR
66672 + bool "/proc/<pid>/ipaddr support"
66673 + default y if GRKERNSEC_CONFIG_AUTO
66674 + help
66675 + If you say Y here, a new entry will be added to each /proc/<pid>
66676 + directory that contains the IP address of the person using the task.
66677 + The IP is carried across local TCP and AF_UNIX stream sockets.
66678 + This information can be useful for IDS/IPSes to perform remote response
66679 + to a local attack. The entry is readable by only the owner of the
66680 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66681 + the RBAC system), and thus does not create privacy concerns.
66682 +
66683 +config GRKERNSEC_RWXMAP_LOG
66684 + bool 'Denied RWX mmap/mprotect logging'
66685 + default y if GRKERNSEC_CONFIG_AUTO
66686 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66687 + help
66688 + If you say Y here, calls to mmap() and mprotect() with explicit
66689 + usage of PROT_WRITE and PROT_EXEC together will be logged when
66690 + denied by the PAX_MPROTECT feature. This feature will also
66691 + log other problematic scenarios that can occur when PAX_MPROTECT
66692 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
66693 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66694 + is created.
66695 +
66696 +endmenu
66697 +
66698 +menu "Executable Protections"
66699 +depends on GRKERNSEC
66700 +
66701 +config GRKERNSEC_DMESG
66702 + bool "Dmesg(8) restriction"
66703 + default y if GRKERNSEC_CONFIG_AUTO
66704 + help
66705 + If you say Y here, non-root users will not be able to use dmesg(8)
66706 + to view the contents of the kernel's circular log buffer.
66707 + The kernel's log buffer often contains kernel addresses and other
66708 + identifying information useful to an attacker in fingerprinting a
66709 + system for a targeted exploit.
66710 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
66711 + created.
66712 +
66713 +config GRKERNSEC_HARDEN_PTRACE
66714 + bool "Deter ptrace-based process snooping"
66715 + default y if GRKERNSEC_CONFIG_AUTO
66716 + help
66717 + If you say Y here, TTY sniffers and other malicious monitoring
66718 + programs implemented through ptrace will be defeated. If you
66719 + have been using the RBAC system, this option has already been
66720 + enabled for several years for all users, with the ability to make
66721 + fine-grained exceptions.
66722 +
66723 + This option only affects the ability of non-root users to ptrace
66724 + processes that are not a descendent of the ptracing process.
66725 + This means that strace ./binary and gdb ./binary will still work,
66726 + but attaching to arbitrary processes will not. If the sysctl
66727 + option is enabled, a sysctl option with name "harden_ptrace" is
66728 + created.
66729 +
66730 +config GRKERNSEC_PTRACE_READEXEC
66731 + bool "Require read access to ptrace sensitive binaries"
66732 + default y if GRKERNSEC_CONFIG_AUTO
66733 + help
66734 + If you say Y here, unprivileged users will not be able to ptrace unreadable
66735 + binaries. This option is useful in environments that
66736 + remove the read bits (e.g. file mode 4711) from suid binaries to
66737 + prevent infoleaking of their contents. This option adds
66738 + consistency to the use of that file mode, as the binary could normally
66739 + be read out when run without privileges while ptracing.
66740 +
66741 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66742 + is created.
66743 +
66744 +config GRKERNSEC_SETXID
66745 + bool "Enforce consistent multithreaded privileges"
66746 + default y if GRKERNSEC_CONFIG_AUTO
66747 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66748 + help
66749 + If you say Y here, a change from a root uid to a non-root uid
66750 + in a multithreaded application will cause the resulting uids,
66751 + gids, supplementary groups, and capabilities in that thread
66752 + to be propagated to the other threads of the process. In most
66753 + cases this is unnecessary, as glibc will emulate this behavior
66754 + on behalf of the application. Other libcs do not act in the
66755 + same way, allowing the other threads of the process to continue
66756 + running with root privileges. If the sysctl option is enabled,
66757 + a sysctl option with name "consistent_setxid" is created.
66758 +
66759 +config GRKERNSEC_HARDEN_IPC
66760 + bool "Disallow access to overly-permissive IPC objects"
66761 + default y if GRKERNSEC_CONFIG_AUTO
66762 + depends on SYSVIPC
66763 + help
66764 + If you say Y here, access to overly-permissive IPC objects (shared
66765 + memory, message queues, and semaphores) will be denied for processes
66766 + given the following criteria beyond normal permission checks:
66767 + 1) If the IPC object is world-accessible and the euid doesn't match
66768 + that of the creator or current uid for the IPC object
66769 + 2) If the IPC object is group-accessible and the egid doesn't
66770 + match that of the creator or current gid for the IPC object
66771 + It's a common error to grant too much permission to these objects,
66772 + with impact ranging from denial of service and information leaking to
66773 + privilege escalation. This feature was developed in response to
66774 + research by Tim Brown:
66775 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66776 + who found hundreds of such insecure usages. Processes with
66777 + CAP_IPC_OWNER are still permitted to access these IPC objects.
66778 + If the sysctl option is enabled, a sysctl option with name
66779 + "harden_ipc" is created.
66780 +
66781 +config GRKERNSEC_TPE
66782 + bool "Trusted Path Execution (TPE)"
66783 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66784 + help
66785 + If you say Y here, you will be able to choose a gid to add to the
66786 + supplementary groups of users you want to mark as "untrusted."
66787 + These users will not be able to execute any files that are not in
66788 + root-owned directories writable only by root. If the sysctl option
66789 + is enabled, a sysctl option with name "tpe" is created.
66790 +
66791 +config GRKERNSEC_TPE_ALL
66792 + bool "Partially restrict all non-root users"
66793 + depends on GRKERNSEC_TPE
66794 + help
66795 + If you say Y here, all non-root users will be covered under
66796 + a weaker TPE restriction. This is separate from, and in addition to,
66797 + the main TPE options that you have selected elsewhere. Thus, if a
66798 + "trusted" GID is chosen, this restriction applies to even that GID.
66799 + Under this restriction, all non-root users will only be allowed to
66800 + execute files in directories they own that are not group or
66801 + world-writable, or in directories owned by root and writable only by
66802 + root. If the sysctl option is enabled, a sysctl option with name
66803 + "tpe_restrict_all" is created.
66804 +
66805 +config GRKERNSEC_TPE_INVERT
66806 + bool "Invert GID option"
66807 + depends on GRKERNSEC_TPE
66808 + help
66809 + If you say Y here, the group you specify in the TPE configuration will
66810 + decide what group TPE restrictions will be *disabled* for. This
66811 + option is useful if you want TPE restrictions to be applied to most
66812 + users on the system. If the sysctl option is enabled, a sysctl option
66813 + with name "tpe_invert" is created. Unlike other sysctl options, this
66814 + entry will default to on for backward-compatibility.
66815 +
66816 +config GRKERNSEC_TPE_GID
66817 + int
66818 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66819 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66820 +
66821 +config GRKERNSEC_TPE_UNTRUSTED_GID
66822 + int "GID for TPE-untrusted users"
66823 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66824 + default 1005
66825 + help
66826 + Setting this GID determines what group TPE restrictions will be
66827 + *enabled* for. If the sysctl option is enabled, a sysctl option
66828 + with name "tpe_gid" is created.
66829 +
66830 +config GRKERNSEC_TPE_TRUSTED_GID
66831 + int "GID for TPE-trusted users"
66832 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66833 + default 1005
66834 + help
66835 + Setting this GID determines what group TPE restrictions will be
66836 + *disabled* for. If the sysctl option is enabled, a sysctl option
66837 + with name "tpe_gid" is created.
66838 +
66839 +endmenu
66840 +menu "Network Protections"
66841 +depends on GRKERNSEC
66842 +
66843 +config GRKERNSEC_RANDNET
66844 + bool "Larger entropy pools"
66845 + default y if GRKERNSEC_CONFIG_AUTO
66846 + help
66847 + If you say Y here, the entropy pools used for many features of Linux
66848 + and grsecurity will be doubled in size. Since several grsecurity
66849 + features use additional randomness, it is recommended that you say Y
66850 + here. Saying Y here has a similar effect as modifying
66851 + /proc/sys/kernel/random/poolsize.
66852 +
66853 +config GRKERNSEC_BLACKHOLE
66854 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66855 + default y if GRKERNSEC_CONFIG_AUTO
66856 + depends on NET
66857 + help
66858 + If you say Y here, neither TCP resets nor ICMP
66859 + destination-unreachable packets will be sent in response to packets
66860 + sent to ports for which no associated listening process exists.
66861 + This feature supports both IPV4 and IPV6 and exempts the
66862 + loopback interface from blackholing. Enabling this feature
66863 + makes a host more resilient to DoS attacks and reduces network
66864 + visibility against scanners.
66865 +
66866 + The blackhole feature as-implemented is equivalent to the FreeBSD
66867 + blackhole feature, as it prevents RST responses to all packets, not
66868 + just SYNs. Under most application behavior this causes no
66869 + problems, but applications (like haproxy) may not close certain
66870 + connections in a way that cleanly terminates them on the remote
66871 + end, leaving the remote host in LAST_ACK state. Because of this
66872 + side-effect and to prevent intentional LAST_ACK DoSes, this
66873 + feature also adds automatic mitigation against such attacks.
66874 + The mitigation drastically reduces the amount of time a socket
66875 + can spend in LAST_ACK state. If you're using haproxy and not
66876 + all servers it connects to have this option enabled, consider
66877 + disabling this feature on the haproxy host.
66878 +
66879 + If the sysctl option is enabled, two sysctl options with names
66880 + "ip_blackhole" and "lastack_retries" will be created.
66881 + While "ip_blackhole" takes the standard zero/non-zero on/off
66882 + toggle, "lastack_retries" uses the same kinds of values as
66883 + "tcp_retries1" and "tcp_retries2". The default value of 4
66884 + prevents a socket from lasting more than 45 seconds in LAST_ACK
66885 + state.
66886 +
66887 +config GRKERNSEC_NO_SIMULT_CONNECT
66888 + bool "Disable TCP Simultaneous Connect"
66889 + default y if GRKERNSEC_CONFIG_AUTO
66890 + depends on NET
66891 + help
66892 + If you say Y here, a feature by Willy Tarreau will be enabled that
66893 + removes a weakness in Linux's strict implementation of TCP that
66894 + allows two clients to connect to each other without either entering
66895 + a listening state. The weakness allows an attacker to easily prevent
66896 + a client from connecting to a known server provided the source port
66897 + for the connection is guessed correctly.
66898 +
66899 + As the weakness could be used to prevent an antivirus or IPS from
66900 + fetching updates, or prevent an SSL gateway from fetching a CRL,
66901 + it should be eliminated by enabling this option. Though Linux is
66902 + one of few operating systems supporting simultaneous connect, it
66903 + has no legitimate use in practice and is rarely supported by firewalls.
66904 +
66905 +config GRKERNSEC_SOCKET
66906 + bool "Socket restrictions"
66907 + depends on NET
66908 + help
66909 + If you say Y here, you will be able to choose from several options.
66910 + If you assign a GID on your system and add it to the supplementary
66911 + groups of users you want to restrict socket access to, this patch
66912 + will perform up to three things, based on the option(s) you choose.
66913 +
66914 +config GRKERNSEC_SOCKET_ALL
66915 + bool "Deny any sockets to group"
66916 + depends on GRKERNSEC_SOCKET
66917 + help
66918 + If you say Y here, you will be able to choose a GID of whose users will
66919 + be unable to connect to other hosts from your machine or run server
66920 + applications from your machine. If the sysctl option is enabled, a
66921 + sysctl option with name "socket_all" is created.
66922 +
66923 +config GRKERNSEC_SOCKET_ALL_GID
66924 + int "GID to deny all sockets for"
66925 + depends on GRKERNSEC_SOCKET_ALL
66926 + default 1004
66927 + help
66928 + Here you can choose the GID to disable socket access for. Remember to
66929 + add the users you want socket access disabled for to the GID
66930 + specified here. If the sysctl option is enabled, a sysctl option
66931 + with name "socket_all_gid" is created.
66932 +
66933 +config GRKERNSEC_SOCKET_CLIENT
66934 + bool "Deny client sockets to group"
66935 + depends on GRKERNSEC_SOCKET
66936 + help
66937 + If you say Y here, you will be able to choose a GID of whose users will
66938 + be unable to connect to other hosts from your machine, but will be
66939 + able to run servers. If this option is enabled, all users in the group
66940 + you specify will have to use passive mode when initiating ftp transfers
66941 + from the shell on your machine. If the sysctl option is enabled, a
66942 + sysctl option with name "socket_client" is created.
66943 +
66944 +config GRKERNSEC_SOCKET_CLIENT_GID
66945 + int "GID to deny client sockets for"
66946 + depends on GRKERNSEC_SOCKET_CLIENT
66947 + default 1003
66948 + help
66949 + Here you can choose the GID to disable client socket access for.
66950 + Remember to add the users you want client socket access disabled for to
66951 + the GID specified here. If the sysctl option is enabled, a sysctl
66952 + option with name "socket_client_gid" is created.
66953 +
66954 +config GRKERNSEC_SOCKET_SERVER
66955 + bool "Deny server sockets to group"
66956 + depends on GRKERNSEC_SOCKET
66957 + help
66958 + If you say Y here, you will be able to choose a GID of whose users will
66959 + be unable to run server applications from your machine. If the sysctl
66960 + option is enabled, a sysctl option with name "socket_server" is created.
66961 +
66962 +config GRKERNSEC_SOCKET_SERVER_GID
66963 + int "GID to deny server sockets for"
66964 + depends on GRKERNSEC_SOCKET_SERVER
66965 + default 1002
66966 + help
66967 + Here you can choose the GID to disable server socket access for.
66968 + Remember to add the users you want server socket access disabled for to
66969 + the GID specified here. If the sysctl option is enabled, a sysctl
66970 + option with name "socket_server_gid" is created.
66971 +
66972 +endmenu
66973 +
66974 +menu "Physical Protections"
66975 +depends on GRKERNSEC
66976 +
66977 +config GRKERNSEC_DENYUSB
66978 + bool "Deny new USB connections after toggle"
66979 + default y if GRKERNSEC_CONFIG_AUTO
66980 + depends on SYSCTL && USB_SUPPORT
66981 + help
66982 + If you say Y here, a new sysctl option with name "deny_new_usb"
66983 + will be created. Setting its value to 1 will prevent any new
66984 + USB devices from being recognized by the OS. Any attempted USB
66985 + device insertion will be logged. This option is intended to be
66986 + used against custom USB devices designed to exploit vulnerabilities
66987 + in various USB device drivers.
66988 +
66989 + For greatest effectiveness, this sysctl should be set after any
66990 + relevant init scripts. This option is safe to enable in distros
66991 + as each user can choose whether or not to toggle the sysctl.
66992 +
66993 +config GRKERNSEC_DENYUSB_FORCE
66994 + bool "Reject all USB devices not connected at boot"
66995 + select USB
66996 + depends on GRKERNSEC_DENYUSB
66997 + help
66998 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66999 + that doesn't involve a sysctl entry. This option should only be
67000 + enabled if you're sure you want to deny all new USB connections
67001 + at runtime and don't want to modify init scripts. This should not
67002 + be enabled by distros. It forces the core USB code to be built
67003 + into the kernel image so that all devices connected at boot time
67004 + can be recognized and new USB device connections can be prevented
67005 + prior to init running.
67006 +
67007 +endmenu
67008 +
67009 +menu "Sysctl Support"
67010 +depends on GRKERNSEC && SYSCTL
67011 +
67012 +config GRKERNSEC_SYSCTL
67013 + bool "Sysctl support"
67014 + default y if GRKERNSEC_CONFIG_AUTO
67015 + help
67016 + If you say Y here, you will be able to change the options that
67017 + grsecurity runs with at bootup, without having to recompile your
67018 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
67019 + to enable (1) or disable (0) various features. All the sysctl entries
67020 + are mutable until the "grsec_lock" entry is set to a non-zero value.
67021 + All features enabled in the kernel configuration are disabled at boot
67022 + if you do not say Y to the "Turn on features by default" option.
67023 + All options should be set at startup, and the grsec_lock entry should
67024 + be set to a non-zero value after all the options are set.
67025 + *THIS IS EXTREMELY IMPORTANT*
67026 +
67027 +config GRKERNSEC_SYSCTL_DISTRO
67028 + bool "Extra sysctl support for distro makers (READ HELP)"
67029 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
67030 + help
67031 + If you say Y here, additional sysctl options will be created
67032 + for features that affect processes running as root. Therefore,
67033 + it is critical when using this option that the grsec_lock entry be
67034 + enabled after boot. Only distros with prebuilt kernel packages
67035 + with this option enabled that can ensure grsec_lock is enabled
67036 + after boot should use this option.
67037 + *Failure to set grsec_lock after boot makes all grsec features
67038 + this option covers useless*
67039 +
67040 + Currently this option creates the following sysctl entries:
67041 + "Disable Privileged I/O": "disable_priv_io"
67042 +
67043 +config GRKERNSEC_SYSCTL_ON
67044 + bool "Turn on features by default"
67045 + default y if GRKERNSEC_CONFIG_AUTO
67046 + depends on GRKERNSEC_SYSCTL
67047 + help
67048 + If you say Y here, instead of having all features enabled in the
67049 + kernel configuration disabled at boot time, the features will be
67050 + enabled at boot time. It is recommended you say Y here unless
67051 + there is some reason you would want all sysctl-tunable features to
67052 + be disabled by default. As mentioned elsewhere, it is important
67053 + to enable the grsec_lock entry once you have finished modifying
67054 + the sysctl entries.
67055 +
67056 +endmenu
67057 +menu "Logging Options"
67058 +depends on GRKERNSEC
67059 +
67060 +config GRKERNSEC_FLOODTIME
67061 + int "Seconds in between log messages (minimum)"
67062 + default 10
67063 + help
67064 + This option allows you to enforce the number of seconds between
67065 + grsecurity log messages. The default should be suitable for most
67066 + people, however, if you choose to change it, choose a value small enough
67067 + to allow informative logs to be produced, but large enough to
67068 + prevent flooding.
67069 +
67070 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
67071 + any rate limiting on grsecurity log messages.
67072 +
67073 +config GRKERNSEC_FLOODBURST
67074 + int "Number of messages in a burst (maximum)"
67075 + default 6
67076 + help
67077 + This option allows you to choose the maximum number of messages allowed
67078 + within the flood time interval you chose in a separate option. The
67079 + default should be suitable for most people, however if you find that
67080 + many of your logs are being interpreted as flooding, you may want to
67081 + raise this value.
67082 +
67083 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
67084 + any rate limiting on grsecurity log messages.
67085 +
67086 +endmenu
67087 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
67088 new file mode 100644
67089 index 0000000..30ababb
67090 --- /dev/null
67091 +++ b/grsecurity/Makefile
67092 @@ -0,0 +1,54 @@
67093 +# grsecurity – access control and security hardening for Linux
67094 +# All code in this directory and various hooks located throughout the Linux kernel are
67095 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
67096 +# http://www.grsecurity.net spender@grsecurity.net
67097 +#
67098 +# This program is free software; you can redistribute it and/or
67099 +# modify it under the terms of the GNU General Public License version 2
67100 +# as published by the Free Software Foundation.
67101 +#
67102 +# This program is distributed in the hope that it will be useful,
67103 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
67104 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67105 +# GNU General Public License for more details.
67106 +#
67107 +# You should have received a copy of the GNU General Public License
67108 +# along with this program; if not, write to the Free Software
67109 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
67110 +
67111 +KBUILD_CFLAGS += -Werror
67112 +
67113 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
67114 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
67115 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
67116 + grsec_usb.o grsec_ipc.o grsec_proc.o
67117 +
67118 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
67119 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
67120 + gracl_learn.o grsec_log.o gracl_policy.o
67121 +ifdef CONFIG_COMPAT
67122 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
67123 +endif
67124 +
67125 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
67126 +
67127 +ifdef CONFIG_NET
67128 +obj-y += grsec_sock.o
67129 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
67130 +endif
67131 +
67132 +ifndef CONFIG_GRKERNSEC
67133 +obj-y += grsec_disabled.o
67134 +endif
67135 +
67136 +ifdef CONFIG_GRKERNSEC_HIDESYM
67137 +extra-y := grsec_hidesym.o
67138 +$(obj)/grsec_hidesym.o:
67139 + @-chmod -f 500 /boot
67140 + @-chmod -f 500 /lib/modules
67141 + @-chmod -f 500 /lib64/modules
67142 + @-chmod -f 500 /lib32/modules
67143 + @-chmod -f 700 .
67144 + @-chmod -f 700 $(objtree)
67145 + @echo ' grsec: protected kernel image paths'
67146 +endif
67147 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
67148 new file mode 100644
67149 index 0000000..58223f6
67150 --- /dev/null
67151 +++ b/grsecurity/gracl.c
67152 @@ -0,0 +1,2702 @@
67153 +#include <linux/kernel.h>
67154 +#include <linux/module.h>
67155 +#include <linux/sched.h>
67156 +#include <linux/mm.h>
67157 +#include <linux/file.h>
67158 +#include <linux/fs.h>
67159 +#include <linux/namei.h>
67160 +#include <linux/mount.h>
67161 +#include <linux/tty.h>
67162 +#include <linux/proc_fs.h>
67163 +#include <linux/lglock.h>
67164 +#include <linux/slab.h>
67165 +#include <linux/vmalloc.h>
67166 +#include <linux/types.h>
67167 +#include <linux/sysctl.h>
67168 +#include <linux/netdevice.h>
67169 +#include <linux/ptrace.h>
67170 +#include <linux/gracl.h>
67171 +#include <linux/gralloc.h>
67172 +#include <linux/security.h>
67173 +#include <linux/grinternal.h>
67174 +#include <linux/pid_namespace.h>
67175 +#include <linux/stop_machine.h>
67176 +#include <linux/fdtable.h>
67177 +#include <linux/percpu.h>
67178 +#include <linux/lglock.h>
67179 +#include <linux/hugetlb.h>
67180 +#include <linux/posix-timers.h>
67181 +#include <linux/prefetch.h>
67182 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67183 +#include <linux/magic.h>
67184 +#include <linux/pagemap.h>
67185 +#include "../fs/btrfs/async-thread.h"
67186 +#include "../fs/btrfs/ctree.h"
67187 +#include "../fs/btrfs/btrfs_inode.h"
67188 +#endif
67189 +#include "../fs/mount.h"
67190 +
67191 +#include <asm/uaccess.h>
67192 +#include <asm/errno.h>
67193 +#include <asm/mman.h>
67194 +
67195 +#define FOR_EACH_ROLE_START(role) \
67196 + role = running_polstate.role_list; \
67197 + while (role) {
67198 +
67199 +#define FOR_EACH_ROLE_END(role) \
67200 + role = role->prev; \
67201 + }
67202 +
67203 +extern struct path gr_real_root;
67204 +
67205 +static struct gr_policy_state running_polstate;
67206 +struct gr_policy_state *polstate = &running_polstate;
67207 +extern struct gr_alloc_state *current_alloc_state;
67208 +
67209 +extern char *gr_shared_page[4];
67210 +DEFINE_RWLOCK(gr_inode_lock);
67211 +
67212 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
67213 +
67214 +#ifdef CONFIG_NET
67215 +extern struct vfsmount *sock_mnt;
67216 +#endif
67217 +
67218 +extern struct vfsmount *pipe_mnt;
67219 +extern struct vfsmount *shm_mnt;
67220 +
67221 +#ifdef CONFIG_HUGETLBFS
67222 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
67223 +#endif
67224 +
67225 +extern u16 acl_sp_role_value;
67226 +extern struct acl_object_label *fakefs_obj_rw;
67227 +extern struct acl_object_label *fakefs_obj_rwx;
67228 +
67229 +int gr_acl_is_enabled(void)
67230 +{
67231 + return (gr_status & GR_READY);
67232 +}
67233 +
67234 +void gr_enable_rbac_system(void)
67235 +{
67236 + pax_open_kernel();
67237 + gr_status |= GR_READY;
67238 + pax_close_kernel();
67239 +}
67240 +
67241 +int gr_rbac_disable(void *unused)
67242 +{
67243 + pax_open_kernel();
67244 + gr_status &= ~GR_READY;
67245 + pax_close_kernel();
67246 +
67247 + return 0;
67248 +}
67249 +
67250 +static inline dev_t __get_dev(const struct dentry *dentry)
67251 +{
67252 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67253 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67254 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
67255 + else
67256 +#endif
67257 + return dentry->d_sb->s_dev;
67258 +}
67259 +
67260 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
67261 +{
67262 + return __get_dev(dentry);
67263 +}
67264 +
67265 +static char gr_task_roletype_to_char(struct task_struct *task)
67266 +{
67267 + switch (task->role->roletype &
67268 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
67269 + GR_ROLE_SPECIAL)) {
67270 + case GR_ROLE_DEFAULT:
67271 + return 'D';
67272 + case GR_ROLE_USER:
67273 + return 'U';
67274 + case GR_ROLE_GROUP:
67275 + return 'G';
67276 + case GR_ROLE_SPECIAL:
67277 + return 'S';
67278 + }
67279 +
67280 + return 'X';
67281 +}
67282 +
67283 +char gr_roletype_to_char(void)
67284 +{
67285 + return gr_task_roletype_to_char(current);
67286 +}
67287 +
67288 +__inline__ int
67289 +gr_acl_tpe_check(void)
67290 +{
67291 + if (unlikely(!(gr_status & GR_READY)))
67292 + return 0;
67293 + if (current->role->roletype & GR_ROLE_TPE)
67294 + return 1;
67295 + else
67296 + return 0;
67297 +}
67298 +
67299 +int
67300 +gr_handle_rawio(const struct inode *inode)
67301 +{
67302 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67303 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
67304 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
67305 + !capable(CAP_SYS_RAWIO))
67306 + return 1;
67307 +#endif
67308 + return 0;
67309 +}
67310 +
67311 +int
67312 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
67313 +{
67314 + if (likely(lena != lenb))
67315 + return 0;
67316 +
67317 + return !memcmp(a, b, lena);
67318 +}
67319 +
67320 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
67321 +{
67322 + *buflen -= namelen;
67323 + if (*buflen < 0)
67324 + return -ENAMETOOLONG;
67325 + *buffer -= namelen;
67326 + memcpy(*buffer, str, namelen);
67327 + return 0;
67328 +}
67329 +
67330 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
67331 +{
67332 + return prepend(buffer, buflen, name->name, name->len);
67333 +}
67334 +
67335 +static int prepend_path(const struct path *path, struct path *root,
67336 + char **buffer, int *buflen)
67337 +{
67338 + struct dentry *dentry = path->dentry;
67339 + struct vfsmount *vfsmnt = path->mnt;
67340 + struct mount *mnt = real_mount(vfsmnt);
67341 + bool slash = false;
67342 + int error = 0;
67343 +
67344 + while (dentry != root->dentry || vfsmnt != root->mnt) {
67345 + struct dentry * parent;
67346 +
67347 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
67348 + /* Global root? */
67349 + if (!mnt_has_parent(mnt)) {
67350 + goto out;
67351 + }
67352 + dentry = mnt->mnt_mountpoint;
67353 + mnt = mnt->mnt_parent;
67354 + vfsmnt = &mnt->mnt;
67355 + continue;
67356 + }
67357 + parent = dentry->d_parent;
67358 + prefetch(parent);
67359 + spin_lock(&dentry->d_lock);
67360 + error = prepend_name(buffer, buflen, &dentry->d_name);
67361 + spin_unlock(&dentry->d_lock);
67362 + if (!error)
67363 + error = prepend(buffer, buflen, "/", 1);
67364 + if (error)
67365 + break;
67366 +
67367 + slash = true;
67368 + dentry = parent;
67369 + }
67370 +
67371 +out:
67372 + if (!error && !slash)
67373 + error = prepend(buffer, buflen, "/", 1);
67374 +
67375 + return error;
67376 +}
67377 +
67378 +/* this must be called with mount_lock and rename_lock held */
67379 +
67380 +static char *__our_d_path(const struct path *path, struct path *root,
67381 + char *buf, int buflen)
67382 +{
67383 + char *res = buf + buflen;
67384 + int error;
67385 +
67386 + prepend(&res, &buflen, "\0", 1);
67387 + error = prepend_path(path, root, &res, &buflen);
67388 + if (error)
67389 + return ERR_PTR(error);
67390 +
67391 + return res;
67392 +}
67393 +
67394 +static char *
67395 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67396 +{
67397 + char *retval;
67398 +
67399 + retval = __our_d_path(path, root, buf, buflen);
67400 + if (unlikely(IS_ERR(retval)))
67401 + retval = strcpy(buf, "<path too long>");
67402 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67403 + retval[1] = '\0';
67404 +
67405 + return retval;
67406 +}
67407 +
67408 +static char *
67409 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67410 + char *buf, int buflen)
67411 +{
67412 + struct path path;
67413 + char *res;
67414 +
67415 + path.dentry = (struct dentry *)dentry;
67416 + path.mnt = (struct vfsmount *)vfsmnt;
67417 +
67418 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67419 + by the RBAC system */
67420 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
67421 +
67422 + return res;
67423 +}
67424 +
67425 +static char *
67426 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67427 + char *buf, int buflen)
67428 +{
67429 + char *res;
67430 + struct path path;
67431 + struct path root;
67432 + struct task_struct *reaper = init_pid_ns.child_reaper;
67433 +
67434 + path.dentry = (struct dentry *)dentry;
67435 + path.mnt = (struct vfsmount *)vfsmnt;
67436 +
67437 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67438 + get_fs_root(reaper->fs, &root);
67439 +
67440 + read_seqlock_excl(&mount_lock);
67441 + write_seqlock(&rename_lock);
67442 + res = gen_full_path(&path, &root, buf, buflen);
67443 + write_sequnlock(&rename_lock);
67444 + read_sequnlock_excl(&mount_lock);
67445 +
67446 + path_put(&root);
67447 + return res;
67448 +}
67449 +
67450 +char *
67451 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67452 +{
67453 + char *ret;
67454 + read_seqlock_excl(&mount_lock);
67455 + write_seqlock(&rename_lock);
67456 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67457 + PAGE_SIZE);
67458 + write_sequnlock(&rename_lock);
67459 + read_sequnlock_excl(&mount_lock);
67460 + return ret;
67461 +}
67462 +
67463 +static char *
67464 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67465 +{
67466 + char *ret;
67467 + char *buf;
67468 + int buflen;
67469 +
67470 + read_seqlock_excl(&mount_lock);
67471 + write_seqlock(&rename_lock);
67472 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67473 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67474 + buflen = (int)(ret - buf);
67475 + if (buflen >= 5)
67476 + prepend(&ret, &buflen, "/proc", 5);
67477 + else
67478 + ret = strcpy(buf, "<path too long>");
67479 + write_sequnlock(&rename_lock);
67480 + read_sequnlock_excl(&mount_lock);
67481 + return ret;
67482 +}
67483 +
67484 +char *
67485 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67486 +{
67487 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67488 + PAGE_SIZE);
67489 +}
67490 +
67491 +char *
67492 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67493 +{
67494 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67495 + PAGE_SIZE);
67496 +}
67497 +
67498 +char *
67499 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67500 +{
67501 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67502 + PAGE_SIZE);
67503 +}
67504 +
67505 +char *
67506 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67507 +{
67508 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67509 + PAGE_SIZE);
67510 +}
67511 +
67512 +char *
67513 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67514 +{
67515 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67516 + PAGE_SIZE);
67517 +}
67518 +
67519 +__inline__ __u32
67520 +to_gr_audit(const __u32 reqmode)
67521 +{
67522 + /* masks off auditable permission flags, then shifts them to create
67523 + auditing flags, and adds the special case of append auditing if
67524 + we're requesting write */
67525 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67526 +}
67527 +
67528 +struct acl_role_label *
67529 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67530 + const gid_t gid)
67531 +{
67532 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67533 + struct acl_role_label *match;
67534 + struct role_allowed_ip *ipp;
67535 + unsigned int x;
67536 + u32 curr_ip = task->signal->saved_ip;
67537 +
67538 + match = state->acl_role_set.r_hash[index];
67539 +
67540 + while (match) {
67541 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67542 + for (x = 0; x < match->domain_child_num; x++) {
67543 + if (match->domain_children[x] == uid)
67544 + goto found;
67545 + }
67546 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67547 + break;
67548 + match = match->next;
67549 + }
67550 +found:
67551 + if (match == NULL) {
67552 + try_group:
67553 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67554 + match = state->acl_role_set.r_hash[index];
67555 +
67556 + while (match) {
67557 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67558 + for (x = 0; x < match->domain_child_num; x++) {
67559 + if (match->domain_children[x] == gid)
67560 + goto found2;
67561 + }
67562 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67563 + break;
67564 + match = match->next;
67565 + }
67566 +found2:
67567 + if (match == NULL)
67568 + match = state->default_role;
67569 + if (match->allowed_ips == NULL)
67570 + return match;
67571 + else {
67572 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67573 + if (likely
67574 + ((ntohl(curr_ip) & ipp->netmask) ==
67575 + (ntohl(ipp->addr) & ipp->netmask)))
67576 + return match;
67577 + }
67578 + match = state->default_role;
67579 + }
67580 + } else if (match->allowed_ips == NULL) {
67581 + return match;
67582 + } else {
67583 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67584 + if (likely
67585 + ((ntohl(curr_ip) & ipp->netmask) ==
67586 + (ntohl(ipp->addr) & ipp->netmask)))
67587 + return match;
67588 + }
67589 + goto try_group;
67590 + }
67591 +
67592 + return match;
67593 +}
67594 +
67595 +static struct acl_role_label *
67596 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67597 + const gid_t gid)
67598 +{
67599 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67600 +}
67601 +
67602 +struct acl_subject_label *
67603 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67604 + const struct acl_role_label *role)
67605 +{
67606 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67607 + struct acl_subject_label *match;
67608 +
67609 + match = role->subj_hash[index];
67610 +
67611 + while (match && (match->inode != ino || match->device != dev ||
67612 + (match->mode & GR_DELETED))) {
67613 + match = match->next;
67614 + }
67615 +
67616 + if (match && !(match->mode & GR_DELETED))
67617 + return match;
67618 + else
67619 + return NULL;
67620 +}
67621 +
67622 +struct acl_subject_label *
67623 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67624 + const struct acl_role_label *role)
67625 +{
67626 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67627 + struct acl_subject_label *match;
67628 +
67629 + match = role->subj_hash[index];
67630 +
67631 + while (match && (match->inode != ino || match->device != dev ||
67632 + !(match->mode & GR_DELETED))) {
67633 + match = match->next;
67634 + }
67635 +
67636 + if (match && (match->mode & GR_DELETED))
67637 + return match;
67638 + else
67639 + return NULL;
67640 +}
67641 +
67642 +static struct acl_object_label *
67643 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67644 + const struct acl_subject_label *subj)
67645 +{
67646 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67647 + struct acl_object_label *match;
67648 +
67649 + match = subj->obj_hash[index];
67650 +
67651 + while (match && (match->inode != ino || match->device != dev ||
67652 + (match->mode & GR_DELETED))) {
67653 + match = match->next;
67654 + }
67655 +
67656 + if (match && !(match->mode & GR_DELETED))
67657 + return match;
67658 + else
67659 + return NULL;
67660 +}
67661 +
67662 +static struct acl_object_label *
67663 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67664 + const struct acl_subject_label *subj)
67665 +{
67666 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67667 + struct acl_object_label *match;
67668 +
67669 + match = subj->obj_hash[index];
67670 +
67671 + while (match && (match->inode != ino || match->device != dev ||
67672 + !(match->mode & GR_DELETED))) {
67673 + match = match->next;
67674 + }
67675 +
67676 + if (match && (match->mode & GR_DELETED))
67677 + return match;
67678 +
67679 + match = subj->obj_hash[index];
67680 +
67681 + while (match && (match->inode != ino || match->device != dev ||
67682 + (match->mode & GR_DELETED))) {
67683 + match = match->next;
67684 + }
67685 +
67686 + if (match && !(match->mode & GR_DELETED))
67687 + return match;
67688 + else
67689 + return NULL;
67690 +}
67691 +
67692 +struct name_entry *
67693 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67694 +{
67695 + unsigned int len = strlen(name);
67696 + unsigned int key = full_name_hash(name, len);
67697 + unsigned int index = key % state->name_set.n_size;
67698 + struct name_entry *match;
67699 +
67700 + match = state->name_set.n_hash[index];
67701 +
67702 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67703 + match = match->next;
67704 +
67705 + return match;
67706 +}
67707 +
67708 +static struct name_entry *
67709 +lookup_name_entry(const char *name)
67710 +{
67711 + return __lookup_name_entry(&running_polstate, name);
67712 +}
67713 +
67714 +static struct name_entry *
67715 +lookup_name_entry_create(const char *name)
67716 +{
67717 + unsigned int len = strlen(name);
67718 + unsigned int key = full_name_hash(name, len);
67719 + unsigned int index = key % running_polstate.name_set.n_size;
67720 + struct name_entry *match;
67721 +
67722 + match = running_polstate.name_set.n_hash[index];
67723 +
67724 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67725 + !match->deleted))
67726 + match = match->next;
67727 +
67728 + if (match && match->deleted)
67729 + return match;
67730 +
67731 + match = running_polstate.name_set.n_hash[index];
67732 +
67733 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67734 + match->deleted))
67735 + match = match->next;
67736 +
67737 + if (match && !match->deleted)
67738 + return match;
67739 + else
67740 + return NULL;
67741 +}
67742 +
67743 +static struct inodev_entry *
67744 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
67745 +{
67746 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67747 + struct inodev_entry *match;
67748 +
67749 + match = running_polstate.inodev_set.i_hash[index];
67750 +
67751 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67752 + match = match->next;
67753 +
67754 + return match;
67755 +}
67756 +
67757 +void
67758 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67759 +{
67760 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67761 + state->inodev_set.i_size);
67762 + struct inodev_entry **curr;
67763 +
67764 + entry->prev = NULL;
67765 +
67766 + curr = &state->inodev_set.i_hash[index];
67767 + if (*curr != NULL)
67768 + (*curr)->prev = entry;
67769 +
67770 + entry->next = *curr;
67771 + *curr = entry;
67772 +
67773 + return;
67774 +}
67775 +
67776 +static void
67777 +insert_inodev_entry(struct inodev_entry *entry)
67778 +{
67779 + __insert_inodev_entry(&running_polstate, entry);
67780 +}
67781 +
67782 +void
67783 +insert_acl_obj_label(struct acl_object_label *obj,
67784 + struct acl_subject_label *subj)
67785 +{
67786 + unsigned int index =
67787 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67788 + struct acl_object_label **curr;
67789 +
67790 + obj->prev = NULL;
67791 +
67792 + curr = &subj->obj_hash[index];
67793 + if (*curr != NULL)
67794 + (*curr)->prev = obj;
67795 +
67796 + obj->next = *curr;
67797 + *curr = obj;
67798 +
67799 + return;
67800 +}
67801 +
67802 +void
67803 +insert_acl_subj_label(struct acl_subject_label *obj,
67804 + struct acl_role_label *role)
67805 +{
67806 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67807 + struct acl_subject_label **curr;
67808 +
67809 + obj->prev = NULL;
67810 +
67811 + curr = &role->subj_hash[index];
67812 + if (*curr != NULL)
67813 + (*curr)->prev = obj;
67814 +
67815 + obj->next = *curr;
67816 + *curr = obj;
67817 +
67818 + return;
67819 +}
67820 +
67821 +/* derived from glibc fnmatch() 0: match, 1: no match*/
67822 +
67823 +static int
67824 +glob_match(const char *p, const char *n)
67825 +{
67826 + char c;
67827 +
67828 + while ((c = *p++) != '\0') {
67829 + switch (c) {
67830 + case '?':
67831 + if (*n == '\0')
67832 + return 1;
67833 + else if (*n == '/')
67834 + return 1;
67835 + break;
67836 + case '\\':
67837 + if (*n != c)
67838 + return 1;
67839 + break;
67840 + case '*':
67841 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
67842 + if (*n == '/')
67843 + return 1;
67844 + else if (c == '?') {
67845 + if (*n == '\0')
67846 + return 1;
67847 + else
67848 + ++n;
67849 + }
67850 + }
67851 + if (c == '\0') {
67852 + return 0;
67853 + } else {
67854 + const char *endp;
67855 +
67856 + if ((endp = strchr(n, '/')) == NULL)
67857 + endp = n + strlen(n);
67858 +
67859 + if (c == '[') {
67860 + for (--p; n < endp; ++n)
67861 + if (!glob_match(p, n))
67862 + return 0;
67863 + } else if (c == '/') {
67864 + while (*n != '\0' && *n != '/')
67865 + ++n;
67866 + if (*n == '/' && !glob_match(p, n + 1))
67867 + return 0;
67868 + } else {
67869 + for (--p; n < endp; ++n)
67870 + if (*n == c && !glob_match(p, n))
67871 + return 0;
67872 + }
67873 +
67874 + return 1;
67875 + }
67876 + case '[':
67877 + {
67878 + int not;
67879 + char cold;
67880 +
67881 + if (*n == '\0' || *n == '/')
67882 + return 1;
67883 +
67884 + not = (*p == '!' || *p == '^');
67885 + if (not)
67886 + ++p;
67887 +
67888 + c = *p++;
67889 + for (;;) {
67890 + unsigned char fn = (unsigned char)*n;
67891 +
67892 + if (c == '\0')
67893 + return 1;
67894 + else {
67895 + if (c == fn)
67896 + goto matched;
67897 + cold = c;
67898 + c = *p++;
67899 +
67900 + if (c == '-' && *p != ']') {
67901 + unsigned char cend = *p++;
67902 +
67903 + if (cend == '\0')
67904 + return 1;
67905 +
67906 + if (cold <= fn && fn <= cend)
67907 + goto matched;
67908 +
67909 + c = *p++;
67910 + }
67911 + }
67912 +
67913 + if (c == ']')
67914 + break;
67915 + }
67916 + if (!not)
67917 + return 1;
67918 + break;
67919 + matched:
67920 + while (c != ']') {
67921 + if (c == '\0')
67922 + return 1;
67923 +
67924 + c = *p++;
67925 + }
67926 + if (not)
67927 + return 1;
67928 + }
67929 + break;
67930 + default:
67931 + if (c != *n)
67932 + return 1;
67933 + }
67934 +
67935 + ++n;
67936 + }
67937 +
67938 + if (*n == '\0')
67939 + return 0;
67940 +
67941 + if (*n == '/')
67942 + return 0;
67943 +
67944 + return 1;
67945 +}
67946 +
67947 +static struct acl_object_label *
67948 +chk_glob_label(struct acl_object_label *globbed,
67949 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67950 +{
67951 + struct acl_object_label *tmp;
67952 +
67953 + if (*path == NULL)
67954 + *path = gr_to_filename_nolock(dentry, mnt);
67955 +
67956 + tmp = globbed;
67957 +
67958 + while (tmp) {
67959 + if (!glob_match(tmp->filename, *path))
67960 + return tmp;
67961 + tmp = tmp->next;
67962 + }
67963 +
67964 + return NULL;
67965 +}
67966 +
67967 +static struct acl_object_label *
67968 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67969 + const ino_t curr_ino, const dev_t curr_dev,
67970 + const struct acl_subject_label *subj, char **path, const int checkglob)
67971 +{
67972 + struct acl_subject_label *tmpsubj;
67973 + struct acl_object_label *retval;
67974 + struct acl_object_label *retval2;
67975 +
67976 + tmpsubj = (struct acl_subject_label *) subj;
67977 + read_lock(&gr_inode_lock);
67978 + do {
67979 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67980 + if (retval) {
67981 + if (checkglob && retval->globbed) {
67982 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67983 + if (retval2)
67984 + retval = retval2;
67985 + }
67986 + break;
67987 + }
67988 + } while ((tmpsubj = tmpsubj->parent_subject));
67989 + read_unlock(&gr_inode_lock);
67990 +
67991 + return retval;
67992 +}
67993 +
67994 +static __inline__ struct acl_object_label *
67995 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67996 + struct dentry *curr_dentry,
67997 + const struct acl_subject_label *subj, char **path, const int checkglob)
67998 +{
67999 + int newglob = checkglob;
68000 + ino_t inode;
68001 + dev_t device;
68002 +
68003 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
68004 + as we don't want a / * rule to match instead of the / object
68005 + don't do this for create lookups that call this function though, since they're looking up
68006 + on the parent and thus need globbing checks on all paths
68007 + */
68008 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
68009 + newglob = GR_NO_GLOB;
68010 +
68011 + spin_lock(&curr_dentry->d_lock);
68012 + inode = curr_dentry->d_inode->i_ino;
68013 + device = __get_dev(curr_dentry);
68014 + spin_unlock(&curr_dentry->d_lock);
68015 +
68016 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
68017 +}
68018 +
68019 +#ifdef CONFIG_HUGETLBFS
68020 +static inline bool
68021 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
68022 +{
68023 + int i;
68024 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
68025 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
68026 + return true;
68027 + }
68028 +
68029 + return false;
68030 +}
68031 +#endif
68032 +
68033 +static struct acl_object_label *
68034 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68035 + const struct acl_subject_label *subj, char *path, const int checkglob)
68036 +{
68037 + struct dentry *dentry = (struct dentry *) l_dentry;
68038 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68039 + struct mount *real_mnt = real_mount(mnt);
68040 + struct acl_object_label *retval;
68041 + struct dentry *parent;
68042 +
68043 + read_seqlock_excl(&mount_lock);
68044 + write_seqlock(&rename_lock);
68045 +
68046 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
68047 +#ifdef CONFIG_NET
68048 + mnt == sock_mnt ||
68049 +#endif
68050 +#ifdef CONFIG_HUGETLBFS
68051 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
68052 +#endif
68053 + /* ignore Eric Biederman */
68054 + IS_PRIVATE(l_dentry->d_inode))) {
68055 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
68056 + goto out;
68057 + }
68058 +
68059 + for (;;) {
68060 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68061 + break;
68062 +
68063 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68064 + if (!mnt_has_parent(real_mnt))
68065 + break;
68066 +
68067 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68068 + if (retval != NULL)
68069 + goto out;
68070 +
68071 + dentry = real_mnt->mnt_mountpoint;
68072 + real_mnt = real_mnt->mnt_parent;
68073 + mnt = &real_mnt->mnt;
68074 + continue;
68075 + }
68076 +
68077 + parent = dentry->d_parent;
68078 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68079 + if (retval != NULL)
68080 + goto out;
68081 +
68082 + dentry = parent;
68083 + }
68084 +
68085 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68086 +
68087 + /* gr_real_root is pinned so we don't have to hold a reference */
68088 + if (retval == NULL)
68089 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
68090 +out:
68091 + write_sequnlock(&rename_lock);
68092 + read_sequnlock_excl(&mount_lock);
68093 +
68094 + BUG_ON(retval == NULL);
68095 +
68096 + return retval;
68097 +}
68098 +
68099 +static __inline__ struct acl_object_label *
68100 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68101 + const struct acl_subject_label *subj)
68102 +{
68103 + char *path = NULL;
68104 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
68105 +}
68106 +
68107 +static __inline__ struct acl_object_label *
68108 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68109 + const struct acl_subject_label *subj)
68110 +{
68111 + char *path = NULL;
68112 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
68113 +}
68114 +
68115 +static __inline__ struct acl_object_label *
68116 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68117 + const struct acl_subject_label *subj, char *path)
68118 +{
68119 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
68120 +}
68121 +
68122 +struct acl_subject_label *
68123 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68124 + const struct acl_role_label *role)
68125 +{
68126 + struct dentry *dentry = (struct dentry *) l_dentry;
68127 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68128 + struct mount *real_mnt = real_mount(mnt);
68129 + struct acl_subject_label *retval;
68130 + struct dentry *parent;
68131 +
68132 + read_seqlock_excl(&mount_lock);
68133 + write_seqlock(&rename_lock);
68134 +
68135 + for (;;) {
68136 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68137 + break;
68138 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68139 + if (!mnt_has_parent(real_mnt))
68140 + break;
68141 +
68142 + spin_lock(&dentry->d_lock);
68143 + read_lock(&gr_inode_lock);
68144 + retval =
68145 + lookup_acl_subj_label(dentry->d_inode->i_ino,
68146 + __get_dev(dentry), role);
68147 + read_unlock(&gr_inode_lock);
68148 + spin_unlock(&dentry->d_lock);
68149 + if (retval != NULL)
68150 + goto out;
68151 +
68152 + dentry = real_mnt->mnt_mountpoint;
68153 + real_mnt = real_mnt->mnt_parent;
68154 + mnt = &real_mnt->mnt;
68155 + continue;
68156 + }
68157 +
68158 + spin_lock(&dentry->d_lock);
68159 + read_lock(&gr_inode_lock);
68160 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68161 + __get_dev(dentry), role);
68162 + read_unlock(&gr_inode_lock);
68163 + parent = dentry->d_parent;
68164 + spin_unlock(&dentry->d_lock);
68165 +
68166 + if (retval != NULL)
68167 + goto out;
68168 +
68169 + dentry = parent;
68170 + }
68171 +
68172 + spin_lock(&dentry->d_lock);
68173 + read_lock(&gr_inode_lock);
68174 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68175 + __get_dev(dentry), role);
68176 + read_unlock(&gr_inode_lock);
68177 + spin_unlock(&dentry->d_lock);
68178 +
68179 + if (unlikely(retval == NULL)) {
68180 + /* gr_real_root is pinned, we don't need to hold a reference */
68181 + read_lock(&gr_inode_lock);
68182 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
68183 + __get_dev(gr_real_root.dentry), role);
68184 + read_unlock(&gr_inode_lock);
68185 + }
68186 +out:
68187 + write_sequnlock(&rename_lock);
68188 + read_sequnlock_excl(&mount_lock);
68189 +
68190 + BUG_ON(retval == NULL);
68191 +
68192 + return retval;
68193 +}
68194 +
68195 +void
68196 +assign_special_role(const char *rolename)
68197 +{
68198 + struct acl_object_label *obj;
68199 + struct acl_role_label *r;
68200 + struct acl_role_label *assigned = NULL;
68201 + struct task_struct *tsk;
68202 + struct file *filp;
68203 +
68204 + FOR_EACH_ROLE_START(r)
68205 + if (!strcmp(rolename, r->rolename) &&
68206 + (r->roletype & GR_ROLE_SPECIAL)) {
68207 + assigned = r;
68208 + break;
68209 + }
68210 + FOR_EACH_ROLE_END(r)
68211 +
68212 + if (!assigned)
68213 + return;
68214 +
68215 + read_lock(&tasklist_lock);
68216 + read_lock(&grsec_exec_file_lock);
68217 +
68218 + tsk = current->real_parent;
68219 + if (tsk == NULL)
68220 + goto out_unlock;
68221 +
68222 + filp = tsk->exec_file;
68223 + if (filp == NULL)
68224 + goto out_unlock;
68225 +
68226 + tsk->is_writable = 0;
68227 + tsk->inherited = 0;
68228 +
68229 + tsk->acl_sp_role = 1;
68230 + tsk->acl_role_id = ++acl_sp_role_value;
68231 + tsk->role = assigned;
68232 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
68233 +
68234 + /* ignore additional mmap checks for processes that are writable
68235 + by the default ACL */
68236 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68237 + if (unlikely(obj->mode & GR_WRITE))
68238 + tsk->is_writable = 1;
68239 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
68240 + if (unlikely(obj->mode & GR_WRITE))
68241 + tsk->is_writable = 1;
68242 +
68243 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68244 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
68245 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
68246 +#endif
68247 +
68248 +out_unlock:
68249 + read_unlock(&grsec_exec_file_lock);
68250 + read_unlock(&tasklist_lock);
68251 + return;
68252 +}
68253 +
68254 +
68255 +static void
68256 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
68257 +{
68258 + struct task_struct *task = current;
68259 + const struct cred *cred = current_cred();
68260 +
68261 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
68262 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68263 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68264 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
68265 +
68266 + return;
68267 +}
68268 +
68269 +static void
68270 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
68271 +{
68272 + struct task_struct *task = current;
68273 + const struct cred *cred = current_cred();
68274 +
68275 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68276 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68277 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68278 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
68279 +
68280 + return;
68281 +}
68282 +
68283 +static void
68284 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
68285 +{
68286 + struct task_struct *task = current;
68287 + const struct cred *cred = current_cred();
68288 +
68289 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68290 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68291 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68292 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
68293 +
68294 + return;
68295 +}
68296 +
68297 +static void
68298 +gr_set_proc_res(struct task_struct *task)
68299 +{
68300 + struct acl_subject_label *proc;
68301 + unsigned short i;
68302 +
68303 + proc = task->acl;
68304 +
68305 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
68306 + return;
68307 +
68308 + for (i = 0; i < RLIM_NLIMITS; i++) {
68309 + if (!(proc->resmask & (1U << i)))
68310 + continue;
68311 +
68312 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
68313 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
68314 +
68315 + if (i == RLIMIT_CPU)
68316 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
68317 + }
68318 +
68319 + return;
68320 +}
68321 +
68322 +/* both of the below must be called with
68323 + rcu_read_lock();
68324 + read_lock(&tasklist_lock);
68325 + read_lock(&grsec_exec_file_lock);
68326 +*/
68327 +
68328 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
68329 +{
68330 + char *tmpname;
68331 + struct acl_subject_label *tmpsubj;
68332 + struct file *filp;
68333 + struct name_entry *nmatch;
68334 +
68335 + filp = task->exec_file;
68336 + if (filp == NULL)
68337 + return NULL;
68338 +
68339 + /* the following is to apply the correct subject
68340 + on binaries running when the RBAC system
68341 + is enabled, when the binaries have been
68342 + replaced or deleted since their execution
68343 + -----
68344 + when the RBAC system starts, the inode/dev
68345 + from exec_file will be one the RBAC system
68346 + is unaware of. It only knows the inode/dev
68347 + of the present file on disk, or the absence
68348 + of it.
68349 + */
68350 +
68351 + if (filename)
68352 + nmatch = __lookup_name_entry(state, filename);
68353 + else {
68354 + preempt_disable();
68355 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68356 +
68357 + nmatch = __lookup_name_entry(state, tmpname);
68358 + preempt_enable();
68359 + }
68360 + tmpsubj = NULL;
68361 + if (nmatch) {
68362 + if (nmatch->deleted)
68363 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68364 + else
68365 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68366 + }
68367 + /* this also works for the reload case -- if we don't match a potentially inherited subject
68368 + then we fall back to a normal lookup based on the binary's ino/dev
68369 + */
68370 + if (tmpsubj == NULL)
68371 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68372 +
68373 + return tmpsubj;
68374 +}
68375 +
68376 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68377 +{
68378 + return __gr_get_subject_for_task(&running_polstate, task, filename);
68379 +}
68380 +
68381 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68382 +{
68383 + struct acl_object_label *obj;
68384 + struct file *filp;
68385 +
68386 + filp = task->exec_file;
68387 +
68388 + task->acl = subj;
68389 + task->is_writable = 0;
68390 + /* ignore additional mmap checks for processes that are writable
68391 + by the default ACL */
68392 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68393 + if (unlikely(obj->mode & GR_WRITE))
68394 + task->is_writable = 1;
68395 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68396 + if (unlikely(obj->mode & GR_WRITE))
68397 + task->is_writable = 1;
68398 +
68399 + gr_set_proc_res(task);
68400 +
68401 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68402 + 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);
68403 +#endif
68404 +}
68405 +
68406 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68407 +{
68408 + __gr_apply_subject_to_task(&running_polstate, task, subj);
68409 +}
68410 +
68411 +__u32
68412 +gr_search_file(const struct dentry * dentry, const __u32 mode,
68413 + const struct vfsmount * mnt)
68414 +{
68415 + __u32 retval = mode;
68416 + struct acl_subject_label *curracl;
68417 + struct acl_object_label *currobj;
68418 +
68419 + if (unlikely(!(gr_status & GR_READY)))
68420 + return (mode & ~GR_AUDITS);
68421 +
68422 + curracl = current->acl;
68423 +
68424 + currobj = chk_obj_label(dentry, mnt, curracl);
68425 + retval = currobj->mode & mode;
68426 +
68427 + /* if we're opening a specified transfer file for writing
68428 + (e.g. /dev/initctl), then transfer our role to init
68429 + */
68430 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68431 + current->role->roletype & GR_ROLE_PERSIST)) {
68432 + struct task_struct *task = init_pid_ns.child_reaper;
68433 +
68434 + if (task->role != current->role) {
68435 + struct acl_subject_label *subj;
68436 +
68437 + task->acl_sp_role = 0;
68438 + task->acl_role_id = current->acl_role_id;
68439 + task->role = current->role;
68440 + rcu_read_lock();
68441 + read_lock(&grsec_exec_file_lock);
68442 + subj = gr_get_subject_for_task(task, NULL);
68443 + gr_apply_subject_to_task(task, subj);
68444 + read_unlock(&grsec_exec_file_lock);
68445 + rcu_read_unlock();
68446 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68447 + }
68448 + }
68449 +
68450 + if (unlikely
68451 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68452 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68453 + __u32 new_mode = mode;
68454 +
68455 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68456 +
68457 + retval = new_mode;
68458 +
68459 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68460 + new_mode |= GR_INHERIT;
68461 +
68462 + if (!(mode & GR_NOLEARN))
68463 + gr_log_learn(dentry, mnt, new_mode);
68464 + }
68465 +
68466 + return retval;
68467 +}
68468 +
68469 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68470 + const struct dentry *parent,
68471 + const struct vfsmount *mnt)
68472 +{
68473 + struct name_entry *match;
68474 + struct acl_object_label *matchpo;
68475 + struct acl_subject_label *curracl;
68476 + char *path;
68477 +
68478 + if (unlikely(!(gr_status & GR_READY)))
68479 + return NULL;
68480 +
68481 + preempt_disable();
68482 + path = gr_to_filename_rbac(new_dentry, mnt);
68483 + match = lookup_name_entry_create(path);
68484 +
68485 + curracl = current->acl;
68486 +
68487 + if (match) {
68488 + read_lock(&gr_inode_lock);
68489 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68490 + read_unlock(&gr_inode_lock);
68491 +
68492 + if (matchpo) {
68493 + preempt_enable();
68494 + return matchpo;
68495 + }
68496 + }
68497 +
68498 + // lookup parent
68499 +
68500 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68501 +
68502 + preempt_enable();
68503 + return matchpo;
68504 +}
68505 +
68506 +__u32
68507 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68508 + const struct vfsmount * mnt, const __u32 mode)
68509 +{
68510 + struct acl_object_label *matchpo;
68511 + __u32 retval;
68512 +
68513 + if (unlikely(!(gr_status & GR_READY)))
68514 + return (mode & ~GR_AUDITS);
68515 +
68516 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
68517 +
68518 + retval = matchpo->mode & mode;
68519 +
68520 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68521 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68522 + __u32 new_mode = mode;
68523 +
68524 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68525 +
68526 + gr_log_learn(new_dentry, mnt, new_mode);
68527 + return new_mode;
68528 + }
68529 +
68530 + return retval;
68531 +}
68532 +
68533 +__u32
68534 +gr_check_link(const struct dentry * new_dentry,
68535 + const struct dentry * parent_dentry,
68536 + const struct vfsmount * parent_mnt,
68537 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68538 +{
68539 + struct acl_object_label *obj;
68540 + __u32 oldmode, newmode;
68541 + __u32 needmode;
68542 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68543 + GR_DELETE | GR_INHERIT;
68544 +
68545 + if (unlikely(!(gr_status & GR_READY)))
68546 + return (GR_CREATE | GR_LINK);
68547 +
68548 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68549 + oldmode = obj->mode;
68550 +
68551 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68552 + newmode = obj->mode;
68553 +
68554 + needmode = newmode & checkmodes;
68555 +
68556 + // old name for hardlink must have at least the permissions of the new name
68557 + if ((oldmode & needmode) != needmode)
68558 + goto bad;
68559 +
68560 + // if old name had restrictions/auditing, make sure the new name does as well
68561 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68562 +
68563 + // don't allow hardlinking of suid/sgid/fcapped files without permission
68564 + if (is_privileged_binary(old_dentry))
68565 + needmode |= GR_SETID;
68566 +
68567 + if ((newmode & needmode) != needmode)
68568 + goto bad;
68569 +
68570 + // enforce minimum permissions
68571 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68572 + return newmode;
68573 +bad:
68574 + needmode = oldmode;
68575 + if (is_privileged_binary(old_dentry))
68576 + needmode |= GR_SETID;
68577 +
68578 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68579 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68580 + return (GR_CREATE | GR_LINK);
68581 + } else if (newmode & GR_SUPPRESS)
68582 + return GR_SUPPRESS;
68583 + else
68584 + return 0;
68585 +}
68586 +
68587 +int
68588 +gr_check_hidden_task(const struct task_struct *task)
68589 +{
68590 + if (unlikely(!(gr_status & GR_READY)))
68591 + return 0;
68592 +
68593 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68594 + return 1;
68595 +
68596 + return 0;
68597 +}
68598 +
68599 +int
68600 +gr_check_protected_task(const struct task_struct *task)
68601 +{
68602 + if (unlikely(!(gr_status & GR_READY) || !task))
68603 + return 0;
68604 +
68605 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68606 + task->acl != current->acl)
68607 + return 1;
68608 +
68609 + return 0;
68610 +}
68611 +
68612 +int
68613 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68614 +{
68615 + struct task_struct *p;
68616 + int ret = 0;
68617 +
68618 + if (unlikely(!(gr_status & GR_READY) || !pid))
68619 + return ret;
68620 +
68621 + read_lock(&tasklist_lock);
68622 + do_each_pid_task(pid, type, p) {
68623 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68624 + p->acl != current->acl) {
68625 + ret = 1;
68626 + goto out;
68627 + }
68628 + } while_each_pid_task(pid, type, p);
68629 +out:
68630 + read_unlock(&tasklist_lock);
68631 +
68632 + return ret;
68633 +}
68634 +
68635 +void
68636 +gr_copy_label(struct task_struct *tsk)
68637 +{
68638 + struct task_struct *p = current;
68639 +
68640 + tsk->inherited = p->inherited;
68641 + tsk->acl_sp_role = 0;
68642 + tsk->acl_role_id = p->acl_role_id;
68643 + tsk->acl = p->acl;
68644 + tsk->role = p->role;
68645 + tsk->signal->used_accept = 0;
68646 + tsk->signal->curr_ip = p->signal->curr_ip;
68647 + tsk->signal->saved_ip = p->signal->saved_ip;
68648 + if (p->exec_file)
68649 + get_file(p->exec_file);
68650 + tsk->exec_file = p->exec_file;
68651 + tsk->is_writable = p->is_writable;
68652 + if (unlikely(p->signal->used_accept)) {
68653 + p->signal->curr_ip = 0;
68654 + p->signal->saved_ip = 0;
68655 + }
68656 +
68657 + return;
68658 +}
68659 +
68660 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68661 +
68662 +int
68663 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68664 +{
68665 + unsigned int i;
68666 + __u16 num;
68667 + uid_t *uidlist;
68668 + uid_t curuid;
68669 + int realok = 0;
68670 + int effectiveok = 0;
68671 + int fsok = 0;
68672 + uid_t globalreal, globaleffective, globalfs;
68673 +
68674 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68675 + struct user_struct *user;
68676 +
68677 + if (!uid_valid(real))
68678 + goto skipit;
68679 +
68680 + /* find user based on global namespace */
68681 +
68682 + globalreal = GR_GLOBAL_UID(real);
68683 +
68684 + user = find_user(make_kuid(&init_user_ns, globalreal));
68685 + if (user == NULL)
68686 + goto skipit;
68687 +
68688 + if (gr_process_kernel_setuid_ban(user)) {
68689 + /* for find_user */
68690 + free_uid(user);
68691 + return 1;
68692 + }
68693 +
68694 + /* for find_user */
68695 + free_uid(user);
68696 +
68697 +skipit:
68698 +#endif
68699 +
68700 + if (unlikely(!(gr_status & GR_READY)))
68701 + return 0;
68702 +
68703 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68704 + gr_log_learn_uid_change(real, effective, fs);
68705 +
68706 + num = current->acl->user_trans_num;
68707 + uidlist = current->acl->user_transitions;
68708 +
68709 + if (uidlist == NULL)
68710 + return 0;
68711 +
68712 + if (!uid_valid(real)) {
68713 + realok = 1;
68714 + globalreal = (uid_t)-1;
68715 + } else {
68716 + globalreal = GR_GLOBAL_UID(real);
68717 + }
68718 + if (!uid_valid(effective)) {
68719 + effectiveok = 1;
68720 + globaleffective = (uid_t)-1;
68721 + } else {
68722 + globaleffective = GR_GLOBAL_UID(effective);
68723 + }
68724 + if (!uid_valid(fs)) {
68725 + fsok = 1;
68726 + globalfs = (uid_t)-1;
68727 + } else {
68728 + globalfs = GR_GLOBAL_UID(fs);
68729 + }
68730 +
68731 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
68732 + for (i = 0; i < num; i++) {
68733 + curuid = uidlist[i];
68734 + if (globalreal == curuid)
68735 + realok = 1;
68736 + if (globaleffective == curuid)
68737 + effectiveok = 1;
68738 + if (globalfs == curuid)
68739 + fsok = 1;
68740 + }
68741 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
68742 + for (i = 0; i < num; i++) {
68743 + curuid = uidlist[i];
68744 + if (globalreal == curuid)
68745 + break;
68746 + if (globaleffective == curuid)
68747 + break;
68748 + if (globalfs == curuid)
68749 + break;
68750 + }
68751 + /* not in deny list */
68752 + if (i == num) {
68753 + realok = 1;
68754 + effectiveok = 1;
68755 + fsok = 1;
68756 + }
68757 + }
68758 +
68759 + if (realok && effectiveok && fsok)
68760 + return 0;
68761 + else {
68762 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68763 + return 1;
68764 + }
68765 +}
68766 +
68767 +int
68768 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68769 +{
68770 + unsigned int i;
68771 + __u16 num;
68772 + gid_t *gidlist;
68773 + gid_t curgid;
68774 + int realok = 0;
68775 + int effectiveok = 0;
68776 + int fsok = 0;
68777 + gid_t globalreal, globaleffective, globalfs;
68778 +
68779 + if (unlikely(!(gr_status & GR_READY)))
68780 + return 0;
68781 +
68782 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68783 + gr_log_learn_gid_change(real, effective, fs);
68784 +
68785 + num = current->acl->group_trans_num;
68786 + gidlist = current->acl->group_transitions;
68787 +
68788 + if (gidlist == NULL)
68789 + return 0;
68790 +
68791 + if (!gid_valid(real)) {
68792 + realok = 1;
68793 + globalreal = (gid_t)-1;
68794 + } else {
68795 + globalreal = GR_GLOBAL_GID(real);
68796 + }
68797 + if (!gid_valid(effective)) {
68798 + effectiveok = 1;
68799 + globaleffective = (gid_t)-1;
68800 + } else {
68801 + globaleffective = GR_GLOBAL_GID(effective);
68802 + }
68803 + if (!gid_valid(fs)) {
68804 + fsok = 1;
68805 + globalfs = (gid_t)-1;
68806 + } else {
68807 + globalfs = GR_GLOBAL_GID(fs);
68808 + }
68809 +
68810 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
68811 + for (i = 0; i < num; i++) {
68812 + curgid = gidlist[i];
68813 + if (globalreal == curgid)
68814 + realok = 1;
68815 + if (globaleffective == curgid)
68816 + effectiveok = 1;
68817 + if (globalfs == curgid)
68818 + fsok = 1;
68819 + }
68820 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
68821 + for (i = 0; i < num; i++) {
68822 + curgid = gidlist[i];
68823 + if (globalreal == curgid)
68824 + break;
68825 + if (globaleffective == curgid)
68826 + break;
68827 + if (globalfs == curgid)
68828 + break;
68829 + }
68830 + /* not in deny list */
68831 + if (i == num) {
68832 + realok = 1;
68833 + effectiveok = 1;
68834 + fsok = 1;
68835 + }
68836 + }
68837 +
68838 + if (realok && effectiveok && fsok)
68839 + return 0;
68840 + else {
68841 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68842 + return 1;
68843 + }
68844 +}
68845 +
68846 +extern int gr_acl_is_capable(const int cap);
68847 +
68848 +void
68849 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68850 +{
68851 + struct acl_role_label *role = task->role;
68852 + struct acl_subject_label *subj = NULL;
68853 + struct acl_object_label *obj;
68854 + struct file *filp;
68855 + uid_t uid;
68856 + gid_t gid;
68857 +
68858 + if (unlikely(!(gr_status & GR_READY)))
68859 + return;
68860 +
68861 + uid = GR_GLOBAL_UID(kuid);
68862 + gid = GR_GLOBAL_GID(kgid);
68863 +
68864 + filp = task->exec_file;
68865 +
68866 + /* kernel process, we'll give them the kernel role */
68867 + if (unlikely(!filp)) {
68868 + task->role = running_polstate.kernel_role;
68869 + task->acl = running_polstate.kernel_role->root_label;
68870 + return;
68871 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68872 + /* save the current ip at time of role lookup so that the proper
68873 + IP will be learned for role_allowed_ip */
68874 + task->signal->saved_ip = task->signal->curr_ip;
68875 + role = lookup_acl_role_label(task, uid, gid);
68876 + }
68877 +
68878 + /* don't change the role if we're not a privileged process */
68879 + if (role && task->role != role &&
68880 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68881 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68882 + return;
68883 +
68884 + /* perform subject lookup in possibly new role
68885 + we can use this result below in the case where role == task->role
68886 + */
68887 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68888 +
68889 + /* if we changed uid/gid, but result in the same role
68890 + and are using inheritance, don't lose the inherited subject
68891 + if current subject is other than what normal lookup
68892 + would result in, we arrived via inheritance, don't
68893 + lose subject
68894 + */
68895 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68896 + (subj == task->acl)))
68897 + task->acl = subj;
68898 +
68899 + /* leave task->inherited unaffected */
68900 +
68901 + task->role = role;
68902 +
68903 + task->is_writable = 0;
68904 +
68905 + /* ignore additional mmap checks for processes that are writable
68906 + by the default ACL */
68907 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68908 + if (unlikely(obj->mode & GR_WRITE))
68909 + task->is_writable = 1;
68910 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68911 + if (unlikely(obj->mode & GR_WRITE))
68912 + task->is_writable = 1;
68913 +
68914 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68915 + 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);
68916 +#endif
68917 +
68918 + gr_set_proc_res(task);
68919 +
68920 + return;
68921 +}
68922 +
68923 +int
68924 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68925 + const int unsafe_flags)
68926 +{
68927 + struct task_struct *task = current;
68928 + struct acl_subject_label *newacl;
68929 + struct acl_object_label *obj;
68930 + __u32 retmode;
68931 +
68932 + if (unlikely(!(gr_status & GR_READY)))
68933 + return 0;
68934 +
68935 + newacl = chk_subj_label(dentry, mnt, task->role);
68936 +
68937 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68938 + did an exec
68939 + */
68940 + rcu_read_lock();
68941 + read_lock(&tasklist_lock);
68942 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68943 + (task->parent->acl->mode & GR_POVERRIDE))) {
68944 + read_unlock(&tasklist_lock);
68945 + rcu_read_unlock();
68946 + goto skip_check;
68947 + }
68948 + read_unlock(&tasklist_lock);
68949 + rcu_read_unlock();
68950 +
68951 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68952 + !(task->role->roletype & GR_ROLE_GOD) &&
68953 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68954 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68955 + if (unsafe_flags & LSM_UNSAFE_SHARE)
68956 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68957 + else
68958 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68959 + return -EACCES;
68960 + }
68961 +
68962 +skip_check:
68963 +
68964 + obj = chk_obj_label(dentry, mnt, task->acl);
68965 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68966 +
68967 + if (!(task->acl->mode & GR_INHERITLEARN) &&
68968 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68969 + if (obj->nested)
68970 + task->acl = obj->nested;
68971 + else
68972 + task->acl = newacl;
68973 + task->inherited = 0;
68974 + } else {
68975 + task->inherited = 1;
68976 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68977 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68978 + }
68979 +
68980 + task->is_writable = 0;
68981 +
68982 + /* ignore additional mmap checks for processes that are writable
68983 + by the default ACL */
68984 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68985 + if (unlikely(obj->mode & GR_WRITE))
68986 + task->is_writable = 1;
68987 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
68988 + if (unlikely(obj->mode & GR_WRITE))
68989 + task->is_writable = 1;
68990 +
68991 + gr_set_proc_res(task);
68992 +
68993 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68994 + 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);
68995 +#endif
68996 + return 0;
68997 +}
68998 +
68999 +/* always called with valid inodev ptr */
69000 +static void
69001 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
69002 +{
69003 + struct acl_object_label *matchpo;
69004 + struct acl_subject_label *matchps;
69005 + struct acl_subject_label *subj;
69006 + struct acl_role_label *role;
69007 + unsigned int x;
69008 +
69009 + FOR_EACH_ROLE_START(role)
69010 + FOR_EACH_SUBJECT_START(role, subj, x)
69011 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69012 + matchpo->mode |= GR_DELETED;
69013 + FOR_EACH_SUBJECT_END(subj,x)
69014 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
69015 + /* nested subjects aren't in the role's subj_hash table */
69016 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69017 + matchpo->mode |= GR_DELETED;
69018 + FOR_EACH_NESTED_SUBJECT_END(subj)
69019 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
69020 + matchps->mode |= GR_DELETED;
69021 + FOR_EACH_ROLE_END(role)
69022 +
69023 + inodev->nentry->deleted = 1;
69024 +
69025 + return;
69026 +}
69027 +
69028 +void
69029 +gr_handle_delete(const ino_t ino, const dev_t dev)
69030 +{
69031 + struct inodev_entry *inodev;
69032 +
69033 + if (unlikely(!(gr_status & GR_READY)))
69034 + return;
69035 +
69036 + write_lock(&gr_inode_lock);
69037 + inodev = lookup_inodev_entry(ino, dev);
69038 + if (inodev != NULL)
69039 + do_handle_delete(inodev, ino, dev);
69040 + write_unlock(&gr_inode_lock);
69041 +
69042 + return;
69043 +}
69044 +
69045 +static void
69046 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
69047 + const ino_t newinode, const dev_t newdevice,
69048 + struct acl_subject_label *subj)
69049 +{
69050 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
69051 + struct acl_object_label *match;
69052 +
69053 + match = subj->obj_hash[index];
69054 +
69055 + while (match && (match->inode != oldinode ||
69056 + match->device != olddevice ||
69057 + !(match->mode & GR_DELETED)))
69058 + match = match->next;
69059 +
69060 + if (match && (match->inode == oldinode)
69061 + && (match->device == olddevice)
69062 + && (match->mode & GR_DELETED)) {
69063 + if (match->prev == NULL) {
69064 + subj->obj_hash[index] = match->next;
69065 + if (match->next != NULL)
69066 + match->next->prev = NULL;
69067 + } else {
69068 + match->prev->next = match->next;
69069 + if (match->next != NULL)
69070 + match->next->prev = match->prev;
69071 + }
69072 + match->prev = NULL;
69073 + match->next = NULL;
69074 + match->inode = newinode;
69075 + match->device = newdevice;
69076 + match->mode &= ~GR_DELETED;
69077 +
69078 + insert_acl_obj_label(match, subj);
69079 + }
69080 +
69081 + return;
69082 +}
69083 +
69084 +static void
69085 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
69086 + const ino_t newinode, const dev_t newdevice,
69087 + struct acl_role_label *role)
69088 +{
69089 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
69090 + struct acl_subject_label *match;
69091 +
69092 + match = role->subj_hash[index];
69093 +
69094 + while (match && (match->inode != oldinode ||
69095 + match->device != olddevice ||
69096 + !(match->mode & GR_DELETED)))
69097 + match = match->next;
69098 +
69099 + if (match && (match->inode == oldinode)
69100 + && (match->device == olddevice)
69101 + && (match->mode & GR_DELETED)) {
69102 + if (match->prev == NULL) {
69103 + role->subj_hash[index] = match->next;
69104 + if (match->next != NULL)
69105 + match->next->prev = NULL;
69106 + } else {
69107 + match->prev->next = match->next;
69108 + if (match->next != NULL)
69109 + match->next->prev = match->prev;
69110 + }
69111 + match->prev = NULL;
69112 + match->next = NULL;
69113 + match->inode = newinode;
69114 + match->device = newdevice;
69115 + match->mode &= ~GR_DELETED;
69116 +
69117 + insert_acl_subj_label(match, role);
69118 + }
69119 +
69120 + return;
69121 +}
69122 +
69123 +static void
69124 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
69125 + const ino_t newinode, const dev_t newdevice)
69126 +{
69127 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
69128 + struct inodev_entry *match;
69129 +
69130 + match = running_polstate.inodev_set.i_hash[index];
69131 +
69132 + while (match && (match->nentry->inode != oldinode ||
69133 + match->nentry->device != olddevice || !match->nentry->deleted))
69134 + match = match->next;
69135 +
69136 + if (match && (match->nentry->inode == oldinode)
69137 + && (match->nentry->device == olddevice) &&
69138 + match->nentry->deleted) {
69139 + if (match->prev == NULL) {
69140 + running_polstate.inodev_set.i_hash[index] = match->next;
69141 + if (match->next != NULL)
69142 + match->next->prev = NULL;
69143 + } else {
69144 + match->prev->next = match->next;
69145 + if (match->next != NULL)
69146 + match->next->prev = match->prev;
69147 + }
69148 + match->prev = NULL;
69149 + match->next = NULL;
69150 + match->nentry->inode = newinode;
69151 + match->nentry->device = newdevice;
69152 + match->nentry->deleted = 0;
69153 +
69154 + insert_inodev_entry(match);
69155 + }
69156 +
69157 + return;
69158 +}
69159 +
69160 +static void
69161 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
69162 +{
69163 + struct acl_subject_label *subj;
69164 + struct acl_role_label *role;
69165 + unsigned int x;
69166 +
69167 + FOR_EACH_ROLE_START(role)
69168 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
69169 +
69170 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
69171 + if ((subj->inode == ino) && (subj->device == dev)) {
69172 + subj->inode = ino;
69173 + subj->device = dev;
69174 + }
69175 + /* nested subjects aren't in the role's subj_hash table */
69176 + update_acl_obj_label(matchn->inode, matchn->device,
69177 + ino, dev, subj);
69178 + FOR_EACH_NESTED_SUBJECT_END(subj)
69179 + FOR_EACH_SUBJECT_START(role, subj, x)
69180 + update_acl_obj_label(matchn->inode, matchn->device,
69181 + ino, dev, subj);
69182 + FOR_EACH_SUBJECT_END(subj,x)
69183 + FOR_EACH_ROLE_END(role)
69184 +
69185 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
69186 +
69187 + return;
69188 +}
69189 +
69190 +static void
69191 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
69192 + const struct vfsmount *mnt)
69193 +{
69194 + ino_t ino = dentry->d_inode->i_ino;
69195 + dev_t dev = __get_dev(dentry);
69196 +
69197 + __do_handle_create(matchn, ino, dev);
69198 +
69199 + return;
69200 +}
69201 +
69202 +void
69203 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69204 +{
69205 + struct name_entry *matchn;
69206 +
69207 + if (unlikely(!(gr_status & GR_READY)))
69208 + return;
69209 +
69210 + preempt_disable();
69211 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
69212 +
69213 + if (unlikely((unsigned long)matchn)) {
69214 + write_lock(&gr_inode_lock);
69215 + do_handle_create(matchn, dentry, mnt);
69216 + write_unlock(&gr_inode_lock);
69217 + }
69218 + preempt_enable();
69219 +
69220 + return;
69221 +}
69222 +
69223 +void
69224 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
69225 +{
69226 + struct name_entry *matchn;
69227 +
69228 + if (unlikely(!(gr_status & GR_READY)))
69229 + return;
69230 +
69231 + preempt_disable();
69232 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
69233 +
69234 + if (unlikely((unsigned long)matchn)) {
69235 + write_lock(&gr_inode_lock);
69236 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
69237 + write_unlock(&gr_inode_lock);
69238 + }
69239 + preempt_enable();
69240 +
69241 + return;
69242 +}
69243 +
69244 +void
69245 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69246 + struct dentry *old_dentry,
69247 + struct dentry *new_dentry,
69248 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
69249 +{
69250 + struct name_entry *matchn;
69251 + struct name_entry *matchn2 = NULL;
69252 + struct inodev_entry *inodev;
69253 + struct inode *inode = new_dentry->d_inode;
69254 + ino_t old_ino = old_dentry->d_inode->i_ino;
69255 + dev_t old_dev = __get_dev(old_dentry);
69256 + unsigned int exchange = flags & RENAME_EXCHANGE;
69257 +
69258 + /* vfs_rename swaps the name and parent link for old_dentry and
69259 + new_dentry
69260 + at this point, old_dentry has the new name, parent link, and inode
69261 + for the renamed file
69262 + if a file is being replaced by a rename, new_dentry has the inode
69263 + and name for the replaced file
69264 + */
69265 +
69266 + if (unlikely(!(gr_status & GR_READY)))
69267 + return;
69268 +
69269 + preempt_disable();
69270 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
69271 +
69272 + /* exchange cases:
69273 + a filename exists for the source, but not dest
69274 + do a recreate on source
69275 + a filename exists for the dest, but not source
69276 + do a recreate on dest
69277 + a filename exists for both source and dest
69278 + delete source and dest, then create source and dest
69279 + a filename exists for neither source nor dest
69280 + no updates needed
69281 +
69282 + the name entry lookups get us the old inode/dev associated with
69283 + each name, so do the deletes first (if possible) so that when
69284 + we do the create, we pick up on the right entries
69285 + */
69286 +
69287 + if (exchange)
69288 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
69289 +
69290 + /* we wouldn't have to check d_inode if it weren't for
69291 + NFS silly-renaming
69292 + */
69293 +
69294 + write_lock(&gr_inode_lock);
69295 + if (unlikely((replace || exchange) && inode)) {
69296 + ino_t new_ino = inode->i_ino;
69297 + dev_t new_dev = __get_dev(new_dentry);
69298 +
69299 + inodev = lookup_inodev_entry(new_ino, new_dev);
69300 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
69301 + do_handle_delete(inodev, new_ino, new_dev);
69302 + }
69303 +
69304 + inodev = lookup_inodev_entry(old_ino, old_dev);
69305 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
69306 + do_handle_delete(inodev, old_ino, old_dev);
69307 +
69308 + if (unlikely(matchn != NULL))
69309 + do_handle_create(matchn, old_dentry, mnt);
69310 +
69311 + if (unlikely(matchn2 != NULL))
69312 + do_handle_create(matchn2, new_dentry, mnt);
69313 +
69314 + write_unlock(&gr_inode_lock);
69315 + preempt_enable();
69316 +
69317 + return;
69318 +}
69319 +
69320 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
69321 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
69322 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
69323 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
69324 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
69325 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
69326 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
69327 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
69328 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
69329 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
69330 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
69331 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
69332 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
69333 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
69334 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
69335 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
69336 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
69337 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
69338 +};
69339 +
69340 +void
69341 +gr_learn_resource(const struct task_struct *task,
69342 + const int res, const unsigned long wanted, const int gt)
69343 +{
69344 + struct acl_subject_label *acl;
69345 + const struct cred *cred;
69346 +
69347 + if (unlikely((gr_status & GR_READY) &&
69348 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
69349 + goto skip_reslog;
69350 +
69351 + gr_log_resource(task, res, wanted, gt);
69352 +skip_reslog:
69353 +
69354 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
69355 + return;
69356 +
69357 + acl = task->acl;
69358 +
69359 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
69360 + !(acl->resmask & (1U << (unsigned short) res))))
69361 + return;
69362 +
69363 + if (wanted >= acl->res[res].rlim_cur) {
69364 + unsigned long res_add;
69365 +
69366 + res_add = wanted + res_learn_bumps[res];
69367 +
69368 + acl->res[res].rlim_cur = res_add;
69369 +
69370 + if (wanted > acl->res[res].rlim_max)
69371 + acl->res[res].rlim_max = res_add;
69372 +
69373 + /* only log the subject filename, since resource logging is supported for
69374 + single-subject learning only */
69375 + rcu_read_lock();
69376 + cred = __task_cred(task);
69377 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69378 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69379 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69380 + "", (unsigned long) res, &task->signal->saved_ip);
69381 + rcu_read_unlock();
69382 + }
69383 +
69384 + return;
69385 +}
69386 +EXPORT_SYMBOL_GPL(gr_learn_resource);
69387 +#endif
69388 +
69389 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69390 +void
69391 +pax_set_initial_flags(struct linux_binprm *bprm)
69392 +{
69393 + struct task_struct *task = current;
69394 + struct acl_subject_label *proc;
69395 + unsigned long flags;
69396 +
69397 + if (unlikely(!(gr_status & GR_READY)))
69398 + return;
69399 +
69400 + flags = pax_get_flags(task);
69401 +
69402 + proc = task->acl;
69403 +
69404 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69405 + flags &= ~MF_PAX_PAGEEXEC;
69406 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69407 + flags &= ~MF_PAX_SEGMEXEC;
69408 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69409 + flags &= ~MF_PAX_RANDMMAP;
69410 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69411 + flags &= ~MF_PAX_EMUTRAMP;
69412 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69413 + flags &= ~MF_PAX_MPROTECT;
69414 +
69415 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69416 + flags |= MF_PAX_PAGEEXEC;
69417 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69418 + flags |= MF_PAX_SEGMEXEC;
69419 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69420 + flags |= MF_PAX_RANDMMAP;
69421 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69422 + flags |= MF_PAX_EMUTRAMP;
69423 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69424 + flags |= MF_PAX_MPROTECT;
69425 +
69426 + pax_set_flags(task, flags);
69427 +
69428 + return;
69429 +}
69430 +#endif
69431 +
69432 +int
69433 +gr_handle_proc_ptrace(struct task_struct *task)
69434 +{
69435 + struct file *filp;
69436 + struct task_struct *tmp = task;
69437 + struct task_struct *curtemp = current;
69438 + __u32 retmode;
69439 +
69440 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69441 + if (unlikely(!(gr_status & GR_READY)))
69442 + return 0;
69443 +#endif
69444 +
69445 + read_lock(&tasklist_lock);
69446 + read_lock(&grsec_exec_file_lock);
69447 + filp = task->exec_file;
69448 +
69449 + while (task_pid_nr(tmp) > 0) {
69450 + if (tmp == curtemp)
69451 + break;
69452 + tmp = tmp->real_parent;
69453 + }
69454 +
69455 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69456 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69457 + read_unlock(&grsec_exec_file_lock);
69458 + read_unlock(&tasklist_lock);
69459 + return 1;
69460 + }
69461 +
69462 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69463 + if (!(gr_status & GR_READY)) {
69464 + read_unlock(&grsec_exec_file_lock);
69465 + read_unlock(&tasklist_lock);
69466 + return 0;
69467 + }
69468 +#endif
69469 +
69470 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69471 + read_unlock(&grsec_exec_file_lock);
69472 + read_unlock(&tasklist_lock);
69473 +
69474 + if (retmode & GR_NOPTRACE)
69475 + return 1;
69476 +
69477 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69478 + && (current->acl != task->acl || (current->acl != current->role->root_label
69479 + && task_pid_nr(current) != task_pid_nr(task))))
69480 + return 1;
69481 +
69482 + return 0;
69483 +}
69484 +
69485 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69486 +{
69487 + if (unlikely(!(gr_status & GR_READY)))
69488 + return;
69489 +
69490 + if (!(current->role->roletype & GR_ROLE_GOD))
69491 + return;
69492 +
69493 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69494 + p->role->rolename, gr_task_roletype_to_char(p),
69495 + p->acl->filename);
69496 +}
69497 +
69498 +int
69499 +gr_handle_ptrace(struct task_struct *task, const long request)
69500 +{
69501 + struct task_struct *tmp = task;
69502 + struct task_struct *curtemp = current;
69503 + __u32 retmode;
69504 +
69505 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69506 + if (unlikely(!(gr_status & GR_READY)))
69507 + return 0;
69508 +#endif
69509 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69510 + read_lock(&tasklist_lock);
69511 + while (task_pid_nr(tmp) > 0) {
69512 + if (tmp == curtemp)
69513 + break;
69514 + tmp = tmp->real_parent;
69515 + }
69516 +
69517 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69518 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69519 + read_unlock(&tasklist_lock);
69520 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69521 + return 1;
69522 + }
69523 + read_unlock(&tasklist_lock);
69524 + }
69525 +
69526 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69527 + if (!(gr_status & GR_READY))
69528 + return 0;
69529 +#endif
69530 +
69531 + read_lock(&grsec_exec_file_lock);
69532 + if (unlikely(!task->exec_file)) {
69533 + read_unlock(&grsec_exec_file_lock);
69534 + return 0;
69535 + }
69536 +
69537 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69538 + read_unlock(&grsec_exec_file_lock);
69539 +
69540 + if (retmode & GR_NOPTRACE) {
69541 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69542 + return 1;
69543 + }
69544 +
69545 + if (retmode & GR_PTRACERD) {
69546 + switch (request) {
69547 + case PTRACE_SEIZE:
69548 + case PTRACE_POKETEXT:
69549 + case PTRACE_POKEDATA:
69550 + case PTRACE_POKEUSR:
69551 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69552 + case PTRACE_SETREGS:
69553 + case PTRACE_SETFPREGS:
69554 +#endif
69555 +#ifdef CONFIG_X86
69556 + case PTRACE_SETFPXREGS:
69557 +#endif
69558 +#ifdef CONFIG_ALTIVEC
69559 + case PTRACE_SETVRREGS:
69560 +#endif
69561 + return 1;
69562 + default:
69563 + return 0;
69564 + }
69565 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
69566 + !(current->role->roletype & GR_ROLE_GOD) &&
69567 + (current->acl != task->acl)) {
69568 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69569 + return 1;
69570 + }
69571 +
69572 + return 0;
69573 +}
69574 +
69575 +static int is_writable_mmap(const struct file *filp)
69576 +{
69577 + struct task_struct *task = current;
69578 + struct acl_object_label *obj, *obj2;
69579 +
69580 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69581 + !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))) {
69582 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69583 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69584 + task->role->root_label);
69585 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69586 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69587 + return 1;
69588 + }
69589 + }
69590 + return 0;
69591 +}
69592 +
69593 +int
69594 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69595 +{
69596 + __u32 mode;
69597 +
69598 + if (unlikely(!file || !(prot & PROT_EXEC)))
69599 + return 1;
69600 +
69601 + if (is_writable_mmap(file))
69602 + return 0;
69603 +
69604 + mode =
69605 + gr_search_file(file->f_path.dentry,
69606 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69607 + file->f_path.mnt);
69608 +
69609 + if (!gr_tpe_allow(file))
69610 + return 0;
69611 +
69612 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69613 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69614 + return 0;
69615 + } else if (unlikely(!(mode & GR_EXEC))) {
69616 + return 0;
69617 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69618 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69619 + return 1;
69620 + }
69621 +
69622 + return 1;
69623 +}
69624 +
69625 +int
69626 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69627 +{
69628 + __u32 mode;
69629 +
69630 + if (unlikely(!file || !(prot & PROT_EXEC)))
69631 + return 1;
69632 +
69633 + if (is_writable_mmap(file))
69634 + return 0;
69635 +
69636 + mode =
69637 + gr_search_file(file->f_path.dentry,
69638 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69639 + file->f_path.mnt);
69640 +
69641 + if (!gr_tpe_allow(file))
69642 + return 0;
69643 +
69644 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69645 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69646 + return 0;
69647 + } else if (unlikely(!(mode & GR_EXEC))) {
69648 + return 0;
69649 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69650 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69651 + return 1;
69652 + }
69653 +
69654 + return 1;
69655 +}
69656 +
69657 +void
69658 +gr_acl_handle_psacct(struct task_struct *task, const long code)
69659 +{
69660 + unsigned long runtime, cputime;
69661 + cputime_t utime, stime;
69662 + unsigned int wday, cday;
69663 + __u8 whr, chr;
69664 + __u8 wmin, cmin;
69665 + __u8 wsec, csec;
69666 + struct timespec timeval;
69667 +
69668 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69669 + !(task->acl->mode & GR_PROCACCT)))
69670 + return;
69671 +
69672 + do_posix_clock_monotonic_gettime(&timeval);
69673 + runtime = timeval.tv_sec - task->start_time.tv_sec;
69674 + wday = runtime / (60 * 60 * 24);
69675 + runtime -= wday * (60 * 60 * 24);
69676 + whr = runtime / (60 * 60);
69677 + runtime -= whr * (60 * 60);
69678 + wmin = runtime / 60;
69679 + runtime -= wmin * 60;
69680 + wsec = runtime;
69681 +
69682 + task_cputime(task, &utime, &stime);
69683 + cputime = cputime_to_secs(utime + stime);
69684 + cday = cputime / (60 * 60 * 24);
69685 + cputime -= cday * (60 * 60 * 24);
69686 + chr = cputime / (60 * 60);
69687 + cputime -= chr * (60 * 60);
69688 + cmin = cputime / 60;
69689 + cputime -= cmin * 60;
69690 + csec = cputime;
69691 +
69692 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69693 +
69694 + return;
69695 +}
69696 +
69697 +#ifdef CONFIG_TASKSTATS
69698 +int gr_is_taskstats_denied(int pid)
69699 +{
69700 + struct task_struct *task;
69701 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69702 + const struct cred *cred;
69703 +#endif
69704 + int ret = 0;
69705 +
69706 + /* restrict taskstats viewing to un-chrooted root users
69707 + who have the 'view' subject flag if the RBAC system is enabled
69708 + */
69709 +
69710 + rcu_read_lock();
69711 + read_lock(&tasklist_lock);
69712 + task = find_task_by_vpid(pid);
69713 + if (task) {
69714 +#ifdef CONFIG_GRKERNSEC_CHROOT
69715 + if (proc_is_chrooted(task))
69716 + ret = -EACCES;
69717 +#endif
69718 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69719 + cred = __task_cred(task);
69720 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69721 + if (gr_is_global_nonroot(cred->uid))
69722 + ret = -EACCES;
69723 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69724 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69725 + ret = -EACCES;
69726 +#endif
69727 +#endif
69728 + if (gr_status & GR_READY) {
69729 + if (!(task->acl->mode & GR_VIEW))
69730 + ret = -EACCES;
69731 + }
69732 + } else
69733 + ret = -ENOENT;
69734 +
69735 + read_unlock(&tasklist_lock);
69736 + rcu_read_unlock();
69737 +
69738 + return ret;
69739 +}
69740 +#endif
69741 +
69742 +/* AUXV entries are filled via a descendant of search_binary_handler
69743 + after we've already applied the subject for the target
69744 +*/
69745 +int gr_acl_enable_at_secure(void)
69746 +{
69747 + if (unlikely(!(gr_status & GR_READY)))
69748 + return 0;
69749 +
69750 + if (current->acl->mode & GR_ATSECURE)
69751 + return 1;
69752 +
69753 + return 0;
69754 +}
69755 +
69756 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69757 +{
69758 + struct task_struct *task = current;
69759 + struct dentry *dentry = file->f_path.dentry;
69760 + struct vfsmount *mnt = file->f_path.mnt;
69761 + struct acl_object_label *obj, *tmp;
69762 + struct acl_subject_label *subj;
69763 + unsigned int bufsize;
69764 + int is_not_root;
69765 + char *path;
69766 + dev_t dev = __get_dev(dentry);
69767 +
69768 + if (unlikely(!(gr_status & GR_READY)))
69769 + return 1;
69770 +
69771 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69772 + return 1;
69773 +
69774 + /* ignore Eric Biederman */
69775 + if (IS_PRIVATE(dentry->d_inode))
69776 + return 1;
69777 +
69778 + subj = task->acl;
69779 + read_lock(&gr_inode_lock);
69780 + do {
69781 + obj = lookup_acl_obj_label(ino, dev, subj);
69782 + if (obj != NULL) {
69783 + read_unlock(&gr_inode_lock);
69784 + return (obj->mode & GR_FIND) ? 1 : 0;
69785 + }
69786 + } while ((subj = subj->parent_subject));
69787 + read_unlock(&gr_inode_lock);
69788 +
69789 + /* this is purely an optimization since we're looking for an object
69790 + for the directory we're doing a readdir on
69791 + if it's possible for any globbed object to match the entry we're
69792 + filling into the directory, then the object we find here will be
69793 + an anchor point with attached globbed objects
69794 + */
69795 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69796 + if (obj->globbed == NULL)
69797 + return (obj->mode & GR_FIND) ? 1 : 0;
69798 +
69799 + is_not_root = ((obj->filename[0] == '/') &&
69800 + (obj->filename[1] == '\0')) ? 0 : 1;
69801 + bufsize = PAGE_SIZE - namelen - is_not_root;
69802 +
69803 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
69804 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69805 + return 1;
69806 +
69807 + preempt_disable();
69808 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69809 + bufsize);
69810 +
69811 + bufsize = strlen(path);
69812 +
69813 + /* if base is "/", don't append an additional slash */
69814 + if (is_not_root)
69815 + *(path + bufsize) = '/';
69816 + memcpy(path + bufsize + is_not_root, name, namelen);
69817 + *(path + bufsize + namelen + is_not_root) = '\0';
69818 +
69819 + tmp = obj->globbed;
69820 + while (tmp) {
69821 + if (!glob_match(tmp->filename, path)) {
69822 + preempt_enable();
69823 + return (tmp->mode & GR_FIND) ? 1 : 0;
69824 + }
69825 + tmp = tmp->next;
69826 + }
69827 + preempt_enable();
69828 + return (obj->mode & GR_FIND) ? 1 : 0;
69829 +}
69830 +
69831 +void gr_put_exec_file(struct task_struct *task)
69832 +{
69833 + struct file *filp;
69834 +
69835 + write_lock(&grsec_exec_file_lock);
69836 + filp = task->exec_file;
69837 + task->exec_file = NULL;
69838 + write_unlock(&grsec_exec_file_lock);
69839 +
69840 + if (filp)
69841 + fput(filp);
69842 +
69843 + return;
69844 +}
69845 +
69846 +
69847 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69848 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69849 +#endif
69850 +#ifdef CONFIG_SECURITY
69851 +EXPORT_SYMBOL_GPL(gr_check_user_change);
69852 +EXPORT_SYMBOL_GPL(gr_check_group_change);
69853 +#endif
69854 +
69855 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69856 new file mode 100644
69857 index 0000000..18ffbbd
69858 --- /dev/null
69859 +++ b/grsecurity/gracl_alloc.c
69860 @@ -0,0 +1,105 @@
69861 +#include <linux/kernel.h>
69862 +#include <linux/mm.h>
69863 +#include <linux/slab.h>
69864 +#include <linux/vmalloc.h>
69865 +#include <linux/gracl.h>
69866 +#include <linux/grsecurity.h>
69867 +
69868 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69869 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69870 +
69871 +static __inline__ int
69872 +alloc_pop(void)
69873 +{
69874 + if (current_alloc_state->alloc_stack_next == 1)
69875 + return 0;
69876 +
69877 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69878 +
69879 + current_alloc_state->alloc_stack_next--;
69880 +
69881 + return 1;
69882 +}
69883 +
69884 +static __inline__ int
69885 +alloc_push(void *buf)
69886 +{
69887 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69888 + return 1;
69889 +
69890 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69891 +
69892 + current_alloc_state->alloc_stack_next++;
69893 +
69894 + return 0;
69895 +}
69896 +
69897 +void *
69898 +acl_alloc(unsigned long len)
69899 +{
69900 + void *ret = NULL;
69901 +
69902 + if (!len || len > PAGE_SIZE)
69903 + goto out;
69904 +
69905 + ret = kmalloc(len, GFP_KERNEL);
69906 +
69907 + if (ret) {
69908 + if (alloc_push(ret)) {
69909 + kfree(ret);
69910 + ret = NULL;
69911 + }
69912 + }
69913 +
69914 +out:
69915 + return ret;
69916 +}
69917 +
69918 +void *
69919 +acl_alloc_num(unsigned long num, unsigned long len)
69920 +{
69921 + if (!len || (num > (PAGE_SIZE / len)))
69922 + return NULL;
69923 +
69924 + return acl_alloc(num * len);
69925 +}
69926 +
69927 +void
69928 +acl_free_all(void)
69929 +{
69930 + if (!current_alloc_state->alloc_stack)
69931 + return;
69932 +
69933 + while (alloc_pop()) ;
69934 +
69935 + if (current_alloc_state->alloc_stack) {
69936 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69937 + kfree(current_alloc_state->alloc_stack);
69938 + else
69939 + vfree(current_alloc_state->alloc_stack);
69940 + }
69941 +
69942 + current_alloc_state->alloc_stack = NULL;
69943 + current_alloc_state->alloc_stack_size = 1;
69944 + current_alloc_state->alloc_stack_next = 1;
69945 +
69946 + return;
69947 +}
69948 +
69949 +int
69950 +acl_alloc_stack_init(unsigned long size)
69951 +{
69952 + if ((size * sizeof (void *)) <= PAGE_SIZE)
69953 + current_alloc_state->alloc_stack =
69954 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69955 + else
69956 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69957 +
69958 + current_alloc_state->alloc_stack_size = size;
69959 + current_alloc_state->alloc_stack_next = 1;
69960 +
69961 + if (!current_alloc_state->alloc_stack)
69962 + return 0;
69963 + else
69964 + return 1;
69965 +}
69966 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69967 new file mode 100644
69968 index 0000000..bdd51ea
69969 --- /dev/null
69970 +++ b/grsecurity/gracl_cap.c
69971 @@ -0,0 +1,110 @@
69972 +#include <linux/kernel.h>
69973 +#include <linux/module.h>
69974 +#include <linux/sched.h>
69975 +#include <linux/gracl.h>
69976 +#include <linux/grsecurity.h>
69977 +#include <linux/grinternal.h>
69978 +
69979 +extern const char *captab_log[];
69980 +extern int captab_log_entries;
69981 +
69982 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69983 +{
69984 + struct acl_subject_label *curracl;
69985 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69986 + kernel_cap_t cap_audit = __cap_empty_set;
69987 +
69988 + if (!gr_acl_is_enabled())
69989 + return 1;
69990 +
69991 + curracl = task->acl;
69992 +
69993 + cap_drop = curracl->cap_lower;
69994 + cap_mask = curracl->cap_mask;
69995 + cap_audit = curracl->cap_invert_audit;
69996 +
69997 + while ((curracl = curracl->parent_subject)) {
69998 + /* if the cap isn't specified in the current computed mask but is specified in the
69999 + current level subject, and is lowered in the current level subject, then add
70000 + it to the set of dropped capabilities
70001 + otherwise, add the current level subject's mask to the current computed mask
70002 + */
70003 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70004 + cap_raise(cap_mask, cap);
70005 + if (cap_raised(curracl->cap_lower, cap))
70006 + cap_raise(cap_drop, cap);
70007 + if (cap_raised(curracl->cap_invert_audit, cap))
70008 + cap_raise(cap_audit, cap);
70009 + }
70010 + }
70011 +
70012 + if (!cap_raised(cap_drop, cap)) {
70013 + if (cap_raised(cap_audit, cap))
70014 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
70015 + return 1;
70016 + }
70017 +
70018 + curracl = task->acl;
70019 +
70020 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
70021 + && cap_raised(cred->cap_effective, cap)) {
70022 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
70023 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
70024 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
70025 + gr_to_filename(task->exec_file->f_path.dentry,
70026 + task->exec_file->f_path.mnt) : curracl->filename,
70027 + curracl->filename, 0UL,
70028 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
70029 + return 1;
70030 + }
70031 +
70032 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
70033 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
70034 +
70035 + return 0;
70036 +}
70037 +
70038 +int
70039 +gr_acl_is_capable(const int cap)
70040 +{
70041 + return gr_task_acl_is_capable(current, current_cred(), cap);
70042 +}
70043 +
70044 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
70045 +{
70046 + struct acl_subject_label *curracl;
70047 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70048 +
70049 + if (!gr_acl_is_enabled())
70050 + return 1;
70051 +
70052 + curracl = task->acl;
70053 +
70054 + cap_drop = curracl->cap_lower;
70055 + cap_mask = curracl->cap_mask;
70056 +
70057 + while ((curracl = curracl->parent_subject)) {
70058 + /* if the cap isn't specified in the current computed mask but is specified in the
70059 + current level subject, and is lowered in the current level subject, then add
70060 + it to the set of dropped capabilities
70061 + otherwise, add the current level subject's mask to the current computed mask
70062 + */
70063 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70064 + cap_raise(cap_mask, cap);
70065 + if (cap_raised(curracl->cap_lower, cap))
70066 + cap_raise(cap_drop, cap);
70067 + }
70068 + }
70069 +
70070 + if (!cap_raised(cap_drop, cap))
70071 + return 1;
70072 +
70073 + return 0;
70074 +}
70075 +
70076 +int
70077 +gr_acl_is_capable_nolog(const int cap)
70078 +{
70079 + return gr_task_acl_is_capable_nolog(current, cap);
70080 +}
70081 +
70082 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
70083 new file mode 100644
70084 index 0000000..ca25605
70085 --- /dev/null
70086 +++ b/grsecurity/gracl_compat.c
70087 @@ -0,0 +1,270 @@
70088 +#include <linux/kernel.h>
70089 +#include <linux/gracl.h>
70090 +#include <linux/compat.h>
70091 +#include <linux/gracl_compat.h>
70092 +
70093 +#include <asm/uaccess.h>
70094 +
70095 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
70096 +{
70097 + struct gr_arg_wrapper_compat uwrapcompat;
70098 +
70099 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
70100 + return -EFAULT;
70101 +
70102 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
70103 + (uwrapcompat.version != 0x2901)) ||
70104 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
70105 + return -EINVAL;
70106 +
70107 + uwrap->arg = compat_ptr(uwrapcompat.arg);
70108 + uwrap->version = uwrapcompat.version;
70109 + uwrap->size = sizeof(struct gr_arg);
70110 +
70111 + return 0;
70112 +}
70113 +
70114 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
70115 +{
70116 + struct gr_arg_compat argcompat;
70117 +
70118 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
70119 + return -EFAULT;
70120 +
70121 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
70122 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
70123 + arg->role_db.num_roles = argcompat.role_db.num_roles;
70124 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
70125 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
70126 + arg->role_db.num_objects = argcompat.role_db.num_objects;
70127 +
70128 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
70129 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
70130 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
70131 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
70132 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
70133 + arg->segv_device = argcompat.segv_device;
70134 + arg->segv_inode = argcompat.segv_inode;
70135 + arg->segv_uid = argcompat.segv_uid;
70136 + arg->num_sprole_pws = argcompat.num_sprole_pws;
70137 + arg->mode = argcompat.mode;
70138 +
70139 + return 0;
70140 +}
70141 +
70142 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
70143 +{
70144 + struct acl_object_label_compat objcompat;
70145 +
70146 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
70147 + return -EFAULT;
70148 +
70149 + obj->filename = compat_ptr(objcompat.filename);
70150 + obj->inode = objcompat.inode;
70151 + obj->device = objcompat.device;
70152 + obj->mode = objcompat.mode;
70153 +
70154 + obj->nested = compat_ptr(objcompat.nested);
70155 + obj->globbed = compat_ptr(objcompat.globbed);
70156 +
70157 + obj->prev = compat_ptr(objcompat.prev);
70158 + obj->next = compat_ptr(objcompat.next);
70159 +
70160 + return 0;
70161 +}
70162 +
70163 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70164 +{
70165 + unsigned int i;
70166 + struct acl_subject_label_compat subjcompat;
70167 +
70168 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
70169 + return -EFAULT;
70170 +
70171 + subj->filename = compat_ptr(subjcompat.filename);
70172 + subj->inode = subjcompat.inode;
70173 + subj->device = subjcompat.device;
70174 + subj->mode = subjcompat.mode;
70175 + subj->cap_mask = subjcompat.cap_mask;
70176 + subj->cap_lower = subjcompat.cap_lower;
70177 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
70178 +
70179 + for (i = 0; i < GR_NLIMITS; i++) {
70180 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
70181 + subj->res[i].rlim_cur = RLIM_INFINITY;
70182 + else
70183 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
70184 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
70185 + subj->res[i].rlim_max = RLIM_INFINITY;
70186 + else
70187 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
70188 + }
70189 + subj->resmask = subjcompat.resmask;
70190 +
70191 + subj->user_trans_type = subjcompat.user_trans_type;
70192 + subj->group_trans_type = subjcompat.group_trans_type;
70193 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
70194 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
70195 + subj->user_trans_num = subjcompat.user_trans_num;
70196 + subj->group_trans_num = subjcompat.group_trans_num;
70197 +
70198 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
70199 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
70200 + subj->ip_type = subjcompat.ip_type;
70201 + subj->ips = compat_ptr(subjcompat.ips);
70202 + subj->ip_num = subjcompat.ip_num;
70203 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
70204 +
70205 + subj->crashes = subjcompat.crashes;
70206 + subj->expires = subjcompat.expires;
70207 +
70208 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
70209 + subj->hash = compat_ptr(subjcompat.hash);
70210 + subj->prev = compat_ptr(subjcompat.prev);
70211 + subj->next = compat_ptr(subjcompat.next);
70212 +
70213 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
70214 + subj->obj_hash_size = subjcompat.obj_hash_size;
70215 + subj->pax_flags = subjcompat.pax_flags;
70216 +
70217 + return 0;
70218 +}
70219 +
70220 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
70221 +{
70222 + struct acl_role_label_compat rolecompat;
70223 +
70224 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
70225 + return -EFAULT;
70226 +
70227 + role->rolename = compat_ptr(rolecompat.rolename);
70228 + role->uidgid = rolecompat.uidgid;
70229 + role->roletype = rolecompat.roletype;
70230 +
70231 + role->auth_attempts = rolecompat.auth_attempts;
70232 + role->expires = rolecompat.expires;
70233 +
70234 + role->root_label = compat_ptr(rolecompat.root_label);
70235 + role->hash = compat_ptr(rolecompat.hash);
70236 +
70237 + role->prev = compat_ptr(rolecompat.prev);
70238 + role->next = compat_ptr(rolecompat.next);
70239 +
70240 + role->transitions = compat_ptr(rolecompat.transitions);
70241 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
70242 + role->domain_children = compat_ptr(rolecompat.domain_children);
70243 + role->domain_child_num = rolecompat.domain_child_num;
70244 +
70245 + role->umask = rolecompat.umask;
70246 +
70247 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
70248 + role->subj_hash_size = rolecompat.subj_hash_size;
70249 +
70250 + return 0;
70251 +}
70252 +
70253 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70254 +{
70255 + struct role_allowed_ip_compat roleip_compat;
70256 +
70257 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
70258 + return -EFAULT;
70259 +
70260 + roleip->addr = roleip_compat.addr;
70261 + roleip->netmask = roleip_compat.netmask;
70262 +
70263 + roleip->prev = compat_ptr(roleip_compat.prev);
70264 + roleip->next = compat_ptr(roleip_compat.next);
70265 +
70266 + return 0;
70267 +}
70268 +
70269 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
70270 +{
70271 + struct role_transition_compat trans_compat;
70272 +
70273 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
70274 + return -EFAULT;
70275 +
70276 + trans->rolename = compat_ptr(trans_compat.rolename);
70277 +
70278 + trans->prev = compat_ptr(trans_compat.prev);
70279 + trans->next = compat_ptr(trans_compat.next);
70280 +
70281 + return 0;
70282 +
70283 +}
70284 +
70285 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70286 +{
70287 + struct gr_hash_struct_compat hash_compat;
70288 +
70289 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
70290 + return -EFAULT;
70291 +
70292 + hash->table = compat_ptr(hash_compat.table);
70293 + hash->nametable = compat_ptr(hash_compat.nametable);
70294 + hash->first = compat_ptr(hash_compat.first);
70295 +
70296 + hash->table_size = hash_compat.table_size;
70297 + hash->used_size = hash_compat.used_size;
70298 +
70299 + hash->type = hash_compat.type;
70300 +
70301 + return 0;
70302 +}
70303 +
70304 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
70305 +{
70306 + compat_uptr_t ptrcompat;
70307 +
70308 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
70309 + return -EFAULT;
70310 +
70311 + *(void **)ptr = compat_ptr(ptrcompat);
70312 +
70313 + return 0;
70314 +}
70315 +
70316 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70317 +{
70318 + struct acl_ip_label_compat ip_compat;
70319 +
70320 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
70321 + return -EFAULT;
70322 +
70323 + ip->iface = compat_ptr(ip_compat.iface);
70324 + ip->addr = ip_compat.addr;
70325 + ip->netmask = ip_compat.netmask;
70326 + ip->low = ip_compat.low;
70327 + ip->high = ip_compat.high;
70328 + ip->mode = ip_compat.mode;
70329 + ip->type = ip_compat.type;
70330 +
70331 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
70332 +
70333 + ip->prev = compat_ptr(ip_compat.prev);
70334 + ip->next = compat_ptr(ip_compat.next);
70335 +
70336 + return 0;
70337 +}
70338 +
70339 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70340 +{
70341 + struct sprole_pw_compat pw_compat;
70342 +
70343 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
70344 + return -EFAULT;
70345 +
70346 + pw->rolename = compat_ptr(pw_compat.rolename);
70347 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
70348 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
70349 +
70350 + return 0;
70351 +}
70352 +
70353 +size_t get_gr_arg_wrapper_size_compat(void)
70354 +{
70355 + return sizeof(struct gr_arg_wrapper_compat);
70356 +}
70357 +
70358 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
70359 new file mode 100644
70360 index 0000000..4008fdc
70361 --- /dev/null
70362 +++ b/grsecurity/gracl_fs.c
70363 @@ -0,0 +1,445 @@
70364 +#include <linux/kernel.h>
70365 +#include <linux/sched.h>
70366 +#include <linux/types.h>
70367 +#include <linux/fs.h>
70368 +#include <linux/file.h>
70369 +#include <linux/stat.h>
70370 +#include <linux/grsecurity.h>
70371 +#include <linux/grinternal.h>
70372 +#include <linux/gracl.h>
70373 +
70374 +umode_t
70375 +gr_acl_umask(void)
70376 +{
70377 + if (unlikely(!gr_acl_is_enabled()))
70378 + return 0;
70379 +
70380 + return current->role->umask;
70381 +}
70382 +
70383 +__u32
70384 +gr_acl_handle_hidden_file(const struct dentry * dentry,
70385 + const struct vfsmount * mnt)
70386 +{
70387 + __u32 mode;
70388 +
70389 + if (unlikely(d_is_negative(dentry)))
70390 + return GR_FIND;
70391 +
70392 + mode =
70393 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70394 +
70395 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70396 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70397 + return mode;
70398 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70399 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70400 + return 0;
70401 + } else if (unlikely(!(mode & GR_FIND)))
70402 + return 0;
70403 +
70404 + return GR_FIND;
70405 +}
70406 +
70407 +__u32
70408 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70409 + int acc_mode)
70410 +{
70411 + __u32 reqmode = GR_FIND;
70412 + __u32 mode;
70413 +
70414 + if (unlikely(d_is_negative(dentry)))
70415 + return reqmode;
70416 +
70417 + if (acc_mode & MAY_APPEND)
70418 + reqmode |= GR_APPEND;
70419 + else if (acc_mode & MAY_WRITE)
70420 + reqmode |= GR_WRITE;
70421 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70422 + reqmode |= GR_READ;
70423 +
70424 + mode =
70425 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70426 + mnt);
70427 +
70428 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70429 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70430 + reqmode & GR_READ ? " reading" : "",
70431 + reqmode & GR_WRITE ? " writing" : reqmode &
70432 + GR_APPEND ? " appending" : "");
70433 + return reqmode;
70434 + } else
70435 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70436 + {
70437 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70438 + reqmode & GR_READ ? " reading" : "",
70439 + reqmode & GR_WRITE ? " writing" : reqmode &
70440 + GR_APPEND ? " appending" : "");
70441 + return 0;
70442 + } else if (unlikely((mode & reqmode) != reqmode))
70443 + return 0;
70444 +
70445 + return reqmode;
70446 +}
70447 +
70448 +__u32
70449 +gr_acl_handle_creat(const struct dentry * dentry,
70450 + const struct dentry * p_dentry,
70451 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70452 + const int imode)
70453 +{
70454 + __u32 reqmode = GR_WRITE | GR_CREATE;
70455 + __u32 mode;
70456 +
70457 + if (acc_mode & MAY_APPEND)
70458 + reqmode |= GR_APPEND;
70459 + // if a directory was required or the directory already exists, then
70460 + // don't count this open as a read
70461 + if ((acc_mode & MAY_READ) &&
70462 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70463 + reqmode |= GR_READ;
70464 + if ((open_flags & O_CREAT) &&
70465 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70466 + reqmode |= GR_SETID;
70467 +
70468 + mode =
70469 + gr_check_create(dentry, p_dentry, p_mnt,
70470 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70471 +
70472 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70473 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70474 + reqmode & GR_READ ? " reading" : "",
70475 + reqmode & GR_WRITE ? " writing" : reqmode &
70476 + GR_APPEND ? " appending" : "");
70477 + return reqmode;
70478 + } else
70479 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70480 + {
70481 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70482 + reqmode & GR_READ ? " reading" : "",
70483 + reqmode & GR_WRITE ? " writing" : reqmode &
70484 + GR_APPEND ? " appending" : "");
70485 + return 0;
70486 + } else if (unlikely((mode & reqmode) != reqmode))
70487 + return 0;
70488 +
70489 + return reqmode;
70490 +}
70491 +
70492 +__u32
70493 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70494 + const int fmode)
70495 +{
70496 + __u32 mode, reqmode = GR_FIND;
70497 +
70498 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70499 + reqmode |= GR_EXEC;
70500 + if (fmode & S_IWOTH)
70501 + reqmode |= GR_WRITE;
70502 + if (fmode & S_IROTH)
70503 + reqmode |= GR_READ;
70504 +
70505 + mode =
70506 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70507 + mnt);
70508 +
70509 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70510 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70511 + reqmode & GR_READ ? " reading" : "",
70512 + reqmode & GR_WRITE ? " writing" : "",
70513 + reqmode & GR_EXEC ? " executing" : "");
70514 + return reqmode;
70515 + } else
70516 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70517 + {
70518 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70519 + reqmode & GR_READ ? " reading" : "",
70520 + reqmode & GR_WRITE ? " writing" : "",
70521 + reqmode & GR_EXEC ? " executing" : "");
70522 + return 0;
70523 + } else if (unlikely((mode & reqmode) != reqmode))
70524 + return 0;
70525 +
70526 + return reqmode;
70527 +}
70528 +
70529 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70530 +{
70531 + __u32 mode;
70532 +
70533 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70534 +
70535 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70536 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70537 + return mode;
70538 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70539 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70540 + return 0;
70541 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
70542 + return 0;
70543 +
70544 + return (reqmode);
70545 +}
70546 +
70547 +__u32
70548 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70549 +{
70550 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70551 +}
70552 +
70553 +__u32
70554 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70555 +{
70556 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70557 +}
70558 +
70559 +__u32
70560 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70561 +{
70562 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70563 +}
70564 +
70565 +__u32
70566 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70567 +{
70568 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70569 +}
70570 +
70571 +__u32
70572 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70573 + umode_t *modeptr)
70574 +{
70575 + umode_t mode;
70576 +
70577 + *modeptr &= ~gr_acl_umask();
70578 + mode = *modeptr;
70579 +
70580 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70581 + return 1;
70582 +
70583 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70584 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70585 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70586 + GR_CHMOD_ACL_MSG);
70587 + } else {
70588 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70589 + }
70590 +}
70591 +
70592 +__u32
70593 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70594 +{
70595 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70596 +}
70597 +
70598 +__u32
70599 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70600 +{
70601 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70602 +}
70603 +
70604 +__u32
70605 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70606 +{
70607 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70608 +}
70609 +
70610 +__u32
70611 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70612 +{
70613 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70614 +}
70615 +
70616 +__u32
70617 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70618 +{
70619 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70620 + GR_UNIXCONNECT_ACL_MSG);
70621 +}
70622 +
70623 +/* hardlinks require at minimum create and link permission,
70624 + any additional privilege required is based on the
70625 + privilege of the file being linked to
70626 +*/
70627 +__u32
70628 +gr_acl_handle_link(const struct dentry * new_dentry,
70629 + const struct dentry * parent_dentry,
70630 + const struct vfsmount * parent_mnt,
70631 + const struct dentry * old_dentry,
70632 + const struct vfsmount * old_mnt, const struct filename *to)
70633 +{
70634 + __u32 mode;
70635 + __u32 needmode = GR_CREATE | GR_LINK;
70636 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70637 +
70638 + mode =
70639 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70640 + old_mnt);
70641 +
70642 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70643 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70644 + return mode;
70645 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70646 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70647 + return 0;
70648 + } else if (unlikely((mode & needmode) != needmode))
70649 + return 0;
70650 +
70651 + return 1;
70652 +}
70653 +
70654 +__u32
70655 +gr_acl_handle_symlink(const struct dentry * new_dentry,
70656 + const struct dentry * parent_dentry,
70657 + const struct vfsmount * parent_mnt, const struct filename *from)
70658 +{
70659 + __u32 needmode = GR_WRITE | GR_CREATE;
70660 + __u32 mode;
70661 +
70662 + mode =
70663 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
70664 + GR_CREATE | GR_AUDIT_CREATE |
70665 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70666 +
70667 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70668 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70669 + return mode;
70670 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70671 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70672 + return 0;
70673 + } else if (unlikely((mode & needmode) != needmode))
70674 + return 0;
70675 +
70676 + return (GR_WRITE | GR_CREATE);
70677 +}
70678 +
70679 +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)
70680 +{
70681 + __u32 mode;
70682 +
70683 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70684 +
70685 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70686 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70687 + return mode;
70688 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70689 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70690 + return 0;
70691 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
70692 + return 0;
70693 +
70694 + return (reqmode);
70695 +}
70696 +
70697 +__u32
70698 +gr_acl_handle_mknod(const struct dentry * new_dentry,
70699 + const struct dentry * parent_dentry,
70700 + const struct vfsmount * parent_mnt,
70701 + const int mode)
70702 +{
70703 + __u32 reqmode = GR_WRITE | GR_CREATE;
70704 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70705 + reqmode |= GR_SETID;
70706 +
70707 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70708 + reqmode, GR_MKNOD_ACL_MSG);
70709 +}
70710 +
70711 +__u32
70712 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
70713 + const struct dentry *parent_dentry,
70714 + const struct vfsmount *parent_mnt)
70715 +{
70716 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70717 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70718 +}
70719 +
70720 +#define RENAME_CHECK_SUCCESS(old, new) \
70721 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70722 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70723 +
70724 +int
70725 +gr_acl_handle_rename(struct dentry *new_dentry,
70726 + struct dentry *parent_dentry,
70727 + const struct vfsmount *parent_mnt,
70728 + struct dentry *old_dentry,
70729 + struct inode *old_parent_inode,
70730 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
70731 +{
70732 + __u32 comp1, comp2;
70733 + int error = 0;
70734 +
70735 + if (unlikely(!gr_acl_is_enabled()))
70736 + return 0;
70737 +
70738 + if (flags & RENAME_EXCHANGE) {
70739 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70740 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70741 + GR_SUPPRESS, parent_mnt);
70742 + comp2 =
70743 + gr_search_file(old_dentry,
70744 + GR_READ | GR_WRITE | GR_AUDIT_READ |
70745 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70746 + } else if (d_is_negative(new_dentry)) {
70747 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70748 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70749 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70750 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70751 + GR_DELETE | GR_AUDIT_DELETE |
70752 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70753 + GR_SUPPRESS, old_mnt);
70754 + } else {
70755 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70756 + GR_CREATE | GR_DELETE |
70757 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70758 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70759 + GR_SUPPRESS, parent_mnt);
70760 + comp2 =
70761 + gr_search_file(old_dentry,
70762 + GR_READ | GR_WRITE | GR_AUDIT_READ |
70763 + GR_DELETE | GR_AUDIT_DELETE |
70764 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70765 + }
70766 +
70767 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70768 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70769 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70770 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70771 + && !(comp2 & GR_SUPPRESS)) {
70772 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70773 + error = -EACCES;
70774 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70775 + error = -EACCES;
70776 +
70777 + return error;
70778 +}
70779 +
70780 +void
70781 +gr_acl_handle_exit(void)
70782 +{
70783 + u16 id;
70784 + char *rolename;
70785 +
70786 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70787 + !(current->role->roletype & GR_ROLE_PERSIST))) {
70788 + id = current->acl_role_id;
70789 + rolename = current->role->rolename;
70790 + gr_set_acls(1);
70791 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70792 + }
70793 +
70794 + gr_put_exec_file(current);
70795 + return;
70796 +}
70797 +
70798 +int
70799 +gr_acl_handle_procpidmem(const struct task_struct *task)
70800 +{
70801 + if (unlikely(!gr_acl_is_enabled()))
70802 + return 0;
70803 +
70804 + if (task != current && task->acl->mode & GR_PROTPROCFD)
70805 + return -EACCES;
70806 +
70807 + return 0;
70808 +}
70809 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70810 new file mode 100644
70811 index 0000000..f056b81
70812 --- /dev/null
70813 +++ b/grsecurity/gracl_ip.c
70814 @@ -0,0 +1,386 @@
70815 +#include <linux/kernel.h>
70816 +#include <asm/uaccess.h>
70817 +#include <asm/errno.h>
70818 +#include <net/sock.h>
70819 +#include <linux/file.h>
70820 +#include <linux/fs.h>
70821 +#include <linux/net.h>
70822 +#include <linux/in.h>
70823 +#include <linux/skbuff.h>
70824 +#include <linux/ip.h>
70825 +#include <linux/udp.h>
70826 +#include <linux/types.h>
70827 +#include <linux/sched.h>
70828 +#include <linux/netdevice.h>
70829 +#include <linux/inetdevice.h>
70830 +#include <linux/gracl.h>
70831 +#include <linux/grsecurity.h>
70832 +#include <linux/grinternal.h>
70833 +
70834 +#define GR_BIND 0x01
70835 +#define GR_CONNECT 0x02
70836 +#define GR_INVERT 0x04
70837 +#define GR_BINDOVERRIDE 0x08
70838 +#define GR_CONNECTOVERRIDE 0x10
70839 +#define GR_SOCK_FAMILY 0x20
70840 +
70841 +static const char * gr_protocols[IPPROTO_MAX] = {
70842 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70843 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70844 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70845 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70846 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70847 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70848 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70849 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70850 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70851 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70852 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70853 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70854 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70855 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70856 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70857 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70858 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70859 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70860 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70861 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70862 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70863 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70864 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70865 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70866 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70867 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70868 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70869 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70870 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70871 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70872 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70873 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70874 + };
70875 +
70876 +static const char * gr_socktypes[SOCK_MAX] = {
70877 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70878 + "unknown:7", "unknown:8", "unknown:9", "packet"
70879 + };
70880 +
70881 +static const char * gr_sockfamilies[AF_MAX+1] = {
70882 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70883 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70884 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70885 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70886 + };
70887 +
70888 +const char *
70889 +gr_proto_to_name(unsigned char proto)
70890 +{
70891 + return gr_protocols[proto];
70892 +}
70893 +
70894 +const char *
70895 +gr_socktype_to_name(unsigned char type)
70896 +{
70897 + return gr_socktypes[type];
70898 +}
70899 +
70900 +const char *
70901 +gr_sockfamily_to_name(unsigned char family)
70902 +{
70903 + return gr_sockfamilies[family];
70904 +}
70905 +
70906 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70907 +
70908 +int
70909 +gr_search_socket(const int domain, const int type, const int protocol)
70910 +{
70911 + struct acl_subject_label *curr;
70912 + const struct cred *cred = current_cred();
70913 +
70914 + if (unlikely(!gr_acl_is_enabled()))
70915 + goto exit;
70916 +
70917 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
70918 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70919 + goto exit; // let the kernel handle it
70920 +
70921 + curr = current->acl;
70922 +
70923 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70924 + /* the family is allowed, if this is PF_INET allow it only if
70925 + the extra sock type/protocol checks pass */
70926 + if (domain == PF_INET)
70927 + goto inet_check;
70928 + goto exit;
70929 + } else {
70930 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70931 + __u32 fakeip = 0;
70932 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70933 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70934 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70935 + gr_to_filename(current->exec_file->f_path.dentry,
70936 + current->exec_file->f_path.mnt) :
70937 + curr->filename, curr->filename,
70938 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70939 + &current->signal->saved_ip);
70940 + goto exit;
70941 + }
70942 + goto exit_fail;
70943 + }
70944 +
70945 +inet_check:
70946 + /* the rest of this checking is for IPv4 only */
70947 + if (!curr->ips)
70948 + goto exit;
70949 +
70950 + if ((curr->ip_type & (1U << type)) &&
70951 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70952 + goto exit;
70953 +
70954 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70955 + /* we don't place acls on raw sockets , and sometimes
70956 + dgram/ip sockets are opened for ioctl and not
70957 + bind/connect, so we'll fake a bind learn log */
70958 + if (type == SOCK_RAW || type == SOCK_PACKET) {
70959 + __u32 fakeip = 0;
70960 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70961 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70962 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70963 + gr_to_filename(current->exec_file->f_path.dentry,
70964 + current->exec_file->f_path.mnt) :
70965 + curr->filename, curr->filename,
70966 + &fakeip, 0, type,
70967 + protocol, GR_CONNECT, &current->signal->saved_ip);
70968 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70969 + __u32 fakeip = 0;
70970 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70971 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70972 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70973 + gr_to_filename(current->exec_file->f_path.dentry,
70974 + current->exec_file->f_path.mnt) :
70975 + curr->filename, curr->filename,
70976 + &fakeip, 0, type,
70977 + protocol, GR_BIND, &current->signal->saved_ip);
70978 + }
70979 + /* we'll log when they use connect or bind */
70980 + goto exit;
70981 + }
70982 +
70983 +exit_fail:
70984 + if (domain == PF_INET)
70985 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70986 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
70987 + else if (rcu_access_pointer(net_families[domain]) != NULL)
70988 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70989 + gr_socktype_to_name(type), protocol);
70990 +
70991 + return 0;
70992 +exit:
70993 + return 1;
70994 +}
70995 +
70996 +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)
70997 +{
70998 + if ((ip->mode & mode) &&
70999 + (ip_port >= ip->low) &&
71000 + (ip_port <= ip->high) &&
71001 + ((ntohl(ip_addr) & our_netmask) ==
71002 + (ntohl(our_addr) & our_netmask))
71003 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
71004 + && (ip->type & (1U << type))) {
71005 + if (ip->mode & GR_INVERT)
71006 + return 2; // specifically denied
71007 + else
71008 + return 1; // allowed
71009 + }
71010 +
71011 + return 0; // not specifically allowed, may continue parsing
71012 +}
71013 +
71014 +static int
71015 +gr_search_connectbind(const int full_mode, struct sock *sk,
71016 + struct sockaddr_in *addr, const int type)
71017 +{
71018 + char iface[IFNAMSIZ] = {0};
71019 + struct acl_subject_label *curr;
71020 + struct acl_ip_label *ip;
71021 + struct inet_sock *isk;
71022 + struct net_device *dev;
71023 + struct in_device *idev;
71024 + unsigned long i;
71025 + int ret;
71026 + int mode = full_mode & (GR_BIND | GR_CONNECT);
71027 + __u32 ip_addr = 0;
71028 + __u32 our_addr;
71029 + __u32 our_netmask;
71030 + char *p;
71031 + __u16 ip_port = 0;
71032 + const struct cred *cred = current_cred();
71033 +
71034 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
71035 + return 0;
71036 +
71037 + curr = current->acl;
71038 + isk = inet_sk(sk);
71039 +
71040 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
71041 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
71042 + addr->sin_addr.s_addr = curr->inaddr_any_override;
71043 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
71044 + struct sockaddr_in saddr;
71045 + int err;
71046 +
71047 + saddr.sin_family = AF_INET;
71048 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
71049 + saddr.sin_port = isk->inet_sport;
71050 +
71051 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71052 + if (err)
71053 + return err;
71054 +
71055 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71056 + if (err)
71057 + return err;
71058 + }
71059 +
71060 + if (!curr->ips)
71061 + return 0;
71062 +
71063 + ip_addr = addr->sin_addr.s_addr;
71064 + ip_port = ntohs(addr->sin_port);
71065 +
71066 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71067 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71068 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
71069 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
71070 + gr_to_filename(current->exec_file->f_path.dentry,
71071 + current->exec_file->f_path.mnt) :
71072 + curr->filename, curr->filename,
71073 + &ip_addr, ip_port, type,
71074 + sk->sk_protocol, mode, &current->signal->saved_ip);
71075 + return 0;
71076 + }
71077 +
71078 + for (i = 0; i < curr->ip_num; i++) {
71079 + ip = *(curr->ips + i);
71080 + if (ip->iface != NULL) {
71081 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
71082 + p = strchr(iface, ':');
71083 + if (p != NULL)
71084 + *p = '\0';
71085 + dev = dev_get_by_name(sock_net(sk), iface);
71086 + if (dev == NULL)
71087 + continue;
71088 + idev = in_dev_get(dev);
71089 + if (idev == NULL) {
71090 + dev_put(dev);
71091 + continue;
71092 + }
71093 + rcu_read_lock();
71094 + for_ifa(idev) {
71095 + if (!strcmp(ip->iface, ifa->ifa_label)) {
71096 + our_addr = ifa->ifa_address;
71097 + our_netmask = 0xffffffff;
71098 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71099 + if (ret == 1) {
71100 + rcu_read_unlock();
71101 + in_dev_put(idev);
71102 + dev_put(dev);
71103 + return 0;
71104 + } else if (ret == 2) {
71105 + rcu_read_unlock();
71106 + in_dev_put(idev);
71107 + dev_put(dev);
71108 + goto denied;
71109 + }
71110 + }
71111 + } endfor_ifa(idev);
71112 + rcu_read_unlock();
71113 + in_dev_put(idev);
71114 + dev_put(dev);
71115 + } else {
71116 + our_addr = ip->addr;
71117 + our_netmask = ip->netmask;
71118 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71119 + if (ret == 1)
71120 + return 0;
71121 + else if (ret == 2)
71122 + goto denied;
71123 + }
71124 + }
71125 +
71126 +denied:
71127 + if (mode == GR_BIND)
71128 + 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));
71129 + else if (mode == GR_CONNECT)
71130 + 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));
71131 +
71132 + return -EACCES;
71133 +}
71134 +
71135 +int
71136 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
71137 +{
71138 + /* always allow disconnection of dgram sockets with connect */
71139 + if (addr->sin_family == AF_UNSPEC)
71140 + return 0;
71141 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
71142 +}
71143 +
71144 +int
71145 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
71146 +{
71147 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
71148 +}
71149 +
71150 +int gr_search_listen(struct socket *sock)
71151 +{
71152 + struct sock *sk = sock->sk;
71153 + struct sockaddr_in addr;
71154 +
71155 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71156 + addr.sin_port = inet_sk(sk)->inet_sport;
71157 +
71158 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71159 +}
71160 +
71161 +int gr_search_accept(struct socket *sock)
71162 +{
71163 + struct sock *sk = sock->sk;
71164 + struct sockaddr_in addr;
71165 +
71166 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71167 + addr.sin_port = inet_sk(sk)->inet_sport;
71168 +
71169 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71170 +}
71171 +
71172 +int
71173 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
71174 +{
71175 + if (addr)
71176 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
71177 + else {
71178 + struct sockaddr_in sin;
71179 + const struct inet_sock *inet = inet_sk(sk);
71180 +
71181 + sin.sin_addr.s_addr = inet->inet_daddr;
71182 + sin.sin_port = inet->inet_dport;
71183 +
71184 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71185 + }
71186 +}
71187 +
71188 +int
71189 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
71190 +{
71191 + struct sockaddr_in sin;
71192 +
71193 + if (unlikely(skb->len < sizeof (struct udphdr)))
71194 + return 0; // skip this packet
71195 +
71196 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
71197 + sin.sin_port = udp_hdr(skb)->source;
71198 +
71199 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71200 +}
71201 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
71202 new file mode 100644
71203 index 0000000..25f54ef
71204 --- /dev/null
71205 +++ b/grsecurity/gracl_learn.c
71206 @@ -0,0 +1,207 @@
71207 +#include <linux/kernel.h>
71208 +#include <linux/mm.h>
71209 +#include <linux/sched.h>
71210 +#include <linux/poll.h>
71211 +#include <linux/string.h>
71212 +#include <linux/file.h>
71213 +#include <linux/types.h>
71214 +#include <linux/vmalloc.h>
71215 +#include <linux/grinternal.h>
71216 +
71217 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
71218 + size_t count, loff_t *ppos);
71219 +extern int gr_acl_is_enabled(void);
71220 +
71221 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
71222 +static int gr_learn_attached;
71223 +
71224 +/* use a 512k buffer */
71225 +#define LEARN_BUFFER_SIZE (512 * 1024)
71226 +
71227 +static DEFINE_SPINLOCK(gr_learn_lock);
71228 +static DEFINE_MUTEX(gr_learn_user_mutex);
71229 +
71230 +/* we need to maintain two buffers, so that the kernel context of grlearn
71231 + uses a semaphore around the userspace copying, and the other kernel contexts
71232 + use a spinlock when copying into the buffer, since they cannot sleep
71233 +*/
71234 +static char *learn_buffer;
71235 +static char *learn_buffer_user;
71236 +static int learn_buffer_len;
71237 +static int learn_buffer_user_len;
71238 +
71239 +static ssize_t
71240 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
71241 +{
71242 + DECLARE_WAITQUEUE(wait, current);
71243 + ssize_t retval = 0;
71244 +
71245 + add_wait_queue(&learn_wait, &wait);
71246 + set_current_state(TASK_INTERRUPTIBLE);
71247 + do {
71248 + mutex_lock(&gr_learn_user_mutex);
71249 + spin_lock(&gr_learn_lock);
71250 + if (learn_buffer_len)
71251 + break;
71252 + spin_unlock(&gr_learn_lock);
71253 + mutex_unlock(&gr_learn_user_mutex);
71254 + if (file->f_flags & O_NONBLOCK) {
71255 + retval = -EAGAIN;
71256 + goto out;
71257 + }
71258 + if (signal_pending(current)) {
71259 + retval = -ERESTARTSYS;
71260 + goto out;
71261 + }
71262 +
71263 + schedule();
71264 + } while (1);
71265 +
71266 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
71267 + learn_buffer_user_len = learn_buffer_len;
71268 + retval = learn_buffer_len;
71269 + learn_buffer_len = 0;
71270 +
71271 + spin_unlock(&gr_learn_lock);
71272 +
71273 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
71274 + retval = -EFAULT;
71275 +
71276 + mutex_unlock(&gr_learn_user_mutex);
71277 +out:
71278 + set_current_state(TASK_RUNNING);
71279 + remove_wait_queue(&learn_wait, &wait);
71280 + return retval;
71281 +}
71282 +
71283 +static unsigned int
71284 +poll_learn(struct file * file, poll_table * wait)
71285 +{
71286 + poll_wait(file, &learn_wait, wait);
71287 +
71288 + if (learn_buffer_len)
71289 + return (POLLIN | POLLRDNORM);
71290 +
71291 + return 0;
71292 +}
71293 +
71294 +void
71295 +gr_clear_learn_entries(void)
71296 +{
71297 + char *tmp;
71298 +
71299 + mutex_lock(&gr_learn_user_mutex);
71300 + spin_lock(&gr_learn_lock);
71301 + tmp = learn_buffer;
71302 + learn_buffer = NULL;
71303 + spin_unlock(&gr_learn_lock);
71304 + if (tmp)
71305 + vfree(tmp);
71306 + if (learn_buffer_user != NULL) {
71307 + vfree(learn_buffer_user);
71308 + learn_buffer_user = NULL;
71309 + }
71310 + learn_buffer_len = 0;
71311 + mutex_unlock(&gr_learn_user_mutex);
71312 +
71313 + return;
71314 +}
71315 +
71316 +void
71317 +gr_add_learn_entry(const char *fmt, ...)
71318 +{
71319 + va_list args;
71320 + unsigned int len;
71321 +
71322 + if (!gr_learn_attached)
71323 + return;
71324 +
71325 + spin_lock(&gr_learn_lock);
71326 +
71327 + /* leave a gap at the end so we know when it's "full" but don't have to
71328 + compute the exact length of the string we're trying to append
71329 + */
71330 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
71331 + spin_unlock(&gr_learn_lock);
71332 + wake_up_interruptible(&learn_wait);
71333 + return;
71334 + }
71335 + if (learn_buffer == NULL) {
71336 + spin_unlock(&gr_learn_lock);
71337 + return;
71338 + }
71339 +
71340 + va_start(args, fmt);
71341 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
71342 + va_end(args);
71343 +
71344 + learn_buffer_len += len + 1;
71345 +
71346 + spin_unlock(&gr_learn_lock);
71347 + wake_up_interruptible(&learn_wait);
71348 +
71349 + return;
71350 +}
71351 +
71352 +static int
71353 +open_learn(struct inode *inode, struct file *file)
71354 +{
71355 + if (file->f_mode & FMODE_READ && gr_learn_attached)
71356 + return -EBUSY;
71357 + if (file->f_mode & FMODE_READ) {
71358 + int retval = 0;
71359 + mutex_lock(&gr_learn_user_mutex);
71360 + if (learn_buffer == NULL)
71361 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
71362 + if (learn_buffer_user == NULL)
71363 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
71364 + if (learn_buffer == NULL) {
71365 + retval = -ENOMEM;
71366 + goto out_error;
71367 + }
71368 + if (learn_buffer_user == NULL) {
71369 + retval = -ENOMEM;
71370 + goto out_error;
71371 + }
71372 + learn_buffer_len = 0;
71373 + learn_buffer_user_len = 0;
71374 + gr_learn_attached = 1;
71375 +out_error:
71376 + mutex_unlock(&gr_learn_user_mutex);
71377 + return retval;
71378 + }
71379 + return 0;
71380 +}
71381 +
71382 +static int
71383 +close_learn(struct inode *inode, struct file *file)
71384 +{
71385 + if (file->f_mode & FMODE_READ) {
71386 + char *tmp = NULL;
71387 + mutex_lock(&gr_learn_user_mutex);
71388 + spin_lock(&gr_learn_lock);
71389 + tmp = learn_buffer;
71390 + learn_buffer = NULL;
71391 + spin_unlock(&gr_learn_lock);
71392 + if (tmp)
71393 + vfree(tmp);
71394 + if (learn_buffer_user != NULL) {
71395 + vfree(learn_buffer_user);
71396 + learn_buffer_user = NULL;
71397 + }
71398 + learn_buffer_len = 0;
71399 + learn_buffer_user_len = 0;
71400 + gr_learn_attached = 0;
71401 + mutex_unlock(&gr_learn_user_mutex);
71402 + }
71403 +
71404 + return 0;
71405 +}
71406 +
71407 +const struct file_operations grsec_fops = {
71408 + .read = read_learn,
71409 + .write = write_grsec_handler,
71410 + .open = open_learn,
71411 + .release = close_learn,
71412 + .poll = poll_learn,
71413 +};
71414 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71415 new file mode 100644
71416 index 0000000..361a099
71417 --- /dev/null
71418 +++ b/grsecurity/gracl_policy.c
71419 @@ -0,0 +1,1782 @@
71420 +#include <linux/kernel.h>
71421 +#include <linux/module.h>
71422 +#include <linux/sched.h>
71423 +#include <linux/mm.h>
71424 +#include <linux/file.h>
71425 +#include <linux/fs.h>
71426 +#include <linux/namei.h>
71427 +#include <linux/mount.h>
71428 +#include <linux/tty.h>
71429 +#include <linux/proc_fs.h>
71430 +#include <linux/lglock.h>
71431 +#include <linux/slab.h>
71432 +#include <linux/vmalloc.h>
71433 +#include <linux/types.h>
71434 +#include <linux/sysctl.h>
71435 +#include <linux/netdevice.h>
71436 +#include <linux/ptrace.h>
71437 +#include <linux/gracl.h>
71438 +#include <linux/gralloc.h>
71439 +#include <linux/security.h>
71440 +#include <linux/grinternal.h>
71441 +#include <linux/pid_namespace.h>
71442 +#include <linux/stop_machine.h>
71443 +#include <linux/fdtable.h>
71444 +#include <linux/percpu.h>
71445 +#include <linux/lglock.h>
71446 +#include <linux/hugetlb.h>
71447 +#include <linux/posix-timers.h>
71448 +#include "../fs/mount.h"
71449 +
71450 +#include <asm/uaccess.h>
71451 +#include <asm/errno.h>
71452 +#include <asm/mman.h>
71453 +
71454 +extern struct gr_policy_state *polstate;
71455 +
71456 +#define FOR_EACH_ROLE_START(role) \
71457 + role = polstate->role_list; \
71458 + while (role) {
71459 +
71460 +#define FOR_EACH_ROLE_END(role) \
71461 + role = role->prev; \
71462 + }
71463 +
71464 +struct path gr_real_root;
71465 +
71466 +extern struct gr_alloc_state *current_alloc_state;
71467 +
71468 +u16 acl_sp_role_value;
71469 +
71470 +static DEFINE_MUTEX(gr_dev_mutex);
71471 +
71472 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71473 +extern void gr_clear_learn_entries(void);
71474 +
71475 +static struct gr_arg gr_usermode;
71476 +static unsigned char gr_system_salt[GR_SALT_LEN];
71477 +static unsigned char gr_system_sum[GR_SHA_LEN];
71478 +
71479 +static unsigned int gr_auth_attempts = 0;
71480 +static unsigned long gr_auth_expires = 0UL;
71481 +
71482 +struct acl_object_label *fakefs_obj_rw;
71483 +struct acl_object_label *fakefs_obj_rwx;
71484 +
71485 +extern int gr_init_uidset(void);
71486 +extern void gr_free_uidset(void);
71487 +extern void gr_remove_uid(uid_t uid);
71488 +extern int gr_find_uid(uid_t uid);
71489 +
71490 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71491 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71492 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71493 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71494 +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);
71495 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71496 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71497 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71498 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71499 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71500 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71501 +extern void assign_special_role(const char *rolename);
71502 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71503 +extern int gr_rbac_disable(void *unused);
71504 +extern void gr_enable_rbac_system(void);
71505 +
71506 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71507 +{
71508 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71509 + return -EFAULT;
71510 +
71511 + return 0;
71512 +}
71513 +
71514 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71515 +{
71516 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71517 + return -EFAULT;
71518 +
71519 + return 0;
71520 +}
71521 +
71522 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71523 +{
71524 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71525 + return -EFAULT;
71526 +
71527 + return 0;
71528 +}
71529 +
71530 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71531 +{
71532 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71533 + return -EFAULT;
71534 +
71535 + return 0;
71536 +}
71537 +
71538 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71539 +{
71540 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71541 + return -EFAULT;
71542 +
71543 + return 0;
71544 +}
71545 +
71546 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71547 +{
71548 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71549 + return -EFAULT;
71550 +
71551 + return 0;
71552 +}
71553 +
71554 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71555 +{
71556 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71557 + return -EFAULT;
71558 +
71559 + return 0;
71560 +}
71561 +
71562 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71563 +{
71564 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71565 + return -EFAULT;
71566 +
71567 + return 0;
71568 +}
71569 +
71570 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71571 +{
71572 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71573 + return -EFAULT;
71574 +
71575 + return 0;
71576 +}
71577 +
71578 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71579 +{
71580 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71581 + return -EFAULT;
71582 +
71583 + if (((uwrap->version != GRSECURITY_VERSION) &&
71584 + (uwrap->version != 0x2901)) ||
71585 + (uwrap->size != sizeof(struct gr_arg)))
71586 + return -EINVAL;
71587 +
71588 + return 0;
71589 +}
71590 +
71591 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71592 +{
71593 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71594 + return -EFAULT;
71595 +
71596 + return 0;
71597 +}
71598 +
71599 +static size_t get_gr_arg_wrapper_size_normal(void)
71600 +{
71601 + return sizeof(struct gr_arg_wrapper);
71602 +}
71603 +
71604 +#ifdef CONFIG_COMPAT
71605 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71606 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71607 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71608 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71609 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71610 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71611 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71612 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71613 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71614 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71615 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71616 +extern size_t get_gr_arg_wrapper_size_compat(void);
71617 +
71618 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71619 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71620 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71621 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71622 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71623 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71624 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71625 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71626 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71627 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71628 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71629 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71630 +
71631 +#else
71632 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71633 +#define copy_gr_arg copy_gr_arg_normal
71634 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
71635 +#define copy_acl_object_label copy_acl_object_label_normal
71636 +#define copy_acl_subject_label copy_acl_subject_label_normal
71637 +#define copy_acl_role_label copy_acl_role_label_normal
71638 +#define copy_acl_ip_label copy_acl_ip_label_normal
71639 +#define copy_pointer_from_array copy_pointer_from_array_normal
71640 +#define copy_sprole_pw copy_sprole_pw_normal
71641 +#define copy_role_transition copy_role_transition_normal
71642 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
71643 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71644 +#endif
71645 +
71646 +static struct acl_subject_label *
71647 +lookup_subject_map(const struct acl_subject_label *userp)
71648 +{
71649 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71650 + struct subject_map *match;
71651 +
71652 + match = polstate->subj_map_set.s_hash[index];
71653 +
71654 + while (match && match->user != userp)
71655 + match = match->next;
71656 +
71657 + if (match != NULL)
71658 + return match->kernel;
71659 + else
71660 + return NULL;
71661 +}
71662 +
71663 +static void
71664 +insert_subj_map_entry(struct subject_map *subjmap)
71665 +{
71666 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71667 + struct subject_map **curr;
71668 +
71669 + subjmap->prev = NULL;
71670 +
71671 + curr = &polstate->subj_map_set.s_hash[index];
71672 + if (*curr != NULL)
71673 + (*curr)->prev = subjmap;
71674 +
71675 + subjmap->next = *curr;
71676 + *curr = subjmap;
71677 +
71678 + return;
71679 +}
71680 +
71681 +static void
71682 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71683 +{
71684 + unsigned int index =
71685 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71686 + struct acl_role_label **curr;
71687 + struct acl_role_label *tmp, *tmp2;
71688 +
71689 + curr = &polstate->acl_role_set.r_hash[index];
71690 +
71691 + /* simple case, slot is empty, just set it to our role */
71692 + if (*curr == NULL) {
71693 + *curr = role;
71694 + } else {
71695 + /* example:
71696 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
71697 + 2 -> 3
71698 + */
71699 + /* first check to see if we can already be reached via this slot */
71700 + tmp = *curr;
71701 + while (tmp && tmp != role)
71702 + tmp = tmp->next;
71703 + if (tmp == role) {
71704 + /* we don't need to add ourselves to this slot's chain */
71705 + return;
71706 + }
71707 + /* we need to add ourselves to this chain, two cases */
71708 + if (role->next == NULL) {
71709 + /* simple case, append the current chain to our role */
71710 + role->next = *curr;
71711 + *curr = role;
71712 + } else {
71713 + /* 1 -> 2 -> 3 -> 4
71714 + 2 -> 3 -> 4
71715 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71716 + */
71717 + /* trickier case: walk our role's chain until we find
71718 + the role for the start of the current slot's chain */
71719 + tmp = role;
71720 + tmp2 = *curr;
71721 + while (tmp->next && tmp->next != tmp2)
71722 + tmp = tmp->next;
71723 + if (tmp->next == tmp2) {
71724 + /* from example above, we found 3, so just
71725 + replace this slot's chain with ours */
71726 + *curr = role;
71727 + } else {
71728 + /* we didn't find a subset of our role's chain
71729 + in the current slot's chain, so append their
71730 + chain to ours, and set us as the first role in
71731 + the slot's chain
71732 +
71733 + we could fold this case with the case above,
71734 + but making it explicit for clarity
71735 + */
71736 + tmp->next = tmp2;
71737 + *curr = role;
71738 + }
71739 + }
71740 + }
71741 +
71742 + return;
71743 +}
71744 +
71745 +static void
71746 +insert_acl_role_label(struct acl_role_label *role)
71747 +{
71748 + int i;
71749 +
71750 + if (polstate->role_list == NULL) {
71751 + polstate->role_list = role;
71752 + role->prev = NULL;
71753 + } else {
71754 + role->prev = polstate->role_list;
71755 + polstate->role_list = role;
71756 + }
71757 +
71758 + /* used for hash chains */
71759 + role->next = NULL;
71760 +
71761 + if (role->roletype & GR_ROLE_DOMAIN) {
71762 + for (i = 0; i < role->domain_child_num; i++)
71763 + __insert_acl_role_label(role, role->domain_children[i]);
71764 + } else
71765 + __insert_acl_role_label(role, role->uidgid);
71766 +}
71767 +
71768 +static int
71769 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71770 +{
71771 + struct name_entry **curr, *nentry;
71772 + struct inodev_entry *ientry;
71773 + unsigned int len = strlen(name);
71774 + unsigned int key = full_name_hash(name, len);
71775 + unsigned int index = key % polstate->name_set.n_size;
71776 +
71777 + curr = &polstate->name_set.n_hash[index];
71778 +
71779 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71780 + curr = &((*curr)->next);
71781 +
71782 + if (*curr != NULL)
71783 + return 1;
71784 +
71785 + nentry = acl_alloc(sizeof (struct name_entry));
71786 + if (nentry == NULL)
71787 + return 0;
71788 + ientry = acl_alloc(sizeof (struct inodev_entry));
71789 + if (ientry == NULL)
71790 + return 0;
71791 + ientry->nentry = nentry;
71792 +
71793 + nentry->key = key;
71794 + nentry->name = name;
71795 + nentry->inode = inode;
71796 + nentry->device = device;
71797 + nentry->len = len;
71798 + nentry->deleted = deleted;
71799 +
71800 + nentry->prev = NULL;
71801 + curr = &polstate->name_set.n_hash[index];
71802 + if (*curr != NULL)
71803 + (*curr)->prev = nentry;
71804 + nentry->next = *curr;
71805 + *curr = nentry;
71806 +
71807 + /* insert us into the table searchable by inode/dev */
71808 + __insert_inodev_entry(polstate, ientry);
71809 +
71810 + return 1;
71811 +}
71812 +
71813 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71814 +
71815 +static void *
71816 +create_table(__u32 * len, int elementsize)
71817 +{
71818 + unsigned int table_sizes[] = {
71819 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71820 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71821 + 4194301, 8388593, 16777213, 33554393, 67108859
71822 + };
71823 + void *newtable = NULL;
71824 + unsigned int pwr = 0;
71825 +
71826 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71827 + table_sizes[pwr] <= *len)
71828 + pwr++;
71829 +
71830 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71831 + return newtable;
71832 +
71833 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71834 + newtable =
71835 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71836 + else
71837 + newtable = vmalloc(table_sizes[pwr] * elementsize);
71838 +
71839 + *len = table_sizes[pwr];
71840 +
71841 + return newtable;
71842 +}
71843 +
71844 +static int
71845 +init_variables(const struct gr_arg *arg, bool reload)
71846 +{
71847 + struct task_struct *reaper = init_pid_ns.child_reaper;
71848 + unsigned int stacksize;
71849 +
71850 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71851 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71852 + polstate->name_set.n_size = arg->role_db.num_objects;
71853 + polstate->inodev_set.i_size = arg->role_db.num_objects;
71854 +
71855 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71856 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71857 + return 1;
71858 +
71859 + if (!reload) {
71860 + if (!gr_init_uidset())
71861 + return 1;
71862 + }
71863 +
71864 + /* set up the stack that holds allocation info */
71865 +
71866 + stacksize = arg->role_db.num_pointers + 5;
71867 +
71868 + if (!acl_alloc_stack_init(stacksize))
71869 + return 1;
71870 +
71871 + if (!reload) {
71872 + /* grab reference for the real root dentry and vfsmount */
71873 + get_fs_root(reaper->fs, &gr_real_root);
71874 +
71875 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71876 + 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);
71877 +#endif
71878 +
71879 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71880 + if (fakefs_obj_rw == NULL)
71881 + return 1;
71882 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71883 +
71884 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71885 + if (fakefs_obj_rwx == NULL)
71886 + return 1;
71887 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71888 + }
71889 +
71890 + polstate->subj_map_set.s_hash =
71891 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71892 + polstate->acl_role_set.r_hash =
71893 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71894 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71895 + polstate->inodev_set.i_hash =
71896 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71897 +
71898 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71899 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71900 + return 1;
71901 +
71902 + memset(polstate->subj_map_set.s_hash, 0,
71903 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71904 + memset(polstate->acl_role_set.r_hash, 0,
71905 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71906 + memset(polstate->name_set.n_hash, 0,
71907 + sizeof (struct name_entry *) * polstate->name_set.n_size);
71908 + memset(polstate->inodev_set.i_hash, 0,
71909 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71910 +
71911 + return 0;
71912 +}
71913 +
71914 +/* free information not needed after startup
71915 + currently contains user->kernel pointer mappings for subjects
71916 +*/
71917 +
71918 +static void
71919 +free_init_variables(void)
71920 +{
71921 + __u32 i;
71922 +
71923 + if (polstate->subj_map_set.s_hash) {
71924 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71925 + if (polstate->subj_map_set.s_hash[i]) {
71926 + kfree(polstate->subj_map_set.s_hash[i]);
71927 + polstate->subj_map_set.s_hash[i] = NULL;
71928 + }
71929 + }
71930 +
71931 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71932 + PAGE_SIZE)
71933 + kfree(polstate->subj_map_set.s_hash);
71934 + else
71935 + vfree(polstate->subj_map_set.s_hash);
71936 + }
71937 +
71938 + return;
71939 +}
71940 +
71941 +static void
71942 +free_variables(bool reload)
71943 +{
71944 + struct acl_subject_label *s;
71945 + struct acl_role_label *r;
71946 + struct task_struct *task, *task2;
71947 + unsigned int x;
71948 +
71949 + if (!reload) {
71950 + gr_clear_learn_entries();
71951 +
71952 + read_lock(&tasklist_lock);
71953 + do_each_thread(task2, task) {
71954 + task->acl_sp_role = 0;
71955 + task->acl_role_id = 0;
71956 + task->inherited = 0;
71957 + task->acl = NULL;
71958 + task->role = NULL;
71959 + } while_each_thread(task2, task);
71960 + read_unlock(&tasklist_lock);
71961 +
71962 + kfree(fakefs_obj_rw);
71963 + fakefs_obj_rw = NULL;
71964 + kfree(fakefs_obj_rwx);
71965 + fakefs_obj_rwx = NULL;
71966 +
71967 + /* release the reference to the real root dentry and vfsmount */
71968 + path_put(&gr_real_root);
71969 + memset(&gr_real_root, 0, sizeof(gr_real_root));
71970 + }
71971 +
71972 + /* free all object hash tables */
71973 +
71974 + FOR_EACH_ROLE_START(r)
71975 + if (r->subj_hash == NULL)
71976 + goto next_role;
71977 + FOR_EACH_SUBJECT_START(r, s, x)
71978 + if (s->obj_hash == NULL)
71979 + break;
71980 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71981 + kfree(s->obj_hash);
71982 + else
71983 + vfree(s->obj_hash);
71984 + FOR_EACH_SUBJECT_END(s, x)
71985 + FOR_EACH_NESTED_SUBJECT_START(r, s)
71986 + if (s->obj_hash == NULL)
71987 + break;
71988 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71989 + kfree(s->obj_hash);
71990 + else
71991 + vfree(s->obj_hash);
71992 + FOR_EACH_NESTED_SUBJECT_END(s)
71993 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71994 + kfree(r->subj_hash);
71995 + else
71996 + vfree(r->subj_hash);
71997 + r->subj_hash = NULL;
71998 +next_role:
71999 + FOR_EACH_ROLE_END(r)
72000 +
72001 + acl_free_all();
72002 +
72003 + if (polstate->acl_role_set.r_hash) {
72004 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
72005 + PAGE_SIZE)
72006 + kfree(polstate->acl_role_set.r_hash);
72007 + else
72008 + vfree(polstate->acl_role_set.r_hash);
72009 + }
72010 + if (polstate->name_set.n_hash) {
72011 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
72012 + PAGE_SIZE)
72013 + kfree(polstate->name_set.n_hash);
72014 + else
72015 + vfree(polstate->name_set.n_hash);
72016 + }
72017 +
72018 + if (polstate->inodev_set.i_hash) {
72019 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
72020 + PAGE_SIZE)
72021 + kfree(polstate->inodev_set.i_hash);
72022 + else
72023 + vfree(polstate->inodev_set.i_hash);
72024 + }
72025 +
72026 + if (!reload)
72027 + gr_free_uidset();
72028 +
72029 + memset(&polstate->name_set, 0, sizeof (struct name_db));
72030 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
72031 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
72032 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
72033 +
72034 + polstate->default_role = NULL;
72035 + polstate->kernel_role = NULL;
72036 + polstate->role_list = NULL;
72037 +
72038 + return;
72039 +}
72040 +
72041 +static struct acl_subject_label *
72042 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
72043 +
72044 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
72045 +{
72046 + unsigned int len = strnlen_user(*name, maxlen);
72047 + char *tmp;
72048 +
72049 + if (!len || len >= maxlen)
72050 + return -EINVAL;
72051 +
72052 + if ((tmp = (char *) acl_alloc(len)) == NULL)
72053 + return -ENOMEM;
72054 +
72055 + if (copy_from_user(tmp, *name, len))
72056 + return -EFAULT;
72057 +
72058 + tmp[len-1] = '\0';
72059 + *name = tmp;
72060 +
72061 + return 0;
72062 +}
72063 +
72064 +static int
72065 +copy_user_glob(struct acl_object_label *obj)
72066 +{
72067 + struct acl_object_label *g_tmp, **guser;
72068 + int error;
72069 +
72070 + if (obj->globbed == NULL)
72071 + return 0;
72072 +
72073 + guser = &obj->globbed;
72074 + while (*guser) {
72075 + g_tmp = (struct acl_object_label *)
72076 + acl_alloc(sizeof (struct acl_object_label));
72077 + if (g_tmp == NULL)
72078 + return -ENOMEM;
72079 +
72080 + if (copy_acl_object_label(g_tmp, *guser))
72081 + return -EFAULT;
72082 +
72083 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
72084 + if (error)
72085 + return error;
72086 +
72087 + *guser = g_tmp;
72088 + guser = &(g_tmp->next);
72089 + }
72090 +
72091 + return 0;
72092 +}
72093 +
72094 +static int
72095 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
72096 + struct acl_role_label *role)
72097 +{
72098 + struct acl_object_label *o_tmp;
72099 + int ret;
72100 +
72101 + while (userp) {
72102 + if ((o_tmp = (struct acl_object_label *)
72103 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
72104 + return -ENOMEM;
72105 +
72106 + if (copy_acl_object_label(o_tmp, userp))
72107 + return -EFAULT;
72108 +
72109 + userp = o_tmp->prev;
72110 +
72111 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
72112 + if (ret)
72113 + return ret;
72114 +
72115 + insert_acl_obj_label(o_tmp, subj);
72116 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
72117 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
72118 + return -ENOMEM;
72119 +
72120 + ret = copy_user_glob(o_tmp);
72121 + if (ret)
72122 + return ret;
72123 +
72124 + if (o_tmp->nested) {
72125 + int already_copied;
72126 +
72127 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
72128 + if (IS_ERR(o_tmp->nested))
72129 + return PTR_ERR(o_tmp->nested);
72130 +
72131 + /* insert into nested subject list if we haven't copied this one yet
72132 + to prevent duplicate entries */
72133 + if (!already_copied) {
72134 + o_tmp->nested->next = role->hash->first;
72135 + role->hash->first = o_tmp->nested;
72136 + }
72137 + }
72138 + }
72139 +
72140 + return 0;
72141 +}
72142 +
72143 +static __u32
72144 +count_user_subjs(struct acl_subject_label *userp)
72145 +{
72146 + struct acl_subject_label s_tmp;
72147 + __u32 num = 0;
72148 +
72149 + while (userp) {
72150 + if (copy_acl_subject_label(&s_tmp, userp))
72151 + break;
72152 +
72153 + userp = s_tmp.prev;
72154 + }
72155 +
72156 + return num;
72157 +}
72158 +
72159 +static int
72160 +copy_user_allowedips(struct acl_role_label *rolep)
72161 +{
72162 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
72163 +
72164 + ruserip = rolep->allowed_ips;
72165 +
72166 + while (ruserip) {
72167 + rlast = rtmp;
72168 +
72169 + if ((rtmp = (struct role_allowed_ip *)
72170 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
72171 + return -ENOMEM;
72172 +
72173 + if (copy_role_allowed_ip(rtmp, ruserip))
72174 + return -EFAULT;
72175 +
72176 + ruserip = rtmp->prev;
72177 +
72178 + if (!rlast) {
72179 + rtmp->prev = NULL;
72180 + rolep->allowed_ips = rtmp;
72181 + } else {
72182 + rlast->next = rtmp;
72183 + rtmp->prev = rlast;
72184 + }
72185 +
72186 + if (!ruserip)
72187 + rtmp->next = NULL;
72188 + }
72189 +
72190 + return 0;
72191 +}
72192 +
72193 +static int
72194 +copy_user_transitions(struct acl_role_label *rolep)
72195 +{
72196 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
72197 + int error;
72198 +
72199 + rusertp = rolep->transitions;
72200 +
72201 + while (rusertp) {
72202 + rlast = rtmp;
72203 +
72204 + if ((rtmp = (struct role_transition *)
72205 + acl_alloc(sizeof (struct role_transition))) == NULL)
72206 + return -ENOMEM;
72207 +
72208 + if (copy_role_transition(rtmp, rusertp))
72209 + return -EFAULT;
72210 +
72211 + rusertp = rtmp->prev;
72212 +
72213 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
72214 + if (error)
72215 + return error;
72216 +
72217 + if (!rlast) {
72218 + rtmp->prev = NULL;
72219 + rolep->transitions = rtmp;
72220 + } else {
72221 + rlast->next = rtmp;
72222 + rtmp->prev = rlast;
72223 + }
72224 +
72225 + if (!rusertp)
72226 + rtmp->next = NULL;
72227 + }
72228 +
72229 + return 0;
72230 +}
72231 +
72232 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
72233 +{
72234 + struct acl_object_label o_tmp;
72235 + __u32 num = 0;
72236 +
72237 + while (userp) {
72238 + if (copy_acl_object_label(&o_tmp, userp))
72239 + break;
72240 +
72241 + userp = o_tmp.prev;
72242 + num++;
72243 + }
72244 +
72245 + return num;
72246 +}
72247 +
72248 +static struct acl_subject_label *
72249 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
72250 +{
72251 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
72252 + __u32 num_objs;
72253 + struct acl_ip_label **i_tmp, *i_utmp2;
72254 + struct gr_hash_struct ghash;
72255 + struct subject_map *subjmap;
72256 + unsigned int i_num;
72257 + int err;
72258 +
72259 + if (already_copied != NULL)
72260 + *already_copied = 0;
72261 +
72262 + s_tmp = lookup_subject_map(userp);
72263 +
72264 + /* we've already copied this subject into the kernel, just return
72265 + the reference to it, and don't copy it over again
72266 + */
72267 + if (s_tmp) {
72268 + if (already_copied != NULL)
72269 + *already_copied = 1;
72270 + return(s_tmp);
72271 + }
72272 +
72273 + if ((s_tmp = (struct acl_subject_label *)
72274 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
72275 + return ERR_PTR(-ENOMEM);
72276 +
72277 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
72278 + if (subjmap == NULL)
72279 + return ERR_PTR(-ENOMEM);
72280 +
72281 + subjmap->user = userp;
72282 + subjmap->kernel = s_tmp;
72283 + insert_subj_map_entry(subjmap);
72284 +
72285 + if (copy_acl_subject_label(s_tmp, userp))
72286 + return ERR_PTR(-EFAULT);
72287 +
72288 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
72289 + if (err)
72290 + return ERR_PTR(err);
72291 +
72292 + if (!strcmp(s_tmp->filename, "/"))
72293 + role->root_label = s_tmp;
72294 +
72295 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
72296 + return ERR_PTR(-EFAULT);
72297 +
72298 + /* copy user and group transition tables */
72299 +
72300 + if (s_tmp->user_trans_num) {
72301 + uid_t *uidlist;
72302 +
72303 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
72304 + if (uidlist == NULL)
72305 + return ERR_PTR(-ENOMEM);
72306 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
72307 + return ERR_PTR(-EFAULT);
72308 +
72309 + s_tmp->user_transitions = uidlist;
72310 + }
72311 +
72312 + if (s_tmp->group_trans_num) {
72313 + gid_t *gidlist;
72314 +
72315 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
72316 + if (gidlist == NULL)
72317 + return ERR_PTR(-ENOMEM);
72318 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
72319 + return ERR_PTR(-EFAULT);
72320 +
72321 + s_tmp->group_transitions = gidlist;
72322 + }
72323 +
72324 + /* set up object hash table */
72325 + num_objs = count_user_objs(ghash.first);
72326 +
72327 + s_tmp->obj_hash_size = num_objs;
72328 + s_tmp->obj_hash =
72329 + (struct acl_object_label **)
72330 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
72331 +
72332 + if (!s_tmp->obj_hash)
72333 + return ERR_PTR(-ENOMEM);
72334 +
72335 + memset(s_tmp->obj_hash, 0,
72336 + s_tmp->obj_hash_size *
72337 + sizeof (struct acl_object_label *));
72338 +
72339 + /* add in objects */
72340 + err = copy_user_objs(ghash.first, s_tmp, role);
72341 +
72342 + if (err)
72343 + return ERR_PTR(err);
72344 +
72345 + /* set pointer for parent subject */
72346 + if (s_tmp->parent_subject) {
72347 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
72348 +
72349 + if (IS_ERR(s_tmp2))
72350 + return s_tmp2;
72351 +
72352 + s_tmp->parent_subject = s_tmp2;
72353 + }
72354 +
72355 + /* add in ip acls */
72356 +
72357 + if (!s_tmp->ip_num) {
72358 + s_tmp->ips = NULL;
72359 + goto insert;
72360 + }
72361 +
72362 + i_tmp =
72363 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
72364 + sizeof (struct acl_ip_label *));
72365 +
72366 + if (!i_tmp)
72367 + return ERR_PTR(-ENOMEM);
72368 +
72369 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72370 + *(i_tmp + i_num) =
72371 + (struct acl_ip_label *)
72372 + acl_alloc(sizeof (struct acl_ip_label));
72373 + if (!*(i_tmp + i_num))
72374 + return ERR_PTR(-ENOMEM);
72375 +
72376 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72377 + return ERR_PTR(-EFAULT);
72378 +
72379 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72380 + return ERR_PTR(-EFAULT);
72381 +
72382 + if ((*(i_tmp + i_num))->iface == NULL)
72383 + continue;
72384 +
72385 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72386 + if (err)
72387 + return ERR_PTR(err);
72388 + }
72389 +
72390 + s_tmp->ips = i_tmp;
72391 +
72392 +insert:
72393 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72394 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72395 + return ERR_PTR(-ENOMEM);
72396 +
72397 + return s_tmp;
72398 +}
72399 +
72400 +static int
72401 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72402 +{
72403 + struct acl_subject_label s_pre;
72404 + struct acl_subject_label * ret;
72405 + int err;
72406 +
72407 + while (userp) {
72408 + if (copy_acl_subject_label(&s_pre, userp))
72409 + return -EFAULT;
72410 +
72411 + ret = do_copy_user_subj(userp, role, NULL);
72412 +
72413 + err = PTR_ERR(ret);
72414 + if (IS_ERR(ret))
72415 + return err;
72416 +
72417 + insert_acl_subj_label(ret, role);
72418 +
72419 + userp = s_pre.prev;
72420 + }
72421 +
72422 + return 0;
72423 +}
72424 +
72425 +static int
72426 +copy_user_acl(struct gr_arg *arg)
72427 +{
72428 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72429 + struct acl_subject_label *subj_list;
72430 + struct sprole_pw *sptmp;
72431 + struct gr_hash_struct *ghash;
72432 + uid_t *domainlist;
72433 + unsigned int r_num;
72434 + int err = 0;
72435 + __u16 i;
72436 + __u32 num_subjs;
72437 +
72438 + /* we need a default and kernel role */
72439 + if (arg->role_db.num_roles < 2)
72440 + return -EINVAL;
72441 +
72442 + /* copy special role authentication info from userspace */
72443 +
72444 + polstate->num_sprole_pws = arg->num_sprole_pws;
72445 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72446 +
72447 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72448 + return -ENOMEM;
72449 +
72450 + for (i = 0; i < polstate->num_sprole_pws; i++) {
72451 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72452 + if (!sptmp)
72453 + return -ENOMEM;
72454 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72455 + return -EFAULT;
72456 +
72457 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72458 + if (err)
72459 + return err;
72460 +
72461 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72462 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72463 +#endif
72464 +
72465 + polstate->acl_special_roles[i] = sptmp;
72466 + }
72467 +
72468 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72469 +
72470 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72471 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
72472 +
72473 + if (!r_tmp)
72474 + return -ENOMEM;
72475 +
72476 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72477 + return -EFAULT;
72478 +
72479 + if (copy_acl_role_label(r_tmp, r_utmp2))
72480 + return -EFAULT;
72481 +
72482 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72483 + if (err)
72484 + return err;
72485 +
72486 + if (!strcmp(r_tmp->rolename, "default")
72487 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72488 + polstate->default_role = r_tmp;
72489 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72490 + polstate->kernel_role = r_tmp;
72491 + }
72492 +
72493 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72494 + return -ENOMEM;
72495 +
72496 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
72497 + return -EFAULT;
72498 +
72499 + r_tmp->hash = ghash;
72500 +
72501 + num_subjs = count_user_subjs(r_tmp->hash->first);
72502 +
72503 + r_tmp->subj_hash_size = num_subjs;
72504 + r_tmp->subj_hash =
72505 + (struct acl_subject_label **)
72506 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72507 +
72508 + if (!r_tmp->subj_hash)
72509 + return -ENOMEM;
72510 +
72511 + err = copy_user_allowedips(r_tmp);
72512 + if (err)
72513 + return err;
72514 +
72515 + /* copy domain info */
72516 + if (r_tmp->domain_children != NULL) {
72517 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72518 + if (domainlist == NULL)
72519 + return -ENOMEM;
72520 +
72521 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72522 + return -EFAULT;
72523 +
72524 + r_tmp->domain_children = domainlist;
72525 + }
72526 +
72527 + err = copy_user_transitions(r_tmp);
72528 + if (err)
72529 + return err;
72530 +
72531 + memset(r_tmp->subj_hash, 0,
72532 + r_tmp->subj_hash_size *
72533 + sizeof (struct acl_subject_label *));
72534 +
72535 + /* acquire the list of subjects, then NULL out
72536 + the list prior to parsing the subjects for this role,
72537 + as during this parsing the list is replaced with a list
72538 + of *nested* subjects for the role
72539 + */
72540 + subj_list = r_tmp->hash->first;
72541 +
72542 + /* set nested subject list to null */
72543 + r_tmp->hash->first = NULL;
72544 +
72545 + err = copy_user_subjs(subj_list, r_tmp);
72546 +
72547 + if (err)
72548 + return err;
72549 +
72550 + insert_acl_role_label(r_tmp);
72551 + }
72552 +
72553 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72554 + return -EINVAL;
72555 +
72556 + return err;
72557 +}
72558 +
72559 +static int gracl_reload_apply_policies(void *reload)
72560 +{
72561 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72562 + struct task_struct *task, *task2;
72563 + struct acl_role_label *role, *rtmp;
72564 + struct acl_subject_label *subj;
72565 + const struct cred *cred;
72566 + int role_applied;
72567 + int ret = 0;
72568 +
72569 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72570 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72571 +
72572 + /* first make sure we'll be able to apply the new policy cleanly */
72573 + do_each_thread(task2, task) {
72574 + if (task->exec_file == NULL)
72575 + continue;
72576 + role_applied = 0;
72577 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72578 + /* preserve special roles */
72579 + FOR_EACH_ROLE_START(role)
72580 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72581 + rtmp = task->role;
72582 + task->role = role;
72583 + role_applied = 1;
72584 + break;
72585 + }
72586 + FOR_EACH_ROLE_END(role)
72587 + }
72588 + if (!role_applied) {
72589 + cred = __task_cred(task);
72590 + rtmp = task->role;
72591 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72592 + }
72593 + /* this handles non-nested inherited subjects, nested subjects will still
72594 + be dropped currently */
72595 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72596 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72597 + /* change the role back so that we've made no modifications to the policy */
72598 + task->role = rtmp;
72599 +
72600 + if (subj == NULL || task->tmpacl == NULL) {
72601 + ret = -EINVAL;
72602 + goto out;
72603 + }
72604 + } while_each_thread(task2, task);
72605 +
72606 + /* now actually apply the policy */
72607 +
72608 + do_each_thread(task2, task) {
72609 + if (task->exec_file) {
72610 + role_applied = 0;
72611 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72612 + /* preserve special roles */
72613 + FOR_EACH_ROLE_START(role)
72614 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72615 + task->role = role;
72616 + role_applied = 1;
72617 + break;
72618 + }
72619 + FOR_EACH_ROLE_END(role)
72620 + }
72621 + if (!role_applied) {
72622 + cred = __task_cred(task);
72623 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72624 + }
72625 + /* this handles non-nested inherited subjects, nested subjects will still
72626 + be dropped currently */
72627 + if (!reload_state->oldmode && task->inherited)
72628 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72629 + else {
72630 + /* looked up and tagged to the task previously */
72631 + subj = task->tmpacl;
72632 + }
72633 + /* subj will be non-null */
72634 + __gr_apply_subject_to_task(polstate, task, subj);
72635 + if (reload_state->oldmode) {
72636 + task->acl_role_id = 0;
72637 + task->acl_sp_role = 0;
72638 + task->inherited = 0;
72639 + }
72640 + } else {
72641 + // it's a kernel process
72642 + task->role = polstate->kernel_role;
72643 + task->acl = polstate->kernel_role->root_label;
72644 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72645 + task->acl->mode &= ~GR_PROCFIND;
72646 +#endif
72647 + }
72648 + } while_each_thread(task2, task);
72649 +
72650 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72651 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72652 +
72653 +out:
72654 +
72655 + return ret;
72656 +}
72657 +
72658 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72659 +{
72660 + struct gr_reload_state new_reload_state = { };
72661 + int err;
72662 +
72663 + new_reload_state.oldpolicy_ptr = polstate;
72664 + new_reload_state.oldalloc_ptr = current_alloc_state;
72665 + new_reload_state.oldmode = oldmode;
72666 +
72667 + current_alloc_state = &new_reload_state.newalloc;
72668 + polstate = &new_reload_state.newpolicy;
72669 +
72670 + /* everything relevant is now saved off, copy in the new policy */
72671 + if (init_variables(args, true)) {
72672 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72673 + err = -ENOMEM;
72674 + goto error;
72675 + }
72676 +
72677 + err = copy_user_acl(args);
72678 + free_init_variables();
72679 + if (err)
72680 + goto error;
72681 + /* the new policy is copied in, with the old policy available via saved_state
72682 + first go through applying roles, making sure to preserve special roles
72683 + then apply new subjects, making sure to preserve inherited and nested subjects,
72684 + though currently only inherited subjects will be preserved
72685 + */
72686 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72687 + if (err)
72688 + goto error;
72689 +
72690 + /* we've now applied the new policy, so restore the old policy state to free it */
72691 + polstate = &new_reload_state.oldpolicy;
72692 + current_alloc_state = &new_reload_state.oldalloc;
72693 + free_variables(true);
72694 +
72695 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72696 + to running_polstate/current_alloc_state inside stop_machine
72697 + */
72698 + err = 0;
72699 + goto out;
72700 +error:
72701 + /* on error of loading the new policy, we'll just keep the previous
72702 + policy set around
72703 + */
72704 + free_variables(true);
72705 +
72706 + /* doesn't affect runtime, but maintains consistent state */
72707 +out:
72708 + polstate = new_reload_state.oldpolicy_ptr;
72709 + current_alloc_state = new_reload_state.oldalloc_ptr;
72710 +
72711 + return err;
72712 +}
72713 +
72714 +static int
72715 +gracl_init(struct gr_arg *args)
72716 +{
72717 + int error = 0;
72718 +
72719 + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72720 + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72721 +
72722 + if (init_variables(args, false)) {
72723 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72724 + error = -ENOMEM;
72725 + goto out;
72726 + }
72727 +
72728 + error = copy_user_acl(args);
72729 + free_init_variables();
72730 + if (error)
72731 + goto out;
72732 +
72733 + error = gr_set_acls(0);
72734 + if (error)
72735 + goto out;
72736 +
72737 + gr_enable_rbac_system();
72738 +
72739 + return 0;
72740 +
72741 +out:
72742 + free_variables(false);
72743 + return error;
72744 +}
72745 +
72746 +static int
72747 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72748 + unsigned char **sum)
72749 +{
72750 + struct acl_role_label *r;
72751 + struct role_allowed_ip *ipp;
72752 + struct role_transition *trans;
72753 + unsigned int i;
72754 + int found = 0;
72755 + u32 curr_ip = current->signal->curr_ip;
72756 +
72757 + current->signal->saved_ip = curr_ip;
72758 +
72759 + /* check transition table */
72760 +
72761 + for (trans = current->role->transitions; trans; trans = trans->next) {
72762 + if (!strcmp(rolename, trans->rolename)) {
72763 + found = 1;
72764 + break;
72765 + }
72766 + }
72767 +
72768 + if (!found)
72769 + return 0;
72770 +
72771 + /* handle special roles that do not require authentication
72772 + and check ip */
72773 +
72774 + FOR_EACH_ROLE_START(r)
72775 + if (!strcmp(rolename, r->rolename) &&
72776 + (r->roletype & GR_ROLE_SPECIAL)) {
72777 + found = 0;
72778 + if (r->allowed_ips != NULL) {
72779 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72780 + if ((ntohl(curr_ip) & ipp->netmask) ==
72781 + (ntohl(ipp->addr) & ipp->netmask))
72782 + found = 1;
72783 + }
72784 + } else
72785 + found = 2;
72786 + if (!found)
72787 + return 0;
72788 +
72789 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72790 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72791 + *salt = NULL;
72792 + *sum = NULL;
72793 + return 1;
72794 + }
72795 + }
72796 + FOR_EACH_ROLE_END(r)
72797 +
72798 + for (i = 0; i < polstate->num_sprole_pws; i++) {
72799 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72800 + *salt = polstate->acl_special_roles[i]->salt;
72801 + *sum = polstate->acl_special_roles[i]->sum;
72802 + return 1;
72803 + }
72804 + }
72805 +
72806 + return 0;
72807 +}
72808 +
72809 +int gr_check_secure_terminal(struct task_struct *task)
72810 +{
72811 + struct task_struct *p, *p2, *p3;
72812 + struct files_struct *files;
72813 + struct fdtable *fdt;
72814 + struct file *our_file = NULL, *file;
72815 + int i;
72816 +
72817 + if (task->signal->tty == NULL)
72818 + return 1;
72819 +
72820 + files = get_files_struct(task);
72821 + if (files != NULL) {
72822 + rcu_read_lock();
72823 + fdt = files_fdtable(files);
72824 + for (i=0; i < fdt->max_fds; i++) {
72825 + file = fcheck_files(files, i);
72826 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72827 + get_file(file);
72828 + our_file = file;
72829 + }
72830 + }
72831 + rcu_read_unlock();
72832 + put_files_struct(files);
72833 + }
72834 +
72835 + if (our_file == NULL)
72836 + return 1;
72837 +
72838 + read_lock(&tasklist_lock);
72839 + do_each_thread(p2, p) {
72840 + files = get_files_struct(p);
72841 + if (files == NULL ||
72842 + (p->signal && p->signal->tty == task->signal->tty)) {
72843 + if (files != NULL)
72844 + put_files_struct(files);
72845 + continue;
72846 + }
72847 + rcu_read_lock();
72848 + fdt = files_fdtable(files);
72849 + for (i=0; i < fdt->max_fds; i++) {
72850 + file = fcheck_files(files, i);
72851 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72852 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72853 + p3 = task;
72854 + while (task_pid_nr(p3) > 0) {
72855 + if (p3 == p)
72856 + break;
72857 + p3 = p3->real_parent;
72858 + }
72859 + if (p3 == p)
72860 + break;
72861 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72862 + gr_handle_alertkill(p);
72863 + rcu_read_unlock();
72864 + put_files_struct(files);
72865 + read_unlock(&tasklist_lock);
72866 + fput(our_file);
72867 + return 0;
72868 + }
72869 + }
72870 + rcu_read_unlock();
72871 + put_files_struct(files);
72872 + } while_each_thread(p2, p);
72873 + read_unlock(&tasklist_lock);
72874 +
72875 + fput(our_file);
72876 + return 1;
72877 +}
72878 +
72879 +ssize_t
72880 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72881 +{
72882 + struct gr_arg_wrapper uwrap;
72883 + unsigned char *sprole_salt = NULL;
72884 + unsigned char *sprole_sum = NULL;
72885 + int error = 0;
72886 + int error2 = 0;
72887 + size_t req_count = 0;
72888 + unsigned char oldmode = 0;
72889 +
72890 + mutex_lock(&gr_dev_mutex);
72891 +
72892 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72893 + error = -EPERM;
72894 + goto out;
72895 + }
72896 +
72897 +#ifdef CONFIG_COMPAT
72898 + pax_open_kernel();
72899 + if (is_compat_task()) {
72900 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72901 + copy_gr_arg = &copy_gr_arg_compat;
72902 + copy_acl_object_label = &copy_acl_object_label_compat;
72903 + copy_acl_subject_label = &copy_acl_subject_label_compat;
72904 + copy_acl_role_label = &copy_acl_role_label_compat;
72905 + copy_acl_ip_label = &copy_acl_ip_label_compat;
72906 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72907 + copy_role_transition = &copy_role_transition_compat;
72908 + copy_sprole_pw = &copy_sprole_pw_compat;
72909 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72910 + copy_pointer_from_array = &copy_pointer_from_array_compat;
72911 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72912 + } else {
72913 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72914 + copy_gr_arg = &copy_gr_arg_normal;
72915 + copy_acl_object_label = &copy_acl_object_label_normal;
72916 + copy_acl_subject_label = &copy_acl_subject_label_normal;
72917 + copy_acl_role_label = &copy_acl_role_label_normal;
72918 + copy_acl_ip_label = &copy_acl_ip_label_normal;
72919 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72920 + copy_role_transition = &copy_role_transition_normal;
72921 + copy_sprole_pw = &copy_sprole_pw_normal;
72922 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72923 + copy_pointer_from_array = &copy_pointer_from_array_normal;
72924 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72925 + }
72926 + pax_close_kernel();
72927 +#endif
72928 +
72929 + req_count = get_gr_arg_wrapper_size();
72930 +
72931 + if (count != req_count) {
72932 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72933 + error = -EINVAL;
72934 + goto out;
72935 + }
72936 +
72937 +
72938 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72939 + gr_auth_expires = 0;
72940 + gr_auth_attempts = 0;
72941 + }
72942 +
72943 + error = copy_gr_arg_wrapper(buf, &uwrap);
72944 + if (error)
72945 + goto out;
72946 +
72947 + error = copy_gr_arg(uwrap.arg, &gr_usermode);
72948 + if (error)
72949 + goto out;
72950 +
72951 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72952 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72953 + time_after(gr_auth_expires, get_seconds())) {
72954 + error = -EBUSY;
72955 + goto out;
72956 + }
72957 +
72958 + /* if non-root trying to do anything other than use a special role,
72959 + do not attempt authentication, do not count towards authentication
72960 + locking
72961 + */
72962 +
72963 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72964 + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72965 + gr_is_global_nonroot(current_uid())) {
72966 + error = -EPERM;
72967 + goto out;
72968 + }
72969 +
72970 + /* ensure pw and special role name are null terminated */
72971 +
72972 + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72973 + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72974 +
72975 + /* Okay.
72976 + * We have our enough of the argument structure..(we have yet
72977 + * to copy_from_user the tables themselves) . Copy the tables
72978 + * only if we need them, i.e. for loading operations. */
72979 +
72980 + switch (gr_usermode.mode) {
72981 + case GR_STATUS:
72982 + if (gr_acl_is_enabled()) {
72983 + error = 1;
72984 + if (!gr_check_secure_terminal(current))
72985 + error = 3;
72986 + } else
72987 + error = 2;
72988 + goto out;
72989 + case GR_SHUTDOWN:
72990 + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72991 + stop_machine(gr_rbac_disable, NULL, NULL);
72992 + free_variables(false);
72993 + memset(&gr_usermode, 0, sizeof(gr_usermode));
72994 + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72995 + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72996 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72997 + } else if (gr_acl_is_enabled()) {
72998 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72999 + error = -EPERM;
73000 + } else {
73001 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
73002 + error = -EAGAIN;
73003 + }
73004 + break;
73005 + case GR_ENABLE:
73006 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
73007 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
73008 + else {
73009 + if (gr_acl_is_enabled())
73010 + error = -EAGAIN;
73011 + else
73012 + error = error2;
73013 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
73014 + }
73015 + break;
73016 + case GR_OLDRELOAD:
73017 + oldmode = 1;
73018 + case GR_RELOAD:
73019 + if (!gr_acl_is_enabled()) {
73020 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
73021 + error = -EAGAIN;
73022 + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
73023 + error2 = gracl_reload(&gr_usermode, oldmode);
73024 + if (!error2)
73025 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
73026 + else {
73027 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73028 + error = error2;
73029 + }
73030 + } else {
73031 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73032 + error = -EPERM;
73033 + }
73034 + break;
73035 + case GR_SEGVMOD:
73036 + if (unlikely(!gr_acl_is_enabled())) {
73037 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
73038 + error = -EAGAIN;
73039 + break;
73040 + }
73041 +
73042 + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
73043 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
73044 + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
73045 + struct acl_subject_label *segvacl;
73046 + segvacl =
73047 + lookup_acl_subj_label(gr_usermode.segv_inode,
73048 + gr_usermode.segv_device,
73049 + current->role);
73050 + if (segvacl) {
73051 + segvacl->crashes = 0;
73052 + segvacl->expires = 0;
73053 + }
73054 + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
73055 + gr_remove_uid(gr_usermode.segv_uid);
73056 + }
73057 + } else {
73058 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
73059 + error = -EPERM;
73060 + }
73061 + break;
73062 + case GR_SPROLE:
73063 + case GR_SPROLEPAM:
73064 + if (unlikely(!gr_acl_is_enabled())) {
73065 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
73066 + error = -EAGAIN;
73067 + break;
73068 + }
73069 +
73070 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
73071 + current->role->expires = 0;
73072 + current->role->auth_attempts = 0;
73073 + }
73074 +
73075 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73076 + time_after(current->role->expires, get_seconds())) {
73077 + error = -EBUSY;
73078 + goto out;
73079 + }
73080 +
73081 + if (lookup_special_role_auth
73082 + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
73083 + && ((!sprole_salt && !sprole_sum)
73084 + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
73085 + char *p = "";
73086 + assign_special_role(gr_usermode.sp_role);
73087 + read_lock(&tasklist_lock);
73088 + if (current->real_parent)
73089 + p = current->real_parent->role->rolename;
73090 + read_unlock(&tasklist_lock);
73091 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
73092 + p, acl_sp_role_value);
73093 + } else {
73094 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
73095 + error = -EPERM;
73096 + if(!(current->role->auth_attempts++))
73097 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73098 +
73099 + goto out;
73100 + }
73101 + break;
73102 + case GR_UNSPROLE:
73103 + if (unlikely(!gr_acl_is_enabled())) {
73104 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
73105 + error = -EAGAIN;
73106 + break;
73107 + }
73108 +
73109 + if (current->role->roletype & GR_ROLE_SPECIAL) {
73110 + char *p = "";
73111 + int i = 0;
73112 +
73113 + read_lock(&tasklist_lock);
73114 + if (current->real_parent) {
73115 + p = current->real_parent->role->rolename;
73116 + i = current->real_parent->acl_role_id;
73117 + }
73118 + read_unlock(&tasklist_lock);
73119 +
73120 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
73121 + gr_set_acls(1);
73122 + } else {
73123 + error = -EPERM;
73124 + goto out;
73125 + }
73126 + break;
73127 + default:
73128 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
73129 + error = -EINVAL;
73130 + break;
73131 + }
73132 +
73133 + if (error != -EPERM)
73134 + goto out;
73135 +
73136 + if(!(gr_auth_attempts++))
73137 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73138 +
73139 + out:
73140 + mutex_unlock(&gr_dev_mutex);
73141 +
73142 + if (!error)
73143 + error = req_count;
73144 +
73145 + return error;
73146 +}
73147 +
73148 +int
73149 +gr_set_acls(const int type)
73150 +{
73151 + struct task_struct *task, *task2;
73152 + struct acl_role_label *role = current->role;
73153 + struct acl_subject_label *subj;
73154 + __u16 acl_role_id = current->acl_role_id;
73155 + const struct cred *cred;
73156 + int ret;
73157 +
73158 + rcu_read_lock();
73159 + read_lock(&tasklist_lock);
73160 + read_lock(&grsec_exec_file_lock);
73161 + do_each_thread(task2, task) {
73162 + /* check to see if we're called from the exit handler,
73163 + if so, only replace ACLs that have inherited the admin
73164 + ACL */
73165 +
73166 + if (type && (task->role != role ||
73167 + task->acl_role_id != acl_role_id))
73168 + continue;
73169 +
73170 + task->acl_role_id = 0;
73171 + task->acl_sp_role = 0;
73172 + task->inherited = 0;
73173 +
73174 + if (task->exec_file) {
73175 + cred = __task_cred(task);
73176 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
73177 + subj = __gr_get_subject_for_task(polstate, task, NULL);
73178 + if (subj == NULL) {
73179 + ret = -EINVAL;
73180 + read_unlock(&grsec_exec_file_lock);
73181 + read_unlock(&tasklist_lock);
73182 + rcu_read_unlock();
73183 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
73184 + return ret;
73185 + }
73186 + __gr_apply_subject_to_task(polstate, task, subj);
73187 + } else {
73188 + // it's a kernel process
73189 + task->role = polstate->kernel_role;
73190 + task->acl = polstate->kernel_role->root_label;
73191 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
73192 + task->acl->mode &= ~GR_PROCFIND;
73193 +#endif
73194 + }
73195 + } while_each_thread(task2, task);
73196 + read_unlock(&grsec_exec_file_lock);
73197 + read_unlock(&tasklist_lock);
73198 + rcu_read_unlock();
73199 +
73200 + return 0;
73201 +}
73202 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
73203 new file mode 100644
73204 index 0000000..39645c9
73205 --- /dev/null
73206 +++ b/grsecurity/gracl_res.c
73207 @@ -0,0 +1,68 @@
73208 +#include <linux/kernel.h>
73209 +#include <linux/sched.h>
73210 +#include <linux/gracl.h>
73211 +#include <linux/grinternal.h>
73212 +
73213 +static const char *restab_log[] = {
73214 + [RLIMIT_CPU] = "RLIMIT_CPU",
73215 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
73216 + [RLIMIT_DATA] = "RLIMIT_DATA",
73217 + [RLIMIT_STACK] = "RLIMIT_STACK",
73218 + [RLIMIT_CORE] = "RLIMIT_CORE",
73219 + [RLIMIT_RSS] = "RLIMIT_RSS",
73220 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
73221 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
73222 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
73223 + [RLIMIT_AS] = "RLIMIT_AS",
73224 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
73225 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
73226 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
73227 + [RLIMIT_NICE] = "RLIMIT_NICE",
73228 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
73229 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
73230 + [GR_CRASH_RES] = "RLIMIT_CRASH"
73231 +};
73232 +
73233 +void
73234 +gr_log_resource(const struct task_struct *task,
73235 + const int res, const unsigned long wanted, const int gt)
73236 +{
73237 + const struct cred *cred;
73238 + unsigned long rlim;
73239 +
73240 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
73241 + return;
73242 +
73243 + // not yet supported resource
73244 + if (unlikely(!restab_log[res]))
73245 + return;
73246 +
73247 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
73248 + rlim = task_rlimit_max(task, res);
73249 + else
73250 + rlim = task_rlimit(task, res);
73251 +
73252 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
73253 + return;
73254 +
73255 + rcu_read_lock();
73256 + cred = __task_cred(task);
73257 +
73258 + if (res == RLIMIT_NPROC &&
73259 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
73260 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
73261 + goto out_rcu_unlock;
73262 + else if (res == RLIMIT_MEMLOCK &&
73263 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
73264 + goto out_rcu_unlock;
73265 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
73266 + goto out_rcu_unlock;
73267 + rcu_read_unlock();
73268 +
73269 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
73270 +
73271 + return;
73272 +out_rcu_unlock:
73273 + rcu_read_unlock();
73274 + return;
73275 +}
73276 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
73277 new file mode 100644
73278 index 0000000..2040e61
73279 --- /dev/null
73280 +++ b/grsecurity/gracl_segv.c
73281 @@ -0,0 +1,313 @@
73282 +#include <linux/kernel.h>
73283 +#include <linux/mm.h>
73284 +#include <asm/uaccess.h>
73285 +#include <asm/errno.h>
73286 +#include <asm/mman.h>
73287 +#include <net/sock.h>
73288 +#include <linux/file.h>
73289 +#include <linux/fs.h>
73290 +#include <linux/net.h>
73291 +#include <linux/in.h>
73292 +#include <linux/slab.h>
73293 +#include <linux/types.h>
73294 +#include <linux/sched.h>
73295 +#include <linux/timer.h>
73296 +#include <linux/gracl.h>
73297 +#include <linux/grsecurity.h>
73298 +#include <linux/grinternal.h>
73299 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73300 +#include <linux/magic.h>
73301 +#include <linux/pagemap.h>
73302 +#include "../fs/btrfs/async-thread.h"
73303 +#include "../fs/btrfs/ctree.h"
73304 +#include "../fs/btrfs/btrfs_inode.h"
73305 +#endif
73306 +
73307 +static struct crash_uid *uid_set;
73308 +static unsigned short uid_used;
73309 +static DEFINE_SPINLOCK(gr_uid_lock);
73310 +extern rwlock_t gr_inode_lock;
73311 +extern struct acl_subject_label *
73312 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
73313 + struct acl_role_label *role);
73314 +
73315 +static inline dev_t __get_dev(const struct dentry *dentry)
73316 +{
73317 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73318 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
73319 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
73320 + else
73321 +#endif
73322 + return dentry->d_sb->s_dev;
73323 +}
73324 +
73325 +int
73326 +gr_init_uidset(void)
73327 +{
73328 + uid_set =
73329 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
73330 + uid_used = 0;
73331 +
73332 + return uid_set ? 1 : 0;
73333 +}
73334 +
73335 +void
73336 +gr_free_uidset(void)
73337 +{
73338 + if (uid_set) {
73339 + struct crash_uid *tmpset;
73340 + spin_lock(&gr_uid_lock);
73341 + tmpset = uid_set;
73342 + uid_set = NULL;
73343 + uid_used = 0;
73344 + spin_unlock(&gr_uid_lock);
73345 + if (tmpset)
73346 + kfree(tmpset);
73347 + }
73348 +
73349 + return;
73350 +}
73351 +
73352 +int
73353 +gr_find_uid(const uid_t uid)
73354 +{
73355 + struct crash_uid *tmp = uid_set;
73356 + uid_t buid;
73357 + int low = 0, high = uid_used - 1, mid;
73358 +
73359 + while (high >= low) {
73360 + mid = (low + high) >> 1;
73361 + buid = tmp[mid].uid;
73362 + if (buid == uid)
73363 + return mid;
73364 + if (buid > uid)
73365 + high = mid - 1;
73366 + if (buid < uid)
73367 + low = mid + 1;
73368 + }
73369 +
73370 + return -1;
73371 +}
73372 +
73373 +static __inline__ void
73374 +gr_insertsort(void)
73375 +{
73376 + unsigned short i, j;
73377 + struct crash_uid index;
73378 +
73379 + for (i = 1; i < uid_used; i++) {
73380 + index = uid_set[i];
73381 + j = i;
73382 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73383 + uid_set[j] = uid_set[j - 1];
73384 + j--;
73385 + }
73386 + uid_set[j] = index;
73387 + }
73388 +
73389 + return;
73390 +}
73391 +
73392 +static __inline__ void
73393 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73394 +{
73395 + int loc;
73396 + uid_t uid = GR_GLOBAL_UID(kuid);
73397 +
73398 + if (uid_used == GR_UIDTABLE_MAX)
73399 + return;
73400 +
73401 + loc = gr_find_uid(uid);
73402 +
73403 + if (loc >= 0) {
73404 + uid_set[loc].expires = expires;
73405 + return;
73406 + }
73407 +
73408 + uid_set[uid_used].uid = uid;
73409 + uid_set[uid_used].expires = expires;
73410 + uid_used++;
73411 +
73412 + gr_insertsort();
73413 +
73414 + return;
73415 +}
73416 +
73417 +void
73418 +gr_remove_uid(const unsigned short loc)
73419 +{
73420 + unsigned short i;
73421 +
73422 + for (i = loc + 1; i < uid_used; i++)
73423 + uid_set[i - 1] = uid_set[i];
73424 +
73425 + uid_used--;
73426 +
73427 + return;
73428 +}
73429 +
73430 +int
73431 +gr_check_crash_uid(const kuid_t kuid)
73432 +{
73433 + int loc;
73434 + int ret = 0;
73435 + uid_t uid;
73436 +
73437 + if (unlikely(!gr_acl_is_enabled()))
73438 + return 0;
73439 +
73440 + uid = GR_GLOBAL_UID(kuid);
73441 +
73442 + spin_lock(&gr_uid_lock);
73443 + loc = gr_find_uid(uid);
73444 +
73445 + if (loc < 0)
73446 + goto out_unlock;
73447 +
73448 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
73449 + gr_remove_uid(loc);
73450 + else
73451 + ret = 1;
73452 +
73453 +out_unlock:
73454 + spin_unlock(&gr_uid_lock);
73455 + return ret;
73456 +}
73457 +
73458 +static __inline__ int
73459 +proc_is_setxid(const struct cred *cred)
73460 +{
73461 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73462 + !uid_eq(cred->uid, cred->fsuid))
73463 + return 1;
73464 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73465 + !gid_eq(cred->gid, cred->fsgid))
73466 + return 1;
73467 +
73468 + return 0;
73469 +}
73470 +
73471 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
73472 +
73473 +void
73474 +gr_handle_crash(struct task_struct *task, const int sig)
73475 +{
73476 + struct acl_subject_label *curr;
73477 + struct task_struct *tsk, *tsk2;
73478 + const struct cred *cred;
73479 + const struct cred *cred2;
73480 +
73481 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73482 + return;
73483 +
73484 + if (unlikely(!gr_acl_is_enabled()))
73485 + return;
73486 +
73487 + curr = task->acl;
73488 +
73489 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
73490 + return;
73491 +
73492 + if (time_before_eq(curr->expires, get_seconds())) {
73493 + curr->expires = 0;
73494 + curr->crashes = 0;
73495 + }
73496 +
73497 + curr->crashes++;
73498 +
73499 + if (!curr->expires)
73500 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73501 +
73502 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73503 + time_after(curr->expires, get_seconds())) {
73504 + rcu_read_lock();
73505 + cred = __task_cred(task);
73506 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73507 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73508 + spin_lock(&gr_uid_lock);
73509 + gr_insert_uid(cred->uid, curr->expires);
73510 + spin_unlock(&gr_uid_lock);
73511 + curr->expires = 0;
73512 + curr->crashes = 0;
73513 + read_lock(&tasklist_lock);
73514 + do_each_thread(tsk2, tsk) {
73515 + cred2 = __task_cred(tsk);
73516 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
73517 + gr_fake_force_sig(SIGKILL, tsk);
73518 + } while_each_thread(tsk2, tsk);
73519 + read_unlock(&tasklist_lock);
73520 + } else {
73521 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73522 + read_lock(&tasklist_lock);
73523 + read_lock(&grsec_exec_file_lock);
73524 + do_each_thread(tsk2, tsk) {
73525 + if (likely(tsk != task)) {
73526 + // if this thread has the same subject as the one that triggered
73527 + // RES_CRASH and it's the same binary, kill it
73528 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73529 + gr_fake_force_sig(SIGKILL, tsk);
73530 + }
73531 + } while_each_thread(tsk2, tsk);
73532 + read_unlock(&grsec_exec_file_lock);
73533 + read_unlock(&tasklist_lock);
73534 + }
73535 + rcu_read_unlock();
73536 + }
73537 +
73538 + return;
73539 +}
73540 +
73541 +int
73542 +gr_check_crash_exec(const struct file *filp)
73543 +{
73544 + struct acl_subject_label *curr;
73545 +
73546 + if (unlikely(!gr_acl_is_enabled()))
73547 + return 0;
73548 +
73549 + read_lock(&gr_inode_lock);
73550 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73551 + __get_dev(filp->f_path.dentry),
73552 + current->role);
73553 + read_unlock(&gr_inode_lock);
73554 +
73555 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73556 + (!curr->crashes && !curr->expires))
73557 + return 0;
73558 +
73559 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73560 + time_after(curr->expires, get_seconds()))
73561 + return 1;
73562 + else if (time_before_eq(curr->expires, get_seconds())) {
73563 + curr->crashes = 0;
73564 + curr->expires = 0;
73565 + }
73566 +
73567 + return 0;
73568 +}
73569 +
73570 +void
73571 +gr_handle_alertkill(struct task_struct *task)
73572 +{
73573 + struct acl_subject_label *curracl;
73574 + __u32 curr_ip;
73575 + struct task_struct *p, *p2;
73576 +
73577 + if (unlikely(!gr_acl_is_enabled()))
73578 + return;
73579 +
73580 + curracl = task->acl;
73581 + curr_ip = task->signal->curr_ip;
73582 +
73583 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73584 + read_lock(&tasklist_lock);
73585 + do_each_thread(p2, p) {
73586 + if (p->signal->curr_ip == curr_ip)
73587 + gr_fake_force_sig(SIGKILL, p);
73588 + } while_each_thread(p2, p);
73589 + read_unlock(&tasklist_lock);
73590 + } else if (curracl->mode & GR_KILLPROC)
73591 + gr_fake_force_sig(SIGKILL, task);
73592 +
73593 + return;
73594 +}
73595 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73596 new file mode 100644
73597 index 0000000..98011b0
73598 --- /dev/null
73599 +++ b/grsecurity/gracl_shm.c
73600 @@ -0,0 +1,40 @@
73601 +#include <linux/kernel.h>
73602 +#include <linux/mm.h>
73603 +#include <linux/sched.h>
73604 +#include <linux/file.h>
73605 +#include <linux/ipc.h>
73606 +#include <linux/gracl.h>
73607 +#include <linux/grsecurity.h>
73608 +#include <linux/grinternal.h>
73609 +
73610 +int
73611 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73612 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
73613 +{
73614 + struct task_struct *task;
73615 +
73616 + if (!gr_acl_is_enabled())
73617 + return 1;
73618 +
73619 + rcu_read_lock();
73620 + read_lock(&tasklist_lock);
73621 +
73622 + task = find_task_by_vpid(shm_cprid);
73623 +
73624 + if (unlikely(!task))
73625 + task = find_task_by_vpid(shm_lapid);
73626 +
73627 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73628 + (task_pid_nr(task) == shm_lapid)) &&
73629 + (task->acl->mode & GR_PROTSHM) &&
73630 + (task->acl != current->acl))) {
73631 + read_unlock(&tasklist_lock);
73632 + rcu_read_unlock();
73633 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73634 + return 0;
73635 + }
73636 + read_unlock(&tasklist_lock);
73637 + rcu_read_unlock();
73638 +
73639 + return 1;
73640 +}
73641 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73642 new file mode 100644
73643 index 0000000..bc0be01
73644 --- /dev/null
73645 +++ b/grsecurity/grsec_chdir.c
73646 @@ -0,0 +1,19 @@
73647 +#include <linux/kernel.h>
73648 +#include <linux/sched.h>
73649 +#include <linux/fs.h>
73650 +#include <linux/file.h>
73651 +#include <linux/grsecurity.h>
73652 +#include <linux/grinternal.h>
73653 +
73654 +void
73655 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73656 +{
73657 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73658 + if ((grsec_enable_chdir && grsec_enable_group &&
73659 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73660 + !grsec_enable_group)) {
73661 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73662 + }
73663 +#endif
73664 + return;
73665 +}
73666 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73667 new file mode 100644
73668 index 0000000..baa635c
73669 --- /dev/null
73670 +++ b/grsecurity/grsec_chroot.c
73671 @@ -0,0 +1,387 @@
73672 +#include <linux/kernel.h>
73673 +#include <linux/module.h>
73674 +#include <linux/sched.h>
73675 +#include <linux/file.h>
73676 +#include <linux/fs.h>
73677 +#include <linux/mount.h>
73678 +#include <linux/types.h>
73679 +#include "../fs/mount.h"
73680 +#include <linux/grsecurity.h>
73681 +#include <linux/grinternal.h>
73682 +
73683 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73684 +int gr_init_ran;
73685 +#endif
73686 +
73687 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73688 +{
73689 +#ifdef CONFIG_GRKERNSEC
73690 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73691 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73692 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73693 + && gr_init_ran
73694 +#endif
73695 + )
73696 + task->gr_is_chrooted = 1;
73697 + else {
73698 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73699 + if (task_pid_nr(task) == 1 && !gr_init_ran)
73700 + gr_init_ran = 1;
73701 +#endif
73702 + task->gr_is_chrooted = 0;
73703 + }
73704 +
73705 + task->gr_chroot_dentry = path->dentry;
73706 +#endif
73707 + return;
73708 +}
73709 +
73710 +void gr_clear_chroot_entries(struct task_struct *task)
73711 +{
73712 +#ifdef CONFIG_GRKERNSEC
73713 + task->gr_is_chrooted = 0;
73714 + task->gr_chroot_dentry = NULL;
73715 +#endif
73716 + return;
73717 +}
73718 +
73719 +int
73720 +gr_handle_chroot_unix(const pid_t pid)
73721 +{
73722 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73723 + struct task_struct *p;
73724 +
73725 + if (unlikely(!grsec_enable_chroot_unix))
73726 + return 1;
73727 +
73728 + if (likely(!proc_is_chrooted(current)))
73729 + return 1;
73730 +
73731 + rcu_read_lock();
73732 + read_lock(&tasklist_lock);
73733 + p = find_task_by_vpid_unrestricted(pid);
73734 + if (unlikely(p && !have_same_root(current, p))) {
73735 + read_unlock(&tasklist_lock);
73736 + rcu_read_unlock();
73737 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73738 + return 0;
73739 + }
73740 + read_unlock(&tasklist_lock);
73741 + rcu_read_unlock();
73742 +#endif
73743 + return 1;
73744 +}
73745 +
73746 +int
73747 +gr_handle_chroot_nice(void)
73748 +{
73749 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73750 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73751 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73752 + return -EPERM;
73753 + }
73754 +#endif
73755 + return 0;
73756 +}
73757 +
73758 +int
73759 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73760 +{
73761 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73762 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73763 + && proc_is_chrooted(current)) {
73764 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73765 + return -EACCES;
73766 + }
73767 +#endif
73768 + return 0;
73769 +}
73770 +
73771 +int
73772 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73773 +{
73774 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73775 + struct task_struct *p;
73776 + int ret = 0;
73777 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73778 + return ret;
73779 +
73780 + read_lock(&tasklist_lock);
73781 + do_each_pid_task(pid, type, p) {
73782 + if (!have_same_root(current, p)) {
73783 + ret = 1;
73784 + goto out;
73785 + }
73786 + } while_each_pid_task(pid, type, p);
73787 +out:
73788 + read_unlock(&tasklist_lock);
73789 + return ret;
73790 +#endif
73791 + return 0;
73792 +}
73793 +
73794 +int
73795 +gr_pid_is_chrooted(struct task_struct *p)
73796 +{
73797 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73798 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73799 + return 0;
73800 +
73801 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73802 + !have_same_root(current, p)) {
73803 + return 1;
73804 + }
73805 +#endif
73806 + return 0;
73807 +}
73808 +
73809 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73810 +
73811 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73812 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73813 +{
73814 + struct path path, currentroot;
73815 + int ret = 0;
73816 +
73817 + path.dentry = (struct dentry *)u_dentry;
73818 + path.mnt = (struct vfsmount *)u_mnt;
73819 + get_fs_root(current->fs, &currentroot);
73820 + if (path_is_under(&path, &currentroot))
73821 + ret = 1;
73822 + path_put(&currentroot);
73823 +
73824 + return ret;
73825 +}
73826 +#endif
73827 +
73828 +int
73829 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73830 +{
73831 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73832 + if (!grsec_enable_chroot_fchdir)
73833 + return 1;
73834 +
73835 + if (!proc_is_chrooted(current))
73836 + return 1;
73837 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73838 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73839 + return 0;
73840 + }
73841 +#endif
73842 + return 1;
73843 +}
73844 +
73845 +int
73846 +gr_chroot_fhandle(void)
73847 +{
73848 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73849 + if (!grsec_enable_chroot_fchdir)
73850 + return 1;
73851 +
73852 + if (!proc_is_chrooted(current))
73853 + return 1;
73854 + else {
73855 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
73856 + return 0;
73857 + }
73858 +#endif
73859 + return 1;
73860 +}
73861 +
73862 +int
73863 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73864 + const time_t shm_createtime)
73865 +{
73866 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73867 + struct task_struct *p;
73868 + time_t starttime;
73869 +
73870 + if (unlikely(!grsec_enable_chroot_shmat))
73871 + return 1;
73872 +
73873 + if (likely(!proc_is_chrooted(current)))
73874 + return 1;
73875 +
73876 + rcu_read_lock();
73877 + read_lock(&tasklist_lock);
73878 +
73879 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73880 + starttime = p->start_time.tv_sec;
73881 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73882 + if (have_same_root(current, p)) {
73883 + goto allow;
73884 + } else {
73885 + read_unlock(&tasklist_lock);
73886 + rcu_read_unlock();
73887 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73888 + return 0;
73889 + }
73890 + }
73891 + /* creator exited, pid reuse, fall through to next check */
73892 + }
73893 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73894 + if (unlikely(!have_same_root(current, p))) {
73895 + read_unlock(&tasklist_lock);
73896 + rcu_read_unlock();
73897 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73898 + return 0;
73899 + }
73900 + }
73901 +
73902 +allow:
73903 + read_unlock(&tasklist_lock);
73904 + rcu_read_unlock();
73905 +#endif
73906 + return 1;
73907 +}
73908 +
73909 +void
73910 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73911 +{
73912 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73913 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73914 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73915 +#endif
73916 + return;
73917 +}
73918 +
73919 +int
73920 +gr_handle_chroot_mknod(const struct dentry *dentry,
73921 + const struct vfsmount *mnt, const int mode)
73922 +{
73923 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73924 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73925 + proc_is_chrooted(current)) {
73926 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73927 + return -EPERM;
73928 + }
73929 +#endif
73930 + return 0;
73931 +}
73932 +
73933 +int
73934 +gr_handle_chroot_mount(const struct dentry *dentry,
73935 + const struct vfsmount *mnt, const char *dev_name)
73936 +{
73937 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73938 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73939 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73940 + return -EPERM;
73941 + }
73942 +#endif
73943 + return 0;
73944 +}
73945 +
73946 +int
73947 +gr_handle_chroot_pivot(void)
73948 +{
73949 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73950 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73951 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73952 + return -EPERM;
73953 + }
73954 +#endif
73955 + return 0;
73956 +}
73957 +
73958 +int
73959 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73960 +{
73961 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73962 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73963 + !gr_is_outside_chroot(dentry, mnt)) {
73964 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73965 + return -EPERM;
73966 + }
73967 +#endif
73968 + return 0;
73969 +}
73970 +
73971 +extern const char *captab_log[];
73972 +extern int captab_log_entries;
73973 +
73974 +int
73975 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73976 +{
73977 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73978 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73979 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73980 + if (cap_raised(chroot_caps, cap)) {
73981 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73982 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73983 + }
73984 + return 0;
73985 + }
73986 + }
73987 +#endif
73988 + return 1;
73989 +}
73990 +
73991 +int
73992 +gr_chroot_is_capable(const int cap)
73993 +{
73994 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73995 + return gr_task_chroot_is_capable(current, current_cred(), cap);
73996 +#endif
73997 + return 1;
73998 +}
73999 +
74000 +int
74001 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
74002 +{
74003 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74004 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
74005 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
74006 + if (cap_raised(chroot_caps, cap)) {
74007 + return 0;
74008 + }
74009 + }
74010 +#endif
74011 + return 1;
74012 +}
74013 +
74014 +int
74015 +gr_chroot_is_capable_nolog(const int cap)
74016 +{
74017 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74018 + return gr_task_chroot_is_capable_nolog(current, cap);
74019 +#endif
74020 + return 1;
74021 +}
74022 +
74023 +int
74024 +gr_handle_chroot_sysctl(const int op)
74025 +{
74026 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74027 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
74028 + proc_is_chrooted(current))
74029 + return -EACCES;
74030 +#endif
74031 + return 0;
74032 +}
74033 +
74034 +void
74035 +gr_handle_chroot_chdir(const struct path *path)
74036 +{
74037 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74038 + if (grsec_enable_chroot_chdir)
74039 + set_fs_pwd(current->fs, path);
74040 +#endif
74041 + return;
74042 +}
74043 +
74044 +int
74045 +gr_handle_chroot_chmod(const struct dentry *dentry,
74046 + const struct vfsmount *mnt, const int mode)
74047 +{
74048 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74049 + /* allow chmod +s on directories, but not files */
74050 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
74051 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
74052 + proc_is_chrooted(current)) {
74053 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
74054 + return -EPERM;
74055 + }
74056 +#endif
74057 + return 0;
74058 +}
74059 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
74060 new file mode 100644
74061 index 0000000..de31e65
74062 --- /dev/null
74063 +++ b/grsecurity/grsec_disabled.c
74064 @@ -0,0 +1,434 @@
74065 +#include <linux/kernel.h>
74066 +#include <linux/module.h>
74067 +#include <linux/sched.h>
74068 +#include <linux/file.h>
74069 +#include <linux/fs.h>
74070 +#include <linux/kdev_t.h>
74071 +#include <linux/net.h>
74072 +#include <linux/in.h>
74073 +#include <linux/ip.h>
74074 +#include <linux/skbuff.h>
74075 +#include <linux/sysctl.h>
74076 +
74077 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
74078 +void
74079 +pax_set_initial_flags(struct linux_binprm *bprm)
74080 +{
74081 + return;
74082 +}
74083 +#endif
74084 +
74085 +#ifdef CONFIG_SYSCTL
74086 +__u32
74087 +gr_handle_sysctl(const struct ctl_table * table, const int op)
74088 +{
74089 + return 0;
74090 +}
74091 +#endif
74092 +
74093 +#ifdef CONFIG_TASKSTATS
74094 +int gr_is_taskstats_denied(int pid)
74095 +{
74096 + return 0;
74097 +}
74098 +#endif
74099 +
74100 +int
74101 +gr_acl_is_enabled(void)
74102 +{
74103 + return 0;
74104 +}
74105 +
74106 +void
74107 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
74108 +{
74109 + return;
74110 +}
74111 +
74112 +int
74113 +gr_handle_rawio(const struct inode *inode)
74114 +{
74115 + return 0;
74116 +}
74117 +
74118 +void
74119 +gr_acl_handle_psacct(struct task_struct *task, const long code)
74120 +{
74121 + return;
74122 +}
74123 +
74124 +int
74125 +gr_handle_ptrace(struct task_struct *task, const long request)
74126 +{
74127 + return 0;
74128 +}
74129 +
74130 +int
74131 +gr_handle_proc_ptrace(struct task_struct *task)
74132 +{
74133 + return 0;
74134 +}
74135 +
74136 +int
74137 +gr_set_acls(const int type)
74138 +{
74139 + return 0;
74140 +}
74141 +
74142 +int
74143 +gr_check_hidden_task(const struct task_struct *tsk)
74144 +{
74145 + return 0;
74146 +}
74147 +
74148 +int
74149 +gr_check_protected_task(const struct task_struct *task)
74150 +{
74151 + return 0;
74152 +}
74153 +
74154 +int
74155 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
74156 +{
74157 + return 0;
74158 +}
74159 +
74160 +void
74161 +gr_copy_label(struct task_struct *tsk)
74162 +{
74163 + return;
74164 +}
74165 +
74166 +void
74167 +gr_set_pax_flags(struct task_struct *task)
74168 +{
74169 + return;
74170 +}
74171 +
74172 +int
74173 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
74174 + const int unsafe_share)
74175 +{
74176 + return 0;
74177 +}
74178 +
74179 +void
74180 +gr_handle_delete(const ino_t ino, const dev_t dev)
74181 +{
74182 + return;
74183 +}
74184 +
74185 +void
74186 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
74187 +{
74188 + return;
74189 +}
74190 +
74191 +void
74192 +gr_handle_crash(struct task_struct *task, const int sig)
74193 +{
74194 + return;
74195 +}
74196 +
74197 +int
74198 +gr_check_crash_exec(const struct file *filp)
74199 +{
74200 + return 0;
74201 +}
74202 +
74203 +int
74204 +gr_check_crash_uid(const kuid_t uid)
74205 +{
74206 + return 0;
74207 +}
74208 +
74209 +void
74210 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74211 + struct dentry *old_dentry,
74212 + struct dentry *new_dentry,
74213 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
74214 +{
74215 + return;
74216 +}
74217 +
74218 +int
74219 +gr_search_socket(const int family, const int type, const int protocol)
74220 +{
74221 + return 1;
74222 +}
74223 +
74224 +int
74225 +gr_search_connectbind(const int mode, const struct socket *sock,
74226 + const struct sockaddr_in *addr)
74227 +{
74228 + return 0;
74229 +}
74230 +
74231 +void
74232 +gr_handle_alertkill(struct task_struct *task)
74233 +{
74234 + return;
74235 +}
74236 +
74237 +__u32
74238 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
74239 +{
74240 + return 1;
74241 +}
74242 +
74243 +__u32
74244 +gr_acl_handle_hidden_file(const struct dentry * dentry,
74245 + const struct vfsmount * mnt)
74246 +{
74247 + return 1;
74248 +}
74249 +
74250 +__u32
74251 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
74252 + int acc_mode)
74253 +{
74254 + return 1;
74255 +}
74256 +
74257 +__u32
74258 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
74259 +{
74260 + return 1;
74261 +}
74262 +
74263 +__u32
74264 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
74265 +{
74266 + return 1;
74267 +}
74268 +
74269 +int
74270 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
74271 + unsigned int *vm_flags)
74272 +{
74273 + return 1;
74274 +}
74275 +
74276 +__u32
74277 +gr_acl_handle_truncate(const struct dentry * dentry,
74278 + const struct vfsmount * mnt)
74279 +{
74280 + return 1;
74281 +}
74282 +
74283 +__u32
74284 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
74285 +{
74286 + return 1;
74287 +}
74288 +
74289 +__u32
74290 +gr_acl_handle_access(const struct dentry * dentry,
74291 + const struct vfsmount * mnt, const int fmode)
74292 +{
74293 + return 1;
74294 +}
74295 +
74296 +__u32
74297 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
74298 + umode_t *mode)
74299 +{
74300 + return 1;
74301 +}
74302 +
74303 +__u32
74304 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
74305 +{
74306 + return 1;
74307 +}
74308 +
74309 +__u32
74310 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
74311 +{
74312 + return 1;
74313 +}
74314 +
74315 +__u32
74316 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
74317 +{
74318 + return 1;
74319 +}
74320 +
74321 +void
74322 +grsecurity_init(void)
74323 +{
74324 + return;
74325 +}
74326 +
74327 +umode_t gr_acl_umask(void)
74328 +{
74329 + return 0;
74330 +}
74331 +
74332 +__u32
74333 +gr_acl_handle_mknod(const struct dentry * new_dentry,
74334 + const struct dentry * parent_dentry,
74335 + const struct vfsmount * parent_mnt,
74336 + const int mode)
74337 +{
74338 + return 1;
74339 +}
74340 +
74341 +__u32
74342 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
74343 + const struct dentry * parent_dentry,
74344 + const struct vfsmount * parent_mnt)
74345 +{
74346 + return 1;
74347 +}
74348 +
74349 +__u32
74350 +gr_acl_handle_symlink(const struct dentry * new_dentry,
74351 + const struct dentry * parent_dentry,
74352 + const struct vfsmount * parent_mnt, const struct filename *from)
74353 +{
74354 + return 1;
74355 +}
74356 +
74357 +__u32
74358 +gr_acl_handle_link(const struct dentry * new_dentry,
74359 + const struct dentry * parent_dentry,
74360 + const struct vfsmount * parent_mnt,
74361 + const struct dentry * old_dentry,
74362 + const struct vfsmount * old_mnt, const struct filename *to)
74363 +{
74364 + return 1;
74365 +}
74366 +
74367 +int
74368 +gr_acl_handle_rename(const struct dentry *new_dentry,
74369 + const struct dentry *parent_dentry,
74370 + const struct vfsmount *parent_mnt,
74371 + const struct dentry *old_dentry,
74372 + const struct inode *old_parent_inode,
74373 + const struct vfsmount *old_mnt, const struct filename *newname,
74374 + unsigned int flags)
74375 +{
74376 + return 0;
74377 +}
74378 +
74379 +int
74380 +gr_acl_handle_filldir(const struct file *file, const char *name,
74381 + const int namelen, const ino_t ino)
74382 +{
74383 + return 1;
74384 +}
74385 +
74386 +int
74387 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74388 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
74389 +{
74390 + return 1;
74391 +}
74392 +
74393 +int
74394 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74395 +{
74396 + return 0;
74397 +}
74398 +
74399 +int
74400 +gr_search_accept(const struct socket *sock)
74401 +{
74402 + return 0;
74403 +}
74404 +
74405 +int
74406 +gr_search_listen(const struct socket *sock)
74407 +{
74408 + return 0;
74409 +}
74410 +
74411 +int
74412 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74413 +{
74414 + return 0;
74415 +}
74416 +
74417 +__u32
74418 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74419 +{
74420 + return 1;
74421 +}
74422 +
74423 +__u32
74424 +gr_acl_handle_creat(const struct dentry * dentry,
74425 + const struct dentry * p_dentry,
74426 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74427 + const int imode)
74428 +{
74429 + return 1;
74430 +}
74431 +
74432 +void
74433 +gr_acl_handle_exit(void)
74434 +{
74435 + return;
74436 +}
74437 +
74438 +int
74439 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74440 +{
74441 + return 1;
74442 +}
74443 +
74444 +void
74445 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
74446 +{
74447 + return;
74448 +}
74449 +
74450 +int
74451 +gr_acl_handle_procpidmem(const struct task_struct *task)
74452 +{
74453 + return 0;
74454 +}
74455 +
74456 +int
74457 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74458 +{
74459 + return 0;
74460 +}
74461 +
74462 +int
74463 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74464 +{
74465 + return 0;
74466 +}
74467 +
74468 +int
74469 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74470 +{
74471 + return 0;
74472 +}
74473 +
74474 +int
74475 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74476 +{
74477 + return 0;
74478 +}
74479 +
74480 +int gr_acl_enable_at_secure(void)
74481 +{
74482 + return 0;
74483 +}
74484 +
74485 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74486 +{
74487 + return dentry->d_sb->s_dev;
74488 +}
74489 +
74490 +void gr_put_exec_file(struct task_struct *task)
74491 +{
74492 + return;
74493 +}
74494 +
74495 +#ifdef CONFIG_SECURITY
74496 +EXPORT_SYMBOL_GPL(gr_check_user_change);
74497 +EXPORT_SYMBOL_GPL(gr_check_group_change);
74498 +#endif
74499 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74500 new file mode 100644
74501 index 0000000..f35f454
74502 --- /dev/null
74503 +++ b/grsecurity/grsec_exec.c
74504 @@ -0,0 +1,187 @@
74505 +#include <linux/kernel.h>
74506 +#include <linux/sched.h>
74507 +#include <linux/file.h>
74508 +#include <linux/binfmts.h>
74509 +#include <linux/fs.h>
74510 +#include <linux/types.h>
74511 +#include <linux/grdefs.h>
74512 +#include <linux/grsecurity.h>
74513 +#include <linux/grinternal.h>
74514 +#include <linux/capability.h>
74515 +#include <linux/module.h>
74516 +#include <linux/compat.h>
74517 +
74518 +#include <asm/uaccess.h>
74519 +
74520 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74521 +static char gr_exec_arg_buf[132];
74522 +static DEFINE_MUTEX(gr_exec_arg_mutex);
74523 +#endif
74524 +
74525 +struct user_arg_ptr {
74526 +#ifdef CONFIG_COMPAT
74527 + bool is_compat;
74528 +#endif
74529 + union {
74530 + const char __user *const __user *native;
74531 +#ifdef CONFIG_COMPAT
74532 + const compat_uptr_t __user *compat;
74533 +#endif
74534 + } ptr;
74535 +};
74536 +
74537 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74538 +
74539 +void
74540 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74541 +{
74542 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74543 + char *grarg = gr_exec_arg_buf;
74544 + unsigned int i, x, execlen = 0;
74545 + char c;
74546 +
74547 + if (!((grsec_enable_execlog && grsec_enable_group &&
74548 + in_group_p(grsec_audit_gid))
74549 + || (grsec_enable_execlog && !grsec_enable_group)))
74550 + return;
74551 +
74552 + mutex_lock(&gr_exec_arg_mutex);
74553 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
74554 +
74555 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
74556 + const char __user *p;
74557 + unsigned int len;
74558 +
74559 + p = get_user_arg_ptr(argv, i);
74560 + if (IS_ERR(p))
74561 + goto log;
74562 +
74563 + len = strnlen_user(p, 128 - execlen);
74564 + if (len > 128 - execlen)
74565 + len = 128 - execlen;
74566 + else if (len > 0)
74567 + len--;
74568 + if (copy_from_user(grarg + execlen, p, len))
74569 + goto log;
74570 +
74571 + /* rewrite unprintable characters */
74572 + for (x = 0; x < len; x++) {
74573 + c = *(grarg + execlen + x);
74574 + if (c < 32 || c > 126)
74575 + *(grarg + execlen + x) = ' ';
74576 + }
74577 +
74578 + execlen += len;
74579 + *(grarg + execlen) = ' ';
74580 + *(grarg + execlen + 1) = '\0';
74581 + execlen++;
74582 + }
74583 +
74584 + log:
74585 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74586 + bprm->file->f_path.mnt, grarg);
74587 + mutex_unlock(&gr_exec_arg_mutex);
74588 +#endif
74589 + return;
74590 +}
74591 +
74592 +#ifdef CONFIG_GRKERNSEC
74593 +extern int gr_acl_is_capable(const int cap);
74594 +extern int gr_acl_is_capable_nolog(const int cap);
74595 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74596 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74597 +extern int gr_chroot_is_capable(const int cap);
74598 +extern int gr_chroot_is_capable_nolog(const int cap);
74599 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74600 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74601 +#endif
74602 +
74603 +const char *captab_log[] = {
74604 + "CAP_CHOWN",
74605 + "CAP_DAC_OVERRIDE",
74606 + "CAP_DAC_READ_SEARCH",
74607 + "CAP_FOWNER",
74608 + "CAP_FSETID",
74609 + "CAP_KILL",
74610 + "CAP_SETGID",
74611 + "CAP_SETUID",
74612 + "CAP_SETPCAP",
74613 + "CAP_LINUX_IMMUTABLE",
74614 + "CAP_NET_BIND_SERVICE",
74615 + "CAP_NET_BROADCAST",
74616 + "CAP_NET_ADMIN",
74617 + "CAP_NET_RAW",
74618 + "CAP_IPC_LOCK",
74619 + "CAP_IPC_OWNER",
74620 + "CAP_SYS_MODULE",
74621 + "CAP_SYS_RAWIO",
74622 + "CAP_SYS_CHROOT",
74623 + "CAP_SYS_PTRACE",
74624 + "CAP_SYS_PACCT",
74625 + "CAP_SYS_ADMIN",
74626 + "CAP_SYS_BOOT",
74627 + "CAP_SYS_NICE",
74628 + "CAP_SYS_RESOURCE",
74629 + "CAP_SYS_TIME",
74630 + "CAP_SYS_TTY_CONFIG",
74631 + "CAP_MKNOD",
74632 + "CAP_LEASE",
74633 + "CAP_AUDIT_WRITE",
74634 + "CAP_AUDIT_CONTROL",
74635 + "CAP_SETFCAP",
74636 + "CAP_MAC_OVERRIDE",
74637 + "CAP_MAC_ADMIN",
74638 + "CAP_SYSLOG",
74639 + "CAP_WAKE_ALARM"
74640 +};
74641 +
74642 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74643 +
74644 +int gr_is_capable(const int cap)
74645 +{
74646 +#ifdef CONFIG_GRKERNSEC
74647 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74648 + return 1;
74649 + return 0;
74650 +#else
74651 + return 1;
74652 +#endif
74653 +}
74654 +
74655 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74656 +{
74657 +#ifdef CONFIG_GRKERNSEC
74658 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74659 + return 1;
74660 + return 0;
74661 +#else
74662 + return 1;
74663 +#endif
74664 +}
74665 +
74666 +int gr_is_capable_nolog(const int cap)
74667 +{
74668 +#ifdef CONFIG_GRKERNSEC
74669 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74670 + return 1;
74671 + return 0;
74672 +#else
74673 + return 1;
74674 +#endif
74675 +}
74676 +
74677 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74678 +{
74679 +#ifdef CONFIG_GRKERNSEC
74680 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74681 + return 1;
74682 + return 0;
74683 +#else
74684 + return 1;
74685 +#endif
74686 +}
74687 +
74688 +EXPORT_SYMBOL_GPL(gr_is_capable);
74689 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74690 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
74691 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74692 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74693 new file mode 100644
74694 index 0000000..06cc6ea
74695 --- /dev/null
74696 +++ b/grsecurity/grsec_fifo.c
74697 @@ -0,0 +1,24 @@
74698 +#include <linux/kernel.h>
74699 +#include <linux/sched.h>
74700 +#include <linux/fs.h>
74701 +#include <linux/file.h>
74702 +#include <linux/grinternal.h>
74703 +
74704 +int
74705 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74706 + const struct dentry *dir, const int flag, const int acc_mode)
74707 +{
74708 +#ifdef CONFIG_GRKERNSEC_FIFO
74709 + const struct cred *cred = current_cred();
74710 +
74711 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74712 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74713 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74714 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74715 + if (!inode_permission(dentry->d_inode, acc_mode))
74716 + 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));
74717 + return -EACCES;
74718 + }
74719 +#endif
74720 + return 0;
74721 +}
74722 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74723 new file mode 100644
74724 index 0000000..8ca18bf
74725 --- /dev/null
74726 +++ b/grsecurity/grsec_fork.c
74727 @@ -0,0 +1,23 @@
74728 +#include <linux/kernel.h>
74729 +#include <linux/sched.h>
74730 +#include <linux/grsecurity.h>
74731 +#include <linux/grinternal.h>
74732 +#include <linux/errno.h>
74733 +
74734 +void
74735 +gr_log_forkfail(const int retval)
74736 +{
74737 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74738 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74739 + switch (retval) {
74740 + case -EAGAIN:
74741 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74742 + break;
74743 + case -ENOMEM:
74744 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74745 + break;
74746 + }
74747 + }
74748 +#endif
74749 + return;
74750 +}
74751 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74752 new file mode 100644
74753 index 0000000..ae6c028
74754 --- /dev/null
74755 +++ b/grsecurity/grsec_init.c
74756 @@ -0,0 +1,272 @@
74757 +#include <linux/kernel.h>
74758 +#include <linux/sched.h>
74759 +#include <linux/mm.h>
74760 +#include <linux/gracl.h>
74761 +#include <linux/slab.h>
74762 +#include <linux/vmalloc.h>
74763 +#include <linux/percpu.h>
74764 +#include <linux/module.h>
74765 +
74766 +int grsec_enable_ptrace_readexec;
74767 +int grsec_enable_setxid;
74768 +int grsec_enable_symlinkown;
74769 +kgid_t grsec_symlinkown_gid;
74770 +int grsec_enable_brute;
74771 +int grsec_enable_link;
74772 +int grsec_enable_dmesg;
74773 +int grsec_enable_harden_ptrace;
74774 +int grsec_enable_harden_ipc;
74775 +int grsec_enable_fifo;
74776 +int grsec_enable_execlog;
74777 +int grsec_enable_signal;
74778 +int grsec_enable_forkfail;
74779 +int grsec_enable_audit_ptrace;
74780 +int grsec_enable_time;
74781 +int grsec_enable_group;
74782 +kgid_t grsec_audit_gid;
74783 +int grsec_enable_chdir;
74784 +int grsec_enable_mount;
74785 +int grsec_enable_rofs;
74786 +int grsec_deny_new_usb;
74787 +int grsec_enable_chroot_findtask;
74788 +int grsec_enable_chroot_mount;
74789 +int grsec_enable_chroot_shmat;
74790 +int grsec_enable_chroot_fchdir;
74791 +int grsec_enable_chroot_double;
74792 +int grsec_enable_chroot_pivot;
74793 +int grsec_enable_chroot_chdir;
74794 +int grsec_enable_chroot_chmod;
74795 +int grsec_enable_chroot_mknod;
74796 +int grsec_enable_chroot_nice;
74797 +int grsec_enable_chroot_execlog;
74798 +int grsec_enable_chroot_caps;
74799 +int grsec_enable_chroot_sysctl;
74800 +int grsec_enable_chroot_unix;
74801 +int grsec_enable_tpe;
74802 +kgid_t grsec_tpe_gid;
74803 +int grsec_enable_blackhole;
74804 +#ifdef CONFIG_IPV6_MODULE
74805 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74806 +#endif
74807 +int grsec_lastack_retries;
74808 +int grsec_enable_tpe_all;
74809 +int grsec_enable_tpe_invert;
74810 +int grsec_enable_socket_all;
74811 +kgid_t grsec_socket_all_gid;
74812 +int grsec_enable_socket_client;
74813 +kgid_t grsec_socket_client_gid;
74814 +int grsec_enable_socket_server;
74815 +kgid_t grsec_socket_server_gid;
74816 +int grsec_resource_logging;
74817 +int grsec_disable_privio;
74818 +int grsec_enable_log_rwxmaps;
74819 +int grsec_lock;
74820 +
74821 +DEFINE_SPINLOCK(grsec_alert_lock);
74822 +unsigned long grsec_alert_wtime = 0;
74823 +unsigned long grsec_alert_fyet = 0;
74824 +
74825 +DEFINE_SPINLOCK(grsec_audit_lock);
74826 +
74827 +DEFINE_RWLOCK(grsec_exec_file_lock);
74828 +
74829 +char *gr_shared_page[4];
74830 +
74831 +char *gr_alert_log_fmt;
74832 +char *gr_audit_log_fmt;
74833 +char *gr_alert_log_buf;
74834 +char *gr_audit_log_buf;
74835 +
74836 +void __init
74837 +grsecurity_init(void)
74838 +{
74839 + int j;
74840 + /* create the per-cpu shared pages */
74841 +
74842 +#ifdef CONFIG_X86
74843 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74844 +#endif
74845 +
74846 + for (j = 0; j < 4; j++) {
74847 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74848 + if (gr_shared_page[j] == NULL) {
74849 + panic("Unable to allocate grsecurity shared page");
74850 + return;
74851 + }
74852 + }
74853 +
74854 + /* allocate log buffers */
74855 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74856 + if (!gr_alert_log_fmt) {
74857 + panic("Unable to allocate grsecurity alert log format buffer");
74858 + return;
74859 + }
74860 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74861 + if (!gr_audit_log_fmt) {
74862 + panic("Unable to allocate grsecurity audit log format buffer");
74863 + return;
74864 + }
74865 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74866 + if (!gr_alert_log_buf) {
74867 + panic("Unable to allocate grsecurity alert log buffer");
74868 + return;
74869 + }
74870 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74871 + if (!gr_audit_log_buf) {
74872 + panic("Unable to allocate grsecurity audit log buffer");
74873 + return;
74874 + }
74875 +
74876 +#ifdef CONFIG_GRKERNSEC_IO
74877 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74878 + grsec_disable_privio = 1;
74879 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74880 + grsec_disable_privio = 1;
74881 +#else
74882 + grsec_disable_privio = 0;
74883 +#endif
74884 +#endif
74885 +
74886 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74887 + /* for backward compatibility, tpe_invert always defaults to on if
74888 + enabled in the kernel
74889 + */
74890 + grsec_enable_tpe_invert = 1;
74891 +#endif
74892 +
74893 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74894 +#ifndef CONFIG_GRKERNSEC_SYSCTL
74895 + grsec_lock = 1;
74896 +#endif
74897 +
74898 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74899 + grsec_enable_log_rwxmaps = 1;
74900 +#endif
74901 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74902 + grsec_enable_group = 1;
74903 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74904 +#endif
74905 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74906 + grsec_enable_ptrace_readexec = 1;
74907 +#endif
74908 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74909 + grsec_enable_chdir = 1;
74910 +#endif
74911 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74912 + grsec_enable_harden_ptrace = 1;
74913 +#endif
74914 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74915 + grsec_enable_harden_ipc = 1;
74916 +#endif
74917 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74918 + grsec_enable_mount = 1;
74919 +#endif
74920 +#ifdef CONFIG_GRKERNSEC_LINK
74921 + grsec_enable_link = 1;
74922 +#endif
74923 +#ifdef CONFIG_GRKERNSEC_BRUTE
74924 + grsec_enable_brute = 1;
74925 +#endif
74926 +#ifdef CONFIG_GRKERNSEC_DMESG
74927 + grsec_enable_dmesg = 1;
74928 +#endif
74929 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74930 + grsec_enable_blackhole = 1;
74931 + grsec_lastack_retries = 4;
74932 +#endif
74933 +#ifdef CONFIG_GRKERNSEC_FIFO
74934 + grsec_enable_fifo = 1;
74935 +#endif
74936 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74937 + grsec_enable_execlog = 1;
74938 +#endif
74939 +#ifdef CONFIG_GRKERNSEC_SETXID
74940 + grsec_enable_setxid = 1;
74941 +#endif
74942 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74943 + grsec_enable_signal = 1;
74944 +#endif
74945 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74946 + grsec_enable_forkfail = 1;
74947 +#endif
74948 +#ifdef CONFIG_GRKERNSEC_TIME
74949 + grsec_enable_time = 1;
74950 +#endif
74951 +#ifdef CONFIG_GRKERNSEC_RESLOG
74952 + grsec_resource_logging = 1;
74953 +#endif
74954 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74955 + grsec_enable_chroot_findtask = 1;
74956 +#endif
74957 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74958 + grsec_enable_chroot_unix = 1;
74959 +#endif
74960 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74961 + grsec_enable_chroot_mount = 1;
74962 +#endif
74963 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74964 + grsec_enable_chroot_fchdir = 1;
74965 +#endif
74966 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74967 + grsec_enable_chroot_shmat = 1;
74968 +#endif
74969 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74970 + grsec_enable_audit_ptrace = 1;
74971 +#endif
74972 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74973 + grsec_enable_chroot_double = 1;
74974 +#endif
74975 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74976 + grsec_enable_chroot_pivot = 1;
74977 +#endif
74978 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74979 + grsec_enable_chroot_chdir = 1;
74980 +#endif
74981 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74982 + grsec_enable_chroot_chmod = 1;
74983 +#endif
74984 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74985 + grsec_enable_chroot_mknod = 1;
74986 +#endif
74987 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74988 + grsec_enable_chroot_nice = 1;
74989 +#endif
74990 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74991 + grsec_enable_chroot_execlog = 1;
74992 +#endif
74993 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74994 + grsec_enable_chroot_caps = 1;
74995 +#endif
74996 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74997 + grsec_enable_chroot_sysctl = 1;
74998 +#endif
74999 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75000 + grsec_enable_symlinkown = 1;
75001 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
75002 +#endif
75003 +#ifdef CONFIG_GRKERNSEC_TPE
75004 + grsec_enable_tpe = 1;
75005 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
75006 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
75007 + grsec_enable_tpe_all = 1;
75008 +#endif
75009 +#endif
75010 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75011 + grsec_enable_socket_all = 1;
75012 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
75013 +#endif
75014 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75015 + grsec_enable_socket_client = 1;
75016 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
75017 +#endif
75018 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75019 + grsec_enable_socket_server = 1;
75020 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
75021 +#endif
75022 +#endif
75023 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
75024 + grsec_deny_new_usb = 1;
75025 +#endif
75026 +
75027 + return;
75028 +}
75029 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
75030 new file mode 100644
75031 index 0000000..1773300
75032 --- /dev/null
75033 +++ b/grsecurity/grsec_ipc.c
75034 @@ -0,0 +1,48 @@
75035 +#include <linux/kernel.h>
75036 +#include <linux/mm.h>
75037 +#include <linux/sched.h>
75038 +#include <linux/file.h>
75039 +#include <linux/ipc.h>
75040 +#include <linux/ipc_namespace.h>
75041 +#include <linux/grsecurity.h>
75042 +#include <linux/grinternal.h>
75043 +
75044 +int
75045 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
75046 +{
75047 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75048 + int write;
75049 + int orig_granted_mode;
75050 + kuid_t euid;
75051 + kgid_t egid;
75052 +
75053 + if (!grsec_enable_harden_ipc)
75054 + return 1;
75055 +
75056 + euid = current_euid();
75057 + egid = current_egid();
75058 +
75059 + write = requested_mode & 00002;
75060 + orig_granted_mode = ipcp->mode;
75061 +
75062 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
75063 + orig_granted_mode >>= 6;
75064 + else {
75065 + /* if likely wrong permissions, lock to user */
75066 + if (orig_granted_mode & 0007)
75067 + orig_granted_mode = 0;
75068 + /* otherwise do a egid-only check */
75069 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
75070 + orig_granted_mode >>= 3;
75071 + /* otherwise, no access */
75072 + else
75073 + orig_granted_mode = 0;
75074 + }
75075 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
75076 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
75077 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
75078 + return 0;
75079 + }
75080 +#endif
75081 + return 1;
75082 +}
75083 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
75084 new file mode 100644
75085 index 0000000..5e05e20
75086 --- /dev/null
75087 +++ b/grsecurity/grsec_link.c
75088 @@ -0,0 +1,58 @@
75089 +#include <linux/kernel.h>
75090 +#include <linux/sched.h>
75091 +#include <linux/fs.h>
75092 +#include <linux/file.h>
75093 +#include <linux/grinternal.h>
75094 +
75095 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
75096 +{
75097 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75098 + const struct inode *link_inode = link->dentry->d_inode;
75099 +
75100 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
75101 + /* ignore root-owned links, e.g. /proc/self */
75102 + gr_is_global_nonroot(link_inode->i_uid) && target &&
75103 + !uid_eq(link_inode->i_uid, target->i_uid)) {
75104 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
75105 + return 1;
75106 + }
75107 +#endif
75108 + return 0;
75109 +}
75110 +
75111 +int
75112 +gr_handle_follow_link(const struct inode *parent,
75113 + const struct inode *inode,
75114 + const struct dentry *dentry, const struct vfsmount *mnt)
75115 +{
75116 +#ifdef CONFIG_GRKERNSEC_LINK
75117 + const struct cred *cred = current_cred();
75118 +
75119 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
75120 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
75121 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
75122 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
75123 + return -EACCES;
75124 + }
75125 +#endif
75126 + return 0;
75127 +}
75128 +
75129 +int
75130 +gr_handle_hardlink(const struct dentry *dentry,
75131 + const struct vfsmount *mnt,
75132 + struct inode *inode, const int mode, const struct filename *to)
75133 +{
75134 +#ifdef CONFIG_GRKERNSEC_LINK
75135 + const struct cred *cred = current_cred();
75136 +
75137 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
75138 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
75139 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
75140 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
75141 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
75142 + return -EPERM;
75143 + }
75144 +#endif
75145 + return 0;
75146 +}
75147 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
75148 new file mode 100644
75149 index 0000000..dbe0a6b
75150 --- /dev/null
75151 +++ b/grsecurity/grsec_log.c
75152 @@ -0,0 +1,341 @@
75153 +#include <linux/kernel.h>
75154 +#include <linux/sched.h>
75155 +#include <linux/file.h>
75156 +#include <linux/tty.h>
75157 +#include <linux/fs.h>
75158 +#include <linux/mm.h>
75159 +#include <linux/grinternal.h>
75160 +
75161 +#ifdef CONFIG_TREE_PREEMPT_RCU
75162 +#define DISABLE_PREEMPT() preempt_disable()
75163 +#define ENABLE_PREEMPT() preempt_enable()
75164 +#else
75165 +#define DISABLE_PREEMPT()
75166 +#define ENABLE_PREEMPT()
75167 +#endif
75168 +
75169 +#define BEGIN_LOCKS(x) \
75170 + DISABLE_PREEMPT(); \
75171 + rcu_read_lock(); \
75172 + read_lock(&tasklist_lock); \
75173 + read_lock(&grsec_exec_file_lock); \
75174 + if (x != GR_DO_AUDIT) \
75175 + spin_lock(&grsec_alert_lock); \
75176 + else \
75177 + spin_lock(&grsec_audit_lock)
75178 +
75179 +#define END_LOCKS(x) \
75180 + if (x != GR_DO_AUDIT) \
75181 + spin_unlock(&grsec_alert_lock); \
75182 + else \
75183 + spin_unlock(&grsec_audit_lock); \
75184 + read_unlock(&grsec_exec_file_lock); \
75185 + read_unlock(&tasklist_lock); \
75186 + rcu_read_unlock(); \
75187 + ENABLE_PREEMPT(); \
75188 + if (x == GR_DONT_AUDIT) \
75189 + gr_handle_alertkill(current)
75190 +
75191 +enum {
75192 + FLOODING,
75193 + NO_FLOODING
75194 +};
75195 +
75196 +extern char *gr_alert_log_fmt;
75197 +extern char *gr_audit_log_fmt;
75198 +extern char *gr_alert_log_buf;
75199 +extern char *gr_audit_log_buf;
75200 +
75201 +static int gr_log_start(int audit)
75202 +{
75203 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
75204 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
75205 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75206 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
75207 + unsigned long curr_secs = get_seconds();
75208 +
75209 + if (audit == GR_DO_AUDIT)
75210 + goto set_fmt;
75211 +
75212 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
75213 + grsec_alert_wtime = curr_secs;
75214 + grsec_alert_fyet = 0;
75215 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
75216 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
75217 + grsec_alert_fyet++;
75218 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
75219 + grsec_alert_wtime = curr_secs;
75220 + grsec_alert_fyet++;
75221 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
75222 + return FLOODING;
75223 + }
75224 + else return FLOODING;
75225 +
75226 +set_fmt:
75227 +#endif
75228 + memset(buf, 0, PAGE_SIZE);
75229 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
75230 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
75231 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75232 + } else if (current->signal->curr_ip) {
75233 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
75234 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
75235 + } else if (gr_acl_is_enabled()) {
75236 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
75237 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75238 + } else {
75239 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
75240 + strcpy(buf, fmt);
75241 + }
75242 +
75243 + return NO_FLOODING;
75244 +}
75245 +
75246 +static void gr_log_middle(int audit, const char *msg, va_list ap)
75247 + __attribute__ ((format (printf, 2, 0)));
75248 +
75249 +static void gr_log_middle(int audit, const char *msg, va_list ap)
75250 +{
75251 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75252 + unsigned int len = strlen(buf);
75253 +
75254 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75255 +
75256 + return;
75257 +}
75258 +
75259 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
75260 + __attribute__ ((format (printf, 2, 3)));
75261 +
75262 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
75263 +{
75264 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75265 + unsigned int len = strlen(buf);
75266 + va_list ap;
75267 +
75268 + va_start(ap, msg);
75269 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75270 + va_end(ap);
75271 +
75272 + return;
75273 +}
75274 +
75275 +static void gr_log_end(int audit, int append_default)
75276 +{
75277 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75278 + if (append_default) {
75279 + struct task_struct *task = current;
75280 + struct task_struct *parent = task->real_parent;
75281 + const struct cred *cred = __task_cred(task);
75282 + const struct cred *pcred = __task_cred(parent);
75283 + unsigned int len = strlen(buf);
75284 +
75285 + 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));
75286 + }
75287 +
75288 + printk("%s\n", buf);
75289 +
75290 + return;
75291 +}
75292 +
75293 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
75294 +{
75295 + int logtype;
75296 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
75297 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
75298 + void *voidptr = NULL;
75299 + int num1 = 0, num2 = 0;
75300 + unsigned long ulong1 = 0, ulong2 = 0;
75301 + struct dentry *dentry = NULL;
75302 + struct vfsmount *mnt = NULL;
75303 + struct file *file = NULL;
75304 + struct task_struct *task = NULL;
75305 + struct vm_area_struct *vma = NULL;
75306 + const struct cred *cred, *pcred;
75307 + va_list ap;
75308 +
75309 + BEGIN_LOCKS(audit);
75310 + logtype = gr_log_start(audit);
75311 + if (logtype == FLOODING) {
75312 + END_LOCKS(audit);
75313 + return;
75314 + }
75315 + va_start(ap, argtypes);
75316 + switch (argtypes) {
75317 + case GR_TTYSNIFF:
75318 + task = va_arg(ap, struct task_struct *);
75319 + 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));
75320 + break;
75321 + case GR_SYSCTL_HIDDEN:
75322 + str1 = va_arg(ap, char *);
75323 + gr_log_middle_varargs(audit, msg, result, str1);
75324 + break;
75325 + case GR_RBAC:
75326 + dentry = va_arg(ap, struct dentry *);
75327 + mnt = va_arg(ap, struct vfsmount *);
75328 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
75329 + break;
75330 + case GR_RBAC_STR:
75331 + dentry = va_arg(ap, struct dentry *);
75332 + mnt = va_arg(ap, struct vfsmount *);
75333 + str1 = va_arg(ap, char *);
75334 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
75335 + break;
75336 + case GR_STR_RBAC:
75337 + str1 = va_arg(ap, char *);
75338 + dentry = va_arg(ap, struct dentry *);
75339 + mnt = va_arg(ap, struct vfsmount *);
75340 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
75341 + break;
75342 + case GR_RBAC_MODE2:
75343 + dentry = va_arg(ap, struct dentry *);
75344 + mnt = va_arg(ap, struct vfsmount *);
75345 + str1 = va_arg(ap, char *);
75346 + str2 = va_arg(ap, char *);
75347 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
75348 + break;
75349 + case GR_RBAC_MODE3:
75350 + dentry = va_arg(ap, struct dentry *);
75351 + mnt = va_arg(ap, struct vfsmount *);
75352 + str1 = va_arg(ap, char *);
75353 + str2 = va_arg(ap, char *);
75354 + str3 = va_arg(ap, char *);
75355 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
75356 + break;
75357 + case GR_FILENAME:
75358 + dentry = va_arg(ap, struct dentry *);
75359 + mnt = va_arg(ap, struct vfsmount *);
75360 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
75361 + break;
75362 + case GR_STR_FILENAME:
75363 + str1 = va_arg(ap, char *);
75364 + dentry = va_arg(ap, struct dentry *);
75365 + mnt = va_arg(ap, struct vfsmount *);
75366 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
75367 + break;
75368 + case GR_FILENAME_STR:
75369 + dentry = va_arg(ap, struct dentry *);
75370 + mnt = va_arg(ap, struct vfsmount *);
75371 + str1 = va_arg(ap, char *);
75372 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75373 + break;
75374 + case GR_FILENAME_TWO_INT:
75375 + dentry = va_arg(ap, struct dentry *);
75376 + mnt = va_arg(ap, struct vfsmount *);
75377 + num1 = va_arg(ap, int);
75378 + num2 = va_arg(ap, int);
75379 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75380 + break;
75381 + case GR_FILENAME_TWO_INT_STR:
75382 + dentry = va_arg(ap, struct dentry *);
75383 + mnt = va_arg(ap, struct vfsmount *);
75384 + num1 = va_arg(ap, int);
75385 + num2 = va_arg(ap, int);
75386 + str1 = va_arg(ap, char *);
75387 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75388 + break;
75389 + case GR_TEXTREL:
75390 + file = va_arg(ap, struct file *);
75391 + ulong1 = va_arg(ap, unsigned long);
75392 + ulong2 = va_arg(ap, unsigned long);
75393 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75394 + break;
75395 + case GR_PTRACE:
75396 + task = va_arg(ap, struct task_struct *);
75397 + 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));
75398 + break;
75399 + case GR_RESOURCE:
75400 + task = va_arg(ap, struct task_struct *);
75401 + cred = __task_cred(task);
75402 + pcred = __task_cred(task->real_parent);
75403 + ulong1 = va_arg(ap, unsigned long);
75404 + str1 = va_arg(ap, char *);
75405 + ulong2 = va_arg(ap, unsigned long);
75406 + 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));
75407 + break;
75408 + case GR_CAP:
75409 + task = va_arg(ap, struct task_struct *);
75410 + cred = __task_cred(task);
75411 + pcred = __task_cred(task->real_parent);
75412 + str1 = va_arg(ap, char *);
75413 + 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));
75414 + break;
75415 + case GR_SIG:
75416 + str1 = va_arg(ap, char *);
75417 + voidptr = va_arg(ap, void *);
75418 + gr_log_middle_varargs(audit, msg, str1, voidptr);
75419 + break;
75420 + case GR_SIG2:
75421 + task = va_arg(ap, struct task_struct *);
75422 + cred = __task_cred(task);
75423 + pcred = __task_cred(task->real_parent);
75424 + num1 = va_arg(ap, int);
75425 + 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));
75426 + break;
75427 + case GR_CRASH1:
75428 + task = va_arg(ap, struct task_struct *);
75429 + cred = __task_cred(task);
75430 + pcred = __task_cred(task->real_parent);
75431 + ulong1 = va_arg(ap, unsigned long);
75432 + 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);
75433 + break;
75434 + case GR_CRASH2:
75435 + task = va_arg(ap, struct task_struct *);
75436 + cred = __task_cred(task);
75437 + pcred = __task_cred(task->real_parent);
75438 + ulong1 = va_arg(ap, unsigned long);
75439 + 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);
75440 + break;
75441 + case GR_RWXMAP:
75442 + file = va_arg(ap, struct file *);
75443 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75444 + break;
75445 + case GR_RWXMAPVMA:
75446 + vma = va_arg(ap, struct vm_area_struct *);
75447 + if (vma->vm_file)
75448 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75449 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75450 + str1 = "<stack>";
75451 + else if (vma->vm_start <= current->mm->brk &&
75452 + vma->vm_end >= current->mm->start_brk)
75453 + str1 = "<heap>";
75454 + else
75455 + str1 = "<anonymous mapping>";
75456 + gr_log_middle_varargs(audit, msg, str1);
75457 + break;
75458 + case GR_PSACCT:
75459 + {
75460 + unsigned int wday, cday;
75461 + __u8 whr, chr;
75462 + __u8 wmin, cmin;
75463 + __u8 wsec, csec;
75464 + char cur_tty[64] = { 0 };
75465 + char parent_tty[64] = { 0 };
75466 +
75467 + task = va_arg(ap, struct task_struct *);
75468 + wday = va_arg(ap, unsigned int);
75469 + cday = va_arg(ap, unsigned int);
75470 + whr = va_arg(ap, int);
75471 + chr = va_arg(ap, int);
75472 + wmin = va_arg(ap, int);
75473 + cmin = va_arg(ap, int);
75474 + wsec = va_arg(ap, int);
75475 + csec = va_arg(ap, int);
75476 + ulong1 = va_arg(ap, unsigned long);
75477 + cred = __task_cred(task);
75478 + pcred = __task_cred(task->real_parent);
75479 +
75480 + 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));
75481 + }
75482 + break;
75483 + default:
75484 + gr_log_middle(audit, msg, ap);
75485 + }
75486 + va_end(ap);
75487 + // these don't need DEFAULTSECARGS printed on the end
75488 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75489 + gr_log_end(audit, 0);
75490 + else
75491 + gr_log_end(audit, 1);
75492 + END_LOCKS(audit);
75493 +}
75494 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75495 new file mode 100644
75496 index 0000000..0e39d8c
75497 --- /dev/null
75498 +++ b/grsecurity/grsec_mem.c
75499 @@ -0,0 +1,48 @@
75500 +#include <linux/kernel.h>
75501 +#include <linux/sched.h>
75502 +#include <linux/mm.h>
75503 +#include <linux/mman.h>
75504 +#include <linux/module.h>
75505 +#include <linux/grinternal.h>
75506 +
75507 +void gr_handle_msr_write(void)
75508 +{
75509 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75510 + return;
75511 +}
75512 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75513 +
75514 +void
75515 +gr_handle_ioperm(void)
75516 +{
75517 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75518 + return;
75519 +}
75520 +
75521 +void
75522 +gr_handle_iopl(void)
75523 +{
75524 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75525 + return;
75526 +}
75527 +
75528 +void
75529 +gr_handle_mem_readwrite(u64 from, u64 to)
75530 +{
75531 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75532 + return;
75533 +}
75534 +
75535 +void
75536 +gr_handle_vm86(void)
75537 +{
75538 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75539 + return;
75540 +}
75541 +
75542 +void
75543 +gr_log_badprocpid(const char *entry)
75544 +{
75545 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75546 + return;
75547 +}
75548 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75549 new file mode 100644
75550 index 0000000..cd9e124
75551 --- /dev/null
75552 +++ b/grsecurity/grsec_mount.c
75553 @@ -0,0 +1,65 @@
75554 +#include <linux/kernel.h>
75555 +#include <linux/sched.h>
75556 +#include <linux/mount.h>
75557 +#include <linux/major.h>
75558 +#include <linux/grsecurity.h>
75559 +#include <linux/grinternal.h>
75560 +
75561 +void
75562 +gr_log_remount(const char *devname, const int retval)
75563 +{
75564 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75565 + if (grsec_enable_mount && (retval >= 0))
75566 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75567 +#endif
75568 + return;
75569 +}
75570 +
75571 +void
75572 +gr_log_unmount(const char *devname, const int retval)
75573 +{
75574 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75575 + if (grsec_enable_mount && (retval >= 0))
75576 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75577 +#endif
75578 + return;
75579 +}
75580 +
75581 +void
75582 +gr_log_mount(const char *from, const char *to, const int retval)
75583 +{
75584 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75585 + if (grsec_enable_mount && (retval >= 0))
75586 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75587 +#endif
75588 + return;
75589 +}
75590 +
75591 +int
75592 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75593 +{
75594 +#ifdef CONFIG_GRKERNSEC_ROFS
75595 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75596 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75597 + return -EPERM;
75598 + } else
75599 + return 0;
75600 +#endif
75601 + return 0;
75602 +}
75603 +
75604 +int
75605 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75606 +{
75607 +#ifdef CONFIG_GRKERNSEC_ROFS
75608 + struct inode *inode = dentry->d_inode;
75609 +
75610 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75611 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75612 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75613 + return -EPERM;
75614 + } else
75615 + return 0;
75616 +#endif
75617 + return 0;
75618 +}
75619 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75620 new file mode 100644
75621 index 0000000..6ee9d50
75622 --- /dev/null
75623 +++ b/grsecurity/grsec_pax.c
75624 @@ -0,0 +1,45 @@
75625 +#include <linux/kernel.h>
75626 +#include <linux/sched.h>
75627 +#include <linux/mm.h>
75628 +#include <linux/file.h>
75629 +#include <linux/grinternal.h>
75630 +#include <linux/grsecurity.h>
75631 +
75632 +void
75633 +gr_log_textrel(struct vm_area_struct * vma)
75634 +{
75635 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75636 + if (grsec_enable_log_rwxmaps)
75637 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75638 +#endif
75639 + return;
75640 +}
75641 +
75642 +void gr_log_ptgnustack(struct file *file)
75643 +{
75644 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75645 + if (grsec_enable_log_rwxmaps)
75646 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75647 +#endif
75648 + return;
75649 +}
75650 +
75651 +void
75652 +gr_log_rwxmmap(struct file *file)
75653 +{
75654 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75655 + if (grsec_enable_log_rwxmaps)
75656 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75657 +#endif
75658 + return;
75659 +}
75660 +
75661 +void
75662 +gr_log_rwxmprotect(struct vm_area_struct *vma)
75663 +{
75664 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75665 + if (grsec_enable_log_rwxmaps)
75666 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75667 +#endif
75668 + return;
75669 +}
75670 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75671 new file mode 100644
75672 index 0000000..2005a3a
75673 --- /dev/null
75674 +++ b/grsecurity/grsec_proc.c
75675 @@ -0,0 +1,20 @@
75676 +#include <linux/kernel.h>
75677 +#include <linux/sched.h>
75678 +#include <linux/grsecurity.h>
75679 +#include <linux/grinternal.h>
75680 +
75681 +int gr_proc_is_restricted(void)
75682 +{
75683 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75684 + const struct cred *cred = current_cred();
75685 +#endif
75686 +
75687 +#ifdef CONFIG_GRKERNSEC_PROC_USER
75688 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75689 + return -EACCES;
75690 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75691 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75692 + return -EACCES;
75693 +#endif
75694 + return 0;
75695 +}
75696 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75697 new file mode 100644
75698 index 0000000..f7f29aa
75699 --- /dev/null
75700 +++ b/grsecurity/grsec_ptrace.c
75701 @@ -0,0 +1,30 @@
75702 +#include <linux/kernel.h>
75703 +#include <linux/sched.h>
75704 +#include <linux/grinternal.h>
75705 +#include <linux/security.h>
75706 +
75707 +void
75708 +gr_audit_ptrace(struct task_struct *task)
75709 +{
75710 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75711 + if (grsec_enable_audit_ptrace)
75712 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75713 +#endif
75714 + return;
75715 +}
75716 +
75717 +int
75718 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
75719 +{
75720 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75721 + const struct dentry *dentry = file->f_path.dentry;
75722 + const struct vfsmount *mnt = file->f_path.mnt;
75723 +
75724 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75725 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75726 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75727 + return -EACCES;
75728 + }
75729 +#endif
75730 + return 0;
75731 +}
75732 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75733 new file mode 100644
75734 index 0000000..3860c7e
75735 --- /dev/null
75736 +++ b/grsecurity/grsec_sig.c
75737 @@ -0,0 +1,236 @@
75738 +#include <linux/kernel.h>
75739 +#include <linux/sched.h>
75740 +#include <linux/fs.h>
75741 +#include <linux/delay.h>
75742 +#include <linux/grsecurity.h>
75743 +#include <linux/grinternal.h>
75744 +#include <linux/hardirq.h>
75745 +
75746 +char *signames[] = {
75747 + [SIGSEGV] = "Segmentation fault",
75748 + [SIGILL] = "Illegal instruction",
75749 + [SIGABRT] = "Abort",
75750 + [SIGBUS] = "Invalid alignment/Bus error"
75751 +};
75752 +
75753 +void
75754 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75755 +{
75756 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75757 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75758 + (sig == SIGABRT) || (sig == SIGBUS))) {
75759 + if (task_pid_nr(t) == task_pid_nr(current)) {
75760 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75761 + } else {
75762 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75763 + }
75764 + }
75765 +#endif
75766 + return;
75767 +}
75768 +
75769 +int
75770 +gr_handle_signal(const struct task_struct *p, const int sig)
75771 +{
75772 +#ifdef CONFIG_GRKERNSEC
75773 + /* ignore the 0 signal for protected task checks */
75774 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75775 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75776 + return -EPERM;
75777 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75778 + return -EPERM;
75779 + }
75780 +#endif
75781 + return 0;
75782 +}
75783 +
75784 +#ifdef CONFIG_GRKERNSEC
75785 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75786 +
75787 +int gr_fake_force_sig(int sig, struct task_struct *t)
75788 +{
75789 + unsigned long int flags;
75790 + int ret, blocked, ignored;
75791 + struct k_sigaction *action;
75792 +
75793 + spin_lock_irqsave(&t->sighand->siglock, flags);
75794 + action = &t->sighand->action[sig-1];
75795 + ignored = action->sa.sa_handler == SIG_IGN;
75796 + blocked = sigismember(&t->blocked, sig);
75797 + if (blocked || ignored) {
75798 + action->sa.sa_handler = SIG_DFL;
75799 + if (blocked) {
75800 + sigdelset(&t->blocked, sig);
75801 + recalc_sigpending_and_wake(t);
75802 + }
75803 + }
75804 + if (action->sa.sa_handler == SIG_DFL)
75805 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
75806 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75807 +
75808 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
75809 +
75810 + return ret;
75811 +}
75812 +#endif
75813 +
75814 +#define GR_USER_BAN_TIME (15 * 60)
75815 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
75816 +
75817 +void gr_handle_brute_attach(int dumpable)
75818 +{
75819 +#ifdef CONFIG_GRKERNSEC_BRUTE
75820 + struct task_struct *p = current;
75821 + kuid_t uid = GLOBAL_ROOT_UID;
75822 + int daemon = 0;
75823 +
75824 + if (!grsec_enable_brute)
75825 + return;
75826 +
75827 + rcu_read_lock();
75828 + read_lock(&tasklist_lock);
75829 + read_lock(&grsec_exec_file_lock);
75830 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75831 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75832 + p->real_parent->brute = 1;
75833 + daemon = 1;
75834 + } else {
75835 + const struct cred *cred = __task_cred(p), *cred2;
75836 + struct task_struct *tsk, *tsk2;
75837 +
75838 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75839 + struct user_struct *user;
75840 +
75841 + uid = cred->uid;
75842 +
75843 + /* this is put upon execution past expiration */
75844 + user = find_user(uid);
75845 + if (user == NULL)
75846 + goto unlock;
75847 + user->suid_banned = 1;
75848 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75849 + if (user->suid_ban_expires == ~0UL)
75850 + user->suid_ban_expires--;
75851 +
75852 + /* only kill other threads of the same binary, from the same user */
75853 + do_each_thread(tsk2, tsk) {
75854 + cred2 = __task_cred(tsk);
75855 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75856 + gr_fake_force_sig(SIGKILL, tsk);
75857 + } while_each_thread(tsk2, tsk);
75858 + }
75859 + }
75860 +unlock:
75861 + read_unlock(&grsec_exec_file_lock);
75862 + read_unlock(&tasklist_lock);
75863 + rcu_read_unlock();
75864 +
75865 + if (gr_is_global_nonroot(uid))
75866 + 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);
75867 + else if (daemon)
75868 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75869 +
75870 +#endif
75871 + return;
75872 +}
75873 +
75874 +void gr_handle_brute_check(void)
75875 +{
75876 +#ifdef CONFIG_GRKERNSEC_BRUTE
75877 + struct task_struct *p = current;
75878 +
75879 + if (unlikely(p->brute)) {
75880 + if (!grsec_enable_brute)
75881 + p->brute = 0;
75882 + else if (time_before(get_seconds(), p->brute_expires))
75883 + msleep(30 * 1000);
75884 + }
75885 +#endif
75886 + return;
75887 +}
75888 +
75889 +void gr_handle_kernel_exploit(void)
75890 +{
75891 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75892 + const struct cred *cred;
75893 + struct task_struct *tsk, *tsk2;
75894 + struct user_struct *user;
75895 + kuid_t uid;
75896 +
75897 + if (in_irq() || in_serving_softirq() || in_nmi())
75898 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75899 +
75900 + uid = current_uid();
75901 +
75902 + if (gr_is_global_root(uid))
75903 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
75904 + else {
75905 + /* kill all the processes of this user, hold a reference
75906 + to their creds struct, and prevent them from creating
75907 + another process until system reset
75908 + */
75909 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75910 + GR_GLOBAL_UID(uid));
75911 + /* we intentionally leak this ref */
75912 + user = get_uid(current->cred->user);
75913 + if (user)
75914 + user->kernel_banned = 1;
75915 +
75916 + /* kill all processes of this user */
75917 + read_lock(&tasklist_lock);
75918 + do_each_thread(tsk2, tsk) {
75919 + cred = __task_cred(tsk);
75920 + if (uid_eq(cred->uid, uid))
75921 + gr_fake_force_sig(SIGKILL, tsk);
75922 + } while_each_thread(tsk2, tsk);
75923 + read_unlock(&tasklist_lock);
75924 + }
75925 +#endif
75926 +}
75927 +
75928 +#ifdef CONFIG_GRKERNSEC_BRUTE
75929 +static bool suid_ban_expired(struct user_struct *user)
75930 +{
75931 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75932 + user->suid_banned = 0;
75933 + user->suid_ban_expires = 0;
75934 + free_uid(user);
75935 + return true;
75936 + }
75937 +
75938 + return false;
75939 +}
75940 +#endif
75941 +
75942 +int gr_process_kernel_exec_ban(void)
75943 +{
75944 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75945 + if (unlikely(current->cred->user->kernel_banned))
75946 + return -EPERM;
75947 +#endif
75948 + return 0;
75949 +}
75950 +
75951 +int gr_process_kernel_setuid_ban(struct user_struct *user)
75952 +{
75953 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75954 + if (unlikely(user->kernel_banned))
75955 + gr_fake_force_sig(SIGKILL, current);
75956 +#endif
75957 + return 0;
75958 +}
75959 +
75960 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75961 +{
75962 +#ifdef CONFIG_GRKERNSEC_BRUTE
75963 + struct user_struct *user = current->cred->user;
75964 + if (unlikely(user->suid_banned)) {
75965 + if (suid_ban_expired(user))
75966 + return 0;
75967 + /* disallow execution of suid binaries only */
75968 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75969 + return -EPERM;
75970 + }
75971 +#endif
75972 + return 0;
75973 +}
75974 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75975 new file mode 100644
75976 index 0000000..c0aef3a
75977 --- /dev/null
75978 +++ b/grsecurity/grsec_sock.c
75979 @@ -0,0 +1,244 @@
75980 +#include <linux/kernel.h>
75981 +#include <linux/module.h>
75982 +#include <linux/sched.h>
75983 +#include <linux/file.h>
75984 +#include <linux/net.h>
75985 +#include <linux/in.h>
75986 +#include <linux/ip.h>
75987 +#include <net/sock.h>
75988 +#include <net/inet_sock.h>
75989 +#include <linux/grsecurity.h>
75990 +#include <linux/grinternal.h>
75991 +#include <linux/gracl.h>
75992 +
75993 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75994 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75995 +
75996 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75997 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75998 +
75999 +#ifdef CONFIG_UNIX_MODULE
76000 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
76001 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
76002 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
76003 +EXPORT_SYMBOL_GPL(gr_handle_create);
76004 +#endif
76005 +
76006 +#ifdef CONFIG_GRKERNSEC
76007 +#define gr_conn_table_size 32749
76008 +struct conn_table_entry {
76009 + struct conn_table_entry *next;
76010 + struct signal_struct *sig;
76011 +};
76012 +
76013 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
76014 +DEFINE_SPINLOCK(gr_conn_table_lock);
76015 +
76016 +extern const char * gr_socktype_to_name(unsigned char type);
76017 +extern const char * gr_proto_to_name(unsigned char proto);
76018 +extern const char * gr_sockfamily_to_name(unsigned char family);
76019 +
76020 +static __inline__ int
76021 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
76022 +{
76023 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
76024 +}
76025 +
76026 +static __inline__ int
76027 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
76028 + __u16 sport, __u16 dport)
76029 +{
76030 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
76031 + sig->gr_sport == sport && sig->gr_dport == dport))
76032 + return 1;
76033 + else
76034 + return 0;
76035 +}
76036 +
76037 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
76038 +{
76039 + struct conn_table_entry **match;
76040 + unsigned int index;
76041 +
76042 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76043 + sig->gr_sport, sig->gr_dport,
76044 + gr_conn_table_size);
76045 +
76046 + newent->sig = sig;
76047 +
76048 + match = &gr_conn_table[index];
76049 + newent->next = *match;
76050 + *match = newent;
76051 +
76052 + return;
76053 +}
76054 +
76055 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
76056 +{
76057 + struct conn_table_entry *match, *last = NULL;
76058 + unsigned int index;
76059 +
76060 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76061 + sig->gr_sport, sig->gr_dport,
76062 + gr_conn_table_size);
76063 +
76064 + match = gr_conn_table[index];
76065 + while (match && !conn_match(match->sig,
76066 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
76067 + sig->gr_dport)) {
76068 + last = match;
76069 + match = match->next;
76070 + }
76071 +
76072 + if (match) {
76073 + if (last)
76074 + last->next = match->next;
76075 + else
76076 + gr_conn_table[index] = NULL;
76077 + kfree(match);
76078 + }
76079 +
76080 + return;
76081 +}
76082 +
76083 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
76084 + __u16 sport, __u16 dport)
76085 +{
76086 + struct conn_table_entry *match;
76087 + unsigned int index;
76088 +
76089 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
76090 +
76091 + match = gr_conn_table[index];
76092 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
76093 + match = match->next;
76094 +
76095 + if (match)
76096 + return match->sig;
76097 + else
76098 + return NULL;
76099 +}
76100 +
76101 +#endif
76102 +
76103 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
76104 +{
76105 +#ifdef CONFIG_GRKERNSEC
76106 + struct signal_struct *sig = task->signal;
76107 + struct conn_table_entry *newent;
76108 +
76109 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
76110 + if (newent == NULL)
76111 + return;
76112 + /* no bh lock needed since we are called with bh disabled */
76113 + spin_lock(&gr_conn_table_lock);
76114 + gr_del_task_from_ip_table_nolock(sig);
76115 + sig->gr_saddr = inet->inet_rcv_saddr;
76116 + sig->gr_daddr = inet->inet_daddr;
76117 + sig->gr_sport = inet->inet_sport;
76118 + sig->gr_dport = inet->inet_dport;
76119 + gr_add_to_task_ip_table_nolock(sig, newent);
76120 + spin_unlock(&gr_conn_table_lock);
76121 +#endif
76122 + return;
76123 +}
76124 +
76125 +void gr_del_task_from_ip_table(struct task_struct *task)
76126 +{
76127 +#ifdef CONFIG_GRKERNSEC
76128 + spin_lock_bh(&gr_conn_table_lock);
76129 + gr_del_task_from_ip_table_nolock(task->signal);
76130 + spin_unlock_bh(&gr_conn_table_lock);
76131 +#endif
76132 + return;
76133 +}
76134 +
76135 +void
76136 +gr_attach_curr_ip(const struct sock *sk)
76137 +{
76138 +#ifdef CONFIG_GRKERNSEC
76139 + struct signal_struct *p, *set;
76140 + const struct inet_sock *inet = inet_sk(sk);
76141 +
76142 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
76143 + return;
76144 +
76145 + set = current->signal;
76146 +
76147 + spin_lock_bh(&gr_conn_table_lock);
76148 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
76149 + inet->inet_dport, inet->inet_sport);
76150 + if (unlikely(p != NULL)) {
76151 + set->curr_ip = p->curr_ip;
76152 + set->used_accept = 1;
76153 + gr_del_task_from_ip_table_nolock(p);
76154 + spin_unlock_bh(&gr_conn_table_lock);
76155 + return;
76156 + }
76157 + spin_unlock_bh(&gr_conn_table_lock);
76158 +
76159 + set->curr_ip = inet->inet_daddr;
76160 + set->used_accept = 1;
76161 +#endif
76162 + return;
76163 +}
76164 +
76165 +int
76166 +gr_handle_sock_all(const int family, const int type, const int protocol)
76167 +{
76168 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76169 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
76170 + (family != AF_UNIX)) {
76171 + if (family == AF_INET)
76172 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
76173 + else
76174 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
76175 + return -EACCES;
76176 + }
76177 +#endif
76178 + return 0;
76179 +}
76180 +
76181 +int
76182 +gr_handle_sock_server(const struct sockaddr *sck)
76183 +{
76184 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76185 + if (grsec_enable_socket_server &&
76186 + in_group_p(grsec_socket_server_gid) &&
76187 + sck && (sck->sa_family != AF_UNIX) &&
76188 + (sck->sa_family != AF_LOCAL)) {
76189 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76190 + return -EACCES;
76191 + }
76192 +#endif
76193 + return 0;
76194 +}
76195 +
76196 +int
76197 +gr_handle_sock_server_other(const struct sock *sck)
76198 +{
76199 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76200 + if (grsec_enable_socket_server &&
76201 + in_group_p(grsec_socket_server_gid) &&
76202 + sck && (sck->sk_family != AF_UNIX) &&
76203 + (sck->sk_family != AF_LOCAL)) {
76204 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76205 + return -EACCES;
76206 + }
76207 +#endif
76208 + return 0;
76209 +}
76210 +
76211 +int
76212 +gr_handle_sock_client(const struct sockaddr *sck)
76213 +{
76214 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76215 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
76216 + sck && (sck->sa_family != AF_UNIX) &&
76217 + (sck->sa_family != AF_LOCAL)) {
76218 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
76219 + return -EACCES;
76220 + }
76221 +#endif
76222 + return 0;
76223 +}
76224 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
76225 new file mode 100644
76226 index 0000000..8159888
76227 --- /dev/null
76228 +++ b/grsecurity/grsec_sysctl.c
76229 @@ -0,0 +1,479 @@
76230 +#include <linux/kernel.h>
76231 +#include <linux/sched.h>
76232 +#include <linux/sysctl.h>
76233 +#include <linux/grsecurity.h>
76234 +#include <linux/grinternal.h>
76235 +
76236 +int
76237 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
76238 +{
76239 +#ifdef CONFIG_GRKERNSEC_SYSCTL
76240 + if (dirname == NULL || name == NULL)
76241 + return 0;
76242 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
76243 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
76244 + return -EACCES;
76245 + }
76246 +#endif
76247 + return 0;
76248 +}
76249 +
76250 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
76251 +static int __maybe_unused __read_only one = 1;
76252 +#endif
76253 +
76254 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
76255 + defined(CONFIG_GRKERNSEC_DENYUSB)
76256 +struct ctl_table grsecurity_table[] = {
76257 +#ifdef CONFIG_GRKERNSEC_SYSCTL
76258 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
76259 +#ifdef CONFIG_GRKERNSEC_IO
76260 + {
76261 + .procname = "disable_priv_io",
76262 + .data = &grsec_disable_privio,
76263 + .maxlen = sizeof(int),
76264 + .mode = 0600,
76265 + .proc_handler = &proc_dointvec,
76266 + },
76267 +#endif
76268 +#endif
76269 +#ifdef CONFIG_GRKERNSEC_LINK
76270 + {
76271 + .procname = "linking_restrictions",
76272 + .data = &grsec_enable_link,
76273 + .maxlen = sizeof(int),
76274 + .mode = 0600,
76275 + .proc_handler = &proc_dointvec,
76276 + },
76277 +#endif
76278 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
76279 + {
76280 + .procname = "enforce_symlinksifowner",
76281 + .data = &grsec_enable_symlinkown,
76282 + .maxlen = sizeof(int),
76283 + .mode = 0600,
76284 + .proc_handler = &proc_dointvec,
76285 + },
76286 + {
76287 + .procname = "symlinkown_gid",
76288 + .data = &grsec_symlinkown_gid,
76289 + .maxlen = sizeof(int),
76290 + .mode = 0600,
76291 + .proc_handler = &proc_dointvec,
76292 + },
76293 +#endif
76294 +#ifdef CONFIG_GRKERNSEC_BRUTE
76295 + {
76296 + .procname = "deter_bruteforce",
76297 + .data = &grsec_enable_brute,
76298 + .maxlen = sizeof(int),
76299 + .mode = 0600,
76300 + .proc_handler = &proc_dointvec,
76301 + },
76302 +#endif
76303 +#ifdef CONFIG_GRKERNSEC_FIFO
76304 + {
76305 + .procname = "fifo_restrictions",
76306 + .data = &grsec_enable_fifo,
76307 + .maxlen = sizeof(int),
76308 + .mode = 0600,
76309 + .proc_handler = &proc_dointvec,
76310 + },
76311 +#endif
76312 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76313 + {
76314 + .procname = "ptrace_readexec",
76315 + .data = &grsec_enable_ptrace_readexec,
76316 + .maxlen = sizeof(int),
76317 + .mode = 0600,
76318 + .proc_handler = &proc_dointvec,
76319 + },
76320 +#endif
76321 +#ifdef CONFIG_GRKERNSEC_SETXID
76322 + {
76323 + .procname = "consistent_setxid",
76324 + .data = &grsec_enable_setxid,
76325 + .maxlen = sizeof(int),
76326 + .mode = 0600,
76327 + .proc_handler = &proc_dointvec,
76328 + },
76329 +#endif
76330 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76331 + {
76332 + .procname = "ip_blackhole",
76333 + .data = &grsec_enable_blackhole,
76334 + .maxlen = sizeof(int),
76335 + .mode = 0600,
76336 + .proc_handler = &proc_dointvec,
76337 + },
76338 + {
76339 + .procname = "lastack_retries",
76340 + .data = &grsec_lastack_retries,
76341 + .maxlen = sizeof(int),
76342 + .mode = 0600,
76343 + .proc_handler = &proc_dointvec,
76344 + },
76345 +#endif
76346 +#ifdef CONFIG_GRKERNSEC_EXECLOG
76347 + {
76348 + .procname = "exec_logging",
76349 + .data = &grsec_enable_execlog,
76350 + .maxlen = sizeof(int),
76351 + .mode = 0600,
76352 + .proc_handler = &proc_dointvec,
76353 + },
76354 +#endif
76355 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76356 + {
76357 + .procname = "rwxmap_logging",
76358 + .data = &grsec_enable_log_rwxmaps,
76359 + .maxlen = sizeof(int),
76360 + .mode = 0600,
76361 + .proc_handler = &proc_dointvec,
76362 + },
76363 +#endif
76364 +#ifdef CONFIG_GRKERNSEC_SIGNAL
76365 + {
76366 + .procname = "signal_logging",
76367 + .data = &grsec_enable_signal,
76368 + .maxlen = sizeof(int),
76369 + .mode = 0600,
76370 + .proc_handler = &proc_dointvec,
76371 + },
76372 +#endif
76373 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
76374 + {
76375 + .procname = "forkfail_logging",
76376 + .data = &grsec_enable_forkfail,
76377 + .maxlen = sizeof(int),
76378 + .mode = 0600,
76379 + .proc_handler = &proc_dointvec,
76380 + },
76381 +#endif
76382 +#ifdef CONFIG_GRKERNSEC_TIME
76383 + {
76384 + .procname = "timechange_logging",
76385 + .data = &grsec_enable_time,
76386 + .maxlen = sizeof(int),
76387 + .mode = 0600,
76388 + .proc_handler = &proc_dointvec,
76389 + },
76390 +#endif
76391 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76392 + {
76393 + .procname = "chroot_deny_shmat",
76394 + .data = &grsec_enable_chroot_shmat,
76395 + .maxlen = sizeof(int),
76396 + .mode = 0600,
76397 + .proc_handler = &proc_dointvec,
76398 + },
76399 +#endif
76400 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76401 + {
76402 + .procname = "chroot_deny_unix",
76403 + .data = &grsec_enable_chroot_unix,
76404 + .maxlen = sizeof(int),
76405 + .mode = 0600,
76406 + .proc_handler = &proc_dointvec,
76407 + },
76408 +#endif
76409 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76410 + {
76411 + .procname = "chroot_deny_mount",
76412 + .data = &grsec_enable_chroot_mount,
76413 + .maxlen = sizeof(int),
76414 + .mode = 0600,
76415 + .proc_handler = &proc_dointvec,
76416 + },
76417 +#endif
76418 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76419 + {
76420 + .procname = "chroot_deny_fchdir",
76421 + .data = &grsec_enable_chroot_fchdir,
76422 + .maxlen = sizeof(int),
76423 + .mode = 0600,
76424 + .proc_handler = &proc_dointvec,
76425 + },
76426 +#endif
76427 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76428 + {
76429 + .procname = "chroot_deny_chroot",
76430 + .data = &grsec_enable_chroot_double,
76431 + .maxlen = sizeof(int),
76432 + .mode = 0600,
76433 + .proc_handler = &proc_dointvec,
76434 + },
76435 +#endif
76436 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76437 + {
76438 + .procname = "chroot_deny_pivot",
76439 + .data = &grsec_enable_chroot_pivot,
76440 + .maxlen = sizeof(int),
76441 + .mode = 0600,
76442 + .proc_handler = &proc_dointvec,
76443 + },
76444 +#endif
76445 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76446 + {
76447 + .procname = "chroot_enforce_chdir",
76448 + .data = &grsec_enable_chroot_chdir,
76449 + .maxlen = sizeof(int),
76450 + .mode = 0600,
76451 + .proc_handler = &proc_dointvec,
76452 + },
76453 +#endif
76454 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76455 + {
76456 + .procname = "chroot_deny_chmod",
76457 + .data = &grsec_enable_chroot_chmod,
76458 + .maxlen = sizeof(int),
76459 + .mode = 0600,
76460 + .proc_handler = &proc_dointvec,
76461 + },
76462 +#endif
76463 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76464 + {
76465 + .procname = "chroot_deny_mknod",
76466 + .data = &grsec_enable_chroot_mknod,
76467 + .maxlen = sizeof(int),
76468 + .mode = 0600,
76469 + .proc_handler = &proc_dointvec,
76470 + },
76471 +#endif
76472 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76473 + {
76474 + .procname = "chroot_restrict_nice",
76475 + .data = &grsec_enable_chroot_nice,
76476 + .maxlen = sizeof(int),
76477 + .mode = 0600,
76478 + .proc_handler = &proc_dointvec,
76479 + },
76480 +#endif
76481 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76482 + {
76483 + .procname = "chroot_execlog",
76484 + .data = &grsec_enable_chroot_execlog,
76485 + .maxlen = sizeof(int),
76486 + .mode = 0600,
76487 + .proc_handler = &proc_dointvec,
76488 + },
76489 +#endif
76490 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76491 + {
76492 + .procname = "chroot_caps",
76493 + .data = &grsec_enable_chroot_caps,
76494 + .maxlen = sizeof(int),
76495 + .mode = 0600,
76496 + .proc_handler = &proc_dointvec,
76497 + },
76498 +#endif
76499 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76500 + {
76501 + .procname = "chroot_deny_sysctl",
76502 + .data = &grsec_enable_chroot_sysctl,
76503 + .maxlen = sizeof(int),
76504 + .mode = 0600,
76505 + .proc_handler = &proc_dointvec,
76506 + },
76507 +#endif
76508 +#ifdef CONFIG_GRKERNSEC_TPE
76509 + {
76510 + .procname = "tpe",
76511 + .data = &grsec_enable_tpe,
76512 + .maxlen = sizeof(int),
76513 + .mode = 0600,
76514 + .proc_handler = &proc_dointvec,
76515 + },
76516 + {
76517 + .procname = "tpe_gid",
76518 + .data = &grsec_tpe_gid,
76519 + .maxlen = sizeof(int),
76520 + .mode = 0600,
76521 + .proc_handler = &proc_dointvec,
76522 + },
76523 +#endif
76524 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76525 + {
76526 + .procname = "tpe_invert",
76527 + .data = &grsec_enable_tpe_invert,
76528 + .maxlen = sizeof(int),
76529 + .mode = 0600,
76530 + .proc_handler = &proc_dointvec,
76531 + },
76532 +#endif
76533 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
76534 + {
76535 + .procname = "tpe_restrict_all",
76536 + .data = &grsec_enable_tpe_all,
76537 + .maxlen = sizeof(int),
76538 + .mode = 0600,
76539 + .proc_handler = &proc_dointvec,
76540 + },
76541 +#endif
76542 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76543 + {
76544 + .procname = "socket_all",
76545 + .data = &grsec_enable_socket_all,
76546 + .maxlen = sizeof(int),
76547 + .mode = 0600,
76548 + .proc_handler = &proc_dointvec,
76549 + },
76550 + {
76551 + .procname = "socket_all_gid",
76552 + .data = &grsec_socket_all_gid,
76553 + .maxlen = sizeof(int),
76554 + .mode = 0600,
76555 + .proc_handler = &proc_dointvec,
76556 + },
76557 +#endif
76558 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76559 + {
76560 + .procname = "socket_client",
76561 + .data = &grsec_enable_socket_client,
76562 + .maxlen = sizeof(int),
76563 + .mode = 0600,
76564 + .proc_handler = &proc_dointvec,
76565 + },
76566 + {
76567 + .procname = "socket_client_gid",
76568 + .data = &grsec_socket_client_gid,
76569 + .maxlen = sizeof(int),
76570 + .mode = 0600,
76571 + .proc_handler = &proc_dointvec,
76572 + },
76573 +#endif
76574 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76575 + {
76576 + .procname = "socket_server",
76577 + .data = &grsec_enable_socket_server,
76578 + .maxlen = sizeof(int),
76579 + .mode = 0600,
76580 + .proc_handler = &proc_dointvec,
76581 + },
76582 + {
76583 + .procname = "socket_server_gid",
76584 + .data = &grsec_socket_server_gid,
76585 + .maxlen = sizeof(int),
76586 + .mode = 0600,
76587 + .proc_handler = &proc_dointvec,
76588 + },
76589 +#endif
76590 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76591 + {
76592 + .procname = "audit_group",
76593 + .data = &grsec_enable_group,
76594 + .maxlen = sizeof(int),
76595 + .mode = 0600,
76596 + .proc_handler = &proc_dointvec,
76597 + },
76598 + {
76599 + .procname = "audit_gid",
76600 + .data = &grsec_audit_gid,
76601 + .maxlen = sizeof(int),
76602 + .mode = 0600,
76603 + .proc_handler = &proc_dointvec,
76604 + },
76605 +#endif
76606 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76607 + {
76608 + .procname = "audit_chdir",
76609 + .data = &grsec_enable_chdir,
76610 + .maxlen = sizeof(int),
76611 + .mode = 0600,
76612 + .proc_handler = &proc_dointvec,
76613 + },
76614 +#endif
76615 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76616 + {
76617 + .procname = "audit_mount",
76618 + .data = &grsec_enable_mount,
76619 + .maxlen = sizeof(int),
76620 + .mode = 0600,
76621 + .proc_handler = &proc_dointvec,
76622 + },
76623 +#endif
76624 +#ifdef CONFIG_GRKERNSEC_DMESG
76625 + {
76626 + .procname = "dmesg",
76627 + .data = &grsec_enable_dmesg,
76628 + .maxlen = sizeof(int),
76629 + .mode = 0600,
76630 + .proc_handler = &proc_dointvec,
76631 + },
76632 +#endif
76633 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76634 + {
76635 + .procname = "chroot_findtask",
76636 + .data = &grsec_enable_chroot_findtask,
76637 + .maxlen = sizeof(int),
76638 + .mode = 0600,
76639 + .proc_handler = &proc_dointvec,
76640 + },
76641 +#endif
76642 +#ifdef CONFIG_GRKERNSEC_RESLOG
76643 + {
76644 + .procname = "resource_logging",
76645 + .data = &grsec_resource_logging,
76646 + .maxlen = sizeof(int),
76647 + .mode = 0600,
76648 + .proc_handler = &proc_dointvec,
76649 + },
76650 +#endif
76651 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76652 + {
76653 + .procname = "audit_ptrace",
76654 + .data = &grsec_enable_audit_ptrace,
76655 + .maxlen = sizeof(int),
76656 + .mode = 0600,
76657 + .proc_handler = &proc_dointvec,
76658 + },
76659 +#endif
76660 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76661 + {
76662 + .procname = "harden_ptrace",
76663 + .data = &grsec_enable_harden_ptrace,
76664 + .maxlen = sizeof(int),
76665 + .mode = 0600,
76666 + .proc_handler = &proc_dointvec,
76667 + },
76668 +#endif
76669 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76670 + {
76671 + .procname = "harden_ipc",
76672 + .data = &grsec_enable_harden_ipc,
76673 + .maxlen = sizeof(int),
76674 + .mode = 0600,
76675 + .proc_handler = &proc_dointvec,
76676 + },
76677 +#endif
76678 + {
76679 + .procname = "grsec_lock",
76680 + .data = &grsec_lock,
76681 + .maxlen = sizeof(int),
76682 + .mode = 0600,
76683 + .proc_handler = &proc_dointvec,
76684 + },
76685 +#endif
76686 +#ifdef CONFIG_GRKERNSEC_ROFS
76687 + {
76688 + .procname = "romount_protect",
76689 + .data = &grsec_enable_rofs,
76690 + .maxlen = sizeof(int),
76691 + .mode = 0600,
76692 + .proc_handler = &proc_dointvec_minmax,
76693 + .extra1 = &one,
76694 + .extra2 = &one,
76695 + },
76696 +#endif
76697 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76698 + {
76699 + .procname = "deny_new_usb",
76700 + .data = &grsec_deny_new_usb,
76701 + .maxlen = sizeof(int),
76702 + .mode = 0600,
76703 + .proc_handler = &proc_dointvec,
76704 + },
76705 +#endif
76706 + { }
76707 +};
76708 +#endif
76709 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76710 new file mode 100644
76711 index 0000000..61b514e
76712 --- /dev/null
76713 +++ b/grsecurity/grsec_time.c
76714 @@ -0,0 +1,16 @@
76715 +#include <linux/kernel.h>
76716 +#include <linux/sched.h>
76717 +#include <linux/grinternal.h>
76718 +#include <linux/module.h>
76719 +
76720 +void
76721 +gr_log_timechange(void)
76722 +{
76723 +#ifdef CONFIG_GRKERNSEC_TIME
76724 + if (grsec_enable_time)
76725 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76726 +#endif
76727 + return;
76728 +}
76729 +
76730 +EXPORT_SYMBOL_GPL(gr_log_timechange);
76731 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76732 new file mode 100644
76733 index 0000000..d1953de
76734 --- /dev/null
76735 +++ b/grsecurity/grsec_tpe.c
76736 @@ -0,0 +1,78 @@
76737 +#include <linux/kernel.h>
76738 +#include <linux/sched.h>
76739 +#include <linux/file.h>
76740 +#include <linux/fs.h>
76741 +#include <linux/grinternal.h>
76742 +
76743 +extern int gr_acl_tpe_check(void);
76744 +
76745 +int
76746 +gr_tpe_allow(const struct file *file)
76747 +{
76748 +#ifdef CONFIG_GRKERNSEC
76749 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76750 + struct inode *file_inode = file->f_path.dentry->d_inode;
76751 + const struct cred *cred = current_cred();
76752 + char *msg = NULL;
76753 + char *msg2 = NULL;
76754 +
76755 + // never restrict root
76756 + if (gr_is_global_root(cred->uid))
76757 + return 1;
76758 +
76759 + if (grsec_enable_tpe) {
76760 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76761 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76762 + msg = "not being in trusted group";
76763 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76764 + msg = "being in untrusted group";
76765 +#else
76766 + if (in_group_p(grsec_tpe_gid))
76767 + msg = "being in untrusted group";
76768 +#endif
76769 + }
76770 + if (!msg && gr_acl_tpe_check())
76771 + msg = "being in untrusted role";
76772 +
76773 + // not in any affected group/role
76774 + if (!msg)
76775 + goto next_check;
76776 +
76777 + if (gr_is_global_nonroot(inode->i_uid))
76778 + msg2 = "file in non-root-owned directory";
76779 + else if (inode->i_mode & S_IWOTH)
76780 + msg2 = "file in world-writable directory";
76781 + else if (inode->i_mode & S_IWGRP)
76782 + msg2 = "file in group-writable directory";
76783 + else if (file_inode->i_mode & S_IWOTH)
76784 + msg2 = "file is world-writable";
76785 +
76786 + if (msg && msg2) {
76787 + char fullmsg[70] = {0};
76788 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76789 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76790 + return 0;
76791 + }
76792 + msg = NULL;
76793 +next_check:
76794 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
76795 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76796 + return 1;
76797 +
76798 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76799 + msg = "directory not owned by user";
76800 + else if (inode->i_mode & S_IWOTH)
76801 + msg = "file in world-writable directory";
76802 + else if (inode->i_mode & S_IWGRP)
76803 + msg = "file in group-writable directory";
76804 + else if (file_inode->i_mode & S_IWOTH)
76805 + msg = "file is world-writable";
76806 +
76807 + if (msg) {
76808 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76809 + return 0;
76810 + }
76811 +#endif
76812 +#endif
76813 + return 1;
76814 +}
76815 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76816 new file mode 100644
76817 index 0000000..ae02d8e
76818 --- /dev/null
76819 +++ b/grsecurity/grsec_usb.c
76820 @@ -0,0 +1,15 @@
76821 +#include <linux/kernel.h>
76822 +#include <linux/grinternal.h>
76823 +#include <linux/module.h>
76824 +
76825 +int gr_handle_new_usb(void)
76826 +{
76827 +#ifdef CONFIG_GRKERNSEC_DENYUSB
76828 + if (grsec_deny_new_usb) {
76829 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76830 + return 1;
76831 + }
76832 +#endif
76833 + return 0;
76834 +}
76835 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76836 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76837 new file mode 100644
76838 index 0000000..9f7b1ac
76839 --- /dev/null
76840 +++ b/grsecurity/grsum.c
76841 @@ -0,0 +1,61 @@
76842 +#include <linux/err.h>
76843 +#include <linux/kernel.h>
76844 +#include <linux/sched.h>
76845 +#include <linux/mm.h>
76846 +#include <linux/scatterlist.h>
76847 +#include <linux/crypto.h>
76848 +#include <linux/gracl.h>
76849 +
76850 +
76851 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76852 +#error "crypto and sha256 must be built into the kernel"
76853 +#endif
76854 +
76855 +int
76856 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76857 +{
76858 + char *p;
76859 + struct crypto_hash *tfm;
76860 + struct hash_desc desc;
76861 + struct scatterlist sg;
76862 + unsigned char temp_sum[GR_SHA_LEN];
76863 + volatile int retval = 0;
76864 + volatile int dummy = 0;
76865 + unsigned int i;
76866 +
76867 + sg_init_table(&sg, 1);
76868 +
76869 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76870 + if (IS_ERR(tfm)) {
76871 + /* should never happen, since sha256 should be built in */
76872 + return 1;
76873 + }
76874 +
76875 + desc.tfm = tfm;
76876 + desc.flags = 0;
76877 +
76878 + crypto_hash_init(&desc);
76879 +
76880 + p = salt;
76881 + sg_set_buf(&sg, p, GR_SALT_LEN);
76882 + crypto_hash_update(&desc, &sg, sg.length);
76883 +
76884 + p = entry->pw;
76885 + sg_set_buf(&sg, p, strlen(p));
76886 +
76887 + crypto_hash_update(&desc, &sg, sg.length);
76888 +
76889 + crypto_hash_final(&desc, temp_sum);
76890 +
76891 + memset(entry->pw, 0, GR_PW_LEN);
76892 +
76893 + for (i = 0; i < GR_SHA_LEN; i++)
76894 + if (sum[i] != temp_sum[i])
76895 + retval = 1;
76896 + else
76897 + dummy = 1; // waste a cycle
76898 +
76899 + crypto_free_hash(tfm);
76900 +
76901 + return retval;
76902 +}
76903 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76904 index 77ff547..181834f 100644
76905 --- a/include/asm-generic/4level-fixup.h
76906 +++ b/include/asm-generic/4level-fixup.h
76907 @@ -13,8 +13,10 @@
76908 #define pmd_alloc(mm, pud, address) \
76909 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76910 NULL: pmd_offset(pud, address))
76911 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76912
76913 #define pud_alloc(mm, pgd, address) (pgd)
76914 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76915 #define pud_offset(pgd, start) (pgd)
76916 #define pud_none(pud) 0
76917 #define pud_bad(pud) 0
76918 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76919 index b7babf0..97f4c4f 100644
76920 --- a/include/asm-generic/atomic-long.h
76921 +++ b/include/asm-generic/atomic-long.h
76922 @@ -22,6 +22,12 @@
76923
76924 typedef atomic64_t atomic_long_t;
76925
76926 +#ifdef CONFIG_PAX_REFCOUNT
76927 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
76928 +#else
76929 +typedef atomic64_t atomic_long_unchecked_t;
76930 +#endif
76931 +
76932 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76933
76934 static inline long atomic_long_read(atomic_long_t *l)
76935 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76936 return (long)atomic64_read(v);
76937 }
76938
76939 +#ifdef CONFIG_PAX_REFCOUNT
76940 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76941 +{
76942 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76943 +
76944 + return (long)atomic64_read_unchecked(v);
76945 +}
76946 +#endif
76947 +
76948 static inline void atomic_long_set(atomic_long_t *l, long i)
76949 {
76950 atomic64_t *v = (atomic64_t *)l;
76951 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76952 atomic64_set(v, i);
76953 }
76954
76955 +#ifdef CONFIG_PAX_REFCOUNT
76956 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76957 +{
76958 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76959 +
76960 + atomic64_set_unchecked(v, i);
76961 +}
76962 +#endif
76963 +
76964 static inline void atomic_long_inc(atomic_long_t *l)
76965 {
76966 atomic64_t *v = (atomic64_t *)l;
76967 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76968 atomic64_inc(v);
76969 }
76970
76971 +#ifdef CONFIG_PAX_REFCOUNT
76972 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76973 +{
76974 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76975 +
76976 + atomic64_inc_unchecked(v);
76977 +}
76978 +#endif
76979 +
76980 static inline void atomic_long_dec(atomic_long_t *l)
76981 {
76982 atomic64_t *v = (atomic64_t *)l;
76983 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76984 atomic64_dec(v);
76985 }
76986
76987 +#ifdef CONFIG_PAX_REFCOUNT
76988 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76989 +{
76990 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76991 +
76992 + atomic64_dec_unchecked(v);
76993 +}
76994 +#endif
76995 +
76996 static inline void atomic_long_add(long i, atomic_long_t *l)
76997 {
76998 atomic64_t *v = (atomic64_t *)l;
76999 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77000 atomic64_add(i, v);
77001 }
77002
77003 +#ifdef CONFIG_PAX_REFCOUNT
77004 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77005 +{
77006 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77007 +
77008 + atomic64_add_unchecked(i, v);
77009 +}
77010 +#endif
77011 +
77012 static inline void atomic_long_sub(long i, atomic_long_t *l)
77013 {
77014 atomic64_t *v = (atomic64_t *)l;
77015 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77016 atomic64_sub(i, v);
77017 }
77018
77019 +#ifdef CONFIG_PAX_REFCOUNT
77020 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77021 +{
77022 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77023 +
77024 + atomic64_sub_unchecked(i, v);
77025 +}
77026 +#endif
77027 +
77028 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77029 {
77030 atomic64_t *v = (atomic64_t *)l;
77031 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
77032 return atomic64_add_negative(i, v);
77033 }
77034
77035 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
77036 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
77037 {
77038 atomic64_t *v = (atomic64_t *)l;
77039
77040 return (long)atomic64_add_return(i, v);
77041 }
77042
77043 +#ifdef CONFIG_PAX_REFCOUNT
77044 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77045 +{
77046 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77047 +
77048 + return (long)atomic64_add_return_unchecked(i, v);
77049 +}
77050 +#endif
77051 +
77052 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77053 {
77054 atomic64_t *v = (atomic64_t *)l;
77055 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77056 return (long)atomic64_inc_return(v);
77057 }
77058
77059 +#ifdef CONFIG_PAX_REFCOUNT
77060 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77061 +{
77062 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77063 +
77064 + return (long)atomic64_inc_return_unchecked(v);
77065 +}
77066 +#endif
77067 +
77068 static inline long atomic_long_dec_return(atomic_long_t *l)
77069 {
77070 atomic64_t *v = (atomic64_t *)l;
77071 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77072
77073 typedef atomic_t atomic_long_t;
77074
77075 +#ifdef CONFIG_PAX_REFCOUNT
77076 +typedef atomic_unchecked_t atomic_long_unchecked_t;
77077 +#else
77078 +typedef atomic_t atomic_long_unchecked_t;
77079 +#endif
77080 +
77081 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
77082 static inline long atomic_long_read(atomic_long_t *l)
77083 {
77084 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
77085 return (long)atomic_read(v);
77086 }
77087
77088 +#ifdef CONFIG_PAX_REFCOUNT
77089 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77090 +{
77091 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77092 +
77093 + return (long)atomic_read_unchecked(v);
77094 +}
77095 +#endif
77096 +
77097 static inline void atomic_long_set(atomic_long_t *l, long i)
77098 {
77099 atomic_t *v = (atomic_t *)l;
77100 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77101 atomic_set(v, i);
77102 }
77103
77104 +#ifdef CONFIG_PAX_REFCOUNT
77105 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77106 +{
77107 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77108 +
77109 + atomic_set_unchecked(v, i);
77110 +}
77111 +#endif
77112 +
77113 static inline void atomic_long_inc(atomic_long_t *l)
77114 {
77115 atomic_t *v = (atomic_t *)l;
77116 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77117 atomic_inc(v);
77118 }
77119
77120 +#ifdef CONFIG_PAX_REFCOUNT
77121 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77122 +{
77123 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77124 +
77125 + atomic_inc_unchecked(v);
77126 +}
77127 +#endif
77128 +
77129 static inline void atomic_long_dec(atomic_long_t *l)
77130 {
77131 atomic_t *v = (atomic_t *)l;
77132 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77133 atomic_dec(v);
77134 }
77135
77136 +#ifdef CONFIG_PAX_REFCOUNT
77137 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77138 +{
77139 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77140 +
77141 + atomic_dec_unchecked(v);
77142 +}
77143 +#endif
77144 +
77145 static inline void atomic_long_add(long i, atomic_long_t *l)
77146 {
77147 atomic_t *v = (atomic_t *)l;
77148 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77149 atomic_add(i, v);
77150 }
77151
77152 +#ifdef CONFIG_PAX_REFCOUNT
77153 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77154 +{
77155 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77156 +
77157 + atomic_add_unchecked(i, v);
77158 +}
77159 +#endif
77160 +
77161 static inline void atomic_long_sub(long i, atomic_long_t *l)
77162 {
77163 atomic_t *v = (atomic_t *)l;
77164 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77165 atomic_sub(i, v);
77166 }
77167
77168 +#ifdef CONFIG_PAX_REFCOUNT
77169 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77170 +{
77171 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77172 +
77173 + atomic_sub_unchecked(i, v);
77174 +}
77175 +#endif
77176 +
77177 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77178 {
77179 atomic_t *v = (atomic_t *)l;
77180 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
77181 return (long)atomic_add_return(i, v);
77182 }
77183
77184 +#ifdef CONFIG_PAX_REFCOUNT
77185 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77186 +{
77187 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77188 +
77189 + return (long)atomic_add_return_unchecked(i, v);
77190 +}
77191 +
77192 +#endif
77193 +
77194 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77195 {
77196 atomic_t *v = (atomic_t *)l;
77197 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77198 return (long)atomic_inc_return(v);
77199 }
77200
77201 +#ifdef CONFIG_PAX_REFCOUNT
77202 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77203 +{
77204 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77205 +
77206 + return (long)atomic_inc_return_unchecked(v);
77207 +}
77208 +#endif
77209 +
77210 static inline long atomic_long_dec_return(atomic_long_t *l)
77211 {
77212 atomic_t *v = (atomic_t *)l;
77213 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77214
77215 #endif /* BITS_PER_LONG == 64 */
77216
77217 +#ifdef CONFIG_PAX_REFCOUNT
77218 +static inline void pax_refcount_needs_these_functions(void)
77219 +{
77220 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
77221 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
77222 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
77223 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
77224 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
77225 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
77226 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
77227 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
77228 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
77229 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
77230 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
77231 +#ifdef CONFIG_X86
77232 + atomic_clear_mask_unchecked(0, NULL);
77233 + atomic_set_mask_unchecked(0, NULL);
77234 +#endif
77235 +
77236 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
77237 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
77238 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
77239 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
77240 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
77241 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
77242 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
77243 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
77244 +}
77245 +#else
77246 +#define atomic_read_unchecked(v) atomic_read(v)
77247 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
77248 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
77249 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
77250 +#define atomic_inc_unchecked(v) atomic_inc(v)
77251 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
77252 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
77253 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
77254 +#define atomic_dec_unchecked(v) atomic_dec(v)
77255 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
77256 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
77257 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
77258 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
77259 +
77260 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
77261 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
77262 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
77263 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
77264 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
77265 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
77266 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
77267 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
77268 +#endif
77269 +
77270 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
77271 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
77272 index 33bd2de..f31bff97 100644
77273 --- a/include/asm-generic/atomic.h
77274 +++ b/include/asm-generic/atomic.h
77275 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
77276 * Atomically clears the bits set in @mask from @v
77277 */
77278 #ifndef atomic_clear_mask
77279 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
77280 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
77281 {
77282 unsigned long flags;
77283
77284 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
77285 index b18ce4f..2ee2843 100644
77286 --- a/include/asm-generic/atomic64.h
77287 +++ b/include/asm-generic/atomic64.h
77288 @@ -16,6 +16,8 @@ typedef struct {
77289 long long counter;
77290 } atomic64_t;
77291
77292 +typedef atomic64_t atomic64_unchecked_t;
77293 +
77294 #define ATOMIC64_INIT(i) { (i) }
77295
77296 extern long long atomic64_read(const atomic64_t *v);
77297 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
77298 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
77299 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
77300
77301 +#define atomic64_read_unchecked(v) atomic64_read(v)
77302 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
77303 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
77304 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
77305 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
77306 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
77307 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
77308 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
77309 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
77310 +
77311 #endif /* _ASM_GENERIC_ATOMIC64_H */
77312 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
77313 index 6f692f8..2ad9dd2 100644
77314 --- a/include/asm-generic/barrier.h
77315 +++ b/include/asm-generic/barrier.h
77316 @@ -66,7 +66,7 @@
77317 do { \
77318 compiletime_assert_atomic_type(*p); \
77319 smp_mb(); \
77320 - ACCESS_ONCE(*p) = (v); \
77321 + ACCESS_ONCE_RW(*p) = (v); \
77322 } while (0)
77323
77324 #define smp_load_acquire(p) \
77325 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
77326 index a60a7cc..0fe12f2 100644
77327 --- a/include/asm-generic/bitops/__fls.h
77328 +++ b/include/asm-generic/bitops/__fls.h
77329 @@ -9,7 +9,7 @@
77330 *
77331 * Undefined if no set bit exists, so code should check against 0 first.
77332 */
77333 -static __always_inline unsigned long __fls(unsigned long word)
77334 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
77335 {
77336 int num = BITS_PER_LONG - 1;
77337
77338 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
77339 index 0576d1f..dad6c71 100644
77340 --- a/include/asm-generic/bitops/fls.h
77341 +++ b/include/asm-generic/bitops/fls.h
77342 @@ -9,7 +9,7 @@
77343 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
77344 */
77345
77346 -static __always_inline int fls(int x)
77347 +static __always_inline int __intentional_overflow(-1) fls(int x)
77348 {
77349 int r = 32;
77350
77351 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
77352 index b097cf8..3d40e14 100644
77353 --- a/include/asm-generic/bitops/fls64.h
77354 +++ b/include/asm-generic/bitops/fls64.h
77355 @@ -15,7 +15,7 @@
77356 * at position 64.
77357 */
77358 #if BITS_PER_LONG == 32
77359 -static __always_inline int fls64(__u64 x)
77360 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77361 {
77362 __u32 h = x >> 32;
77363 if (h)
77364 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
77365 return fls(x);
77366 }
77367 #elif BITS_PER_LONG == 64
77368 -static __always_inline int fls64(__u64 x)
77369 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77370 {
77371 if (x == 0)
77372 return 0;
77373 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77374 index 1bfcfe5..e04c5c9 100644
77375 --- a/include/asm-generic/cache.h
77376 +++ b/include/asm-generic/cache.h
77377 @@ -6,7 +6,7 @@
77378 * cache lines need to provide their own cache.h.
77379 */
77380
77381 -#define L1_CACHE_SHIFT 5
77382 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77383 +#define L1_CACHE_SHIFT 5UL
77384 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77385
77386 #endif /* __ASM_GENERIC_CACHE_H */
77387 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77388 index 0d68a1e..b74a761 100644
77389 --- a/include/asm-generic/emergency-restart.h
77390 +++ b/include/asm-generic/emergency-restart.h
77391 @@ -1,7 +1,7 @@
77392 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77393 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77394
77395 -static inline void machine_emergency_restart(void)
77396 +static inline __noreturn void machine_emergency_restart(void)
77397 {
77398 machine_restart(NULL);
77399 }
77400 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
77401 index 975e1cc..0b8a083 100644
77402 --- a/include/asm-generic/io.h
77403 +++ b/include/asm-generic/io.h
77404 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
77405 * These are pretty trivial
77406 */
77407 #ifndef virt_to_phys
77408 -static inline unsigned long virt_to_phys(volatile void *address)
77409 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
77410 {
77411 return __pa((unsigned long)address);
77412 }
77413 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77414 index 90f99c7..00ce236 100644
77415 --- a/include/asm-generic/kmap_types.h
77416 +++ b/include/asm-generic/kmap_types.h
77417 @@ -2,9 +2,9 @@
77418 #define _ASM_GENERIC_KMAP_TYPES_H
77419
77420 #ifdef __WITH_KM_FENCE
77421 -# define KM_TYPE_NR 41
77422 +# define KM_TYPE_NR 42
77423 #else
77424 -# define KM_TYPE_NR 20
77425 +# define KM_TYPE_NR 21
77426 #endif
77427
77428 #endif
77429 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77430 index 9ceb03b..62b0b8f 100644
77431 --- a/include/asm-generic/local.h
77432 +++ b/include/asm-generic/local.h
77433 @@ -23,24 +23,37 @@ typedef struct
77434 atomic_long_t a;
77435 } local_t;
77436
77437 +typedef struct {
77438 + atomic_long_unchecked_t a;
77439 +} local_unchecked_t;
77440 +
77441 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77442
77443 #define local_read(l) atomic_long_read(&(l)->a)
77444 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77445 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77446 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77447 #define local_inc(l) atomic_long_inc(&(l)->a)
77448 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77449 #define local_dec(l) atomic_long_dec(&(l)->a)
77450 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77451 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77452 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77453 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77454 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77455
77456 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77457 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77458 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77459 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77460 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77461 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77462 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77463 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77464 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77465
77466 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77467 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77468 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77469 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77470 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77471 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77472 index 725612b..9cc513a 100644
77473 --- a/include/asm-generic/pgtable-nopmd.h
77474 +++ b/include/asm-generic/pgtable-nopmd.h
77475 @@ -1,14 +1,19 @@
77476 #ifndef _PGTABLE_NOPMD_H
77477 #define _PGTABLE_NOPMD_H
77478
77479 -#ifndef __ASSEMBLY__
77480 -
77481 #include <asm-generic/pgtable-nopud.h>
77482
77483 -struct mm_struct;
77484 -
77485 #define __PAGETABLE_PMD_FOLDED
77486
77487 +#define PMD_SHIFT PUD_SHIFT
77488 +#define PTRS_PER_PMD 1
77489 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77490 +#define PMD_MASK (~(PMD_SIZE-1))
77491 +
77492 +#ifndef __ASSEMBLY__
77493 +
77494 +struct mm_struct;
77495 +
77496 /*
77497 * Having the pmd type consist of a pud gets the size right, and allows
77498 * us to conceptually access the pud entry that this pmd is folded into
77499 @@ -16,11 +21,6 @@ struct mm_struct;
77500 */
77501 typedef struct { pud_t pud; } pmd_t;
77502
77503 -#define PMD_SHIFT PUD_SHIFT
77504 -#define PTRS_PER_PMD 1
77505 -#define PMD_SIZE (1UL << PMD_SHIFT)
77506 -#define PMD_MASK (~(PMD_SIZE-1))
77507 -
77508 /*
77509 * The "pud_xxx()" functions here are trivial for a folded two-level
77510 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77511 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77512 index 810431d..0ec4804f 100644
77513 --- a/include/asm-generic/pgtable-nopud.h
77514 +++ b/include/asm-generic/pgtable-nopud.h
77515 @@ -1,10 +1,15 @@
77516 #ifndef _PGTABLE_NOPUD_H
77517 #define _PGTABLE_NOPUD_H
77518
77519 -#ifndef __ASSEMBLY__
77520 -
77521 #define __PAGETABLE_PUD_FOLDED
77522
77523 +#define PUD_SHIFT PGDIR_SHIFT
77524 +#define PTRS_PER_PUD 1
77525 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77526 +#define PUD_MASK (~(PUD_SIZE-1))
77527 +
77528 +#ifndef __ASSEMBLY__
77529 +
77530 /*
77531 * Having the pud type consist of a pgd gets the size right, and allows
77532 * us to conceptually access the pgd entry that this pud is folded into
77533 @@ -12,11 +17,6 @@
77534 */
77535 typedef struct { pgd_t pgd; } pud_t;
77536
77537 -#define PUD_SHIFT PGDIR_SHIFT
77538 -#define PTRS_PER_PUD 1
77539 -#define PUD_SIZE (1UL << PUD_SHIFT)
77540 -#define PUD_MASK (~(PUD_SIZE-1))
77541 -
77542 /*
77543 * The "pgd_xxx()" functions here are trivial for a folded two-level
77544 * setup: the pud is never bad, and a pud always exists (as it's folded
77545 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77546 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77547
77548 #define pgd_populate(mm, pgd, pud) do { } while (0)
77549 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77550 /*
77551 * (puds are folded into pgds so this doesn't get actually called,
77552 * but the define is needed for a generic inline function.)
77553 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77554 index a8015a7..7a4407b 100644
77555 --- a/include/asm-generic/pgtable.h
77556 +++ b/include/asm-generic/pgtable.h
77557 @@ -815,6 +815,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77558 }
77559 #endif /* CONFIG_NUMA_BALANCING */
77560
77561 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77562 +#ifdef CONFIG_PAX_KERNEXEC
77563 +#error KERNEXEC requires pax_open_kernel
77564 +#else
77565 +static inline unsigned long pax_open_kernel(void) { return 0; }
77566 +#endif
77567 +#endif
77568 +
77569 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77570 +#ifdef CONFIG_PAX_KERNEXEC
77571 +#error KERNEXEC requires pax_close_kernel
77572 +#else
77573 +static inline unsigned long pax_close_kernel(void) { return 0; }
77574 +#endif
77575 +#endif
77576 +
77577 #endif /* CONFIG_MMU */
77578
77579 #endif /* !__ASSEMBLY__ */
77580 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77581 index 72d8803..cb9749c 100644
77582 --- a/include/asm-generic/uaccess.h
77583 +++ b/include/asm-generic/uaccess.h
77584 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77585 return __clear_user(to, n);
77586 }
77587
77588 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77589 +#ifdef CONFIG_PAX_MEMORY_UDEREF
77590 +#error UDEREF requires pax_open_userland
77591 +#else
77592 +static inline unsigned long pax_open_userland(void) { return 0; }
77593 +#endif
77594 +#endif
77595 +
77596 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77597 +#ifdef CONFIG_PAX_MEMORY_UDEREF
77598 +#error UDEREF requires pax_close_userland
77599 +#else
77600 +static inline unsigned long pax_close_userland(void) { return 0; }
77601 +#endif
77602 +#endif
77603 +
77604 #endif /* __ASM_GENERIC_UACCESS_H */
77605 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77606 index 146e4ff..f4f9609 100644
77607 --- a/include/asm-generic/vmlinux.lds.h
77608 +++ b/include/asm-generic/vmlinux.lds.h
77609 @@ -251,6 +251,7 @@
77610 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77611 VMLINUX_SYMBOL(__start_rodata) = .; \
77612 *(.rodata) *(.rodata.*) \
77613 + *(.data..read_only) \
77614 *(__vermagic) /* Kernel version magic */ \
77615 . = ALIGN(8); \
77616 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77617 @@ -737,17 +738,18 @@
77618 * section in the linker script will go there too. @phdr should have
77619 * a leading colon.
77620 *
77621 - * Note that this macros defines __per_cpu_load as an absolute symbol.
77622 + * Note that this macros defines per_cpu_load as an absolute symbol.
77623 * If there is no need to put the percpu section at a predetermined
77624 * address, use PERCPU_SECTION.
77625 */
77626 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77627 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
77628 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77629 + per_cpu_load = .; \
77630 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77631 - LOAD_OFFSET) { \
77632 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77633 PERCPU_INPUT(cacheline) \
77634 } phdr \
77635 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77636 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77637
77638 /**
77639 * PERCPU_SECTION - define output section for percpu area, simple version
77640 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77641 index 016c2f1..c4baa98 100644
77642 --- a/include/crypto/algapi.h
77643 +++ b/include/crypto/algapi.h
77644 @@ -34,7 +34,7 @@ struct crypto_type {
77645 unsigned int maskclear;
77646 unsigned int maskset;
77647 unsigned int tfmsize;
77648 -};
77649 +} __do_const;
77650
77651 struct crypto_instance {
77652 struct crypto_alg alg;
77653 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77654 index a7c2a86..078f1b6 100644
77655 --- a/include/drm/drmP.h
77656 +++ b/include/drm/drmP.h
77657 @@ -68,6 +68,7 @@
77658 #include <linux/workqueue.h>
77659 #include <linux/poll.h>
77660 #include <asm/pgalloc.h>
77661 +#include <asm/local.h>
77662 #include <drm/drm.h>
77663 #include <drm/drm_sarea.h>
77664 #include <drm/drm_vma_manager.h>
77665 @@ -268,10 +269,12 @@ do { \
77666 * \param cmd command.
77667 * \param arg argument.
77668 */
77669 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77670 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77671 + struct drm_file *file_priv);
77672 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77673 struct drm_file *file_priv);
77674
77675 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77676 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77677 unsigned long arg);
77678
77679 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77680 @@ -287,10 +290,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77681 struct drm_ioctl_desc {
77682 unsigned int cmd;
77683 int flags;
77684 - drm_ioctl_t *func;
77685 + drm_ioctl_t func;
77686 unsigned int cmd_drv;
77687 const char *name;
77688 -};
77689 +} __do_const;
77690
77691 /**
77692 * Creates a driver or general drm_ioctl_desc array entry for the given
77693 @@ -1001,7 +1004,8 @@ struct drm_info_list {
77694 int (*show)(struct seq_file*, void*); /** show callback */
77695 u32 driver_features; /**< Required driver features for this entry */
77696 void *data;
77697 -};
77698 +} __do_const;
77699 +typedef struct drm_info_list __no_const drm_info_list_no_const;
77700
77701 /**
77702 * debugfs node structure. This structure represents a debugfs file.
77703 @@ -1083,7 +1087,7 @@ struct drm_device {
77704
77705 /** \name Usage Counters */
77706 /*@{ */
77707 - int open_count; /**< Outstanding files open */
77708 + local_t open_count; /**< Outstanding files open */
77709 int buf_use; /**< Buffers in use -- cannot alloc */
77710 atomic_t buf_alloc; /**< Buffer allocation in progress */
77711 /*@} */
77712 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77713 index 36a5feb..d9f01aa 100644
77714 --- a/include/drm/drm_crtc_helper.h
77715 +++ b/include/drm/drm_crtc_helper.h
77716 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77717 struct drm_connector *connector);
77718 /* disable encoder when not in use - more explicit than dpms off */
77719 void (*disable)(struct drm_encoder *encoder);
77720 -};
77721 +} __no_const;
77722
77723 /**
77724 * drm_connector_helper_funcs - helper operations for connectors
77725 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77726 index 012d58f..d0a0642 100644
77727 --- a/include/drm/i915_pciids.h
77728 +++ b/include/drm/i915_pciids.h
77729 @@ -37,7 +37,7 @@
77730 */
77731 #define INTEL_VGA_DEVICE(id, info) { \
77732 0x8086, id, \
77733 - ~0, ~0, \
77734 + PCI_ANY_ID, PCI_ANY_ID, \
77735 0x030000, 0xff0000, \
77736 (unsigned long) info }
77737
77738 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77739 index 72dcbe8..8db58d7 100644
77740 --- a/include/drm/ttm/ttm_memory.h
77741 +++ b/include/drm/ttm/ttm_memory.h
77742 @@ -48,7 +48,7 @@
77743
77744 struct ttm_mem_shrink {
77745 int (*do_shrink) (struct ttm_mem_shrink *);
77746 -};
77747 +} __no_const;
77748
77749 /**
77750 * struct ttm_mem_global - Global memory accounting structure.
77751 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77752 index 49a8284..9643967 100644
77753 --- a/include/drm/ttm/ttm_page_alloc.h
77754 +++ b/include/drm/ttm/ttm_page_alloc.h
77755 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77756 */
77757 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77758
77759 +struct device;
77760 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77761 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77762
77763 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77764 index 4b840e8..155d235 100644
77765 --- a/include/keys/asymmetric-subtype.h
77766 +++ b/include/keys/asymmetric-subtype.h
77767 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77768 /* Verify the signature on a key of this subtype (optional) */
77769 int (*verify_signature)(const struct key *key,
77770 const struct public_key_signature *sig);
77771 -};
77772 +} __do_const;
77773
77774 /**
77775 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77776 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77777 index c1da539..1dcec55 100644
77778 --- a/include/linux/atmdev.h
77779 +++ b/include/linux/atmdev.h
77780 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77781 #endif
77782
77783 struct k_atm_aal_stats {
77784 -#define __HANDLE_ITEM(i) atomic_t i
77785 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
77786 __AAL_STAT_ITEMS
77787 #undef __HANDLE_ITEM
77788 };
77789 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77790 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77791 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77792 struct module *owner;
77793 -};
77794 +} __do_const ;
77795
77796 struct atmphy_ops {
77797 int (*start)(struct atm_dev *dev);
77798 diff --git a/include/linux/audit.h b/include/linux/audit.h
77799 index 22cfddb..ab759e8 100644
77800 --- a/include/linux/audit.h
77801 +++ b/include/linux/audit.h
77802 @@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
77803 extern unsigned int audit_serial(void);
77804 extern int auditsc_get_stamp(struct audit_context *ctx,
77805 struct timespec *t, unsigned int *serial);
77806 -extern int audit_set_loginuid(kuid_t loginuid);
77807 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77808
77809 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77810 {
77811 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77812 index 61f29e5..e67c658 100644
77813 --- a/include/linux/binfmts.h
77814 +++ b/include/linux/binfmts.h
77815 @@ -44,7 +44,7 @@ struct linux_binprm {
77816 unsigned interp_flags;
77817 unsigned interp_data;
77818 unsigned long loader, exec;
77819 -};
77820 +} __randomize_layout;
77821
77822 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77823 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77824 @@ -73,8 +73,10 @@ struct linux_binfmt {
77825 int (*load_binary)(struct linux_binprm *);
77826 int (*load_shlib)(struct file *);
77827 int (*core_dump)(struct coredump_params *cprm);
77828 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77829 + void (*handle_mmap)(struct file *);
77830 unsigned long min_coredump; /* minimal dump size */
77831 -};
77832 +} __do_const __randomize_layout;
77833
77834 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77835
77836 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77837 index be5fd38..d71192a 100644
77838 --- a/include/linux/bitops.h
77839 +++ b/include/linux/bitops.h
77840 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77841 * @word: value to rotate
77842 * @shift: bits to roll
77843 */
77844 -static inline __u32 rol32(__u32 word, unsigned int shift)
77845 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77846 {
77847 return (word << shift) | (word >> (32 - shift));
77848 }
77849 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77850 * @word: value to rotate
77851 * @shift: bits to roll
77852 */
77853 -static inline __u32 ror32(__u32 word, unsigned int shift)
77854 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77855 {
77856 return (word >> shift) | (word << (32 - shift));
77857 }
77858 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77859 return (__s32)(value << shift) >> shift;
77860 }
77861
77862 -static inline unsigned fls_long(unsigned long l)
77863 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77864 {
77865 if (sizeof(l) == 4)
77866 return fls(l);
77867 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77868 index 0d84981..bb741c0 100644
77869 --- a/include/linux/blkdev.h
77870 +++ b/include/linux/blkdev.h
77871 @@ -1584,7 +1584,7 @@ struct block_device_operations {
77872 /* this callback is with swap_lock and sometimes page table lock held */
77873 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77874 struct module *owner;
77875 -};
77876 +} __do_const;
77877
77878 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77879 unsigned long);
77880 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77881 index afc1343..9735539 100644
77882 --- a/include/linux/blktrace_api.h
77883 +++ b/include/linux/blktrace_api.h
77884 @@ -25,7 +25,7 @@ struct blk_trace {
77885 struct dentry *dropped_file;
77886 struct dentry *msg_file;
77887 struct list_head running_list;
77888 - atomic_t dropped;
77889 + atomic_unchecked_t dropped;
77890 };
77891
77892 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77893 diff --git a/include/linux/cache.h b/include/linux/cache.h
77894 index 17e7e82..1d7da26 100644
77895 --- a/include/linux/cache.h
77896 +++ b/include/linux/cache.h
77897 @@ -16,6 +16,14 @@
77898 #define __read_mostly
77899 #endif
77900
77901 +#ifndef __read_only
77902 +#ifdef CONFIG_PAX_KERNEXEC
77903 +#error KERNEXEC requires __read_only
77904 +#else
77905 +#define __read_only __read_mostly
77906 +#endif
77907 +#endif
77908 +
77909 #ifndef ____cacheline_aligned
77910 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77911 #endif
77912 diff --git a/include/linux/capability.h b/include/linux/capability.h
77913 index 84b13ad..172cdee 100644
77914 --- a/include/linux/capability.h
77915 +++ b/include/linux/capability.h
77916 @@ -211,9 +211,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
77917 extern bool capable(int cap);
77918 extern bool ns_capable(struct user_namespace *ns, int cap);
77919 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
77920 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
77921 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77922 +extern bool capable_nolog(int cap);
77923 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77924
77925 /* audit system wants to get cap info from files as well */
77926 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77927
77928 +extern int is_privileged_binary(const struct dentry *dentry);
77929 +
77930 #endif /* !_LINUX_CAPABILITY_H */
77931 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77932 index 8609d57..86e4d79 100644
77933 --- a/include/linux/cdrom.h
77934 +++ b/include/linux/cdrom.h
77935 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
77936
77937 /* driver specifications */
77938 const int capability; /* capability flags */
77939 - int n_minors; /* number of active minor devices */
77940 /* handle uniform packets for scsi type devices (scsi,atapi) */
77941 int (*generic_packet) (struct cdrom_device_info *,
77942 struct packet_command *);
77943 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77944 index 4ce9056..86caac6 100644
77945 --- a/include/linux/cleancache.h
77946 +++ b/include/linux/cleancache.h
77947 @@ -31,7 +31,7 @@ struct cleancache_ops {
77948 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77949 void (*invalidate_inode)(int, struct cleancache_filekey);
77950 void (*invalidate_fs)(int);
77951 -};
77952 +} __no_const;
77953
77954 extern struct cleancache_ops *
77955 cleancache_register_ops(struct cleancache_ops *ops);
77956 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77957 index 5119174..8e264f8 100644
77958 --- a/include/linux/clk-provider.h
77959 +++ b/include/linux/clk-provider.h
77960 @@ -174,6 +174,7 @@ struct clk_ops {
77961 void (*init)(struct clk_hw *hw);
77962 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
77963 };
77964 +typedef struct clk_ops __no_const clk_ops_no_const;
77965
77966 /**
77967 * struct clk_init_data - holds init data that's common to all clocks and is
77968 diff --git a/include/linux/compat.h b/include/linux/compat.h
77969 index e649426..a74047b 100644
77970 --- a/include/linux/compat.h
77971 +++ b/include/linux/compat.h
77972 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77973 compat_size_t __user *len_ptr);
77974
77975 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77976 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77977 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77978 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77979 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77980 compat_ssize_t msgsz, int msgflg);
77981 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77982 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77983 compat_ulong_t addr, compat_ulong_t data);
77984 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77985 - compat_long_t addr, compat_long_t data);
77986 + compat_ulong_t addr, compat_ulong_t data);
77987
77988 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77989 /*
77990 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77991 index 2507fd2..55203f8 100644
77992 --- a/include/linux/compiler-gcc4.h
77993 +++ b/include/linux/compiler-gcc4.h
77994 @@ -39,9 +39,34 @@
77995 # define __compiletime_warning(message) __attribute__((warning(message)))
77996 # define __compiletime_error(message) __attribute__((error(message)))
77997 #endif /* __CHECKER__ */
77998 +
77999 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
78000 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
78001 +#define __bos0(ptr) __bos((ptr), 0)
78002 +#define __bos1(ptr) __bos((ptr), 1)
78003 #endif /* GCC_VERSION >= 40300 */
78004
78005 #if GCC_VERSION >= 40500
78006 +
78007 +#ifdef RANDSTRUCT_PLUGIN
78008 +#define __randomize_layout __attribute__((randomize_layout))
78009 +#define __no_randomize_layout __attribute__((no_randomize_layout))
78010 +#endif
78011 +
78012 +#ifdef CONSTIFY_PLUGIN
78013 +#define __no_const __attribute__((no_const))
78014 +#define __do_const __attribute__((do_const))
78015 +#endif
78016 +
78017 +#ifdef SIZE_OVERFLOW_PLUGIN
78018 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
78019 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
78020 +#endif
78021 +
78022 +#ifdef LATENT_ENTROPY_PLUGIN
78023 +#define __latent_entropy __attribute__((latent_entropy))
78024 +#endif
78025 +
78026 /*
78027 * Mark a position in code as unreachable. This can be used to
78028 * suppress control flow warnings after asm blocks that transfer
78029 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
78030 index ee7239e..7c11769 100644
78031 --- a/include/linux/compiler.h
78032 +++ b/include/linux/compiler.h
78033 @@ -5,11 +5,14 @@
78034
78035 #ifdef __CHECKER__
78036 # define __user __attribute__((noderef, address_space(1)))
78037 +# define __force_user __force __user
78038 # define __kernel __attribute__((address_space(0)))
78039 +# define __force_kernel __force __kernel
78040 # define __safe __attribute__((safe))
78041 # define __force __attribute__((force))
78042 # define __nocast __attribute__((nocast))
78043 # define __iomem __attribute__((noderef, address_space(2)))
78044 +# define __force_iomem __force __iomem
78045 # define __must_hold(x) __attribute__((context(x,1,1)))
78046 # define __acquires(x) __attribute__((context(x,0,1)))
78047 # define __releases(x) __attribute__((context(x,1,0)))
78048 @@ -17,20 +20,37 @@
78049 # define __release(x) __context__(x,-1)
78050 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
78051 # define __percpu __attribute__((noderef, address_space(3)))
78052 +# define __force_percpu __force __percpu
78053 #ifdef CONFIG_SPARSE_RCU_POINTER
78054 # define __rcu __attribute__((noderef, address_space(4)))
78055 +# define __force_rcu __force __rcu
78056 #else
78057 # define __rcu
78058 +# define __force_rcu
78059 #endif
78060 extern void __chk_user_ptr(const volatile void __user *);
78061 extern void __chk_io_ptr(const volatile void __iomem *);
78062 #else
78063 -# define __user
78064 -# define __kernel
78065 +# ifdef CHECKER_PLUGIN
78066 +//# define __user
78067 +//# define __force_user
78068 +//# define __kernel
78069 +//# define __force_kernel
78070 +# else
78071 +# ifdef STRUCTLEAK_PLUGIN
78072 +# define __user __attribute__((user))
78073 +# else
78074 +# define __user
78075 +# endif
78076 +# define __force_user
78077 +# define __kernel
78078 +# define __force_kernel
78079 +# endif
78080 # define __safe
78081 # define __force
78082 # define __nocast
78083 # define __iomem
78084 +# define __force_iomem
78085 # define __chk_user_ptr(x) (void)0
78086 # define __chk_io_ptr(x) (void)0
78087 # define __builtin_warning(x, y...) (1)
78088 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
78089 # define __release(x) (void)0
78090 # define __cond_lock(x,c) (c)
78091 # define __percpu
78092 +# define __force_percpu
78093 # define __rcu
78094 +# define __force_rcu
78095 #endif
78096
78097 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
78098 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78099 # define __attribute_const__ /* unimplemented */
78100 #endif
78101
78102 +#ifndef __randomize_layout
78103 +# define __randomize_layout
78104 +#endif
78105 +
78106 +#ifndef __no_randomize_layout
78107 +# define __no_randomize_layout
78108 +#endif
78109 +
78110 +#ifndef __no_const
78111 +# define __no_const
78112 +#endif
78113 +
78114 +#ifndef __do_const
78115 +# define __do_const
78116 +#endif
78117 +
78118 +#ifndef __size_overflow
78119 +# define __size_overflow(...)
78120 +#endif
78121 +
78122 +#ifndef __intentional_overflow
78123 +# define __intentional_overflow(...)
78124 +#endif
78125 +
78126 +#ifndef __latent_entropy
78127 +# define __latent_entropy
78128 +#endif
78129 +
78130 /*
78131 * Tell gcc if a function is cold. The compiler will assume any path
78132 * directly leading to the call is unlikely.
78133 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78134 #define __cold
78135 #endif
78136
78137 +#ifndef __alloc_size
78138 +#define __alloc_size(...)
78139 +#endif
78140 +
78141 +#ifndef __bos
78142 +#define __bos(ptr, arg)
78143 +#endif
78144 +
78145 +#ifndef __bos0
78146 +#define __bos0(ptr)
78147 +#endif
78148 +
78149 +#ifndef __bos1
78150 +#define __bos1(ptr)
78151 +#endif
78152 +
78153 /* Simple shorthand for a section definition */
78154 #ifndef __section
78155 # define __section(S) __attribute__ ((__section__(#S)))
78156 @@ -369,7 +435,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78157 * use is to mediate communication between process-level code and irq/NMI
78158 * handlers, all running on the same CPU.
78159 */
78160 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
78161 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
78162 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
78163
78164 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
78165 #ifdef CONFIG_KPROBES
78166 diff --git a/include/linux/completion.h b/include/linux/completion.h
78167 index 5d5aaae..0ea9b84 100644
78168 --- a/include/linux/completion.h
78169 +++ b/include/linux/completion.h
78170 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
78171
78172 extern void wait_for_completion(struct completion *);
78173 extern void wait_for_completion_io(struct completion *);
78174 -extern int wait_for_completion_interruptible(struct completion *x);
78175 -extern int wait_for_completion_killable(struct completion *x);
78176 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
78177 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
78178 extern unsigned long wait_for_completion_timeout(struct completion *x,
78179 - unsigned long timeout);
78180 + unsigned long timeout) __intentional_overflow(-1);
78181 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
78182 - unsigned long timeout);
78183 + unsigned long timeout) __intentional_overflow(-1);
78184 extern long wait_for_completion_interruptible_timeout(
78185 - struct completion *x, unsigned long timeout);
78186 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78187 extern long wait_for_completion_killable_timeout(
78188 - struct completion *x, unsigned long timeout);
78189 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78190 extern bool try_wait_for_completion(struct completion *x);
78191 extern bool completion_done(struct completion *x);
78192
78193 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
78194 index 34025df..d94bbbc 100644
78195 --- a/include/linux/configfs.h
78196 +++ b/include/linux/configfs.h
78197 @@ -125,7 +125,7 @@ struct configfs_attribute {
78198 const char *ca_name;
78199 struct module *ca_owner;
78200 umode_t ca_mode;
78201 -};
78202 +} __do_const;
78203
78204 /*
78205 * Users often need to create attribute structures for their configurable
78206 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
78207 index 5ae5100..b809662 100644
78208 --- a/include/linux/cpufreq.h
78209 +++ b/include/linux/cpufreq.h
78210 @@ -200,6 +200,7 @@ struct global_attr {
78211 ssize_t (*store)(struct kobject *a, struct attribute *b,
78212 const char *c, size_t count);
78213 };
78214 +typedef struct global_attr __no_const global_attr_no_const;
78215
78216 #define define_one_global_ro(_name) \
78217 static struct global_attr _name = \
78218 @@ -242,7 +243,7 @@ struct cpufreq_driver {
78219 bool boost_supported;
78220 bool boost_enabled;
78221 int (*set_boost) (int state);
78222 -};
78223 +} __do_const;
78224
78225 /* flags */
78226 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
78227 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
78228 index b0238cb..db89e1e 100644
78229 --- a/include/linux/cpuidle.h
78230 +++ b/include/linux/cpuidle.h
78231 @@ -50,7 +50,8 @@ struct cpuidle_state {
78232 int index);
78233
78234 int (*enter_dead) (struct cpuidle_device *dev, int index);
78235 -};
78236 +} __do_const;
78237 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
78238
78239 /* Idle State Flags */
78240 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
78241 @@ -211,7 +212,7 @@ struct cpuidle_governor {
78242 void (*reflect) (struct cpuidle_device *dev, int index);
78243
78244 struct module *owner;
78245 -};
78246 +} __do_const;
78247
78248 #ifdef CONFIG_CPU_IDLE
78249 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
78250 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
78251 index d08e4d2..95fad61 100644
78252 --- a/include/linux/cpumask.h
78253 +++ b/include/linux/cpumask.h
78254 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78255 }
78256
78257 /* Valid inputs for n are -1 and 0. */
78258 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78259 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78260 {
78261 return n+1;
78262 }
78263
78264 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78265 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78266 {
78267 return n+1;
78268 }
78269
78270 -static inline unsigned int cpumask_next_and(int n,
78271 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
78272 const struct cpumask *srcp,
78273 const struct cpumask *andp)
78274 {
78275 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78276 *
78277 * Returns >= nr_cpu_ids if no further cpus set.
78278 */
78279 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78280 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78281 {
78282 /* -1 is a legal arg here. */
78283 if (n != -1)
78284 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78285 *
78286 * Returns >= nr_cpu_ids if no further cpus unset.
78287 */
78288 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78289 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78290 {
78291 /* -1 is a legal arg here. */
78292 if (n != -1)
78293 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78294 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
78295 }
78296
78297 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
78298 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
78299 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
78300
78301 /**
78302 diff --git a/include/linux/cred.h b/include/linux/cred.h
78303 index f61d6c8..d372d95 100644
78304 --- a/include/linux/cred.h
78305 +++ b/include/linux/cred.h
78306 @@ -35,7 +35,7 @@ struct group_info {
78307 int nblocks;
78308 kgid_t small_block[NGROUPS_SMALL];
78309 kgid_t *blocks[0];
78310 -};
78311 +} __randomize_layout;
78312
78313 /**
78314 * get_group_info - Get a reference to a group info structure
78315 @@ -136,7 +136,7 @@ struct cred {
78316 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
78317 struct group_info *group_info; /* supplementary groups for euid/fsgid */
78318 struct rcu_head rcu; /* RCU deletion hook */
78319 -};
78320 +} __randomize_layout;
78321
78322 extern void __put_cred(struct cred *);
78323 extern void exit_creds(struct task_struct *);
78324 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
78325 static inline void validate_process_creds(void)
78326 {
78327 }
78328 +static inline void validate_task_creds(struct task_struct *task)
78329 +{
78330 +}
78331 #endif
78332
78333 /**
78334 @@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
78335
78336 #define task_uid(task) (task_cred_xxx((task), uid))
78337 #define task_euid(task) (task_cred_xxx((task), euid))
78338 +#define task_securebits(task) (task_cred_xxx((task), securebits))
78339
78340 #define current_cred_xxx(xxx) \
78341 ({ \
78342 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
78343 index b92eadf..b4ecdc1 100644
78344 --- a/include/linux/crypto.h
78345 +++ b/include/linux/crypto.h
78346 @@ -373,7 +373,7 @@ struct cipher_tfm {
78347 const u8 *key, unsigned int keylen);
78348 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78349 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78350 -};
78351 +} __no_const;
78352
78353 struct hash_tfm {
78354 int (*init)(struct hash_desc *desc);
78355 @@ -394,13 +394,13 @@ struct compress_tfm {
78356 int (*cot_decompress)(struct crypto_tfm *tfm,
78357 const u8 *src, unsigned int slen,
78358 u8 *dst, unsigned int *dlen);
78359 -};
78360 +} __no_const;
78361
78362 struct rng_tfm {
78363 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
78364 unsigned int dlen);
78365 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
78366 -};
78367 +} __no_const;
78368
78369 #define crt_ablkcipher crt_u.ablkcipher
78370 #define crt_aead crt_u.aead
78371 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78372 index 653589e..4ef254a 100644
78373 --- a/include/linux/ctype.h
78374 +++ b/include/linux/ctype.h
78375 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78376 * Fast implementation of tolower() for internal usage. Do not use in your
78377 * code.
78378 */
78379 -static inline char _tolower(const char c)
78380 +static inline unsigned char _tolower(const unsigned char c)
78381 {
78382 return c | 0x20;
78383 }
78384 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78385 index 3c7ec32..4ca97cc 100644
78386 --- a/include/linux/dcache.h
78387 +++ b/include/linux/dcache.h
78388 @@ -133,7 +133,7 @@ struct dentry {
78389 } d_u;
78390 struct list_head d_subdirs; /* our children */
78391 struct hlist_node d_alias; /* inode alias list */
78392 -};
78393 +} __randomize_layout;
78394
78395 /*
78396 * dentry->d_lock spinlock nesting subclasses:
78397 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78398 index 7925bf0..d5143d2 100644
78399 --- a/include/linux/decompress/mm.h
78400 +++ b/include/linux/decompress/mm.h
78401 @@ -77,7 +77,7 @@ static void free(void *where)
78402 * warnings when not needed (indeed large_malloc / large_free are not
78403 * needed by inflate */
78404
78405 -#define malloc(a) kmalloc(a, GFP_KERNEL)
78406 +#define malloc(a) kmalloc((a), GFP_KERNEL)
78407 #define free(a) kfree(a)
78408
78409 #define large_malloc(a) vmalloc(a)
78410 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78411 index d48dc00..211ee54 100644
78412 --- a/include/linux/devfreq.h
78413 +++ b/include/linux/devfreq.h
78414 @@ -114,7 +114,7 @@ struct devfreq_governor {
78415 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78416 int (*event_handler)(struct devfreq *devfreq,
78417 unsigned int event, void *data);
78418 -};
78419 +} __do_const;
78420
78421 /**
78422 * struct devfreq - Device devfreq structure
78423 diff --git a/include/linux/device.h b/include/linux/device.h
78424 index d1d1c05..a90fdb0 100644
78425 --- a/include/linux/device.h
78426 +++ b/include/linux/device.h
78427 @@ -310,7 +310,7 @@ struct subsys_interface {
78428 struct list_head node;
78429 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78430 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78431 -};
78432 +} __do_const;
78433
78434 int subsys_interface_register(struct subsys_interface *sif);
78435 void subsys_interface_unregister(struct subsys_interface *sif);
78436 @@ -506,7 +506,7 @@ struct device_type {
78437 void (*release)(struct device *dev);
78438
78439 const struct dev_pm_ops *pm;
78440 -};
78441 +} __do_const;
78442
78443 /* interface for exporting device attributes */
78444 struct device_attribute {
78445 @@ -516,11 +516,12 @@ struct device_attribute {
78446 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78447 const char *buf, size_t count);
78448 };
78449 +typedef struct device_attribute __no_const device_attribute_no_const;
78450
78451 struct dev_ext_attribute {
78452 struct device_attribute attr;
78453 void *var;
78454 -};
78455 +} __do_const;
78456
78457 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78458 char *buf);
78459 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78460 index fd4aee2..1f28db9 100644
78461 --- a/include/linux/dma-mapping.h
78462 +++ b/include/linux/dma-mapping.h
78463 @@ -54,7 +54,7 @@ struct dma_map_ops {
78464 u64 (*get_required_mask)(struct device *dev);
78465 #endif
78466 int is_phys;
78467 -};
78468 +} __do_const;
78469
78470 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78471
78472 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78473 index 72cb0dd..7fe9a4b 100644
78474 --- a/include/linux/dmaengine.h
78475 +++ b/include/linux/dmaengine.h
78476 @@ -1147,9 +1147,9 @@ struct dma_pinned_list {
78477 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78478 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78479
78480 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78481 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78482 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78483 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78484 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78485 struct dma_pinned_list *pinned_list, struct page *page,
78486 unsigned int offset, size_t len);
78487
78488 diff --git a/include/linux/efi.h b/include/linux/efi.h
78489 index 6c100ff..e3289b4 100644
78490 --- a/include/linux/efi.h
78491 +++ b/include/linux/efi.h
78492 @@ -1009,6 +1009,7 @@ struct efivar_operations {
78493 efi_set_variable_t *set_variable;
78494 efi_query_variable_store_t *query_variable_store;
78495 };
78496 +typedef struct efivar_operations __no_const efivar_operations_no_const;
78497
78498 struct efivars {
78499 /*
78500 diff --git a/include/linux/elf.h b/include/linux/elf.h
78501 index 67a5fa7..b817372 100644
78502 --- a/include/linux/elf.h
78503 +++ b/include/linux/elf.h
78504 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78505 #define elf_note elf32_note
78506 #define elf_addr_t Elf32_Off
78507 #define Elf_Half Elf32_Half
78508 +#define elf_dyn Elf32_Dyn
78509
78510 #else
78511
78512 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78513 #define elf_note elf64_note
78514 #define elf_addr_t Elf64_Off
78515 #define Elf_Half Elf64_Half
78516 +#define elf_dyn Elf64_Dyn
78517
78518 #endif
78519
78520 diff --git a/include/linux/err.h b/include/linux/err.h
78521 index a729120..6ede2c9 100644
78522 --- a/include/linux/err.h
78523 +++ b/include/linux/err.h
78524 @@ -20,12 +20,12 @@
78525
78526 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78527
78528 -static inline void * __must_check ERR_PTR(long error)
78529 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78530 {
78531 return (void *) error;
78532 }
78533
78534 -static inline long __must_check PTR_ERR(__force const void *ptr)
78535 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78536 {
78537 return (long) ptr;
78538 }
78539 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78540 index f488145..3b6b04e 100644
78541 --- a/include/linux/extcon.h
78542 +++ b/include/linux/extcon.h
78543 @@ -135,7 +135,7 @@ struct extcon_dev {
78544 /* /sys/class/extcon/.../mutually_exclusive/... */
78545 struct attribute_group attr_g_muex;
78546 struct attribute **attrs_muex;
78547 - struct device_attribute *d_attrs_muex;
78548 + device_attribute_no_const *d_attrs_muex;
78549 };
78550
78551 /**
78552 diff --git a/include/linux/fb.h b/include/linux/fb.h
78553 index fe6ac95..898d41d 100644
78554 --- a/include/linux/fb.h
78555 +++ b/include/linux/fb.h
78556 @@ -304,7 +304,7 @@ struct fb_ops {
78557 /* called at KDB enter and leave time to prepare the console */
78558 int (*fb_debug_enter)(struct fb_info *info);
78559 int (*fb_debug_leave)(struct fb_info *info);
78560 -};
78561 +} __do_const;
78562
78563 #ifdef CONFIG_FB_TILEBLITTING
78564 #define FB_TILE_CURSOR_NONE 0
78565 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78566 index 230f87b..1fd0485 100644
78567 --- a/include/linux/fdtable.h
78568 +++ b/include/linux/fdtable.h
78569 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78570 void put_files_struct(struct files_struct *fs);
78571 void reset_files_struct(struct files_struct *);
78572 int unshare_files(struct files_struct **);
78573 -struct files_struct *dup_fd(struct files_struct *, int *);
78574 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78575 void do_close_on_exec(struct files_struct *);
78576 int iterate_fd(struct files_struct *, unsigned,
78577 int (*)(const void *, struct file *, unsigned),
78578 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78579 index 8293262..2b3b8bd 100644
78580 --- a/include/linux/frontswap.h
78581 +++ b/include/linux/frontswap.h
78582 @@ -11,7 +11,7 @@ struct frontswap_ops {
78583 int (*load)(unsigned, pgoff_t, struct page *);
78584 void (*invalidate_page)(unsigned, pgoff_t);
78585 void (*invalidate_area)(unsigned);
78586 -};
78587 +} __no_const;
78588
78589 extern bool frontswap_enabled;
78590 extern struct frontswap_ops *
78591 diff --git a/include/linux/fs.h b/include/linux/fs.h
78592 index 8780312..425cc22 100644
78593 --- a/include/linux/fs.h
78594 +++ b/include/linux/fs.h
78595 @@ -398,7 +398,7 @@ struct address_space {
78596 spinlock_t private_lock; /* for use by the address_space */
78597 struct list_head private_list; /* ditto */
78598 void *private_data; /* ditto */
78599 -} __attribute__((aligned(sizeof(long))));
78600 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78601 /*
78602 * On most architectures that alignment is already the case; but
78603 * must be enforced here for CRIS, to let the least significant bit
78604 @@ -441,7 +441,7 @@ struct block_device {
78605 int bd_fsfreeze_count;
78606 /* Mutex for freeze */
78607 struct mutex bd_fsfreeze_mutex;
78608 -};
78609 +} __randomize_layout;
78610
78611 /*
78612 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78613 @@ -585,7 +585,7 @@ struct inode {
78614 #endif
78615
78616 void *i_private; /* fs or device private pointer */
78617 -};
78618 +} __randomize_layout;
78619
78620 static inline int inode_unhashed(struct inode *inode)
78621 {
78622 @@ -778,7 +778,7 @@ struct file {
78623 struct list_head f_tfile_llink;
78624 #endif /* #ifdef CONFIG_EPOLL */
78625 struct address_space *f_mapping;
78626 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78627 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78628
78629 struct file_handle {
78630 __u32 handle_bytes;
78631 @@ -906,7 +906,7 @@ struct file_lock {
78632 int state; /* state of grant or error if -ve */
78633 } afs;
78634 } fl_u;
78635 -};
78636 +} __randomize_layout;
78637
78638 /* The following constant reflects the upper bound of the file/locking space */
78639 #ifndef OFFSET_MAX
78640 @@ -1255,7 +1255,7 @@ struct super_block {
78641 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78642 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78643 struct rcu_head rcu;
78644 -};
78645 +} __randomize_layout;
78646
78647 extern struct timespec current_fs_time(struct super_block *sb);
78648
78649 @@ -1477,7 +1477,8 @@ struct file_operations {
78650 long (*fallocate)(struct file *file, int mode, loff_t offset,
78651 loff_t len);
78652 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78653 -};
78654 +} __do_const __randomize_layout;
78655 +typedef struct file_operations __no_const file_operations_no_const;
78656
78657 struct inode_operations {
78658 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78659 @@ -2757,4 +2758,14 @@ static inline bool dir_relax(struct inode *inode)
78660 return !IS_DEADDIR(inode);
78661 }
78662
78663 +static inline bool is_sidechannel_device(const struct inode *inode)
78664 +{
78665 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78666 + umode_t mode = inode->i_mode;
78667 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78668 +#else
78669 + return false;
78670 +#endif
78671 +}
78672 +
78673 #endif /* _LINUX_FS_H */
78674 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78675 index 0efc3e6..fd23610 100644
78676 --- a/include/linux/fs_struct.h
78677 +++ b/include/linux/fs_struct.h
78678 @@ -6,13 +6,13 @@
78679 #include <linux/seqlock.h>
78680
78681 struct fs_struct {
78682 - int users;
78683 + atomic_t users;
78684 spinlock_t lock;
78685 seqcount_t seq;
78686 int umask;
78687 int in_exec;
78688 struct path root, pwd;
78689 -};
78690 +} __randomize_layout;
78691
78692 extern struct kmem_cache *fs_cachep;
78693
78694 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78695 index 7714849..a4a5c7a 100644
78696 --- a/include/linux/fscache-cache.h
78697 +++ b/include/linux/fscache-cache.h
78698 @@ -113,7 +113,7 @@ struct fscache_operation {
78699 fscache_operation_release_t release;
78700 };
78701
78702 -extern atomic_t fscache_op_debug_id;
78703 +extern atomic_unchecked_t fscache_op_debug_id;
78704 extern void fscache_op_work_func(struct work_struct *work);
78705
78706 extern void fscache_enqueue_operation(struct fscache_operation *);
78707 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78708 INIT_WORK(&op->work, fscache_op_work_func);
78709 atomic_set(&op->usage, 1);
78710 op->state = FSCACHE_OP_ST_INITIALISED;
78711 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78712 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78713 op->processor = processor;
78714 op->release = release;
78715 INIT_LIST_HEAD(&op->pend_link);
78716 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78717 index 115bb81..e7b812b 100644
78718 --- a/include/linux/fscache.h
78719 +++ b/include/linux/fscache.h
78720 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
78721 * - this is mandatory for any object that may have data
78722 */
78723 void (*now_uncached)(void *cookie_netfs_data);
78724 -};
78725 +} __do_const;
78726
78727 /*
78728 * fscache cached network filesystem type
78729 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78730 index 1c804b0..1432c2b 100644
78731 --- a/include/linux/fsnotify.h
78732 +++ b/include/linux/fsnotify.h
78733 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78734 struct inode *inode = file_inode(file);
78735 __u32 mask = FS_ACCESS;
78736
78737 + if (is_sidechannel_device(inode))
78738 + return;
78739 +
78740 if (S_ISDIR(inode->i_mode))
78741 mask |= FS_ISDIR;
78742
78743 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78744 struct inode *inode = file_inode(file);
78745 __u32 mask = FS_MODIFY;
78746
78747 + if (is_sidechannel_device(inode))
78748 + return;
78749 +
78750 if (S_ISDIR(inode->i_mode))
78751 mask |= FS_ISDIR;
78752
78753 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78754 */
78755 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78756 {
78757 - return kstrdup(name, GFP_KERNEL);
78758 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78759 }
78760
78761 /*
78762 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78763 index 9f3c275..8bdff5d 100644
78764 --- a/include/linux/genhd.h
78765 +++ b/include/linux/genhd.h
78766 @@ -194,7 +194,7 @@ struct gendisk {
78767 struct kobject *slave_dir;
78768
78769 struct timer_rand_state *random;
78770 - atomic_t sync_io; /* RAID */
78771 + atomic_unchecked_t sync_io; /* RAID */
78772 struct disk_events *ev;
78773 #ifdef CONFIG_BLK_DEV_INTEGRITY
78774 struct blk_integrity *integrity;
78775 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78776 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78777
78778 /* drivers/char/random.c */
78779 -extern void add_disk_randomness(struct gendisk *disk);
78780 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78781 extern void rand_initialize_disk(struct gendisk *disk);
78782
78783 static inline sector_t get_start_sect(struct block_device *bdev)
78784 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78785 index c0894dd..2fbf10c 100644
78786 --- a/include/linux/genl_magic_func.h
78787 +++ b/include/linux/genl_magic_func.h
78788 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78789 },
78790
78791 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78792 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78793 +static struct genl_ops ZZZ_genl_ops[] = {
78794 #include GENL_MAGIC_INCLUDE_FILE
78795 };
78796
78797 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78798 index 39b81dc..819dc51 100644
78799 --- a/include/linux/gfp.h
78800 +++ b/include/linux/gfp.h
78801 @@ -36,6 +36,13 @@ struct vm_area_struct;
78802 #define ___GFP_NO_KSWAPD 0x400000u
78803 #define ___GFP_OTHER_NODE 0x800000u
78804 #define ___GFP_WRITE 0x1000000u
78805 +
78806 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78807 +#define ___GFP_USERCOPY 0x2000000u
78808 +#else
78809 +#define ___GFP_USERCOPY 0
78810 +#endif
78811 +
78812 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78813
78814 /*
78815 @@ -93,6 +100,7 @@ struct vm_area_struct;
78816 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78817 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78818 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78819 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78820
78821 /*
78822 * This may seem redundant, but it's a way of annotating false positives vs.
78823 @@ -100,7 +108,7 @@ struct vm_area_struct;
78824 */
78825 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78826
78827 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78828 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78829 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78830
78831 /* This equals 0, but use constants in case they ever change */
78832 @@ -158,6 +166,8 @@ struct vm_area_struct;
78833 /* 4GB DMA on some platforms */
78834 #define GFP_DMA32 __GFP_DMA32
78835
78836 +#define GFP_USERCOPY __GFP_USERCOPY
78837 +
78838 /* Convert GFP flags to their corresponding migrate type */
78839 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78840 {
78841 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78842 new file mode 100644
78843 index 0000000..edb2cb6
78844 --- /dev/null
78845 +++ b/include/linux/gracl.h
78846 @@ -0,0 +1,340 @@
78847 +#ifndef GR_ACL_H
78848 +#define GR_ACL_H
78849 +
78850 +#include <linux/grdefs.h>
78851 +#include <linux/resource.h>
78852 +#include <linux/capability.h>
78853 +#include <linux/dcache.h>
78854 +#include <asm/resource.h>
78855 +
78856 +/* Major status information */
78857 +
78858 +#define GR_VERSION "grsecurity 3.0"
78859 +#define GRSECURITY_VERSION 0x3000
78860 +
78861 +enum {
78862 + GR_SHUTDOWN = 0,
78863 + GR_ENABLE = 1,
78864 + GR_SPROLE = 2,
78865 + GR_OLDRELOAD = 3,
78866 + GR_SEGVMOD = 4,
78867 + GR_STATUS = 5,
78868 + GR_UNSPROLE = 6,
78869 + GR_PASSSET = 7,
78870 + GR_SPROLEPAM = 8,
78871 + GR_RELOAD = 9,
78872 +};
78873 +
78874 +/* Password setup definitions
78875 + * kernel/grhash.c */
78876 +enum {
78877 + GR_PW_LEN = 128,
78878 + GR_SALT_LEN = 16,
78879 + GR_SHA_LEN = 32,
78880 +};
78881 +
78882 +enum {
78883 + GR_SPROLE_LEN = 64,
78884 +};
78885 +
78886 +enum {
78887 + GR_NO_GLOB = 0,
78888 + GR_REG_GLOB,
78889 + GR_CREATE_GLOB
78890 +};
78891 +
78892 +#define GR_NLIMITS 32
78893 +
78894 +/* Begin Data Structures */
78895 +
78896 +struct sprole_pw {
78897 + unsigned char *rolename;
78898 + unsigned char salt[GR_SALT_LEN];
78899 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78900 +};
78901 +
78902 +struct name_entry {
78903 + __u32 key;
78904 + ino_t inode;
78905 + dev_t device;
78906 + char *name;
78907 + __u16 len;
78908 + __u8 deleted;
78909 + struct name_entry *prev;
78910 + struct name_entry *next;
78911 +};
78912 +
78913 +struct inodev_entry {
78914 + struct name_entry *nentry;
78915 + struct inodev_entry *prev;
78916 + struct inodev_entry *next;
78917 +};
78918 +
78919 +struct acl_role_db {
78920 + struct acl_role_label **r_hash;
78921 + __u32 r_size;
78922 +};
78923 +
78924 +struct inodev_db {
78925 + struct inodev_entry **i_hash;
78926 + __u32 i_size;
78927 +};
78928 +
78929 +struct name_db {
78930 + struct name_entry **n_hash;
78931 + __u32 n_size;
78932 +};
78933 +
78934 +struct crash_uid {
78935 + uid_t uid;
78936 + unsigned long expires;
78937 +};
78938 +
78939 +struct gr_hash_struct {
78940 + void **table;
78941 + void **nametable;
78942 + void *first;
78943 + __u32 table_size;
78944 + __u32 used_size;
78945 + int type;
78946 +};
78947 +
78948 +/* Userspace Grsecurity ACL data structures */
78949 +
78950 +struct acl_subject_label {
78951 + char *filename;
78952 + ino_t inode;
78953 + dev_t device;
78954 + __u32 mode;
78955 + kernel_cap_t cap_mask;
78956 + kernel_cap_t cap_lower;
78957 + kernel_cap_t cap_invert_audit;
78958 +
78959 + struct rlimit res[GR_NLIMITS];
78960 + __u32 resmask;
78961 +
78962 + __u8 user_trans_type;
78963 + __u8 group_trans_type;
78964 + uid_t *user_transitions;
78965 + gid_t *group_transitions;
78966 + __u16 user_trans_num;
78967 + __u16 group_trans_num;
78968 +
78969 + __u32 sock_families[2];
78970 + __u32 ip_proto[8];
78971 + __u32 ip_type;
78972 + struct acl_ip_label **ips;
78973 + __u32 ip_num;
78974 + __u32 inaddr_any_override;
78975 +
78976 + __u32 crashes;
78977 + unsigned long expires;
78978 +
78979 + struct acl_subject_label *parent_subject;
78980 + struct gr_hash_struct *hash;
78981 + struct acl_subject_label *prev;
78982 + struct acl_subject_label *next;
78983 +
78984 + struct acl_object_label **obj_hash;
78985 + __u32 obj_hash_size;
78986 + __u16 pax_flags;
78987 +};
78988 +
78989 +struct role_allowed_ip {
78990 + __u32 addr;
78991 + __u32 netmask;
78992 +
78993 + struct role_allowed_ip *prev;
78994 + struct role_allowed_ip *next;
78995 +};
78996 +
78997 +struct role_transition {
78998 + char *rolename;
78999 +
79000 + struct role_transition *prev;
79001 + struct role_transition *next;
79002 +};
79003 +
79004 +struct acl_role_label {
79005 + char *rolename;
79006 + uid_t uidgid;
79007 + __u16 roletype;
79008 +
79009 + __u16 auth_attempts;
79010 + unsigned long expires;
79011 +
79012 + struct acl_subject_label *root_label;
79013 + struct gr_hash_struct *hash;
79014 +
79015 + struct acl_role_label *prev;
79016 + struct acl_role_label *next;
79017 +
79018 + struct role_transition *transitions;
79019 + struct role_allowed_ip *allowed_ips;
79020 + uid_t *domain_children;
79021 + __u16 domain_child_num;
79022 +
79023 + umode_t umask;
79024 +
79025 + struct acl_subject_label **subj_hash;
79026 + __u32 subj_hash_size;
79027 +};
79028 +
79029 +struct user_acl_role_db {
79030 + struct acl_role_label **r_table;
79031 + __u32 num_pointers; /* Number of allocations to track */
79032 + __u32 num_roles; /* Number of roles */
79033 + __u32 num_domain_children; /* Number of domain children */
79034 + __u32 num_subjects; /* Number of subjects */
79035 + __u32 num_objects; /* Number of objects */
79036 +};
79037 +
79038 +struct acl_object_label {
79039 + char *filename;
79040 + ino_t inode;
79041 + dev_t device;
79042 + __u32 mode;
79043 +
79044 + struct acl_subject_label *nested;
79045 + struct acl_object_label *globbed;
79046 +
79047 + /* next two structures not used */
79048 +
79049 + struct acl_object_label *prev;
79050 + struct acl_object_label *next;
79051 +};
79052 +
79053 +struct acl_ip_label {
79054 + char *iface;
79055 + __u32 addr;
79056 + __u32 netmask;
79057 + __u16 low, high;
79058 + __u8 mode;
79059 + __u32 type;
79060 + __u32 proto[8];
79061 +
79062 + /* next two structures not used */
79063 +
79064 + struct acl_ip_label *prev;
79065 + struct acl_ip_label *next;
79066 +};
79067 +
79068 +struct gr_arg {
79069 + struct user_acl_role_db role_db;
79070 + unsigned char pw[GR_PW_LEN];
79071 + unsigned char salt[GR_SALT_LEN];
79072 + unsigned char sum[GR_SHA_LEN];
79073 + unsigned char sp_role[GR_SPROLE_LEN];
79074 + struct sprole_pw *sprole_pws;
79075 + dev_t segv_device;
79076 + ino_t segv_inode;
79077 + uid_t segv_uid;
79078 + __u16 num_sprole_pws;
79079 + __u16 mode;
79080 +};
79081 +
79082 +struct gr_arg_wrapper {
79083 + struct gr_arg *arg;
79084 + __u32 version;
79085 + __u32 size;
79086 +};
79087 +
79088 +struct subject_map {
79089 + struct acl_subject_label *user;
79090 + struct acl_subject_label *kernel;
79091 + struct subject_map *prev;
79092 + struct subject_map *next;
79093 +};
79094 +
79095 +struct acl_subj_map_db {
79096 + struct subject_map **s_hash;
79097 + __u32 s_size;
79098 +};
79099 +
79100 +struct gr_policy_state {
79101 + struct sprole_pw **acl_special_roles;
79102 + __u16 num_sprole_pws;
79103 + struct acl_role_label *kernel_role;
79104 + struct acl_role_label *role_list;
79105 + struct acl_role_label *default_role;
79106 + struct acl_role_db acl_role_set;
79107 + struct acl_subj_map_db subj_map_set;
79108 + struct name_db name_set;
79109 + struct inodev_db inodev_set;
79110 +};
79111 +
79112 +struct gr_alloc_state {
79113 + unsigned long alloc_stack_next;
79114 + unsigned long alloc_stack_size;
79115 + void **alloc_stack;
79116 +};
79117 +
79118 +struct gr_reload_state {
79119 + struct gr_policy_state oldpolicy;
79120 + struct gr_alloc_state oldalloc;
79121 + struct gr_policy_state newpolicy;
79122 + struct gr_alloc_state newalloc;
79123 + struct gr_policy_state *oldpolicy_ptr;
79124 + struct gr_alloc_state *oldalloc_ptr;
79125 + unsigned char oldmode;
79126 +};
79127 +
79128 +/* End Data Structures Section */
79129 +
79130 +/* Hash functions generated by empirical testing by Brad Spengler
79131 + Makes good use of the low bits of the inode. Generally 0-1 times
79132 + in loop for successful match. 0-3 for unsuccessful match.
79133 + Shift/add algorithm with modulus of table size and an XOR*/
79134 +
79135 +static __inline__ unsigned int
79136 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
79137 +{
79138 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
79139 +}
79140 +
79141 + static __inline__ unsigned int
79142 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
79143 +{
79144 + return ((const unsigned long)userp % sz);
79145 +}
79146 +
79147 +static __inline__ unsigned int
79148 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
79149 +{
79150 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
79151 +}
79152 +
79153 +static __inline__ unsigned int
79154 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
79155 +{
79156 + return full_name_hash((const unsigned char *)name, len) % sz;
79157 +}
79158 +
79159 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
79160 + subj = NULL; \
79161 + iter = 0; \
79162 + while (iter < role->subj_hash_size) { \
79163 + if (subj == NULL) \
79164 + subj = role->subj_hash[iter]; \
79165 + if (subj == NULL) { \
79166 + iter++; \
79167 + continue; \
79168 + }
79169 +
79170 +#define FOR_EACH_SUBJECT_END(subj,iter) \
79171 + subj = subj->next; \
79172 + if (subj == NULL) \
79173 + iter++; \
79174 + }
79175 +
79176 +
79177 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
79178 + subj = role->hash->first; \
79179 + while (subj != NULL) {
79180 +
79181 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
79182 + subj = subj->next; \
79183 + }
79184 +
79185 +#endif
79186 +
79187 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
79188 new file mode 100644
79189 index 0000000..33ebd1f
79190 --- /dev/null
79191 +++ b/include/linux/gracl_compat.h
79192 @@ -0,0 +1,156 @@
79193 +#ifndef GR_ACL_COMPAT_H
79194 +#define GR_ACL_COMPAT_H
79195 +
79196 +#include <linux/resource.h>
79197 +#include <asm/resource.h>
79198 +
79199 +struct sprole_pw_compat {
79200 + compat_uptr_t rolename;
79201 + unsigned char salt[GR_SALT_LEN];
79202 + unsigned char sum[GR_SHA_LEN];
79203 +};
79204 +
79205 +struct gr_hash_struct_compat {
79206 + compat_uptr_t table;
79207 + compat_uptr_t nametable;
79208 + compat_uptr_t first;
79209 + __u32 table_size;
79210 + __u32 used_size;
79211 + int type;
79212 +};
79213 +
79214 +struct acl_subject_label_compat {
79215 + compat_uptr_t filename;
79216 + compat_ino_t inode;
79217 + __u32 device;
79218 + __u32 mode;
79219 + kernel_cap_t cap_mask;
79220 + kernel_cap_t cap_lower;
79221 + kernel_cap_t cap_invert_audit;
79222 +
79223 + struct compat_rlimit res[GR_NLIMITS];
79224 + __u32 resmask;
79225 +
79226 + __u8 user_trans_type;
79227 + __u8 group_trans_type;
79228 + compat_uptr_t user_transitions;
79229 + compat_uptr_t group_transitions;
79230 + __u16 user_trans_num;
79231 + __u16 group_trans_num;
79232 +
79233 + __u32 sock_families[2];
79234 + __u32 ip_proto[8];
79235 + __u32 ip_type;
79236 + compat_uptr_t ips;
79237 + __u32 ip_num;
79238 + __u32 inaddr_any_override;
79239 +
79240 + __u32 crashes;
79241 + compat_ulong_t expires;
79242 +
79243 + compat_uptr_t parent_subject;
79244 + compat_uptr_t hash;
79245 + compat_uptr_t prev;
79246 + compat_uptr_t next;
79247 +
79248 + compat_uptr_t obj_hash;
79249 + __u32 obj_hash_size;
79250 + __u16 pax_flags;
79251 +};
79252 +
79253 +struct role_allowed_ip_compat {
79254 + __u32 addr;
79255 + __u32 netmask;
79256 +
79257 + compat_uptr_t prev;
79258 + compat_uptr_t next;
79259 +};
79260 +
79261 +struct role_transition_compat {
79262 + compat_uptr_t rolename;
79263 +
79264 + compat_uptr_t prev;
79265 + compat_uptr_t next;
79266 +};
79267 +
79268 +struct acl_role_label_compat {
79269 + compat_uptr_t rolename;
79270 + uid_t uidgid;
79271 + __u16 roletype;
79272 +
79273 + __u16 auth_attempts;
79274 + compat_ulong_t expires;
79275 +
79276 + compat_uptr_t root_label;
79277 + compat_uptr_t hash;
79278 +
79279 + compat_uptr_t prev;
79280 + compat_uptr_t next;
79281 +
79282 + compat_uptr_t transitions;
79283 + compat_uptr_t allowed_ips;
79284 + compat_uptr_t domain_children;
79285 + __u16 domain_child_num;
79286 +
79287 + umode_t umask;
79288 +
79289 + compat_uptr_t subj_hash;
79290 + __u32 subj_hash_size;
79291 +};
79292 +
79293 +struct user_acl_role_db_compat {
79294 + compat_uptr_t r_table;
79295 + __u32 num_pointers;
79296 + __u32 num_roles;
79297 + __u32 num_domain_children;
79298 + __u32 num_subjects;
79299 + __u32 num_objects;
79300 +};
79301 +
79302 +struct acl_object_label_compat {
79303 + compat_uptr_t filename;
79304 + compat_ino_t inode;
79305 + __u32 device;
79306 + __u32 mode;
79307 +
79308 + compat_uptr_t nested;
79309 + compat_uptr_t globbed;
79310 +
79311 + compat_uptr_t prev;
79312 + compat_uptr_t next;
79313 +};
79314 +
79315 +struct acl_ip_label_compat {
79316 + compat_uptr_t iface;
79317 + __u32 addr;
79318 + __u32 netmask;
79319 + __u16 low, high;
79320 + __u8 mode;
79321 + __u32 type;
79322 + __u32 proto[8];
79323 +
79324 + compat_uptr_t prev;
79325 + compat_uptr_t next;
79326 +};
79327 +
79328 +struct gr_arg_compat {
79329 + struct user_acl_role_db_compat role_db;
79330 + unsigned char pw[GR_PW_LEN];
79331 + unsigned char salt[GR_SALT_LEN];
79332 + unsigned char sum[GR_SHA_LEN];
79333 + unsigned char sp_role[GR_SPROLE_LEN];
79334 + compat_uptr_t sprole_pws;
79335 + __u32 segv_device;
79336 + compat_ino_t segv_inode;
79337 + uid_t segv_uid;
79338 + __u16 num_sprole_pws;
79339 + __u16 mode;
79340 +};
79341 +
79342 +struct gr_arg_wrapper_compat {
79343 + compat_uptr_t arg;
79344 + __u32 version;
79345 + __u32 size;
79346 +};
79347 +
79348 +#endif
79349 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
79350 new file mode 100644
79351 index 0000000..323ecf2
79352 --- /dev/null
79353 +++ b/include/linux/gralloc.h
79354 @@ -0,0 +1,9 @@
79355 +#ifndef __GRALLOC_H
79356 +#define __GRALLOC_H
79357 +
79358 +void acl_free_all(void);
79359 +int acl_alloc_stack_init(unsigned long size);
79360 +void *acl_alloc(unsigned long len);
79361 +void *acl_alloc_num(unsigned long num, unsigned long len);
79362 +
79363 +#endif
79364 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
79365 new file mode 100644
79366 index 0000000..be66033
79367 --- /dev/null
79368 +++ b/include/linux/grdefs.h
79369 @@ -0,0 +1,140 @@
79370 +#ifndef GRDEFS_H
79371 +#define GRDEFS_H
79372 +
79373 +/* Begin grsecurity status declarations */
79374 +
79375 +enum {
79376 + GR_READY = 0x01,
79377 + GR_STATUS_INIT = 0x00 // disabled state
79378 +};
79379 +
79380 +/* Begin ACL declarations */
79381 +
79382 +/* Role flags */
79383 +
79384 +enum {
79385 + GR_ROLE_USER = 0x0001,
79386 + GR_ROLE_GROUP = 0x0002,
79387 + GR_ROLE_DEFAULT = 0x0004,
79388 + GR_ROLE_SPECIAL = 0x0008,
79389 + GR_ROLE_AUTH = 0x0010,
79390 + GR_ROLE_NOPW = 0x0020,
79391 + GR_ROLE_GOD = 0x0040,
79392 + GR_ROLE_LEARN = 0x0080,
79393 + GR_ROLE_TPE = 0x0100,
79394 + GR_ROLE_DOMAIN = 0x0200,
79395 + GR_ROLE_PAM = 0x0400,
79396 + GR_ROLE_PERSIST = 0x0800
79397 +};
79398 +
79399 +/* ACL Subject and Object mode flags */
79400 +enum {
79401 + GR_DELETED = 0x80000000
79402 +};
79403 +
79404 +/* ACL Object-only mode flags */
79405 +enum {
79406 + GR_READ = 0x00000001,
79407 + GR_APPEND = 0x00000002,
79408 + GR_WRITE = 0x00000004,
79409 + GR_EXEC = 0x00000008,
79410 + GR_FIND = 0x00000010,
79411 + GR_INHERIT = 0x00000020,
79412 + GR_SETID = 0x00000040,
79413 + GR_CREATE = 0x00000080,
79414 + GR_DELETE = 0x00000100,
79415 + GR_LINK = 0x00000200,
79416 + GR_AUDIT_READ = 0x00000400,
79417 + GR_AUDIT_APPEND = 0x00000800,
79418 + GR_AUDIT_WRITE = 0x00001000,
79419 + GR_AUDIT_EXEC = 0x00002000,
79420 + GR_AUDIT_FIND = 0x00004000,
79421 + GR_AUDIT_INHERIT= 0x00008000,
79422 + GR_AUDIT_SETID = 0x00010000,
79423 + GR_AUDIT_CREATE = 0x00020000,
79424 + GR_AUDIT_DELETE = 0x00040000,
79425 + GR_AUDIT_LINK = 0x00080000,
79426 + GR_PTRACERD = 0x00100000,
79427 + GR_NOPTRACE = 0x00200000,
79428 + GR_SUPPRESS = 0x00400000,
79429 + GR_NOLEARN = 0x00800000,
79430 + GR_INIT_TRANSFER= 0x01000000
79431 +};
79432 +
79433 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79434 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79435 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79436 +
79437 +/* ACL subject-only mode flags */
79438 +enum {
79439 + GR_KILL = 0x00000001,
79440 + GR_VIEW = 0x00000002,
79441 + GR_PROTECTED = 0x00000004,
79442 + GR_LEARN = 0x00000008,
79443 + GR_OVERRIDE = 0x00000010,
79444 + /* just a placeholder, this mode is only used in userspace */
79445 + GR_DUMMY = 0x00000020,
79446 + GR_PROTSHM = 0x00000040,
79447 + GR_KILLPROC = 0x00000080,
79448 + GR_KILLIPPROC = 0x00000100,
79449 + /* just a placeholder, this mode is only used in userspace */
79450 + GR_NOTROJAN = 0x00000200,
79451 + GR_PROTPROCFD = 0x00000400,
79452 + GR_PROCACCT = 0x00000800,
79453 + GR_RELAXPTRACE = 0x00001000,
79454 + //GR_NESTED = 0x00002000,
79455 + GR_INHERITLEARN = 0x00004000,
79456 + GR_PROCFIND = 0x00008000,
79457 + GR_POVERRIDE = 0x00010000,
79458 + GR_KERNELAUTH = 0x00020000,
79459 + GR_ATSECURE = 0x00040000,
79460 + GR_SHMEXEC = 0x00080000
79461 +};
79462 +
79463 +enum {
79464 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79465 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79466 + GR_PAX_ENABLE_MPROTECT = 0x0004,
79467 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
79468 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79469 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79470 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79471 + GR_PAX_DISABLE_MPROTECT = 0x0400,
79472 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
79473 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79474 +};
79475 +
79476 +enum {
79477 + GR_ID_USER = 0x01,
79478 + GR_ID_GROUP = 0x02,
79479 +};
79480 +
79481 +enum {
79482 + GR_ID_ALLOW = 0x01,
79483 + GR_ID_DENY = 0x02,
79484 +};
79485 +
79486 +#define GR_CRASH_RES 31
79487 +#define GR_UIDTABLE_MAX 500
79488 +
79489 +/* begin resource learning section */
79490 +enum {
79491 + GR_RLIM_CPU_BUMP = 60,
79492 + GR_RLIM_FSIZE_BUMP = 50000,
79493 + GR_RLIM_DATA_BUMP = 10000,
79494 + GR_RLIM_STACK_BUMP = 1000,
79495 + GR_RLIM_CORE_BUMP = 10000,
79496 + GR_RLIM_RSS_BUMP = 500000,
79497 + GR_RLIM_NPROC_BUMP = 1,
79498 + GR_RLIM_NOFILE_BUMP = 5,
79499 + GR_RLIM_MEMLOCK_BUMP = 50000,
79500 + GR_RLIM_AS_BUMP = 500000,
79501 + GR_RLIM_LOCKS_BUMP = 2,
79502 + GR_RLIM_SIGPENDING_BUMP = 5,
79503 + GR_RLIM_MSGQUEUE_BUMP = 10000,
79504 + GR_RLIM_NICE_BUMP = 1,
79505 + GR_RLIM_RTPRIO_BUMP = 1,
79506 + GR_RLIM_RTTIME_BUMP = 1000000
79507 +};
79508 +
79509 +#endif
79510 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79511 new file mode 100644
79512 index 0000000..d25522e
79513 --- /dev/null
79514 +++ b/include/linux/grinternal.h
79515 @@ -0,0 +1,229 @@
79516 +#ifndef __GRINTERNAL_H
79517 +#define __GRINTERNAL_H
79518 +
79519 +#ifdef CONFIG_GRKERNSEC
79520 +
79521 +#include <linux/fs.h>
79522 +#include <linux/mnt_namespace.h>
79523 +#include <linux/nsproxy.h>
79524 +#include <linux/gracl.h>
79525 +#include <linux/grdefs.h>
79526 +#include <linux/grmsg.h>
79527 +
79528 +void gr_add_learn_entry(const char *fmt, ...)
79529 + __attribute__ ((format (printf, 1, 2)));
79530 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79531 + const struct vfsmount *mnt);
79532 +__u32 gr_check_create(const struct dentry *new_dentry,
79533 + const struct dentry *parent,
79534 + const struct vfsmount *mnt, const __u32 mode);
79535 +int gr_check_protected_task(const struct task_struct *task);
79536 +__u32 to_gr_audit(const __u32 reqmode);
79537 +int gr_set_acls(const int type);
79538 +int gr_acl_is_enabled(void);
79539 +char gr_roletype_to_char(void);
79540 +
79541 +void gr_handle_alertkill(struct task_struct *task);
79542 +char *gr_to_filename(const struct dentry *dentry,
79543 + const struct vfsmount *mnt);
79544 +char *gr_to_filename1(const struct dentry *dentry,
79545 + const struct vfsmount *mnt);
79546 +char *gr_to_filename2(const struct dentry *dentry,
79547 + const struct vfsmount *mnt);
79548 +char *gr_to_filename3(const struct dentry *dentry,
79549 + const struct vfsmount *mnt);
79550 +
79551 +extern int grsec_enable_ptrace_readexec;
79552 +extern int grsec_enable_harden_ptrace;
79553 +extern int grsec_enable_link;
79554 +extern int grsec_enable_fifo;
79555 +extern int grsec_enable_execve;
79556 +extern int grsec_enable_shm;
79557 +extern int grsec_enable_execlog;
79558 +extern int grsec_enable_signal;
79559 +extern int grsec_enable_audit_ptrace;
79560 +extern int grsec_enable_forkfail;
79561 +extern int grsec_enable_time;
79562 +extern int grsec_enable_rofs;
79563 +extern int grsec_deny_new_usb;
79564 +extern int grsec_enable_chroot_shmat;
79565 +extern int grsec_enable_chroot_mount;
79566 +extern int grsec_enable_chroot_double;
79567 +extern int grsec_enable_chroot_pivot;
79568 +extern int grsec_enable_chroot_chdir;
79569 +extern int grsec_enable_chroot_chmod;
79570 +extern int grsec_enable_chroot_mknod;
79571 +extern int grsec_enable_chroot_fchdir;
79572 +extern int grsec_enable_chroot_nice;
79573 +extern int grsec_enable_chroot_execlog;
79574 +extern int grsec_enable_chroot_caps;
79575 +extern int grsec_enable_chroot_sysctl;
79576 +extern int grsec_enable_chroot_unix;
79577 +extern int grsec_enable_symlinkown;
79578 +extern kgid_t grsec_symlinkown_gid;
79579 +extern int grsec_enable_tpe;
79580 +extern kgid_t grsec_tpe_gid;
79581 +extern int grsec_enable_tpe_all;
79582 +extern int grsec_enable_tpe_invert;
79583 +extern int grsec_enable_socket_all;
79584 +extern kgid_t grsec_socket_all_gid;
79585 +extern int grsec_enable_socket_client;
79586 +extern kgid_t grsec_socket_client_gid;
79587 +extern int grsec_enable_socket_server;
79588 +extern kgid_t grsec_socket_server_gid;
79589 +extern kgid_t grsec_audit_gid;
79590 +extern int grsec_enable_group;
79591 +extern int grsec_enable_log_rwxmaps;
79592 +extern int grsec_enable_mount;
79593 +extern int grsec_enable_chdir;
79594 +extern int grsec_resource_logging;
79595 +extern int grsec_enable_blackhole;
79596 +extern int grsec_lastack_retries;
79597 +extern int grsec_enable_brute;
79598 +extern int grsec_enable_harden_ipc;
79599 +extern int grsec_lock;
79600 +
79601 +extern spinlock_t grsec_alert_lock;
79602 +extern unsigned long grsec_alert_wtime;
79603 +extern unsigned long grsec_alert_fyet;
79604 +
79605 +extern spinlock_t grsec_audit_lock;
79606 +
79607 +extern rwlock_t grsec_exec_file_lock;
79608 +
79609 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79610 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79611 + (tsk)->exec_file->f_path.mnt) : "/")
79612 +
79613 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79614 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79615 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79616 +
79617 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79618 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
79619 + (tsk)->exec_file->f_path.mnt) : "/")
79620 +
79621 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79622 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79623 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79624 +
79625 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79626 +
79627 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79628 +
79629 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79630 +{
79631 + if (file1 && file2) {
79632 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
79633 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
79634 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79635 + return true;
79636 + }
79637 +
79638 + return false;
79639 +}
79640 +
79641 +#define GR_CHROOT_CAPS {{ \
79642 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79643 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79644 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79645 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79646 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79647 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79648 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79649 +
79650 +#define security_learn(normal_msg,args...) \
79651 +({ \
79652 + read_lock(&grsec_exec_file_lock); \
79653 + gr_add_learn_entry(normal_msg "\n", ## args); \
79654 + read_unlock(&grsec_exec_file_lock); \
79655 +})
79656 +
79657 +enum {
79658 + GR_DO_AUDIT,
79659 + GR_DONT_AUDIT,
79660 + /* used for non-audit messages that we shouldn't kill the task on */
79661 + GR_DONT_AUDIT_GOOD
79662 +};
79663 +
79664 +enum {
79665 + GR_TTYSNIFF,
79666 + GR_RBAC,
79667 + GR_RBAC_STR,
79668 + GR_STR_RBAC,
79669 + GR_RBAC_MODE2,
79670 + GR_RBAC_MODE3,
79671 + GR_FILENAME,
79672 + GR_SYSCTL_HIDDEN,
79673 + GR_NOARGS,
79674 + GR_ONE_INT,
79675 + GR_ONE_INT_TWO_STR,
79676 + GR_ONE_STR,
79677 + GR_STR_INT,
79678 + GR_TWO_STR_INT,
79679 + GR_TWO_INT,
79680 + GR_TWO_U64,
79681 + GR_THREE_INT,
79682 + GR_FIVE_INT_TWO_STR,
79683 + GR_TWO_STR,
79684 + GR_THREE_STR,
79685 + GR_FOUR_STR,
79686 + GR_STR_FILENAME,
79687 + GR_FILENAME_STR,
79688 + GR_FILENAME_TWO_INT,
79689 + GR_FILENAME_TWO_INT_STR,
79690 + GR_TEXTREL,
79691 + GR_PTRACE,
79692 + GR_RESOURCE,
79693 + GR_CAP,
79694 + GR_SIG,
79695 + GR_SIG2,
79696 + GR_CRASH1,
79697 + GR_CRASH2,
79698 + GR_PSACCT,
79699 + GR_RWXMAP,
79700 + GR_RWXMAPVMA
79701 +};
79702 +
79703 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79704 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79705 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79706 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79707 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79708 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79709 +#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)
79710 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79711 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79712 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79713 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79714 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79715 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79716 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79717 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79718 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79719 +#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)
79720 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79721 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79722 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79723 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79724 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79725 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79726 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79727 +#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)
79728 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79729 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79730 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79731 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79732 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79733 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79734 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79735 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79736 +#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)
79737 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79738 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79739 +
79740 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79741 +
79742 +#endif
79743 +
79744 +#endif
79745 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79746 new file mode 100644
79747 index 0000000..b02ba9d
79748 --- /dev/null
79749 +++ b/include/linux/grmsg.h
79750 @@ -0,0 +1,117 @@
79751 +#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"
79752 +#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"
79753 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79754 +#define GR_STOPMOD_MSG "denied modification of module state by "
79755 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79756 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79757 +#define GR_IOPERM_MSG "denied use of ioperm() by "
79758 +#define GR_IOPL_MSG "denied use of iopl() by "
79759 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79760 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79761 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79762 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79763 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79764 +#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"
79765 +#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"
79766 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79767 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79768 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79769 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79770 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79771 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79772 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79773 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79774 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79775 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79776 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79777 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79778 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79779 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79780 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79781 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79782 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79783 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79784 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79785 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79786 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79787 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79788 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79789 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79790 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79791 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79792 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79793 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79794 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79795 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79796 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79797 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
79798 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79799 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79800 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79801 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79802 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79803 +#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"
79804 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79805 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79806 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79807 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79808 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79809 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79810 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79811 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79812 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79813 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79814 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79815 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79816 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79817 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79818 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79819 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79820 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79821 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79822 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79823 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79824 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
79825 +#define GR_NICE_CHROOT_MSG "denied priority change by "
79826 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79827 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79828 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79829 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79830 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79831 +#define GR_TIME_MSG "time set by "
79832 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79833 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79834 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79835 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79836 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79837 +#define GR_BIND_MSG "denied bind() by "
79838 +#define GR_CONNECT_MSG "denied connect() by "
79839 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79840 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79841 +#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"
79842 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79843 +#define GR_CAP_ACL_MSG "use of %s denied for "
79844 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79845 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79846 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79847 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79848 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79849 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79850 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79851 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79852 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79853 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79854 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79855 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79856 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79857 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79858 +#define GR_VM86_MSG "denied use of vm86 by "
79859 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79860 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79861 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79862 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79863 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79864 +#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 "
79865 +#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 "
79866 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79867 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79868 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79869 new file mode 100644
79870 index 0000000..13ac2e2
79871 --- /dev/null
79872 +++ b/include/linux/grsecurity.h
79873 @@ -0,0 +1,249 @@
79874 +#ifndef GR_SECURITY_H
79875 +#define GR_SECURITY_H
79876 +#include <linux/fs.h>
79877 +#include <linux/fs_struct.h>
79878 +#include <linux/binfmts.h>
79879 +#include <linux/gracl.h>
79880 +
79881 +/* notify of brain-dead configs */
79882 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79883 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79884 +#endif
79885 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79886 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79887 +#endif
79888 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79889 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79890 +#endif
79891 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79892 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
79893 +#endif
79894 +
79895 +int gr_handle_new_usb(void);
79896 +
79897 +void gr_handle_brute_attach(int dumpable);
79898 +void gr_handle_brute_check(void);
79899 +void gr_handle_kernel_exploit(void);
79900 +
79901 +char gr_roletype_to_char(void);
79902 +
79903 +int gr_proc_is_restricted(void);
79904 +
79905 +int gr_acl_enable_at_secure(void);
79906 +
79907 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79908 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79909 +
79910 +void gr_del_task_from_ip_table(struct task_struct *p);
79911 +
79912 +int gr_pid_is_chrooted(struct task_struct *p);
79913 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79914 +int gr_handle_chroot_nice(void);
79915 +int gr_handle_chroot_sysctl(const int op);
79916 +int gr_handle_chroot_setpriority(struct task_struct *p,
79917 + const int niceval);
79918 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79919 +int gr_chroot_fhandle(void);
79920 +int gr_handle_chroot_chroot(const struct dentry *dentry,
79921 + const struct vfsmount *mnt);
79922 +void gr_handle_chroot_chdir(const struct path *path);
79923 +int gr_handle_chroot_chmod(const struct dentry *dentry,
79924 + const struct vfsmount *mnt, const int mode);
79925 +int gr_handle_chroot_mknod(const struct dentry *dentry,
79926 + const struct vfsmount *mnt, const int mode);
79927 +int gr_handle_chroot_mount(const struct dentry *dentry,
79928 + const struct vfsmount *mnt,
79929 + const char *dev_name);
79930 +int gr_handle_chroot_pivot(void);
79931 +int gr_handle_chroot_unix(const pid_t pid);
79932 +
79933 +int gr_handle_rawio(const struct inode *inode);
79934 +
79935 +void gr_handle_ioperm(void);
79936 +void gr_handle_iopl(void);
79937 +void gr_handle_msr_write(void);
79938 +
79939 +umode_t gr_acl_umask(void);
79940 +
79941 +int gr_tpe_allow(const struct file *file);
79942 +
79943 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79944 +void gr_clear_chroot_entries(struct task_struct *task);
79945 +
79946 +void gr_log_forkfail(const int retval);
79947 +void gr_log_timechange(void);
79948 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79949 +void gr_log_chdir(const struct dentry *dentry,
79950 + const struct vfsmount *mnt);
79951 +void gr_log_chroot_exec(const struct dentry *dentry,
79952 + const struct vfsmount *mnt);
79953 +void gr_log_remount(const char *devname, const int retval);
79954 +void gr_log_unmount(const char *devname, const int retval);
79955 +void gr_log_mount(const char *from, const char *to, const int retval);
79956 +void gr_log_textrel(struct vm_area_struct *vma);
79957 +void gr_log_ptgnustack(struct file *file);
79958 +void gr_log_rwxmmap(struct file *file);
79959 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
79960 +
79961 +int gr_handle_follow_link(const struct inode *parent,
79962 + const struct inode *inode,
79963 + const struct dentry *dentry,
79964 + const struct vfsmount *mnt);
79965 +int gr_handle_fifo(const struct dentry *dentry,
79966 + const struct vfsmount *mnt,
79967 + const struct dentry *dir, const int flag,
79968 + const int acc_mode);
79969 +int gr_handle_hardlink(const struct dentry *dentry,
79970 + const struct vfsmount *mnt,
79971 + struct inode *inode,
79972 + const int mode, const struct filename *to);
79973 +
79974 +int gr_is_capable(const int cap);
79975 +int gr_is_capable_nolog(const int cap);
79976 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79977 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79978 +
79979 +void gr_copy_label(struct task_struct *tsk);
79980 +void gr_handle_crash(struct task_struct *task, const int sig);
79981 +int gr_handle_signal(const struct task_struct *p, const int sig);
79982 +int gr_check_crash_uid(const kuid_t uid);
79983 +int gr_check_protected_task(const struct task_struct *task);
79984 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79985 +int gr_acl_handle_mmap(const struct file *file,
79986 + const unsigned long prot);
79987 +int gr_acl_handle_mprotect(const struct file *file,
79988 + const unsigned long prot);
79989 +int gr_check_hidden_task(const struct task_struct *tsk);
79990 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79991 + const struct vfsmount *mnt);
79992 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
79993 + const struct vfsmount *mnt);
79994 +__u32 gr_acl_handle_access(const struct dentry *dentry,
79995 + const struct vfsmount *mnt, const int fmode);
79996 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79997 + const struct vfsmount *mnt, umode_t *mode);
79998 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
79999 + const struct vfsmount *mnt);
80000 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
80001 + const struct vfsmount *mnt);
80002 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
80003 + const struct vfsmount *mnt);
80004 +int gr_handle_ptrace(struct task_struct *task, const long request);
80005 +int gr_handle_proc_ptrace(struct task_struct *task);
80006 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
80007 + const struct vfsmount *mnt);
80008 +int gr_check_crash_exec(const struct file *filp);
80009 +int gr_acl_is_enabled(void);
80010 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
80011 + const kgid_t gid);
80012 +int gr_set_proc_label(const struct dentry *dentry,
80013 + const struct vfsmount *mnt,
80014 + const int unsafe_flags);
80015 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
80016 + const struct vfsmount *mnt);
80017 +__u32 gr_acl_handle_open(const struct dentry *dentry,
80018 + const struct vfsmount *mnt, int acc_mode);
80019 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
80020 + const struct dentry *p_dentry,
80021 + const struct vfsmount *p_mnt,
80022 + int open_flags, int acc_mode, const int imode);
80023 +void gr_handle_create(const struct dentry *dentry,
80024 + const struct vfsmount *mnt);
80025 +void gr_handle_proc_create(const struct dentry *dentry,
80026 + const struct inode *inode);
80027 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
80028 + const struct dentry *parent_dentry,
80029 + const struct vfsmount *parent_mnt,
80030 + const int mode);
80031 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
80032 + const struct dentry *parent_dentry,
80033 + const struct vfsmount *parent_mnt);
80034 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
80035 + const struct vfsmount *mnt);
80036 +void gr_handle_delete(const ino_t ino, const dev_t dev);
80037 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
80038 + const struct vfsmount *mnt);
80039 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
80040 + const struct dentry *parent_dentry,
80041 + const struct vfsmount *parent_mnt,
80042 + const struct filename *from);
80043 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
80044 + const struct dentry *parent_dentry,
80045 + const struct vfsmount *parent_mnt,
80046 + const struct dentry *old_dentry,
80047 + const struct vfsmount *old_mnt, const struct filename *to);
80048 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
80049 +int gr_acl_handle_rename(struct dentry *new_dentry,
80050 + struct dentry *parent_dentry,
80051 + const struct vfsmount *parent_mnt,
80052 + struct dentry *old_dentry,
80053 + struct inode *old_parent_inode,
80054 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
80055 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
80056 + struct dentry *old_dentry,
80057 + struct dentry *new_dentry,
80058 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
80059 +__u32 gr_check_link(const struct dentry *new_dentry,
80060 + const struct dentry *parent_dentry,
80061 + const struct vfsmount *parent_mnt,
80062 + const struct dentry *old_dentry,
80063 + const struct vfsmount *old_mnt);
80064 +int gr_acl_handle_filldir(const struct file *file, const char *name,
80065 + const unsigned int namelen, const ino_t ino);
80066 +
80067 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
80068 + const struct vfsmount *mnt);
80069 +void gr_acl_handle_exit(void);
80070 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
80071 +int gr_acl_handle_procpidmem(const struct task_struct *task);
80072 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
80073 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
80074 +void gr_audit_ptrace(struct task_struct *task);
80075 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
80076 +void gr_put_exec_file(struct task_struct *task);
80077 +
80078 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
80079 +
80080 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
80081 +extern void gr_learn_resource(const struct task_struct *task, const int res,
80082 + const unsigned long wanted, const int gt);
80083 +#else
80084 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
80085 + const unsigned long wanted, const int gt)
80086 +{
80087 +}
80088 +#endif
80089 +
80090 +#ifdef CONFIG_GRKERNSEC_RESLOG
80091 +extern void gr_log_resource(const struct task_struct *task, const int res,
80092 + const unsigned long wanted, const int gt);
80093 +#else
80094 +static inline void gr_log_resource(const struct task_struct *task, const int res,
80095 + const unsigned long wanted, const int gt)
80096 +{
80097 +}
80098 +#endif
80099 +
80100 +#ifdef CONFIG_GRKERNSEC
80101 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
80102 +void gr_handle_vm86(void);
80103 +void gr_handle_mem_readwrite(u64 from, u64 to);
80104 +
80105 +void gr_log_badprocpid(const char *entry);
80106 +
80107 +extern int grsec_enable_dmesg;
80108 +extern int grsec_disable_privio;
80109 +
80110 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
80111 +extern kgid_t grsec_proc_gid;
80112 +#endif
80113 +
80114 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
80115 +extern int grsec_enable_chroot_findtask;
80116 +#endif
80117 +#ifdef CONFIG_GRKERNSEC_SETXID
80118 +extern int grsec_enable_setxid;
80119 +#endif
80120 +#endif
80121 +
80122 +#endif
80123 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
80124 new file mode 100644
80125 index 0000000..e7ffaaf
80126 --- /dev/null
80127 +++ b/include/linux/grsock.h
80128 @@ -0,0 +1,19 @@
80129 +#ifndef __GRSOCK_H
80130 +#define __GRSOCK_H
80131 +
80132 +extern void gr_attach_curr_ip(const struct sock *sk);
80133 +extern int gr_handle_sock_all(const int family, const int type,
80134 + const int protocol);
80135 +extern int gr_handle_sock_server(const struct sockaddr *sck);
80136 +extern int gr_handle_sock_server_other(const struct sock *sck);
80137 +extern int gr_handle_sock_client(const struct sockaddr *sck);
80138 +extern int gr_search_connect(struct socket * sock,
80139 + struct sockaddr_in * addr);
80140 +extern int gr_search_bind(struct socket * sock,
80141 + struct sockaddr_in * addr);
80142 +extern int gr_search_listen(struct socket * sock);
80143 +extern int gr_search_accept(struct socket * sock);
80144 +extern int gr_search_socket(const int domain, const int type,
80145 + const int protocol);
80146 +
80147 +#endif
80148 diff --git a/include/linux/hash.h b/include/linux/hash.h
80149 index bd1754c..8240892 100644
80150 --- a/include/linux/hash.h
80151 +++ b/include/linux/hash.h
80152 @@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
80153 struct fast_hash_ops {
80154 u32 (*hash)(const void *data, u32 len, u32 seed);
80155 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
80156 -};
80157 +} __no_const;
80158
80159 /**
80160 * arch_fast_hash - Caclulates a hash over a given buffer that can have
80161 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
80162 index 7fb31da..08b5114 100644
80163 --- a/include/linux/highmem.h
80164 +++ b/include/linux/highmem.h
80165 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
80166 kunmap_atomic(kaddr);
80167 }
80168
80169 +static inline void sanitize_highpage(struct page *page)
80170 +{
80171 + void *kaddr;
80172 + unsigned long flags;
80173 +
80174 + local_irq_save(flags);
80175 + kaddr = kmap_atomic(page);
80176 + clear_page(kaddr);
80177 + kunmap_atomic(kaddr);
80178 + local_irq_restore(flags);
80179 +}
80180 +
80181 static inline void zero_user_segments(struct page *page,
80182 unsigned start1, unsigned end1,
80183 unsigned start2, unsigned end2)
80184 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
80185 index 1c7b89a..7dda400 100644
80186 --- a/include/linux/hwmon-sysfs.h
80187 +++ b/include/linux/hwmon-sysfs.h
80188 @@ -25,7 +25,8 @@
80189 struct sensor_device_attribute{
80190 struct device_attribute dev_attr;
80191 int index;
80192 -};
80193 +} __do_const;
80194 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
80195 #define to_sensor_dev_attr(_dev_attr) \
80196 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
80197
80198 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
80199 struct device_attribute dev_attr;
80200 u8 index;
80201 u8 nr;
80202 -};
80203 +} __do_const;
80204 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
80205 #define to_sensor_dev_attr_2(_dev_attr) \
80206 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
80207
80208 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
80209 index b556e0a..c10a515 100644
80210 --- a/include/linux/i2c.h
80211 +++ b/include/linux/i2c.h
80212 @@ -378,6 +378,7 @@ struct i2c_algorithm {
80213 /* To determine what the adapter supports */
80214 u32 (*functionality) (struct i2c_adapter *);
80215 };
80216 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
80217
80218 /**
80219 * struct i2c_bus_recovery_info - I2C bus recovery information
80220 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
80221 index d23c3c2..eb63c81 100644
80222 --- a/include/linux/i2o.h
80223 +++ b/include/linux/i2o.h
80224 @@ -565,7 +565,7 @@ struct i2o_controller {
80225 struct i2o_device *exec; /* Executive */
80226 #if BITS_PER_LONG == 64
80227 spinlock_t context_list_lock; /* lock for context_list */
80228 - atomic_t context_list_counter; /* needed for unique contexts */
80229 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
80230 struct list_head context_list; /* list of context id's
80231 and pointers */
80232 #endif
80233 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
80234 index aff7ad8..3942bbd 100644
80235 --- a/include/linux/if_pppox.h
80236 +++ b/include/linux/if_pppox.h
80237 @@ -76,7 +76,7 @@ struct pppox_proto {
80238 int (*ioctl)(struct socket *sock, unsigned int cmd,
80239 unsigned long arg);
80240 struct module *owner;
80241 -};
80242 +} __do_const;
80243
80244 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
80245 extern void unregister_pppox_proto(int proto_num);
80246 diff --git a/include/linux/init.h b/include/linux/init.h
80247 index a3ba270..a1b6604 100644
80248 --- a/include/linux/init.h
80249 +++ b/include/linux/init.h
80250 @@ -37,9 +37,17 @@
80251 * section.
80252 */
80253
80254 +#define add_init_latent_entropy __latent_entropy
80255 +
80256 +#ifdef CONFIG_MEMORY_HOTPLUG
80257 +#define add_meminit_latent_entropy
80258 +#else
80259 +#define add_meminit_latent_entropy __latent_entropy
80260 +#endif
80261 +
80262 /* These are for everybody (although not all archs will actually
80263 discard it in modules) */
80264 -#define __init __section(.init.text) __cold notrace
80265 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
80266 #define __initdata __section(.init.data)
80267 #define __initconst __constsection(.init.rodata)
80268 #define __exitdata __section(.exit.data)
80269 @@ -100,7 +108,7 @@
80270 #define __cpuexitconst
80271
80272 /* Used for MEMORY_HOTPLUG */
80273 -#define __meminit __section(.meminit.text) __cold notrace
80274 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
80275 #define __meminitdata __section(.meminit.data)
80276 #define __meminitconst __constsection(.meminit.rodata)
80277 #define __memexit __section(.memexit.text) __exitused __cold notrace
80278 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
80279 index 6df7f9f..d0bf699 100644
80280 --- a/include/linux/init_task.h
80281 +++ b/include/linux/init_task.h
80282 @@ -156,6 +156,12 @@ extern struct task_group root_task_group;
80283
80284 #define INIT_TASK_COMM "swapper"
80285
80286 +#ifdef CONFIG_X86
80287 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
80288 +#else
80289 +#define INIT_TASK_THREAD_INFO
80290 +#endif
80291 +
80292 #ifdef CONFIG_RT_MUTEXES
80293 # define INIT_RT_MUTEXES(tsk) \
80294 .pi_waiters = RB_ROOT, \
80295 @@ -203,6 +209,7 @@ extern struct task_group root_task_group;
80296 RCU_POINTER_INITIALIZER(cred, &init_cred), \
80297 .comm = INIT_TASK_COMM, \
80298 .thread = INIT_THREAD, \
80299 + INIT_TASK_THREAD_INFO \
80300 .fs = &init_fs, \
80301 .files = &init_files, \
80302 .signal = &init_signals, \
80303 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
80304 index 051c850..431f83a 100644
80305 --- a/include/linux/interrupt.h
80306 +++ b/include/linux/interrupt.h
80307 @@ -412,8 +412,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
80308
80309 struct softirq_action
80310 {
80311 - void (*action)(struct softirq_action *);
80312 -};
80313 + void (*action)(void);
80314 +} __no_const;
80315
80316 asmlinkage void do_softirq(void);
80317 asmlinkage void __do_softirq(void);
80318 @@ -427,7 +427,7 @@ static inline void do_softirq_own_stack(void)
80319 }
80320 #endif
80321
80322 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
80323 +extern void open_softirq(int nr, void (*action)(void));
80324 extern void softirq_init(void);
80325 extern void __raise_softirq_irqoff(unsigned int nr);
80326
80327 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
80328 index b96a5b2..2732d1c 100644
80329 --- a/include/linux/iommu.h
80330 +++ b/include/linux/iommu.h
80331 @@ -131,7 +131,7 @@ struct iommu_ops {
80332 u32 (*domain_get_windows)(struct iommu_domain *domain);
80333
80334 unsigned long pgsize_bitmap;
80335 -};
80336 +} __do_const;
80337
80338 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
80339 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
80340 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
80341 index 5e3a906..3131d0f 100644
80342 --- a/include/linux/ioport.h
80343 +++ b/include/linux/ioport.h
80344 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
80345 int adjust_resource(struct resource *res, resource_size_t start,
80346 resource_size_t size);
80347 resource_size_t resource_alignment(struct resource *res);
80348 -static inline resource_size_t resource_size(const struct resource *res)
80349 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
80350 {
80351 return res->end - res->start + 1;
80352 }
80353 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
80354 index 35e7eca..6afb7ad 100644
80355 --- a/include/linux/ipc_namespace.h
80356 +++ b/include/linux/ipc_namespace.h
80357 @@ -69,7 +69,7 @@ struct ipc_namespace {
80358 struct user_namespace *user_ns;
80359
80360 unsigned int proc_inum;
80361 -};
80362 +} __randomize_layout;
80363
80364 extern struct ipc_namespace init_ipc_ns;
80365 extern atomic_t nr_ipc_ns;
80366 diff --git a/include/linux/irq.h b/include/linux/irq.h
80367 index 5c57efb..965a62b 100644
80368 --- a/include/linux/irq.h
80369 +++ b/include/linux/irq.h
80370 @@ -344,7 +344,8 @@ struct irq_chip {
80371 void (*irq_release_resources)(struct irq_data *data);
80372
80373 unsigned long flags;
80374 -};
80375 +} __do_const;
80376 +typedef struct irq_chip __no_const irq_chip_no_const;
80377
80378 /*
80379 * irq_chip specific flags
80380 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80381 index 7ed92d0..589abf5 100644
80382 --- a/include/linux/irqchip/arm-gic.h
80383 +++ b/include/linux/irqchip/arm-gic.h
80384 @@ -73,9 +73,11 @@
80385
80386 #ifndef __ASSEMBLY__
80387
80388 +#include <linux/irq.h>
80389 +
80390 struct device_node;
80391
80392 -extern struct irq_chip gic_arch_extn;
80393 +extern irq_chip_no_const gic_arch_extn;
80394
80395 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80396 u32 offset, struct device_node *);
80397 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80398 index 1f44466..b481806 100644
80399 --- a/include/linux/jiffies.h
80400 +++ b/include/linux/jiffies.h
80401 @@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80402 /*
80403 * Convert various time units to each other:
80404 */
80405 -extern unsigned int jiffies_to_msecs(const unsigned long j);
80406 -extern unsigned int jiffies_to_usecs(const unsigned long j);
80407 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80408 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80409
80410 -static inline u64 jiffies_to_nsecs(const unsigned long j)
80411 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80412 {
80413 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80414 }
80415
80416 -extern unsigned long msecs_to_jiffies(const unsigned int m);
80417 -extern unsigned long usecs_to_jiffies(const unsigned int u);
80418 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80419 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80420 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80421 extern void jiffies_to_timespec(const unsigned long jiffies,
80422 - struct timespec *value);
80423 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
80424 + struct timespec *value) __intentional_overflow(-1);
80425 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80426 extern void jiffies_to_timeval(const unsigned long jiffies,
80427 struct timeval *value);
80428
80429 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80430 index 6883e19..e854fcb 100644
80431 --- a/include/linux/kallsyms.h
80432 +++ b/include/linux/kallsyms.h
80433 @@ -15,7 +15,8 @@
80434
80435 struct module;
80436
80437 -#ifdef CONFIG_KALLSYMS
80438 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80439 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80440 /* Lookup the address for a symbol. Returns 0 if not found. */
80441 unsigned long kallsyms_lookup_name(const char *name);
80442
80443 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80444 /* Stupid that this does nothing, but I didn't create this mess. */
80445 #define __print_symbol(fmt, addr)
80446 #endif /*CONFIG_KALLSYMS*/
80447 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80448 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80449 +extern unsigned long kallsyms_lookup_name(const char *name);
80450 +extern void __print_symbol(const char *fmt, unsigned long address);
80451 +extern int sprint_backtrace(char *buffer, unsigned long address);
80452 +extern int sprint_symbol(char *buffer, unsigned long address);
80453 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80454 +const char *kallsyms_lookup(unsigned long addr,
80455 + unsigned long *symbolsize,
80456 + unsigned long *offset,
80457 + char **modname, char *namebuf);
80458 +extern int kallsyms_lookup_size_offset(unsigned long addr,
80459 + unsigned long *symbolsize,
80460 + unsigned long *offset);
80461 +#endif
80462
80463 /* This macro allows us to keep printk typechecking */
80464 static __printf(1, 2)
80465 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80466 index a74c3a8..28d3f21 100644
80467 --- a/include/linux/key-type.h
80468 +++ b/include/linux/key-type.h
80469 @@ -131,7 +131,7 @@ struct key_type {
80470 /* internal fields */
80471 struct list_head link; /* link in types list */
80472 struct lock_class_key lock_class; /* key->sem lock class */
80473 -};
80474 +} __do_const;
80475
80476 extern struct key_type key_type_keyring;
80477
80478 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80479 index 6b06d37..c134867 100644
80480 --- a/include/linux/kgdb.h
80481 +++ b/include/linux/kgdb.h
80482 @@ -52,7 +52,7 @@ extern int kgdb_connected;
80483 extern int kgdb_io_module_registered;
80484
80485 extern atomic_t kgdb_setting_breakpoint;
80486 -extern atomic_t kgdb_cpu_doing_single_step;
80487 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80488
80489 extern struct task_struct *kgdb_usethread;
80490 extern struct task_struct *kgdb_contthread;
80491 @@ -254,7 +254,7 @@ struct kgdb_arch {
80492 void (*correct_hw_break)(void);
80493
80494 void (*enable_nmi)(bool on);
80495 -};
80496 +} __do_const;
80497
80498 /**
80499 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80500 @@ -279,7 +279,7 @@ struct kgdb_io {
80501 void (*pre_exception) (void);
80502 void (*post_exception) (void);
80503 int is_console;
80504 -};
80505 +} __do_const;
80506
80507 extern struct kgdb_arch arch_kgdb_ops;
80508
80509 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80510 index 0555cc6..40116ce 100644
80511 --- a/include/linux/kmod.h
80512 +++ b/include/linux/kmod.h
80513 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80514 * usually useless though. */
80515 extern __printf(2, 3)
80516 int __request_module(bool wait, const char *name, ...);
80517 +extern __printf(3, 4)
80518 +int ___request_module(bool wait, char *param_name, const char *name, ...);
80519 #define request_module(mod...) __request_module(true, mod)
80520 #define request_module_nowait(mod...) __request_module(false, mod)
80521 #define try_then_request_module(x, mod...) \
80522 @@ -57,6 +59,9 @@ struct subprocess_info {
80523 struct work_struct work;
80524 struct completion *complete;
80525 char *path;
80526 +#ifdef CONFIG_GRKERNSEC
80527 + char *origpath;
80528 +#endif
80529 char **argv;
80530 char **envp;
80531 int wait;
80532 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80533 index f896a33..f2eb10f 100644
80534 --- a/include/linux/kobject.h
80535 +++ b/include/linux/kobject.h
80536 @@ -116,7 +116,7 @@ struct kobj_type {
80537 struct attribute **default_attrs;
80538 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80539 const void *(*namespace)(struct kobject *kobj);
80540 -};
80541 +} __do_const;
80542
80543 struct kobj_uevent_env {
80544 char *argv[3];
80545 @@ -140,6 +140,7 @@ struct kobj_attribute {
80546 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80547 const char *buf, size_t count);
80548 };
80549 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80550
80551 extern const struct sysfs_ops kobj_sysfs_ops;
80552
80553 @@ -167,7 +168,7 @@ struct kset {
80554 spinlock_t list_lock;
80555 struct kobject kobj;
80556 const struct kset_uevent_ops *uevent_ops;
80557 -};
80558 +} __randomize_layout;
80559
80560 extern void kset_init(struct kset *kset);
80561 extern int __must_check kset_register(struct kset *kset);
80562 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80563 index df32d25..fb52e27 100644
80564 --- a/include/linux/kobject_ns.h
80565 +++ b/include/linux/kobject_ns.h
80566 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80567 const void *(*netlink_ns)(struct sock *sk);
80568 const void *(*initial_ns)(void);
80569 void (*drop_ns)(void *);
80570 -};
80571 +} __do_const;
80572
80573 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80574 int kobj_ns_type_registered(enum kobj_ns_type type);
80575 diff --git a/include/linux/kref.h b/include/linux/kref.h
80576 index 484604d..0f6c5b6 100644
80577 --- a/include/linux/kref.h
80578 +++ b/include/linux/kref.h
80579 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80580 static inline int kref_sub(struct kref *kref, unsigned int count,
80581 void (*release)(struct kref *kref))
80582 {
80583 - WARN_ON(release == NULL);
80584 + BUG_ON(release == NULL);
80585
80586 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80587 release(kref);
80588 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80589 index 7d21cf9..bc0c81f 100644
80590 --- a/include/linux/kvm_host.h
80591 +++ b/include/linux/kvm_host.h
80592 @@ -466,7 +466,7 @@ static inline void kvm_irqfd_exit(void)
80593 {
80594 }
80595 #endif
80596 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80597 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80598 struct module *module);
80599 void kvm_exit(void);
80600
80601 @@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80602 struct kvm_guest_debug *dbg);
80603 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80604
80605 -int kvm_arch_init(void *opaque);
80606 +int kvm_arch_init(const void *opaque);
80607 void kvm_arch_exit(void);
80608
80609 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80610 diff --git a/include/linux/libata.h b/include/linux/libata.h
80611 index 5ab4e3a..2fe237b 100644
80612 --- a/include/linux/libata.h
80613 +++ b/include/linux/libata.h
80614 @@ -975,7 +975,7 @@ struct ata_port_operations {
80615 * fields must be pointers.
80616 */
80617 const struct ata_port_operations *inherits;
80618 -};
80619 +} __do_const;
80620
80621 struct ata_port_info {
80622 unsigned long flags;
80623 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80624 index a6a42dd..6c5ebce 100644
80625 --- a/include/linux/linkage.h
80626 +++ b/include/linux/linkage.h
80627 @@ -36,6 +36,7 @@
80628 #endif
80629
80630 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80631 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80632 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80633
80634 /*
80635 diff --git a/include/linux/list.h b/include/linux/list.h
80636 index ef95941..82db65a 100644
80637 --- a/include/linux/list.h
80638 +++ b/include/linux/list.h
80639 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80640 extern void list_del(struct list_head *entry);
80641 #endif
80642
80643 +extern void __pax_list_add(struct list_head *new,
80644 + struct list_head *prev,
80645 + struct list_head *next);
80646 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
80647 +{
80648 + __pax_list_add(new, head, head->next);
80649 +}
80650 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80651 +{
80652 + __pax_list_add(new, head->prev, head);
80653 +}
80654 +extern void pax_list_del(struct list_head *entry);
80655 +
80656 /**
80657 * list_replace - replace old entry by new one
80658 * @old : the element to be replaced
80659 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80660 INIT_LIST_HEAD(entry);
80661 }
80662
80663 +extern void pax_list_del_init(struct list_head *entry);
80664 +
80665 /**
80666 * list_move - delete from one list and add as another's head
80667 * @list: the entry to move
80668 diff --git a/include/linux/math64.h b/include/linux/math64.h
80669 index c45c089..298841c 100644
80670 --- a/include/linux/math64.h
80671 +++ b/include/linux/math64.h
80672 @@ -15,7 +15,7 @@
80673 * This is commonly provided by 32bit archs to provide an optimized 64bit
80674 * divide.
80675 */
80676 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80677 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80678 {
80679 *remainder = dividend % divisor;
80680 return dividend / divisor;
80681 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80682 /**
80683 * div64_u64 - unsigned 64bit divide with 64bit divisor
80684 */
80685 -static inline u64 div64_u64(u64 dividend, u64 divisor)
80686 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80687 {
80688 return dividend / divisor;
80689 }
80690 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80691 #define div64_ul(x, y) div_u64((x), (y))
80692
80693 #ifndef div_u64_rem
80694 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80695 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80696 {
80697 *remainder = do_div(dividend, divisor);
80698 return dividend;
80699 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80700 #endif
80701
80702 #ifndef div64_u64
80703 -extern u64 div64_u64(u64 dividend, u64 divisor);
80704 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80705 #endif
80706
80707 #ifndef div64_s64
80708 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80709 * divide.
80710 */
80711 #ifndef div_u64
80712 -static inline u64 div_u64(u64 dividend, u32 divisor)
80713 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80714 {
80715 u32 remainder;
80716 return div_u64_rem(dividend, divisor, &remainder);
80717 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80718 index f230a97..714c006 100644
80719 --- a/include/linux/mempolicy.h
80720 +++ b/include/linux/mempolicy.h
80721 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80722 }
80723
80724 #define vma_policy(vma) ((vma)->vm_policy)
80725 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80726 +{
80727 + vma->vm_policy = pol;
80728 +}
80729
80730 static inline void mpol_get(struct mempolicy *pol)
80731 {
80732 @@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80733 }
80734
80735 #define vma_policy(vma) NULL
80736 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80737 +{
80738 +}
80739
80740 static inline int
80741 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80742 diff --git a/include/linux/mm.h b/include/linux/mm.h
80743 index d677706..673408c 100644
80744 --- a/include/linux/mm.h
80745 +++ b/include/linux/mm.h
80746 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80747 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80748 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80749 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80750 +
80751 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80752 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80753 +#endif
80754 +
80755 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80756
80757 #ifdef CONFIG_MEM_SOFT_DIRTY
80758 @@ -237,8 +242,8 @@ struct vm_operations_struct {
80759 /* called by access_process_vm when get_user_pages() fails, typically
80760 * for use by special VMAs that can switch between memory and hardware
80761 */
80762 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
80763 - void *buf, int len, int write);
80764 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80765 + void *buf, size_t len, int write);
80766 #ifdef CONFIG_NUMA
80767 /*
80768 * set_policy() op must add a reference to any non-NULL @new mempolicy
80769 @@ -268,6 +273,7 @@ struct vm_operations_struct {
80770 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80771 unsigned long size, pgoff_t pgoff);
80772 };
80773 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80774
80775 struct mmu_gather;
80776 struct inode;
80777 @@ -1133,8 +1139,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80778 unsigned long *pfn);
80779 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80780 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80781 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80782 - void *buf, int len, int write);
80783 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80784 + void *buf, size_t len, int write);
80785
80786 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80787 loff_t const holebegin, loff_t const holelen)
80788 @@ -1173,9 +1179,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80789 }
80790 #endif
80791
80792 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80793 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80794 - void *buf, int len, int write);
80795 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80796 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80797 + void *buf, size_t len, int write);
80798
80799 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80800 unsigned long start, unsigned long nr_pages,
80801 @@ -1208,34 +1214,6 @@ int set_page_dirty_lock(struct page *page);
80802 int clear_page_dirty_for_io(struct page *page);
80803 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
80804
80805 -/* Is the vma a continuation of the stack vma above it? */
80806 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80807 -{
80808 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80809 -}
80810 -
80811 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
80812 - unsigned long addr)
80813 -{
80814 - return (vma->vm_flags & VM_GROWSDOWN) &&
80815 - (vma->vm_start == addr) &&
80816 - !vma_growsdown(vma->vm_prev, addr);
80817 -}
80818 -
80819 -/* Is the vma a continuation of the stack vma below it? */
80820 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80821 -{
80822 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80823 -}
80824 -
80825 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
80826 - unsigned long addr)
80827 -{
80828 - return (vma->vm_flags & VM_GROWSUP) &&
80829 - (vma->vm_end == addr) &&
80830 - !vma_growsup(vma->vm_next, addr);
80831 -}
80832 -
80833 extern pid_t
80834 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80835
80836 @@ -1335,6 +1313,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80837 }
80838 #endif
80839
80840 +#ifdef CONFIG_MMU
80841 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80842 +#else
80843 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80844 +{
80845 + return __pgprot(0);
80846 +}
80847 +#endif
80848 +
80849 int vma_wants_writenotify(struct vm_area_struct *vma);
80850
80851 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80852 @@ -1353,8 +1340,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80853 {
80854 return 0;
80855 }
80856 +
80857 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80858 + unsigned long address)
80859 +{
80860 + return 0;
80861 +}
80862 #else
80863 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80864 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80865 #endif
80866
80867 #ifdef __PAGETABLE_PMD_FOLDED
80868 @@ -1363,8 +1357,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80869 {
80870 return 0;
80871 }
80872 +
80873 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80874 + unsigned long address)
80875 +{
80876 + return 0;
80877 +}
80878 #else
80879 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80880 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80881 #endif
80882
80883 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80884 @@ -1382,11 +1383,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80885 NULL: pud_offset(pgd, address);
80886 }
80887
80888 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80889 +{
80890 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80891 + NULL: pud_offset(pgd, address);
80892 +}
80893 +
80894 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80895 {
80896 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80897 NULL: pmd_offset(pud, address);
80898 }
80899 +
80900 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80901 +{
80902 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80903 + NULL: pmd_offset(pud, address);
80904 +}
80905 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80906
80907 #if USE_SPLIT_PTE_PTLOCKS
80908 @@ -1783,7 +1796,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80909 unsigned long addr, unsigned long len,
80910 unsigned long flags, struct page **pages);
80911
80912 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80913 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80914
80915 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80916 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80917 @@ -1791,6 +1804,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80918 unsigned long len, unsigned long prot, unsigned long flags,
80919 unsigned long pgoff, unsigned long *populate);
80920 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80921 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80922
80923 #ifdef CONFIG_MMU
80924 extern int __mm_populate(unsigned long addr, unsigned long len,
80925 @@ -1819,10 +1833,11 @@ struct vm_unmapped_area_info {
80926 unsigned long high_limit;
80927 unsigned long align_mask;
80928 unsigned long align_offset;
80929 + unsigned long threadstack_offset;
80930 };
80931
80932 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80933 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80934 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80935 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80936
80937 /*
80938 * Search for an unmapped address range.
80939 @@ -1834,7 +1849,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80940 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80941 */
80942 static inline unsigned long
80943 -vm_unmapped_area(struct vm_unmapped_area_info *info)
80944 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
80945 {
80946 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80947 return unmapped_area(info);
80948 @@ -1896,6 +1911,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80949 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80950 struct vm_area_struct **pprev);
80951
80952 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80953 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80954 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80955 +
80956 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80957 NULL if none. Assume start_addr < end_addr. */
80958 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80959 @@ -1924,15 +1943,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80960 return vma;
80961 }
80962
80963 -#ifdef CONFIG_MMU
80964 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
80965 -#else
80966 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80967 -{
80968 - return __pgprot(0);
80969 -}
80970 -#endif
80971 -
80972 #ifdef CONFIG_NUMA_BALANCING
80973 unsigned long change_prot_numa(struct vm_area_struct *vma,
80974 unsigned long start, unsigned long end);
80975 @@ -1984,6 +1994,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80976 static inline void vm_stat_account(struct mm_struct *mm,
80977 unsigned long flags, struct file *file, long pages)
80978 {
80979 +
80980 +#ifdef CONFIG_PAX_RANDMMAP
80981 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80982 +#endif
80983 +
80984 mm->total_vm += pages;
80985 }
80986 #endif /* CONFIG_PROC_FS */
80987 @@ -2065,7 +2080,7 @@ extern int unpoison_memory(unsigned long pfn);
80988 extern int sysctl_memory_failure_early_kill;
80989 extern int sysctl_memory_failure_recovery;
80990 extern void shake_page(struct page *p, int access);
80991 -extern atomic_long_t num_poisoned_pages;
80992 +extern atomic_long_unchecked_t num_poisoned_pages;
80993 extern int soft_offline_page(struct page *page, int flags);
80994
80995 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80996 @@ -2100,5 +2115,11 @@ void __init setup_nr_node_ids(void);
80997 static inline void setup_nr_node_ids(void) {}
80998 #endif
80999
81000 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81001 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
81002 +#else
81003 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
81004 +#endif
81005 +
81006 #endif /* __KERNEL__ */
81007 #endif /* _LINUX_MM_H */
81008 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
81009 index 8967e20..61f7900 100644
81010 --- a/include/linux/mm_types.h
81011 +++ b/include/linux/mm_types.h
81012 @@ -308,7 +308,9 @@ struct vm_area_struct {
81013 #ifdef CONFIG_NUMA
81014 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
81015 #endif
81016 -};
81017 +
81018 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
81019 +} __randomize_layout;
81020
81021 struct core_thread {
81022 struct task_struct *task;
81023 @@ -454,7 +456,25 @@ struct mm_struct {
81024 bool tlb_flush_pending;
81025 #endif
81026 struct uprobes_state uprobes_state;
81027 -};
81028 +
81029 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81030 + unsigned long pax_flags;
81031 +#endif
81032 +
81033 +#ifdef CONFIG_PAX_DLRESOLVE
81034 + unsigned long call_dl_resolve;
81035 +#endif
81036 +
81037 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
81038 + unsigned long call_syscall;
81039 +#endif
81040 +
81041 +#ifdef CONFIG_PAX_ASLR
81042 + unsigned long delta_mmap; /* randomized offset */
81043 + unsigned long delta_stack; /* randomized offset */
81044 +#endif
81045 +
81046 +} __randomize_layout;
81047
81048 static inline void mm_init_cpumask(struct mm_struct *mm)
81049 {
81050 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
81051 index c5d5278..f0b68c8 100644
81052 --- a/include/linux/mmiotrace.h
81053 +++ b/include/linux/mmiotrace.h
81054 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
81055 /* Called from ioremap.c */
81056 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
81057 void __iomem *addr);
81058 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
81059 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
81060
81061 /* For anyone to insert markers. Remember trailing newline. */
81062 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
81063 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
81064 {
81065 }
81066
81067 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
81068 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
81069 {
81070 }
81071
81072 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
81073 index 835aa3d..676b387 100644
81074 --- a/include/linux/mmzone.h
81075 +++ b/include/linux/mmzone.h
81076 @@ -406,7 +406,7 @@ struct zone {
81077 unsigned long flags; /* zone flags, see below */
81078
81079 /* Zone statistics */
81080 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81081 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81082
81083 /*
81084 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
81085 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
81086 index 44eeef0..a92d3f9 100644
81087 --- a/include/linux/mod_devicetable.h
81088 +++ b/include/linux/mod_devicetable.h
81089 @@ -139,7 +139,7 @@ struct usb_device_id {
81090 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
81091 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
81092
81093 -#define HID_ANY_ID (~0)
81094 +#define HID_ANY_ID (~0U)
81095 #define HID_BUS_ANY 0xffff
81096 #define HID_GROUP_ANY 0x0000
81097
81098 @@ -475,7 +475,7 @@ struct dmi_system_id {
81099 const char *ident;
81100 struct dmi_strmatch matches[4];
81101 void *driver_data;
81102 -};
81103 +} __do_const;
81104 /*
81105 * struct dmi_device_id appears during expansion of
81106 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
81107 diff --git a/include/linux/module.h b/include/linux/module.h
81108 index f520a76..5f898ef 100644
81109 --- a/include/linux/module.h
81110 +++ b/include/linux/module.h
81111 @@ -17,9 +17,11 @@
81112 #include <linux/moduleparam.h>
81113 #include <linux/jump_label.h>
81114 #include <linux/export.h>
81115 +#include <linux/fs.h>
81116
81117 #include <linux/percpu.h>
81118 #include <asm/module.h>
81119 +#include <asm/pgtable.h>
81120
81121 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
81122 #define MODULE_SIG_STRING "~Module signature appended~\n"
81123 @@ -42,7 +44,7 @@ struct module_kobject {
81124 struct kobject *drivers_dir;
81125 struct module_param_attrs *mp;
81126 struct completion *kobj_completion;
81127 -};
81128 +} __randomize_layout;
81129
81130 struct module_attribute {
81131 struct attribute attr;
81132 @@ -54,12 +56,13 @@ struct module_attribute {
81133 int (*test)(struct module *);
81134 void (*free)(struct module *);
81135 };
81136 +typedef struct module_attribute __no_const module_attribute_no_const;
81137
81138 struct module_version_attribute {
81139 struct module_attribute mattr;
81140 const char *module_name;
81141 const char *version;
81142 -} __attribute__ ((__aligned__(sizeof(void *))));
81143 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
81144
81145 extern ssize_t __modver_version_show(struct module_attribute *,
81146 struct module_kobject *, char *);
81147 @@ -235,7 +238,7 @@ struct module {
81148
81149 /* Sysfs stuff. */
81150 struct module_kobject mkobj;
81151 - struct module_attribute *modinfo_attrs;
81152 + module_attribute_no_const *modinfo_attrs;
81153 const char *version;
81154 const char *srcversion;
81155 struct kobject *holders_dir;
81156 @@ -284,19 +287,16 @@ struct module {
81157 int (*init)(void);
81158
81159 /* If this is non-NULL, vfree after init() returns */
81160 - void *module_init;
81161 + void *module_init_rx, *module_init_rw;
81162
81163 /* Here is the actual code + data, vfree'd on unload. */
81164 - void *module_core;
81165 + void *module_core_rx, *module_core_rw;
81166
81167 /* Here are the sizes of the init and core sections */
81168 - unsigned int init_size, core_size;
81169 + unsigned int init_size_rw, core_size_rw;
81170
81171 /* The size of the executable code in each section. */
81172 - unsigned int init_text_size, core_text_size;
81173 -
81174 - /* Size of RO sections of the module (text+rodata) */
81175 - unsigned int init_ro_size, core_ro_size;
81176 + unsigned int init_size_rx, core_size_rx;
81177
81178 /* Arch-specific module values */
81179 struct mod_arch_specific arch;
81180 @@ -352,6 +352,10 @@ struct module {
81181 #ifdef CONFIG_EVENT_TRACING
81182 struct ftrace_event_call **trace_events;
81183 unsigned int num_trace_events;
81184 + struct file_operations trace_id;
81185 + struct file_operations trace_enable;
81186 + struct file_operations trace_format;
81187 + struct file_operations trace_filter;
81188 #endif
81189 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
81190 unsigned int num_ftrace_callsites;
81191 @@ -375,7 +379,7 @@ struct module {
81192 ctor_fn_t *ctors;
81193 unsigned int num_ctors;
81194 #endif
81195 -};
81196 +} __randomize_layout;
81197 #ifndef MODULE_ARCH_INIT
81198 #define MODULE_ARCH_INIT {}
81199 #endif
81200 @@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
81201 bool is_module_percpu_address(unsigned long addr);
81202 bool is_module_text_address(unsigned long addr);
81203
81204 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
81205 +{
81206 +
81207 +#ifdef CONFIG_PAX_KERNEXEC
81208 + if (ktla_ktva(addr) >= (unsigned long)start &&
81209 + ktla_ktva(addr) < (unsigned long)start + size)
81210 + return 1;
81211 +#endif
81212 +
81213 + return ((void *)addr >= start && (void *)addr < start + size);
81214 +}
81215 +
81216 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
81217 +{
81218 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
81219 +}
81220 +
81221 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
81222 +{
81223 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
81224 +}
81225 +
81226 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
81227 +{
81228 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
81229 +}
81230 +
81231 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
81232 +{
81233 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
81234 +}
81235 +
81236 static inline int within_module_core(unsigned long addr, const struct module *mod)
81237 {
81238 - return (unsigned long)mod->module_core <= addr &&
81239 - addr < (unsigned long)mod->module_core + mod->core_size;
81240 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
81241 }
81242
81243 static inline int within_module_init(unsigned long addr, const struct module *mod)
81244 {
81245 - return (unsigned long)mod->module_init <= addr &&
81246 - addr < (unsigned long)mod->module_init + mod->init_size;
81247 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
81248 }
81249
81250 /* Search for module by name: must hold module_mutex. */
81251 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
81252 index 560ca53..ef621ef 100644
81253 --- a/include/linux/moduleloader.h
81254 +++ b/include/linux/moduleloader.h
81255 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
81256 sections. Returns NULL on failure. */
81257 void *module_alloc(unsigned long size);
81258
81259 +#ifdef CONFIG_PAX_KERNEXEC
81260 +void *module_alloc_exec(unsigned long size);
81261 +#else
81262 +#define module_alloc_exec(x) module_alloc(x)
81263 +#endif
81264 +
81265 /* Free memory returned from module_alloc. */
81266 void module_free(struct module *mod, void *module_region);
81267
81268 +#ifdef CONFIG_PAX_KERNEXEC
81269 +void module_free_exec(struct module *mod, void *module_region);
81270 +#else
81271 +#define module_free_exec(x, y) module_free((x), (y))
81272 +#endif
81273 +
81274 /*
81275 * Apply the given relocation to the (simplified) ELF. Return -error
81276 * or 0.
81277 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
81278 unsigned int relsec,
81279 struct module *me)
81280 {
81281 +#ifdef CONFIG_MODULES
81282 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81283 +#endif
81284 return -ENOEXEC;
81285 }
81286 #endif
81287 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
81288 unsigned int relsec,
81289 struct module *me)
81290 {
81291 +#ifdef CONFIG_MODULES
81292 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81293 +#endif
81294 return -ENOEXEC;
81295 }
81296 #endif
81297 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
81298 index 204a677..e9b486a 100644
81299 --- a/include/linux/moduleparam.h
81300 +++ b/include/linux/moduleparam.h
81301 @@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
81302 * @len is usually just sizeof(string).
81303 */
81304 #define module_param_string(name, string, len, perm) \
81305 - static const struct kparam_string __param_string_##name \
81306 + static const struct kparam_string __param_string_##name __used \
81307 = { len, string }; \
81308 __module_param_call(MODULE_PARAM_PREFIX, name, \
81309 &param_ops_string, \
81310 @@ -432,7 +432,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
81311 */
81312 #define module_param_array_named(name, array, type, nump, perm) \
81313 param_check_##type(name, &(array)[0]); \
81314 - static const struct kparam_array __param_arr_##name \
81315 + static const struct kparam_array __param_arr_##name __used \
81316 = { .max = ARRAY_SIZE(array), .num = nump, \
81317 .ops = &param_ops_##type, \
81318 .elemsize = sizeof(array[0]), .elem = array }; \
81319 diff --git a/include/linux/mount.h b/include/linux/mount.h
81320 index 839bac2..a96b37c 100644
81321 --- a/include/linux/mount.h
81322 +++ b/include/linux/mount.h
81323 @@ -59,7 +59,7 @@ struct vfsmount {
81324 struct dentry *mnt_root; /* root of the mounted tree */
81325 struct super_block *mnt_sb; /* pointer to superblock */
81326 int mnt_flags;
81327 -};
81328 +} __randomize_layout;
81329
81330 struct file; /* forward dec */
81331
81332 diff --git a/include/linux/namei.h b/include/linux/namei.h
81333 index 492de72..1bddcd4 100644
81334 --- a/include/linux/namei.h
81335 +++ b/include/linux/namei.h
81336 @@ -19,7 +19,7 @@ struct nameidata {
81337 unsigned seq, m_seq;
81338 int last_type;
81339 unsigned depth;
81340 - char *saved_names[MAX_NESTED_LINKS + 1];
81341 + const char *saved_names[MAX_NESTED_LINKS + 1];
81342 };
81343
81344 /*
81345 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
81346
81347 extern void nd_jump_link(struct nameidata *nd, struct path *path);
81348
81349 -static inline void nd_set_link(struct nameidata *nd, char *path)
81350 +static inline void nd_set_link(struct nameidata *nd, const char *path)
81351 {
81352 nd->saved_names[nd->depth] = path;
81353 }
81354
81355 -static inline char *nd_get_link(struct nameidata *nd)
81356 +static inline const char *nd_get_link(const struct nameidata *nd)
81357 {
81358 return nd->saved_names[nd->depth];
81359 }
81360 diff --git a/include/linux/net.h b/include/linux/net.h
81361 index 17d8339..81656c0 100644
81362 --- a/include/linux/net.h
81363 +++ b/include/linux/net.h
81364 @@ -192,7 +192,7 @@ struct net_proto_family {
81365 int (*create)(struct net *net, struct socket *sock,
81366 int protocol, int kern);
81367 struct module *owner;
81368 -};
81369 +} __do_const;
81370
81371 struct iovec;
81372 struct kvec;
81373 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81374 index b42d07b..7f45ae2 100644
81375 --- a/include/linux/netdevice.h
81376 +++ b/include/linux/netdevice.h
81377 @@ -1146,6 +1146,7 @@ struct net_device_ops {
81378 void *priv);
81379 int (*ndo_get_lock_subclass)(struct net_device *dev);
81380 };
81381 +typedef struct net_device_ops __no_const net_device_ops_no_const;
81382
81383 /**
81384 * enum net_device_priv_flags - &struct net_device priv_flags
81385 @@ -1313,11 +1314,11 @@ struct net_device {
81386 struct net_device_stats stats;
81387
81388 /* dropped packets by core network, Do not use this in drivers */
81389 - atomic_long_t rx_dropped;
81390 - atomic_long_t tx_dropped;
81391 + atomic_long_unchecked_t rx_dropped;
81392 + atomic_long_unchecked_t tx_dropped;
81393
81394 /* Stats to monitor carrier on<->off transitions */
81395 - atomic_t carrier_changes;
81396 + atomic_unchecked_t carrier_changes;
81397
81398 #ifdef CONFIG_WIRELESS_EXT
81399 /* List of functions to handle Wireless Extensions (instead of ioctl).
81400 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81401 index 2077489..a15e561 100644
81402 --- a/include/linux/netfilter.h
81403 +++ b/include/linux/netfilter.h
81404 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81405 #endif
81406 /* Use the module struct to lock set/get code in place */
81407 struct module *owner;
81408 -};
81409 +} __do_const;
81410
81411 /* Function to register/unregister hook points. */
81412 int nf_register_hook(struct nf_hook_ops *reg);
81413 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81414 index e955d47..04a5338 100644
81415 --- a/include/linux/netfilter/nfnetlink.h
81416 +++ b/include/linux/netfilter/nfnetlink.h
81417 @@ -19,7 +19,7 @@ struct nfnl_callback {
81418 const struct nlattr * const cda[]);
81419 const struct nla_policy *policy; /* netlink attribute policy */
81420 const u_int16_t attr_count; /* number of nlattr's */
81421 -};
81422 +} __do_const;
81423
81424 struct nfnetlink_subsystem {
81425 const char *name;
81426 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81427 new file mode 100644
81428 index 0000000..33f4af8
81429 --- /dev/null
81430 +++ b/include/linux/netfilter/xt_gradm.h
81431 @@ -0,0 +1,9 @@
81432 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
81433 +#define _LINUX_NETFILTER_XT_GRADM_H 1
81434 +
81435 +struct xt_gradm_mtinfo {
81436 + __u16 flags;
81437 + __u16 invflags;
81438 +};
81439 +
81440 +#endif
81441 diff --git a/include/linux/nls.h b/include/linux/nls.h
81442 index 520681b..1d67ed2 100644
81443 --- a/include/linux/nls.h
81444 +++ b/include/linux/nls.h
81445 @@ -31,7 +31,7 @@ struct nls_table {
81446 const unsigned char *charset2upper;
81447 struct module *owner;
81448 struct nls_table *next;
81449 -};
81450 +} __do_const;
81451
81452 /* this value hold the maximum octet of charset */
81453 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81454 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81455 index d14a4c3..a078786 100644
81456 --- a/include/linux/notifier.h
81457 +++ b/include/linux/notifier.h
81458 @@ -54,7 +54,8 @@ struct notifier_block {
81459 notifier_fn_t notifier_call;
81460 struct notifier_block __rcu *next;
81461 int priority;
81462 -};
81463 +} __do_const;
81464 +typedef struct notifier_block __no_const notifier_block_no_const;
81465
81466 struct atomic_notifier_head {
81467 spinlock_t lock;
81468 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81469 index b2a0f15..4d7da32 100644
81470 --- a/include/linux/oprofile.h
81471 +++ b/include/linux/oprofile.h
81472 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81473 int oprofilefs_create_ro_ulong(struct dentry * root,
81474 char const * name, ulong * val);
81475
81476 -/** Create a file for read-only access to an atomic_t. */
81477 +/** Create a file for read-only access to an atomic_unchecked_t. */
81478 int oprofilefs_create_ro_atomic(struct dentry * root,
81479 - char const * name, atomic_t * val);
81480 + char const * name, atomic_unchecked_t * val);
81481
81482 /** create a directory */
81483 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81484 diff --git a/include/linux/padata.h b/include/linux/padata.h
81485 index 4386946..f50c615 100644
81486 --- a/include/linux/padata.h
81487 +++ b/include/linux/padata.h
81488 @@ -129,7 +129,7 @@ struct parallel_data {
81489 struct padata_serial_queue __percpu *squeue;
81490 atomic_t reorder_objects;
81491 atomic_t refcnt;
81492 - atomic_t seq_nr;
81493 + atomic_unchecked_t seq_nr;
81494 struct padata_cpumask cpumask;
81495 spinlock_t lock ____cacheline_aligned;
81496 unsigned int processed;
81497 diff --git a/include/linux/path.h b/include/linux/path.h
81498 index d137218..be0c176 100644
81499 --- a/include/linux/path.h
81500 +++ b/include/linux/path.h
81501 @@ -1,13 +1,15 @@
81502 #ifndef _LINUX_PATH_H
81503 #define _LINUX_PATH_H
81504
81505 +#include <linux/compiler.h>
81506 +
81507 struct dentry;
81508 struct vfsmount;
81509
81510 struct path {
81511 struct vfsmount *mnt;
81512 struct dentry *dentry;
81513 -};
81514 +} __randomize_layout;
81515
81516 extern void path_get(const struct path *);
81517 extern void path_put(const struct path *);
81518 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81519 index 5f2e559..7d59314 100644
81520 --- a/include/linux/pci_hotplug.h
81521 +++ b/include/linux/pci_hotplug.h
81522 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81523 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81524 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81525 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81526 -};
81527 +} __do_const;
81528 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81529
81530 /**
81531 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81532 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81533 index 3ef6ea1..ed1a248 100644
81534 --- a/include/linux/perf_event.h
81535 +++ b/include/linux/perf_event.h
81536 @@ -328,8 +328,8 @@ struct perf_event {
81537
81538 enum perf_event_active_state state;
81539 unsigned int attach_state;
81540 - local64_t count;
81541 - atomic64_t child_count;
81542 + local64_t count; /* PaX: fix it one day */
81543 + atomic64_unchecked_t child_count;
81544
81545 /*
81546 * These are the total time in nanoseconds that the event
81547 @@ -380,8 +380,8 @@ struct perf_event {
81548 * These accumulate total time (in nanoseconds) that children
81549 * events have been enabled and running, respectively.
81550 */
81551 - atomic64_t child_total_time_enabled;
81552 - atomic64_t child_total_time_running;
81553 + atomic64_unchecked_t child_total_time_enabled;
81554 + atomic64_unchecked_t child_total_time_running;
81555
81556 /*
81557 * Protect attach/detach and child_list:
81558 @@ -710,7 +710,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81559 entry->ip[entry->nr++] = ip;
81560 }
81561
81562 -extern int sysctl_perf_event_paranoid;
81563 +extern int sysctl_perf_event_legitimately_concerned;
81564 extern int sysctl_perf_event_mlock;
81565 extern int sysctl_perf_event_sample_rate;
81566 extern int sysctl_perf_cpu_time_max_percent;
81567 @@ -725,19 +725,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81568 loff_t *ppos);
81569
81570
81571 +static inline bool perf_paranoid_any(void)
81572 +{
81573 + return sysctl_perf_event_legitimately_concerned > 2;
81574 +}
81575 +
81576 static inline bool perf_paranoid_tracepoint_raw(void)
81577 {
81578 - return sysctl_perf_event_paranoid > -1;
81579 + return sysctl_perf_event_legitimately_concerned > -1;
81580 }
81581
81582 static inline bool perf_paranoid_cpu(void)
81583 {
81584 - return sysctl_perf_event_paranoid > 0;
81585 + return sysctl_perf_event_legitimately_concerned > 0;
81586 }
81587
81588 static inline bool perf_paranoid_kernel(void)
81589 {
81590 - return sysctl_perf_event_paranoid > 1;
81591 + return sysctl_perf_event_legitimately_concerned > 1;
81592 }
81593
81594 extern void perf_event_init(void);
81595 @@ -867,7 +872,7 @@ struct perf_pmu_events_attr {
81596 struct device_attribute attr;
81597 u64 id;
81598 const char *event_str;
81599 -};
81600 +} __do_const;
81601
81602 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81603 static struct perf_pmu_events_attr _var = { \
81604 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81605 index 7246ef3..1539ea4 100644
81606 --- a/include/linux/pid_namespace.h
81607 +++ b/include/linux/pid_namespace.h
81608 @@ -43,7 +43,7 @@ struct pid_namespace {
81609 int hide_pid;
81610 int reboot; /* group exit code if this pidns was rebooted */
81611 unsigned int proc_inum;
81612 -};
81613 +} __randomize_layout;
81614
81615 extern struct pid_namespace init_pid_ns;
81616
81617 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81618 index eb8b8ac..62649e1 100644
81619 --- a/include/linux/pipe_fs_i.h
81620 +++ b/include/linux/pipe_fs_i.h
81621 @@ -47,10 +47,10 @@ struct pipe_inode_info {
81622 struct mutex mutex;
81623 wait_queue_head_t wait;
81624 unsigned int nrbufs, curbuf, buffers;
81625 - unsigned int readers;
81626 - unsigned int writers;
81627 - unsigned int files;
81628 - unsigned int waiting_writers;
81629 + atomic_t readers;
81630 + atomic_t writers;
81631 + atomic_t files;
81632 + atomic_t waiting_writers;
81633 unsigned int r_counter;
81634 unsigned int w_counter;
81635 struct page *tmp_page;
81636 diff --git a/include/linux/pm.h b/include/linux/pm.h
81637 index d915d03..0531037 100644
81638 --- a/include/linux/pm.h
81639 +++ b/include/linux/pm.h
81640 @@ -600,6 +600,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81641 struct dev_pm_domain {
81642 struct dev_pm_ops ops;
81643 };
81644 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81645
81646 /*
81647 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81648 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81649 index 7c1d252..0e7061d 100644
81650 --- a/include/linux/pm_domain.h
81651 +++ b/include/linux/pm_domain.h
81652 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
81653 int (*thaw_early)(struct device *dev);
81654 int (*thaw)(struct device *dev);
81655 bool (*active_wakeup)(struct device *dev);
81656 -};
81657 +} __no_const;
81658
81659 struct gpd_cpu_data {
81660 unsigned int saved_exit_latency;
81661 - struct cpuidle_state *idle_state;
81662 + cpuidle_state_no_const *idle_state;
81663 };
81664
81665 struct generic_pm_domain {
81666 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81667 index 2a5897a..4f9af63 100644
81668 --- a/include/linux/pm_runtime.h
81669 +++ b/include/linux/pm_runtime.h
81670 @@ -113,7 +113,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81671
81672 static inline void pm_runtime_mark_last_busy(struct device *dev)
81673 {
81674 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
81675 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81676 }
81677
81678 #else /* !CONFIG_PM_RUNTIME */
81679 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81680 index 195aafc..49a7bc2 100644
81681 --- a/include/linux/pnp.h
81682 +++ b/include/linux/pnp.h
81683 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81684 struct pnp_fixup {
81685 char id[7];
81686 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81687 -};
81688 +} __do_const;
81689
81690 /* config parameters */
81691 #define PNP_CONFIG_NORMAL 0x0001
81692 diff --git a/include/linux/poison.h b/include/linux/poison.h
81693 index 2110a81..13a11bb 100644
81694 --- a/include/linux/poison.h
81695 +++ b/include/linux/poison.h
81696 @@ -19,8 +19,8 @@
81697 * under normal circumstances, used to verify that nobody uses
81698 * non-initialized list entries.
81699 */
81700 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81701 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81702 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81703 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81704
81705 /********** include/linux/timer.h **********/
81706 /*
81707 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81708 index d8b187c3..9a9257a 100644
81709 --- a/include/linux/power/smartreflex.h
81710 +++ b/include/linux/power/smartreflex.h
81711 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
81712 int (*notify)(struct omap_sr *sr, u32 status);
81713 u8 notify_flags;
81714 u8 class_type;
81715 -};
81716 +} __do_const;
81717
81718 /**
81719 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81720 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81721 index 4ea1d37..80f4b33 100644
81722 --- a/include/linux/ppp-comp.h
81723 +++ b/include/linux/ppp-comp.h
81724 @@ -84,7 +84,7 @@ struct compressor {
81725 struct module *owner;
81726 /* Extra skb space needed by the compressor algorithm */
81727 unsigned int comp_extra;
81728 -};
81729 +} __do_const;
81730
81731 /*
81732 * The return value from decompress routine is the length of the
81733 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81734 index de83b4e..c4b997d 100644
81735 --- a/include/linux/preempt.h
81736 +++ b/include/linux/preempt.h
81737 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81738 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81739 #endif
81740
81741 +#define raw_preempt_count_add(val) __preempt_count_add(val)
81742 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81743 +
81744 #define __preempt_count_inc() __preempt_count_add(1)
81745 #define __preempt_count_dec() __preempt_count_sub(1)
81746
81747 #define preempt_count_inc() preempt_count_add(1)
81748 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
81749 #define preempt_count_dec() preempt_count_sub(1)
81750 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81751
81752 #ifdef CONFIG_PREEMPT_COUNT
81753
81754 @@ -41,6 +46,12 @@ do { \
81755 barrier(); \
81756 } while (0)
81757
81758 +#define raw_preempt_disable() \
81759 +do { \
81760 + raw_preempt_count_inc(); \
81761 + barrier(); \
81762 +} while (0)
81763 +
81764 #define sched_preempt_enable_no_resched() \
81765 do { \
81766 barrier(); \
81767 @@ -49,6 +60,12 @@ do { \
81768
81769 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81770
81771 +#define raw_preempt_enable_no_resched() \
81772 +do { \
81773 + barrier(); \
81774 + raw_preempt_count_dec(); \
81775 +} while (0)
81776 +
81777 #ifdef CONFIG_PREEMPT
81778 #define preempt_enable() \
81779 do { \
81780 @@ -113,8 +130,10 @@ do { \
81781 * region.
81782 */
81783 #define preempt_disable() barrier()
81784 +#define raw_preempt_disable() barrier()
81785 #define sched_preempt_enable_no_resched() barrier()
81786 #define preempt_enable_no_resched() barrier()
81787 +#define raw_preempt_enable_no_resched() barrier()
81788 #define preempt_enable() barrier()
81789 #define preempt_check_resched() do { } while (0)
81790
81791 @@ -128,11 +147,13 @@ do { \
81792 /*
81793 * Modules have no business playing preemption tricks.
81794 */
81795 +#ifndef CONFIG_PAX_KERNEXEC
81796 #undef sched_preempt_enable_no_resched
81797 #undef preempt_enable_no_resched
81798 #undef preempt_enable_no_resched_notrace
81799 #undef preempt_check_resched
81800 #endif
81801 +#endif
81802
81803 #define preempt_set_need_resched() \
81804 do { \
81805 diff --git a/include/linux/printk.h b/include/linux/printk.h
81806 index 8752f75..2b80c0f 100644
81807 --- a/include/linux/printk.h
81808 +++ b/include/linux/printk.h
81809 @@ -110,6 +110,8 @@ static inline __printf(1, 2) __cold
81810 void early_printk(const char *s, ...) { }
81811 #endif
81812
81813 +extern int kptr_restrict;
81814 +
81815 #ifdef CONFIG_PRINTK
81816 asmlinkage __printf(5, 0)
81817 int vprintk_emit(int facility, int level,
81818 @@ -144,7 +146,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81819
81820 extern int printk_delay_msec;
81821 extern int dmesg_restrict;
81822 -extern int kptr_restrict;
81823
81824 extern void wake_up_klogd(void);
81825
81826 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81827 index 608e60a..79cfb18 100644
81828 --- a/include/linux/proc_fs.h
81829 +++ b/include/linux/proc_fs.h
81830 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81831 extern struct proc_dir_entry *proc_symlink(const char *,
81832 struct proc_dir_entry *, const char *);
81833 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81834 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81835 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81836 struct proc_dir_entry *, void *);
81837 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81838 + struct proc_dir_entry *, void *);
81839 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81840 struct proc_dir_entry *);
81841
81842 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81843 return proc_create_data(name, mode, parent, proc_fops, NULL);
81844 }
81845
81846 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81847 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81848 +{
81849 +#ifdef CONFIG_GRKERNSEC_PROC_USER
81850 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81851 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81852 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81853 +#else
81854 + return proc_create_data(name, mode, parent, proc_fops, NULL);
81855 +#endif
81856 +}
81857 +
81858 +
81859 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81860 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81861 extern void *PDE_DATA(const struct inode *);
81862 @@ -52,8 +68,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
81863 struct proc_dir_entry *parent,const char *dest) { return NULL;}
81864 static inline struct proc_dir_entry *proc_mkdir(const char *name,
81865 struct proc_dir_entry *parent) {return NULL;}
81866 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
81867 + struct proc_dir_entry *parent) { return NULL; }
81868 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
81869 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81870 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
81871 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81872 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
81873 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
81874 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
81875 @@ -73,7 +93,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81876 static inline struct proc_dir_entry *proc_net_mkdir(
81877 struct net *net, const char *name, struct proc_dir_entry *parent)
81878 {
81879 - return proc_mkdir_data(name, 0, parent, net);
81880 + return proc_mkdir_data_restrict(name, 0, parent, net);
81881 }
81882
81883 #endif /* _LINUX_PROC_FS_H */
81884 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81885 index 34a1e10..70f6bde 100644
81886 --- a/include/linux/proc_ns.h
81887 +++ b/include/linux/proc_ns.h
81888 @@ -14,7 +14,7 @@ struct proc_ns_operations {
81889 void (*put)(void *ns);
81890 int (*install)(struct nsproxy *nsproxy, void *ns);
81891 unsigned int (*inum)(void *ns);
81892 -};
81893 +} __do_const __randomize_layout;
81894
81895 struct proc_ns {
81896 void *ns;
81897 diff --git a/include/linux/quota.h b/include/linux/quota.h
81898 index cc7494a..1e27036 100644
81899 --- a/include/linux/quota.h
81900 +++ b/include/linux/quota.h
81901 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81902
81903 extern bool qid_eq(struct kqid left, struct kqid right);
81904 extern bool qid_lt(struct kqid left, struct kqid right);
81905 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81906 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81907 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81908 extern bool qid_valid(struct kqid qid);
81909
81910 diff --git a/include/linux/random.h b/include/linux/random.h
81911 index 57fbbff..2331f3f 100644
81912 --- a/include/linux/random.h
81913 +++ b/include/linux/random.h
81914 @@ -9,9 +9,19 @@
81915 #include <uapi/linux/random.h>
81916
81917 extern void add_device_randomness(const void *, unsigned int);
81918 +
81919 +static inline void add_latent_entropy(void)
81920 +{
81921 +
81922 +#ifdef LATENT_ENTROPY_PLUGIN
81923 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81924 +#endif
81925 +
81926 +}
81927 +
81928 extern void add_input_randomness(unsigned int type, unsigned int code,
81929 - unsigned int value);
81930 -extern void add_interrupt_randomness(int irq, int irq_flags);
81931 + unsigned int value) __latent_entropy;
81932 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81933
81934 extern void get_random_bytes(void *buf, int nbytes);
81935 extern void get_random_bytes_arch(void *buf, int nbytes);
81936 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81937 extern const struct file_operations random_fops, urandom_fops;
81938 #endif
81939
81940 -unsigned int get_random_int(void);
81941 +unsigned int __intentional_overflow(-1) get_random_int(void);
81942 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81943
81944 -u32 prandom_u32(void);
81945 +u32 prandom_u32(void) __intentional_overflow(-1);
81946 void prandom_bytes(void *buf, int nbytes);
81947 void prandom_seed(u32 seed);
81948 void prandom_reseed_late(void);
81949 @@ -37,6 +47,11 @@ struct rnd_state {
81950 u32 prandom_u32_state(struct rnd_state *state);
81951 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81952
81953 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81954 +{
81955 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81956 +}
81957 +
81958 /**
81959 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81960 * @ep_ro: right open interval endpoint
81961 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81962 index fea49b5..2ac22bb 100644
81963 --- a/include/linux/rbtree_augmented.h
81964 +++ b/include/linux/rbtree_augmented.h
81965 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81966 old->rbaugmented = rbcompute(old); \
81967 } \
81968 rbstatic const struct rb_augment_callbacks rbname = { \
81969 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81970 + .propagate = rbname ## _propagate, \
81971 + .copy = rbname ## _copy, \
81972 + .rotate = rbname ## _rotate \
81973 };
81974
81975
81976 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81977 index 8183b46..a388711 100644
81978 --- a/include/linux/rculist.h
81979 +++ b/include/linux/rculist.h
81980 @@ -29,8 +29,8 @@
81981 */
81982 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81983 {
81984 - ACCESS_ONCE(list->next) = list;
81985 - ACCESS_ONCE(list->prev) = list;
81986 + ACCESS_ONCE_RW(list->next) = list;
81987 + ACCESS_ONCE_RW(list->prev) = list;
81988 }
81989
81990 /*
81991 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81992 struct list_head *prev, struct list_head *next);
81993 #endif
81994
81995 +void __pax_list_add_rcu(struct list_head *new,
81996 + struct list_head *prev, struct list_head *next);
81997 +
81998 /**
81999 * list_add_rcu - add a new entry to rcu-protected list
82000 * @new: new entry to be added
82001 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
82002 __list_add_rcu(new, head, head->next);
82003 }
82004
82005 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
82006 +{
82007 + __pax_list_add_rcu(new, head, head->next);
82008 +}
82009 +
82010 /**
82011 * list_add_tail_rcu - add a new entry to rcu-protected list
82012 * @new: new entry to be added
82013 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
82014 __list_add_rcu(new, head->prev, head);
82015 }
82016
82017 +static inline void pax_list_add_tail_rcu(struct list_head *new,
82018 + struct list_head *head)
82019 +{
82020 + __pax_list_add_rcu(new, head->prev, head);
82021 +}
82022 +
82023 /**
82024 * list_del_rcu - deletes entry from list without re-initialization
82025 * @entry: the element to delete from the list.
82026 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
82027 entry->prev = LIST_POISON2;
82028 }
82029
82030 +extern void pax_list_del_rcu(struct list_head *entry);
82031 +
82032 /**
82033 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
82034 * @n: the element to delete from the hash list.
82035 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
82036 index 48bf152..d38b785 100644
82037 --- a/include/linux/reboot.h
82038 +++ b/include/linux/reboot.h
82039 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
82040 */
82041
82042 extern void migrate_to_reboot_cpu(void);
82043 -extern void machine_restart(char *cmd);
82044 -extern void machine_halt(void);
82045 -extern void machine_power_off(void);
82046 +extern void machine_restart(char *cmd) __noreturn;
82047 +extern void machine_halt(void) __noreturn;
82048 +extern void machine_power_off(void) __noreturn;
82049
82050 extern void machine_shutdown(void);
82051 struct pt_regs;
82052 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
82053 */
82054
82055 extern void kernel_restart_prepare(char *cmd);
82056 -extern void kernel_restart(char *cmd);
82057 -extern void kernel_halt(void);
82058 -extern void kernel_power_off(void);
82059 +extern void kernel_restart(char *cmd) __noreturn;
82060 +extern void kernel_halt(void) __noreturn;
82061 +extern void kernel_power_off(void) __noreturn;
82062
82063 extern int C_A_D; /* for sysctl */
82064 void ctrl_alt_del(void);
82065 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
82066 * Emergency restart, callable from an interrupt handler.
82067 */
82068
82069 -extern void emergency_restart(void);
82070 +extern void emergency_restart(void) __noreturn;
82071 #include <asm/emergency-restart.h>
82072
82073 #endif /* _LINUX_REBOOT_H */
82074 diff --git a/include/linux/regset.h b/include/linux/regset.h
82075 index 8e0c9fe..ac4d221 100644
82076 --- a/include/linux/regset.h
82077 +++ b/include/linux/regset.h
82078 @@ -161,7 +161,8 @@ struct user_regset {
82079 unsigned int align;
82080 unsigned int bias;
82081 unsigned int core_note_type;
82082 -};
82083 +} __do_const;
82084 +typedef struct user_regset __no_const user_regset_no_const;
82085
82086 /**
82087 * struct user_regset_view - available regsets
82088 diff --git a/include/linux/relay.h b/include/linux/relay.h
82089 index d7c8359..818daf5 100644
82090 --- a/include/linux/relay.h
82091 +++ b/include/linux/relay.h
82092 @@ -157,7 +157,7 @@ struct rchan_callbacks
82093 * The callback should return 0 if successful, negative if not.
82094 */
82095 int (*remove_buf_file)(struct dentry *dentry);
82096 -};
82097 +} __no_const;
82098
82099 /*
82100 * CONFIG_RELAY kernel API, kernel/relay.c
82101 diff --git a/include/linux/rio.h b/include/linux/rio.h
82102 index 6bda06f..bf39a9b 100644
82103 --- a/include/linux/rio.h
82104 +++ b/include/linux/rio.h
82105 @@ -358,7 +358,7 @@ struct rio_ops {
82106 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
82107 u64 rstart, u32 size, u32 flags);
82108 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
82109 -};
82110 +} __no_const;
82111
82112 #define RIO_RESOURCE_MEM 0x00000100
82113 #define RIO_RESOURCE_DOORBELL 0x00000200
82114 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
82115 index b66c211..13d2915 100644
82116 --- a/include/linux/rmap.h
82117 +++ b/include/linux/rmap.h
82118 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
82119 void anon_vma_init(void); /* create anon_vma_cachep */
82120 int anon_vma_prepare(struct vm_area_struct *);
82121 void unlink_anon_vmas(struct vm_area_struct *);
82122 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
82123 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
82124 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
82125 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
82126
82127 static inline void anon_vma_merge(struct vm_area_struct *vma,
82128 struct vm_area_struct *next)
82129 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
82130 index a964f72..b475afb 100644
82131 --- a/include/linux/scatterlist.h
82132 +++ b/include/linux/scatterlist.h
82133 @@ -1,6 +1,7 @@
82134 #ifndef _LINUX_SCATTERLIST_H
82135 #define _LINUX_SCATTERLIST_H
82136
82137 +#include <linux/sched.h>
82138 #include <linux/string.h>
82139 #include <linux/bug.h>
82140 #include <linux/mm.h>
82141 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
82142 #ifdef CONFIG_DEBUG_SG
82143 BUG_ON(!virt_addr_valid(buf));
82144 #endif
82145 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82146 + if (object_starts_on_stack(buf)) {
82147 + void *adjbuf = buf - current->stack + current->lowmem_stack;
82148 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
82149 + } else
82150 +#endif
82151 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
82152 }
82153
82154 diff --git a/include/linux/sched.h b/include/linux/sched.h
82155 index 221b2bd..e2e5f82 100644
82156 --- a/include/linux/sched.h
82157 +++ b/include/linux/sched.h
82158 @@ -131,6 +131,7 @@ struct fs_struct;
82159 struct perf_event_context;
82160 struct blk_plug;
82161 struct filename;
82162 +struct linux_binprm;
82163
82164 #define VMACACHE_BITS 2
82165 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
82166 @@ -380,7 +381,7 @@ extern char __sched_text_start[], __sched_text_end[];
82167 extern int in_sched_functions(unsigned long addr);
82168
82169 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
82170 -extern signed long schedule_timeout(signed long timeout);
82171 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
82172 extern signed long schedule_timeout_interruptible(signed long timeout);
82173 extern signed long schedule_timeout_killable(signed long timeout);
82174 extern signed long schedule_timeout_uninterruptible(signed long timeout);
82175 @@ -391,6 +392,19 @@ struct nsproxy;
82176 struct user_namespace;
82177
82178 #ifdef CONFIG_MMU
82179 +
82180 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82181 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
82182 +#else
82183 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82184 +{
82185 + return 0;
82186 +}
82187 +#endif
82188 +
82189 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
82190 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
82191 +
82192 extern void arch_pick_mmap_layout(struct mm_struct *mm);
82193 extern unsigned long
82194 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
82195 @@ -688,6 +702,17 @@ struct signal_struct {
82196 #ifdef CONFIG_TASKSTATS
82197 struct taskstats *stats;
82198 #endif
82199 +
82200 +#ifdef CONFIG_GRKERNSEC
82201 + u32 curr_ip;
82202 + u32 saved_ip;
82203 + u32 gr_saddr;
82204 + u32 gr_daddr;
82205 + u16 gr_sport;
82206 + u16 gr_dport;
82207 + u8 used_accept:1;
82208 +#endif
82209 +
82210 #ifdef CONFIG_AUDIT
82211 unsigned audit_tty;
82212 unsigned audit_tty_log_passwd;
82213 @@ -714,7 +739,7 @@ struct signal_struct {
82214 struct mutex cred_guard_mutex; /* guard against foreign influences on
82215 * credential calculations
82216 * (notably. ptrace) */
82217 -};
82218 +} __randomize_layout;
82219
82220 /*
82221 * Bits in flags field of signal_struct.
82222 @@ -768,6 +793,14 @@ struct user_struct {
82223 struct key *session_keyring; /* UID's default session keyring */
82224 #endif
82225
82226 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
82227 + unsigned char kernel_banned;
82228 +#endif
82229 +#ifdef CONFIG_GRKERNSEC_BRUTE
82230 + unsigned char suid_banned;
82231 + unsigned long suid_ban_expires;
82232 +#endif
82233 +
82234 /* Hash table maintenance information */
82235 struct hlist_node uidhash_node;
82236 kuid_t uid;
82237 @@ -775,7 +808,7 @@ struct user_struct {
82238 #ifdef CONFIG_PERF_EVENTS
82239 atomic_long_t locked_vm;
82240 #endif
82241 -};
82242 +} __randomize_layout;
82243
82244 extern int uids_sysfs_init(void);
82245
82246 @@ -1179,6 +1212,9 @@ enum perf_event_task_context {
82247 struct task_struct {
82248 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
82249 void *stack;
82250 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82251 + void *lowmem_stack;
82252 +#endif
82253 atomic_t usage;
82254 unsigned int flags; /* per process flags, defined below */
82255 unsigned int ptrace;
82256 @@ -1304,8 +1340,8 @@ struct task_struct {
82257 struct list_head thread_node;
82258
82259 struct completion *vfork_done; /* for vfork() */
82260 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
82261 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82262 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
82263 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82264
82265 cputime_t utime, stime, utimescaled, stimescaled;
82266 cputime_t gtime;
82267 @@ -1330,11 +1366,6 @@ struct task_struct {
82268 struct task_cputime cputime_expires;
82269 struct list_head cpu_timers[3];
82270
82271 -/* process credentials */
82272 - const struct cred __rcu *real_cred; /* objective and real subjective task
82273 - * credentials (COW) */
82274 - const struct cred __rcu *cred; /* effective (overridable) subjective task
82275 - * credentials (COW) */
82276 char comm[TASK_COMM_LEN]; /* executable name excluding path
82277 - access with [gs]et_task_comm (which lock
82278 it with task_lock())
82279 @@ -1351,6 +1382,10 @@ struct task_struct {
82280 #endif
82281 /* CPU-specific state of this task */
82282 struct thread_struct thread;
82283 +/* thread_info moved to task_struct */
82284 +#ifdef CONFIG_X86
82285 + struct thread_info tinfo;
82286 +#endif
82287 /* filesystem information */
82288 struct fs_struct *fs;
82289 /* open file information */
82290 @@ -1427,6 +1462,10 @@ struct task_struct {
82291 gfp_t lockdep_reclaim_gfp;
82292 #endif
82293
82294 +/* process credentials */
82295 + const struct cred __rcu *real_cred; /* objective and real subjective task
82296 + * credentials (COW) */
82297 +
82298 /* journalling filesystem info */
82299 void *journal_info;
82300
82301 @@ -1465,6 +1504,10 @@ struct task_struct {
82302 /* cg_list protected by css_set_lock and tsk->alloc_lock */
82303 struct list_head cg_list;
82304 #endif
82305 +
82306 + const struct cred __rcu *cred; /* effective (overridable) subjective task
82307 + * credentials (COW) */
82308 +
82309 #ifdef CONFIG_FUTEX
82310 struct robust_list_head __user *robust_list;
82311 #ifdef CONFIG_COMPAT
82312 @@ -1610,7 +1653,78 @@ struct task_struct {
82313 unsigned int sequential_io;
82314 unsigned int sequential_io_avg;
82315 #endif
82316 -};
82317 +
82318 +#ifdef CONFIG_GRKERNSEC
82319 + /* grsecurity */
82320 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82321 + u64 exec_id;
82322 +#endif
82323 +#ifdef CONFIG_GRKERNSEC_SETXID
82324 + const struct cred *delayed_cred;
82325 +#endif
82326 + struct dentry *gr_chroot_dentry;
82327 + struct acl_subject_label *acl;
82328 + struct acl_subject_label *tmpacl;
82329 + struct acl_role_label *role;
82330 + struct file *exec_file;
82331 + unsigned long brute_expires;
82332 + u16 acl_role_id;
82333 + u8 inherited;
82334 + /* is this the task that authenticated to the special role */
82335 + u8 acl_sp_role;
82336 + u8 is_writable;
82337 + u8 brute;
82338 + u8 gr_is_chrooted;
82339 +#endif
82340 +
82341 +} __randomize_layout;
82342 +
82343 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
82344 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
82345 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
82346 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
82347 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
82348 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
82349 +
82350 +#ifdef CONFIG_PAX_SOFTMODE
82351 +extern int pax_softmode;
82352 +#endif
82353 +
82354 +extern int pax_check_flags(unsigned long *);
82355 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
82356 +
82357 +/* if tsk != current then task_lock must be held on it */
82358 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
82359 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
82360 +{
82361 + if (likely(tsk->mm))
82362 + return tsk->mm->pax_flags;
82363 + else
82364 + return 0UL;
82365 +}
82366 +
82367 +/* if tsk != current then task_lock must be held on it */
82368 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82369 +{
82370 + if (likely(tsk->mm)) {
82371 + tsk->mm->pax_flags = flags;
82372 + return 0;
82373 + }
82374 + return -EINVAL;
82375 +}
82376 +#endif
82377 +
82378 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82379 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
82380 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82381 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82382 +#endif
82383 +
82384 +struct path;
82385 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82386 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82387 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82388 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
82389
82390 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82391 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82392 @@ -1692,7 +1806,7 @@ struct pid_namespace;
82393 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82394 struct pid_namespace *ns);
82395
82396 -static inline pid_t task_pid_nr(struct task_struct *tsk)
82397 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
82398 {
82399 return tsk->pid;
82400 }
82401 @@ -2039,6 +2153,25 @@ extern u64 sched_clock_cpu(int cpu);
82402
82403 extern void sched_clock_init(void);
82404
82405 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82406 +static inline void populate_stack(void)
82407 +{
82408 + struct task_struct *curtask = current;
82409 + int c;
82410 + int *ptr = curtask->stack;
82411 + int *end = curtask->stack + THREAD_SIZE;
82412 +
82413 + while (ptr < end) {
82414 + c = *(volatile int *)ptr;
82415 + ptr += PAGE_SIZE/sizeof(int);
82416 + }
82417 +}
82418 +#else
82419 +static inline void populate_stack(void)
82420 +{
82421 +}
82422 +#endif
82423 +
82424 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
82425 static inline void sched_clock_tick(void)
82426 {
82427 @@ -2172,7 +2305,9 @@ void yield(void);
82428 extern struct exec_domain default_exec_domain;
82429
82430 union thread_union {
82431 +#ifndef CONFIG_X86
82432 struct thread_info thread_info;
82433 +#endif
82434 unsigned long stack[THREAD_SIZE/sizeof(long)];
82435 };
82436
82437 @@ -2205,6 +2340,7 @@ extern struct pid_namespace init_pid_ns;
82438 */
82439
82440 extern struct task_struct *find_task_by_vpid(pid_t nr);
82441 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82442 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82443 struct pid_namespace *ns);
82444
82445 @@ -2367,7 +2503,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82446 extern void exit_itimers(struct signal_struct *);
82447 extern void flush_itimer_signals(void);
82448
82449 -extern void do_group_exit(int);
82450 +extern __noreturn void do_group_exit(int);
82451
82452 extern int allow_signal(int);
82453 extern int disallow_signal(int);
82454 @@ -2568,9 +2704,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82455
82456 #endif
82457
82458 -static inline int object_is_on_stack(void *obj)
82459 +static inline int object_starts_on_stack(const void *obj)
82460 {
82461 - void *stack = task_stack_page(current);
82462 + const void *stack = task_stack_page(current);
82463
82464 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82465 }
82466 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82467 index 8045a55..c959cd5 100644
82468 --- a/include/linux/sched/sysctl.h
82469 +++ b/include/linux/sched/sysctl.h
82470 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82471 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82472
82473 extern int sysctl_max_map_count;
82474 +extern unsigned long sysctl_heap_stack_gap;
82475
82476 extern unsigned int sysctl_sched_latency;
82477 extern unsigned int sysctl_sched_min_granularity;
82478 diff --git a/include/linux/security.h b/include/linux/security.h
82479 index 6478ce3..5e6ad6e 100644
82480 --- a/include/linux/security.h
82481 +++ b/include/linux/security.h
82482 @@ -27,6 +27,7 @@
82483 #include <linux/slab.h>
82484 #include <linux/err.h>
82485 #include <linux/string.h>
82486 +#include <linux/grsecurity.h>
82487
82488 struct linux_binprm;
82489 struct cred;
82490 @@ -116,8 +117,6 @@ struct seq_file;
82491
82492 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82493
82494 -void reset_security_ops(void);
82495 -
82496 #ifdef CONFIG_MMU
82497 extern unsigned long mmap_min_addr;
82498 extern unsigned long dac_mmap_min_addr;
82499 @@ -1719,7 +1718,7 @@ struct security_operations {
82500 struct audit_context *actx);
82501 void (*audit_rule_free) (void *lsmrule);
82502 #endif /* CONFIG_AUDIT */
82503 -};
82504 +} __randomize_layout;
82505
82506 /* prototypes */
82507 extern int security_init(void);
82508 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82509 index dc368b8..e895209 100644
82510 --- a/include/linux/semaphore.h
82511 +++ b/include/linux/semaphore.h
82512 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82513 }
82514
82515 extern void down(struct semaphore *sem);
82516 -extern int __must_check down_interruptible(struct semaphore *sem);
82517 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82518 extern int __must_check down_killable(struct semaphore *sem);
82519 extern int __must_check down_trylock(struct semaphore *sem);
82520 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82521 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82522 index 52e0097..383f21d 100644
82523 --- a/include/linux/seq_file.h
82524 +++ b/include/linux/seq_file.h
82525 @@ -27,6 +27,9 @@ struct seq_file {
82526 struct mutex lock;
82527 const struct seq_operations *op;
82528 int poll_event;
82529 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82530 + u64 exec_id;
82531 +#endif
82532 #ifdef CONFIG_USER_NS
82533 struct user_namespace *user_ns;
82534 #endif
82535 @@ -39,6 +42,7 @@ struct seq_operations {
82536 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82537 int (*show) (struct seq_file *m, void *v);
82538 };
82539 +typedef struct seq_operations __no_const seq_operations_no_const;
82540
82541 #define SEQ_SKIP 1
82542
82543 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82544
82545 char *mangle_path(char *s, const char *p, const char *esc);
82546 int seq_open(struct file *, const struct seq_operations *);
82547 +int seq_open_restrict(struct file *, const struct seq_operations *);
82548 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82549 loff_t seq_lseek(struct file *, loff_t, int);
82550 int seq_release(struct inode *, struct file *);
82551 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82552 }
82553
82554 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82555 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82556 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82557 int single_release(struct inode *, struct file *);
82558 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82559 diff --git a/include/linux/shm.h b/include/linux/shm.h
82560 index 1e2cd2e..0288750 100644
82561 --- a/include/linux/shm.h
82562 +++ b/include/linux/shm.h
82563 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82564
82565 /* The task created the shm object. NULL if the task is dead. */
82566 struct task_struct *shm_creator;
82567 +#ifdef CONFIG_GRKERNSEC
82568 + time_t shm_createtime;
82569 + pid_t shm_lapid;
82570 +#endif
82571 };
82572
82573 /* shm_mode upper byte flags */
82574 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82575 index 08074a8..e2ae280 100644
82576 --- a/include/linux/skbuff.h
82577 +++ b/include/linux/skbuff.h
82578 @@ -717,7 +717,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82579 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82580 int node);
82581 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82582 -static inline struct sk_buff *alloc_skb(unsigned int size,
82583 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82584 gfp_t priority)
82585 {
82586 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82587 @@ -1825,7 +1825,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82588 return skb->inner_transport_header - skb->inner_network_header;
82589 }
82590
82591 -static inline int skb_network_offset(const struct sk_buff *skb)
82592 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82593 {
82594 return skb_network_header(skb) - skb->data;
82595 }
82596 @@ -1885,7 +1885,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82597 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82598 */
82599 #ifndef NET_SKB_PAD
82600 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82601 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82602 #endif
82603
82604 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82605 @@ -2484,7 +2484,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82606 int *err);
82607 unsigned int datagram_poll(struct file *file, struct socket *sock,
82608 struct poll_table_struct *wait);
82609 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82610 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82611 struct iovec *to, int size);
82612 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82613 struct iovec *iov);
82614 @@ -2776,6 +2776,9 @@ static inline void nf_reset(struct sk_buff *skb)
82615 nf_bridge_put(skb->nf_bridge);
82616 skb->nf_bridge = NULL;
82617 #endif
82618 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82619 + skb->nf_trace = 0;
82620 +#endif
82621 }
82622
82623 static inline void nf_reset_trace(struct sk_buff *skb)
82624 diff --git a/include/linux/slab.h b/include/linux/slab.h
82625 index 307bfbe..a999cf3 100644
82626 --- a/include/linux/slab.h
82627 +++ b/include/linux/slab.h
82628 @@ -14,15 +14,29 @@
82629 #include <linux/gfp.h>
82630 #include <linux/types.h>
82631 #include <linux/workqueue.h>
82632 -
82633 +#include <linux/err.h>
82634
82635 /*
82636 * Flags to pass to kmem_cache_create().
82637 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82638 */
82639 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82640 +
82641 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82642 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82643 +#else
82644 +#define SLAB_USERCOPY 0x00000000UL
82645 +#endif
82646 +
82647 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82648 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82649 +
82650 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
82651 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82652 +#else
82653 +#define SLAB_NO_SANITIZE 0x00000000UL
82654 +#endif
82655 +
82656 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82657 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82658 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82659 @@ -98,10 +112,13 @@
82660 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82661 * Both make kfree a no-op.
82662 */
82663 -#define ZERO_SIZE_PTR ((void *)16)
82664 +#define ZERO_SIZE_PTR \
82665 +({ \
82666 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82667 + (void *)(-MAX_ERRNO-1L); \
82668 +})
82669
82670 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82671 - (unsigned long)ZERO_SIZE_PTR)
82672 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82673
82674 #include <linux/kmemleak.h>
82675
82676 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82677 void kfree(const void *);
82678 void kzfree(const void *);
82679 size_t ksize(const void *);
82680 +const char *check_heap_object(const void *ptr, unsigned long n);
82681 +bool is_usercopy_object(const void *ptr);
82682
82683 /*
82684 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82685 @@ -174,7 +193,7 @@ struct kmem_cache {
82686 unsigned int align; /* Alignment as calculated */
82687 unsigned long flags; /* Active flags on the slab */
82688 const char *name; /* Slab name for sysfs */
82689 - int refcount; /* Use counter */
82690 + atomic_t refcount; /* Use counter */
82691 void (*ctor)(void *); /* Called on object slot creation */
82692 struct list_head list; /* List of all slab caches on the system */
82693 };
82694 @@ -259,6 +278,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82695 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82696 #endif
82697
82698 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82699 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82700 +#endif
82701 +
82702 /*
82703 * Figure out which kmalloc slab an allocation of a certain size
82704 * belongs to.
82705 @@ -267,7 +290,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82706 * 2 = 120 .. 192 bytes
82707 * n = 2^(n-1) .. 2^n -1
82708 */
82709 -static __always_inline int kmalloc_index(size_t size)
82710 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82711 {
82712 if (!size)
82713 return 0;
82714 @@ -310,11 +333,11 @@ static __always_inline int kmalloc_index(size_t size)
82715 }
82716 #endif /* !CONFIG_SLOB */
82717
82718 -void *__kmalloc(size_t size, gfp_t flags);
82719 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82720 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82721
82722 #ifdef CONFIG_NUMA
82723 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
82724 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82725 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82726 #else
82727 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82728 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82729 index 8235dfb..47ce586 100644
82730 --- a/include/linux/slab_def.h
82731 +++ b/include/linux/slab_def.h
82732 @@ -38,7 +38,7 @@ struct kmem_cache {
82733 /* 4) cache creation/removal */
82734 const char *name;
82735 struct list_head list;
82736 - int refcount;
82737 + atomic_t refcount;
82738 int object_size;
82739 int align;
82740
82741 @@ -54,10 +54,14 @@ struct kmem_cache {
82742 unsigned long node_allocs;
82743 unsigned long node_frees;
82744 unsigned long node_overflow;
82745 - atomic_t allochit;
82746 - atomic_t allocmiss;
82747 - atomic_t freehit;
82748 - atomic_t freemiss;
82749 + atomic_unchecked_t allochit;
82750 + atomic_unchecked_t allocmiss;
82751 + atomic_unchecked_t freehit;
82752 + atomic_unchecked_t freemiss;
82753 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
82754 + atomic_unchecked_t sanitized;
82755 + atomic_unchecked_t not_sanitized;
82756 +#endif
82757
82758 /*
82759 * If debugging is enabled, then the allocator can add additional
82760 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82761 index d82abd4..408c3a0 100644
82762 --- a/include/linux/slub_def.h
82763 +++ b/include/linux/slub_def.h
82764 @@ -74,7 +74,7 @@ struct kmem_cache {
82765 struct kmem_cache_order_objects max;
82766 struct kmem_cache_order_objects min;
82767 gfp_t allocflags; /* gfp flags to use on each alloc */
82768 - int refcount; /* Refcount for slab cache destroy */
82769 + atomic_t refcount; /* Refcount for slab cache destroy */
82770 void (*ctor)(void *);
82771 int inuse; /* Offset to metadata */
82772 int align; /* Alignment */
82773 diff --git a/include/linux/smp.h b/include/linux/smp.h
82774 index 633f5ed..6c3dc3f 100644
82775 --- a/include/linux/smp.h
82776 +++ b/include/linux/smp.h
82777 @@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
82778 #endif
82779
82780 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82781 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82782 #define put_cpu() preempt_enable()
82783 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82784
82785 /*
82786 * Callback to arch code if there's nosmp or maxcpus=0 on the
82787 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82788 index 46cca4c..3323536 100644
82789 --- a/include/linux/sock_diag.h
82790 +++ b/include/linux/sock_diag.h
82791 @@ -11,7 +11,7 @@ struct sock;
82792 struct sock_diag_handler {
82793 __u8 family;
82794 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82795 -};
82796 +} __do_const;
82797
82798 int sock_diag_register(const struct sock_diag_handler *h);
82799 void sock_diag_unregister(const struct sock_diag_handler *h);
82800 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82801 index 680f9a3..f13aeb0 100644
82802 --- a/include/linux/sonet.h
82803 +++ b/include/linux/sonet.h
82804 @@ -7,7 +7,7 @@
82805 #include <uapi/linux/sonet.h>
82806
82807 struct k_sonet_stats {
82808 -#define __HANDLE_ITEM(i) atomic_t i
82809 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
82810 __SONET_ITEMS
82811 #undef __HANDLE_ITEM
82812 };
82813 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82814 index 07d8e53..dc934c9 100644
82815 --- a/include/linux/sunrpc/addr.h
82816 +++ b/include/linux/sunrpc/addr.h
82817 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82818 {
82819 switch (sap->sa_family) {
82820 case AF_INET:
82821 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
82822 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82823 case AF_INET6:
82824 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82825 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82826 }
82827 return 0;
82828 }
82829 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82830 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82831 const struct sockaddr *src)
82832 {
82833 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82834 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82835 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82836
82837 dsin->sin_family = ssin->sin_family;
82838 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82839 if (sa->sa_family != AF_INET6)
82840 return 0;
82841
82842 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82843 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82844 }
82845
82846 #endif /* _LINUX_SUNRPC_ADDR_H */
82847 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82848 index 70736b9..37f33db 100644
82849 --- a/include/linux/sunrpc/clnt.h
82850 +++ b/include/linux/sunrpc/clnt.h
82851 @@ -97,7 +97,7 @@ struct rpc_procinfo {
82852 unsigned int p_timer; /* Which RTT timer to use */
82853 u32 p_statidx; /* Which procedure to account */
82854 const char * p_name; /* name of procedure */
82855 -};
82856 +} __do_const;
82857
82858 #ifdef __KERNEL__
82859
82860 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82861 index 04e7632..2e2a8a3 100644
82862 --- a/include/linux/sunrpc/svc.h
82863 +++ b/include/linux/sunrpc/svc.h
82864 @@ -412,7 +412,7 @@ struct svc_procedure {
82865 unsigned int pc_count; /* call count */
82866 unsigned int pc_cachetype; /* cache info (NFS) */
82867 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82868 -};
82869 +} __do_const;
82870
82871 /*
82872 * Function prototypes.
82873 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82874 index 0b8e3e6..33e0a01 100644
82875 --- a/include/linux/sunrpc/svc_rdma.h
82876 +++ b/include/linux/sunrpc/svc_rdma.h
82877 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82878 extern unsigned int svcrdma_max_requests;
82879 extern unsigned int svcrdma_max_req_size;
82880
82881 -extern atomic_t rdma_stat_recv;
82882 -extern atomic_t rdma_stat_read;
82883 -extern atomic_t rdma_stat_write;
82884 -extern atomic_t rdma_stat_sq_starve;
82885 -extern atomic_t rdma_stat_rq_starve;
82886 -extern atomic_t rdma_stat_rq_poll;
82887 -extern atomic_t rdma_stat_rq_prod;
82888 -extern atomic_t rdma_stat_sq_poll;
82889 -extern atomic_t rdma_stat_sq_prod;
82890 +extern atomic_unchecked_t rdma_stat_recv;
82891 +extern atomic_unchecked_t rdma_stat_read;
82892 +extern atomic_unchecked_t rdma_stat_write;
82893 +extern atomic_unchecked_t rdma_stat_sq_starve;
82894 +extern atomic_unchecked_t rdma_stat_rq_starve;
82895 +extern atomic_unchecked_t rdma_stat_rq_poll;
82896 +extern atomic_unchecked_t rdma_stat_rq_prod;
82897 +extern atomic_unchecked_t rdma_stat_sq_poll;
82898 +extern atomic_unchecked_t rdma_stat_sq_prod;
82899
82900 #define RPCRDMA_VERSION 1
82901
82902 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82903 index 8d71d65..f79586e 100644
82904 --- a/include/linux/sunrpc/svcauth.h
82905 +++ b/include/linux/sunrpc/svcauth.h
82906 @@ -120,7 +120,7 @@ struct auth_ops {
82907 int (*release)(struct svc_rqst *rq);
82908 void (*domain_release)(struct auth_domain *);
82909 int (*set_client)(struct svc_rqst *rq);
82910 -};
82911 +} __do_const;
82912
82913 #define SVC_GARBAGE 1
82914 #define SVC_SYSERR 2
82915 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82916 index a5ffd32..0935dea 100644
82917 --- a/include/linux/swiotlb.h
82918 +++ b/include/linux/swiotlb.h
82919 @@ -60,7 +60,8 @@ extern void
82920
82921 extern void
82922 swiotlb_free_coherent(struct device *hwdev, size_t size,
82923 - void *vaddr, dma_addr_t dma_handle);
82924 + void *vaddr, dma_addr_t dma_handle,
82925 + struct dma_attrs *attrs);
82926
82927 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82928 unsigned long offset, size_t size,
82929 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82930 index a4a0588..752870e 100644
82931 --- a/include/linux/syscalls.h
82932 +++ b/include/linux/syscalls.h
82933 @@ -98,10 +98,16 @@ struct sigaltstack;
82934 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82935
82936 #define __SC_DECL(t, a) t a
82937 +#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))
82938 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
82939 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
82940 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82941 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82942 +#define __SC_LONG(t, a) __typeof( \
82943 + __builtin_choose_expr( \
82944 + sizeof(t) > sizeof(int), \
82945 + (t) 0, \
82946 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82947 + )) a
82948 #define __SC_CAST(t, a) (t) a
82949 #define __SC_ARGS(t, a) a
82950 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82951 @@ -379,11 +385,11 @@ asmlinkage long sys_sync(void);
82952 asmlinkage long sys_fsync(unsigned int fd);
82953 asmlinkage long sys_fdatasync(unsigned int fd);
82954 asmlinkage long sys_bdflush(int func, long data);
82955 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82956 - char __user *type, unsigned long flags,
82957 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82958 + const char __user *type, unsigned long flags,
82959 void __user *data);
82960 -asmlinkage long sys_umount(char __user *name, int flags);
82961 -asmlinkage long sys_oldumount(char __user *name);
82962 +asmlinkage long sys_umount(const char __user *name, int flags);
82963 +asmlinkage long sys_oldumount(const char __user *name);
82964 asmlinkage long sys_truncate(const char __user *path, long length);
82965 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82966 asmlinkage long sys_stat(const char __user *filename,
82967 @@ -595,7 +601,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82968 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82969 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82970 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82971 - struct sockaddr __user *, int);
82972 + struct sockaddr __user *, int) __intentional_overflow(0);
82973 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82974 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82975 unsigned int vlen, unsigned flags);
82976 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82977 index 27b3b0b..e093dd9 100644
82978 --- a/include/linux/syscore_ops.h
82979 +++ b/include/linux/syscore_ops.h
82980 @@ -16,7 +16,7 @@ struct syscore_ops {
82981 int (*suspend)(void);
82982 void (*resume)(void);
82983 void (*shutdown)(void);
82984 -};
82985 +} __do_const;
82986
82987 extern void register_syscore_ops(struct syscore_ops *ops);
82988 extern void unregister_syscore_ops(struct syscore_ops *ops);
82989 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82990 index 14a8ff2..fa95f3a 100644
82991 --- a/include/linux/sysctl.h
82992 +++ b/include/linux/sysctl.h
82993 @@ -34,13 +34,13 @@ struct ctl_table_root;
82994 struct ctl_table_header;
82995 struct ctl_dir;
82996
82997 -typedef struct ctl_table ctl_table;
82998 -
82999 typedef int proc_handler (struct ctl_table *ctl, int write,
83000 void __user *buffer, size_t *lenp, loff_t *ppos);
83001
83002 extern int proc_dostring(struct ctl_table *, int,
83003 void __user *, size_t *, loff_t *);
83004 +extern int proc_dostring_modpriv(struct ctl_table *, int,
83005 + void __user *, size_t *, loff_t *);
83006 extern int proc_dointvec(struct ctl_table *, int,
83007 void __user *, size_t *, loff_t *);
83008 extern int proc_dointvec_minmax(struct ctl_table *, int,
83009 @@ -115,7 +115,9 @@ struct ctl_table
83010 struct ctl_table_poll *poll;
83011 void *extra1;
83012 void *extra2;
83013 -};
83014 +} __do_const __randomize_layout;
83015 +typedef struct ctl_table __no_const ctl_table_no_const;
83016 +typedef struct ctl_table ctl_table;
83017
83018 struct ctl_node {
83019 struct rb_node node;
83020 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
83021 index 5ffaa34..fe3e31c 100644
83022 --- a/include/linux/sysfs.h
83023 +++ b/include/linux/sysfs.h
83024 @@ -34,7 +34,8 @@ struct attribute {
83025 struct lock_class_key *key;
83026 struct lock_class_key skey;
83027 #endif
83028 -};
83029 +} __do_const;
83030 +typedef struct attribute __no_const attribute_no_const;
83031
83032 /**
83033 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
83034 @@ -63,7 +64,8 @@ struct attribute_group {
83035 struct attribute *, int);
83036 struct attribute **attrs;
83037 struct bin_attribute **bin_attrs;
83038 -};
83039 +} __do_const;
83040 +typedef struct attribute_group __no_const attribute_group_no_const;
83041
83042 /**
83043 * Use these macros to make defining attributes easier. See include/linux/device.h
83044 @@ -128,7 +130,8 @@ struct bin_attribute {
83045 char *, loff_t, size_t);
83046 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
83047 struct vm_area_struct *vma);
83048 -};
83049 +} __do_const;
83050 +typedef struct bin_attribute __no_const bin_attribute_no_const;
83051
83052 /**
83053 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
83054 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
83055 index 387fa7d..3fcde6b 100644
83056 --- a/include/linux/sysrq.h
83057 +++ b/include/linux/sysrq.h
83058 @@ -16,6 +16,7 @@
83059
83060 #include <linux/errno.h>
83061 #include <linux/types.h>
83062 +#include <linux/compiler.h>
83063
83064 /* Possible values of bitmask for enabling sysrq functions */
83065 /* 0x0001 is reserved for enable everything */
83066 @@ -33,7 +34,7 @@ struct sysrq_key_op {
83067 char *help_msg;
83068 char *action_msg;
83069 int enable_mask;
83070 -};
83071 +} __do_const;
83072
83073 #ifdef CONFIG_MAGIC_SYSRQ
83074
83075 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
83076 index fddbe20..a0e76ab 100644
83077 --- a/include/linux/thread_info.h
83078 +++ b/include/linux/thread_info.h
83079 @@ -161,6 +161,13 @@ static inline bool test_and_clear_restore_sigmask(void)
83080 #error "no set_restore_sigmask() provided and default one won't work"
83081 #endif
83082
83083 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
83084 +
83085 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
83086 +{
83087 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
83088 +}
83089 +
83090 #endif /* __KERNEL__ */
83091
83092 #endif /* _LINUX_THREAD_INFO_H */
83093 diff --git a/include/linux/tty.h b/include/linux/tty.h
83094 index 1c3316a..ae83b9f 100644
83095 --- a/include/linux/tty.h
83096 +++ b/include/linux/tty.h
83097 @@ -202,7 +202,7 @@ struct tty_port {
83098 const struct tty_port_operations *ops; /* Port operations */
83099 spinlock_t lock; /* Lock protecting tty field */
83100 int blocked_open; /* Waiting to open */
83101 - int count; /* Usage count */
83102 + atomic_t count; /* Usage count */
83103 wait_queue_head_t open_wait; /* Open waiters */
83104 wait_queue_head_t close_wait; /* Close waiters */
83105 wait_queue_head_t delta_msr_wait; /* Modem status change */
83106 @@ -284,7 +284,7 @@ struct tty_struct {
83107 /* If the tty has a pending do_SAK, queue it here - akpm */
83108 struct work_struct SAK_work;
83109 struct tty_port *port;
83110 -};
83111 +} __randomize_layout;
83112
83113 /* Each of a tty's open files has private_data pointing to tty_file_private */
83114 struct tty_file_private {
83115 @@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
83116 struct tty_struct *tty, struct file *filp);
83117 static inline int tty_port_users(struct tty_port *port)
83118 {
83119 - return port->count + port->blocked_open;
83120 + return atomic_read(&port->count) + port->blocked_open;
83121 }
83122
83123 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
83124 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
83125 index 756a609..89db85e 100644
83126 --- a/include/linux/tty_driver.h
83127 +++ b/include/linux/tty_driver.h
83128 @@ -285,7 +285,7 @@ struct tty_operations {
83129 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
83130 #endif
83131 const struct file_operations *proc_fops;
83132 -};
83133 +} __do_const __randomize_layout;
83134
83135 struct tty_driver {
83136 int magic; /* magic number for this structure */
83137 @@ -319,7 +319,7 @@ struct tty_driver {
83138
83139 const struct tty_operations *ops;
83140 struct list_head tty_drivers;
83141 -};
83142 +} __randomize_layout;
83143
83144 extern struct list_head tty_drivers;
83145
83146 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
83147 index add26da..22c00bef 100644
83148 --- a/include/linux/tty_ldisc.h
83149 +++ b/include/linux/tty_ldisc.h
83150 @@ -212,7 +212,7 @@ struct tty_ldisc_ops {
83151
83152 struct module *owner;
83153
83154 - int refcount;
83155 + atomic_t refcount;
83156 };
83157
83158 struct tty_ldisc {
83159 diff --git a/include/linux/types.h b/include/linux/types.h
83160 index 4d118ba..c3ee9bf 100644
83161 --- a/include/linux/types.h
83162 +++ b/include/linux/types.h
83163 @@ -176,10 +176,26 @@ typedef struct {
83164 int counter;
83165 } atomic_t;
83166
83167 +#ifdef CONFIG_PAX_REFCOUNT
83168 +typedef struct {
83169 + int counter;
83170 +} atomic_unchecked_t;
83171 +#else
83172 +typedef atomic_t atomic_unchecked_t;
83173 +#endif
83174 +
83175 #ifdef CONFIG_64BIT
83176 typedef struct {
83177 long counter;
83178 } atomic64_t;
83179 +
83180 +#ifdef CONFIG_PAX_REFCOUNT
83181 +typedef struct {
83182 + long counter;
83183 +} atomic64_unchecked_t;
83184 +#else
83185 +typedef atomic64_t atomic64_unchecked_t;
83186 +#endif
83187 #endif
83188
83189 struct list_head {
83190 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
83191 index ecd3319..8a36ded 100644
83192 --- a/include/linux/uaccess.h
83193 +++ b/include/linux/uaccess.h
83194 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
83195 long ret; \
83196 mm_segment_t old_fs = get_fs(); \
83197 \
83198 - set_fs(KERNEL_DS); \
83199 pagefault_disable(); \
83200 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
83201 - pagefault_enable(); \
83202 + set_fs(KERNEL_DS); \
83203 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
83204 set_fs(old_fs); \
83205 + pagefault_enable(); \
83206 ret; \
83207 })
83208
83209 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
83210 index 2d1f9b6..d7a9fce 100644
83211 --- a/include/linux/uidgid.h
83212 +++ b/include/linux/uidgid.h
83213 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
83214
83215 #endif /* CONFIG_USER_NS */
83216
83217 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
83218 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
83219 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
83220 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
83221 +
83222 #endif /* _LINUX_UIDGID_H */
83223 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
83224 index 99c1b4d..562e6f3 100644
83225 --- a/include/linux/unaligned/access_ok.h
83226 +++ b/include/linux/unaligned/access_ok.h
83227 @@ -4,34 +4,34 @@
83228 #include <linux/kernel.h>
83229 #include <asm/byteorder.h>
83230
83231 -static inline u16 get_unaligned_le16(const void *p)
83232 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
83233 {
83234 - return le16_to_cpup((__le16 *)p);
83235 + return le16_to_cpup((const __le16 *)p);
83236 }
83237
83238 -static inline u32 get_unaligned_le32(const void *p)
83239 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
83240 {
83241 - return le32_to_cpup((__le32 *)p);
83242 + return le32_to_cpup((const __le32 *)p);
83243 }
83244
83245 -static inline u64 get_unaligned_le64(const void *p)
83246 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
83247 {
83248 - return le64_to_cpup((__le64 *)p);
83249 + return le64_to_cpup((const __le64 *)p);
83250 }
83251
83252 -static inline u16 get_unaligned_be16(const void *p)
83253 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
83254 {
83255 - return be16_to_cpup((__be16 *)p);
83256 + return be16_to_cpup((const __be16 *)p);
83257 }
83258
83259 -static inline u32 get_unaligned_be32(const void *p)
83260 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
83261 {
83262 - return be32_to_cpup((__be32 *)p);
83263 + return be32_to_cpup((const __be32 *)p);
83264 }
83265
83266 -static inline u64 get_unaligned_be64(const void *p)
83267 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
83268 {
83269 - return be64_to_cpup((__be64 *)p);
83270 + return be64_to_cpup((const __be64 *)p);
83271 }
83272
83273 static inline void put_unaligned_le16(u16 val, void *p)
83274 diff --git a/include/linux/usb.h b/include/linux/usb.h
83275 index 6b7ec37..4428419 100644
83276 --- a/include/linux/usb.h
83277 +++ b/include/linux/usb.h
83278 @@ -569,7 +569,7 @@ struct usb_device {
83279 int maxchild;
83280
83281 u32 quirks;
83282 - atomic_t urbnum;
83283 + atomic_unchecked_t urbnum;
83284
83285 unsigned long active_duration;
83286
83287 @@ -1653,7 +1653,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
83288
83289 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
83290 __u8 request, __u8 requesttype, __u16 value, __u16 index,
83291 - void *data, __u16 size, int timeout);
83292 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
83293 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
83294 void *data, int len, int *actual_length, int timeout);
83295 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
83296 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
83297 index e452ba6..78f8e80 100644
83298 --- a/include/linux/usb/renesas_usbhs.h
83299 +++ b/include/linux/usb/renesas_usbhs.h
83300 @@ -39,7 +39,7 @@ enum {
83301 */
83302 struct renesas_usbhs_driver_callback {
83303 int (*notify_hotplug)(struct platform_device *pdev);
83304 -};
83305 +} __no_const;
83306
83307 /*
83308 * callback functions for platform
83309 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
83310 index 4836ba3..603f6ee 100644
83311 --- a/include/linux/user_namespace.h
83312 +++ b/include/linux/user_namespace.h
83313 @@ -33,7 +33,7 @@ struct user_namespace {
83314 struct key *persistent_keyring_register;
83315 struct rw_semaphore persistent_keyring_register_sem;
83316 #endif
83317 -};
83318 +} __randomize_layout;
83319
83320 extern struct user_namespace init_user_ns;
83321
83322 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
83323 index 239e277..22a5cf5 100644
83324 --- a/include/linux/utsname.h
83325 +++ b/include/linux/utsname.h
83326 @@ -24,7 +24,7 @@ struct uts_namespace {
83327 struct new_utsname name;
83328 struct user_namespace *user_ns;
83329 unsigned int proc_inum;
83330 -};
83331 +} __randomize_layout;
83332 extern struct uts_namespace init_uts_ns;
83333
83334 #ifdef CONFIG_UTS_NS
83335 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
83336 index 6f8fbcf..4efc177 100644
83337 --- a/include/linux/vermagic.h
83338 +++ b/include/linux/vermagic.h
83339 @@ -25,9 +25,42 @@
83340 #define MODULE_ARCH_VERMAGIC ""
83341 #endif
83342
83343 +#ifdef CONFIG_PAX_REFCOUNT
83344 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
83345 +#else
83346 +#define MODULE_PAX_REFCOUNT ""
83347 +#endif
83348 +
83349 +#ifdef CONSTIFY_PLUGIN
83350 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
83351 +#else
83352 +#define MODULE_CONSTIFY_PLUGIN ""
83353 +#endif
83354 +
83355 +#ifdef STACKLEAK_PLUGIN
83356 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
83357 +#else
83358 +#define MODULE_STACKLEAK_PLUGIN ""
83359 +#endif
83360 +
83361 +#ifdef RANDSTRUCT_PLUGIN
83362 +#include <generated/randomize_layout_hash.h>
83363 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
83364 +#else
83365 +#define MODULE_RANDSTRUCT_PLUGIN
83366 +#endif
83367 +
83368 +#ifdef CONFIG_GRKERNSEC
83369 +#define MODULE_GRSEC "GRSEC "
83370 +#else
83371 +#define MODULE_GRSEC ""
83372 +#endif
83373 +
83374 #define VERMAGIC_STRING \
83375 UTS_RELEASE " " \
83376 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83377 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83378 - MODULE_ARCH_VERMAGIC
83379 + MODULE_ARCH_VERMAGIC \
83380 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83381 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83382
83383 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83384 index 502073a..a7de024 100644
83385 --- a/include/linux/vga_switcheroo.h
83386 +++ b/include/linux/vga_switcheroo.h
83387 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83388
83389 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83390
83391 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83392 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83393 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83394 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83395 #else
83396
83397 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83398 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83399
83400 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83401
83402 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83403 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83404 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83405 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83406
83407 #endif
83408 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83409 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83410 index 4b8a891..e9a2863 100644
83411 --- a/include/linux/vmalloc.h
83412 +++ b/include/linux/vmalloc.h
83413 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83414 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83415 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83416 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83417 +
83418 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83419 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83420 +#endif
83421 +
83422 /* bits [20..32] reserved for arch specific ioremap internals */
83423
83424 /*
83425 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
83426 unsigned long flags, pgprot_t prot);
83427 extern void vunmap(const void *addr);
83428
83429 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
83430 +extern void unmap_process_stacks(struct task_struct *task);
83431 +#endif
83432 +
83433 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
83434 unsigned long uaddr, void *kaddr,
83435 unsigned long size);
83436 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
83437
83438 /* for /dev/kmem */
83439 extern long vread(char *buf, char *addr, unsigned long count);
83440 -extern long vwrite(char *buf, char *addr, unsigned long count);
83441 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83442
83443 /*
83444 * Internals. Dont't use..
83445 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83446 index 45c9cd1..20bd0bf 100644
83447 --- a/include/linux/vmstat.h
83448 +++ b/include/linux/vmstat.h
83449 @@ -102,18 +102,18 @@ static inline void vm_events_fold_cpu(int cpu)
83450 /*
83451 * Zone based page accounting with per cpu differentials.
83452 */
83453 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83454 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83455
83456 static inline void zone_page_state_add(long x, struct zone *zone,
83457 enum zone_stat_item item)
83458 {
83459 - atomic_long_add(x, &zone->vm_stat[item]);
83460 - atomic_long_add(x, &vm_stat[item]);
83461 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83462 + atomic_long_add_unchecked(x, &vm_stat[item]);
83463 }
83464
83465 -static inline unsigned long global_page_state(enum zone_stat_item item)
83466 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83467 {
83468 - long x = atomic_long_read(&vm_stat[item]);
83469 + long x = atomic_long_read_unchecked(&vm_stat[item]);
83470 #ifdef CONFIG_SMP
83471 if (x < 0)
83472 x = 0;
83473 @@ -121,10 +121,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83474 return x;
83475 }
83476
83477 -static inline unsigned long zone_page_state(struct zone *zone,
83478 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83479 enum zone_stat_item item)
83480 {
83481 - long x = atomic_long_read(&zone->vm_stat[item]);
83482 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83483 #ifdef CONFIG_SMP
83484 if (x < 0)
83485 x = 0;
83486 @@ -141,7 +141,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83487 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83488 enum zone_stat_item item)
83489 {
83490 - long x = atomic_long_read(&zone->vm_stat[item]);
83491 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83492
83493 #ifdef CONFIG_SMP
83494 int cpu;
83495 @@ -228,14 +228,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
83496
83497 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83498 {
83499 - atomic_long_inc(&zone->vm_stat[item]);
83500 - atomic_long_inc(&vm_stat[item]);
83501 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
83502 + atomic_long_inc_unchecked(&vm_stat[item]);
83503 }
83504
83505 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83506 {
83507 - atomic_long_dec(&zone->vm_stat[item]);
83508 - atomic_long_dec(&vm_stat[item]);
83509 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
83510 + atomic_long_dec_unchecked(&vm_stat[item]);
83511 }
83512
83513 static inline void __inc_zone_page_state(struct page *page,
83514 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83515 index 91b0a68..0e9adf6 100644
83516 --- a/include/linux/xattr.h
83517 +++ b/include/linux/xattr.h
83518 @@ -28,7 +28,7 @@ struct xattr_handler {
83519 size_t size, int handler_flags);
83520 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83521 size_t size, int flags, int handler_flags);
83522 -};
83523 +} __do_const;
83524
83525 struct xattr {
83526 const char *name;
83527 @@ -37,6 +37,9 @@ struct xattr {
83528 };
83529
83530 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83531 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83532 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
83533 +#endif
83534 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83535 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83536 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83537 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83538 index 9c5a6b4..09c9438 100644
83539 --- a/include/linux/zlib.h
83540 +++ b/include/linux/zlib.h
83541 @@ -31,6 +31,7 @@
83542 #define _ZLIB_H
83543
83544 #include <linux/zconf.h>
83545 +#include <linux/compiler.h>
83546
83547 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83548 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83549 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83550
83551 /* basic functions */
83552
83553 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83554 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83555 /*
83556 Returns the number of bytes that needs to be allocated for a per-
83557 stream workspace with the specified parameters. A pointer to this
83558 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83559 index eec6e46..82d5641 100644
83560 --- a/include/media/v4l2-dev.h
83561 +++ b/include/media/v4l2-dev.h
83562 @@ -77,7 +77,7 @@ struct v4l2_file_operations {
83563 int (*mmap) (struct file *, struct vm_area_struct *);
83564 int (*open) (struct file *);
83565 int (*release) (struct file *);
83566 -};
83567 +} __do_const;
83568
83569 /*
83570 * Newer version of video_device, handled by videodev2.c
83571 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83572 index c9b1593..a572459 100644
83573 --- a/include/media/v4l2-device.h
83574 +++ b/include/media/v4l2-device.h
83575 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83576 this function returns 0. If the name ends with a digit (e.g. cx18),
83577 then the name will be set to cx18-0 since cx180 looks really odd. */
83578 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83579 - atomic_t *instance);
83580 + atomic_unchecked_t *instance);
83581
83582 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83583 Since the parent disappears this ensures that v4l2_dev doesn't have an
83584 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83585 index d9fa68f..45c88d1 100644
83586 --- a/include/net/9p/transport.h
83587 +++ b/include/net/9p/transport.h
83588 @@ -63,7 +63,7 @@ struct p9_trans_module {
83589 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
83590 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83591 char *, char *, int , int, int, int);
83592 -};
83593 +} __do_const;
83594
83595 void v9fs_register_trans(struct p9_trans_module *m);
83596 void v9fs_unregister_trans(struct p9_trans_module *m);
83597 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83598 index a175ba4..196eb82 100644
83599 --- a/include/net/af_unix.h
83600 +++ b/include/net/af_unix.h
83601 @@ -36,7 +36,7 @@ struct unix_skb_parms {
83602 u32 secid; /* Security ID */
83603 #endif
83604 u32 consumed;
83605 -};
83606 +} __randomize_layout;
83607
83608 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83609 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83610 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83611 index 4abdcb2..945c5cc 100644
83612 --- a/include/net/bluetooth/l2cap.h
83613 +++ b/include/net/bluetooth/l2cap.h
83614 @@ -601,7 +601,7 @@ struct l2cap_ops {
83615 long (*get_sndtimeo) (struct l2cap_chan *chan);
83616 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83617 unsigned long len, int nb);
83618 -};
83619 +} __do_const;
83620
83621 struct l2cap_conn {
83622 struct hci_conn *hcon;
83623 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83624 index f2ae33d..c457cf0 100644
83625 --- a/include/net/caif/cfctrl.h
83626 +++ b/include/net/caif/cfctrl.h
83627 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
83628 void (*radioset_rsp)(void);
83629 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83630 struct cflayer *client_layer);
83631 -};
83632 +} __no_const;
83633
83634 /* Link Setup Parameters for CAIF-Links. */
83635 struct cfctrl_link_param {
83636 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
83637 struct cfctrl {
83638 struct cfsrvl serv;
83639 struct cfctrl_rsp res;
83640 - atomic_t req_seq_no;
83641 - atomic_t rsp_seq_no;
83642 + atomic_unchecked_t req_seq_no;
83643 + atomic_unchecked_t rsp_seq_no;
83644 struct list_head list;
83645 /* Protects from simultaneous access to first_req list */
83646 spinlock_t info_list_lock;
83647 diff --git a/include/net/flow.h b/include/net/flow.h
83648 index 8109a15..504466d 100644
83649 --- a/include/net/flow.h
83650 +++ b/include/net/flow.h
83651 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
83652
83653 void flow_cache_flush(struct net *net);
83654 void flow_cache_flush_deferred(struct net *net);
83655 -extern atomic_t flow_cache_genid;
83656 +extern atomic_unchecked_t flow_cache_genid;
83657
83658 #endif
83659 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83660 index 93695f0..766d71c 100644
83661 --- a/include/net/genetlink.h
83662 +++ b/include/net/genetlink.h
83663 @@ -120,7 +120,7 @@ struct genl_ops {
83664 u8 cmd;
83665 u8 internal_flags;
83666 u8 flags;
83667 -};
83668 +} __do_const;
83669
83670 int __genl_register_family(struct genl_family *family);
83671
83672 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83673 index 734d9b5..48a9a4b 100644
83674 --- a/include/net/gro_cells.h
83675 +++ b/include/net/gro_cells.h
83676 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83677 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83678
83679 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83680 - atomic_long_inc(&dev->rx_dropped);
83681 + atomic_long_inc_unchecked(&dev->rx_dropped);
83682 kfree_skb(skb);
83683 return;
83684 }
83685 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83686 index 7a43138..bc76865 100644
83687 --- a/include/net/inet_connection_sock.h
83688 +++ b/include/net/inet_connection_sock.h
83689 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83690 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83691 int (*bind_conflict)(const struct sock *sk,
83692 const struct inet_bind_bucket *tb, bool relax);
83693 -};
83694 +} __do_const;
83695
83696 /** inet_connection_sock - INET connection oriented sock
83697 *
83698 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83699 index 058271b..1a44af7 100644
83700 --- a/include/net/inetpeer.h
83701 +++ b/include/net/inetpeer.h
83702 @@ -47,8 +47,8 @@ struct inet_peer {
83703 */
83704 union {
83705 struct {
83706 - atomic_t rid; /* Frag reception counter */
83707 - atomic_t ip_id_count; /* IP ID for the next packet */
83708 + atomic_unchecked_t rid; /* Frag reception counter */
83709 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83710 };
83711 struct rcu_head rcu;
83712 struct inet_peer *gc_next;
83713 @@ -179,7 +179,7 @@ static inline int inet_getid(struct inet_peer *p, int more)
83714 {
83715 more++;
83716 inet_peer_refcheck(p);
83717 - return atomic_add_return(more, &p->ip_id_count) - more;
83718 + return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
83719 }
83720
83721 #endif /* _NET_INETPEER_H */
83722 diff --git a/include/net/ip.h b/include/net/ip.h
83723 index 3ec2b0f..72435b6 100644
83724 --- a/include/net/ip.h
83725 +++ b/include/net/ip.h
83726 @@ -220,7 +220,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83727
83728 void inet_get_local_port_range(struct net *net, int *low, int *high);
83729
83730 -extern unsigned long *sysctl_local_reserved_ports;
83731 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83732 static inline int inet_is_reserved_local_port(int port)
83733 {
83734 return test_bit(port, sysctl_local_reserved_ports);
83735 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83736 index 9922093..a1755d6 100644
83737 --- a/include/net/ip_fib.h
83738 +++ b/include/net/ip_fib.h
83739 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83740
83741 #define FIB_RES_SADDR(net, res) \
83742 ((FIB_RES_NH(res).nh_saddr_genid == \
83743 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83744 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83745 FIB_RES_NH(res).nh_saddr : \
83746 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83747 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83748 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83749 index 5679d92..2e7a690 100644
83750 --- a/include/net/ip_vs.h
83751 +++ b/include/net/ip_vs.h
83752 @@ -558,7 +558,7 @@ struct ip_vs_conn {
83753 struct ip_vs_conn *control; /* Master control connection */
83754 atomic_t n_control; /* Number of controlled ones */
83755 struct ip_vs_dest *dest; /* real server */
83756 - atomic_t in_pkts; /* incoming packet counter */
83757 + atomic_unchecked_t in_pkts; /* incoming packet counter */
83758
83759 /* packet transmitter for different forwarding methods. If it
83760 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83761 @@ -705,7 +705,7 @@ struct ip_vs_dest {
83762 __be16 port; /* port number of the server */
83763 union nf_inet_addr addr; /* IP address of the server */
83764 volatile unsigned int flags; /* dest status flags */
83765 - atomic_t conn_flags; /* flags to copy to conn */
83766 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
83767 atomic_t weight; /* server weight */
83768
83769 atomic_t refcnt; /* reference counter */
83770 @@ -960,11 +960,11 @@ struct netns_ipvs {
83771 /* ip_vs_lblc */
83772 int sysctl_lblc_expiration;
83773 struct ctl_table_header *lblc_ctl_header;
83774 - struct ctl_table *lblc_ctl_table;
83775 + ctl_table_no_const *lblc_ctl_table;
83776 /* ip_vs_lblcr */
83777 int sysctl_lblcr_expiration;
83778 struct ctl_table_header *lblcr_ctl_header;
83779 - struct ctl_table *lblcr_ctl_table;
83780 + ctl_table_no_const *lblcr_ctl_table;
83781 /* ip_vs_est */
83782 struct list_head est_list; /* estimator list */
83783 spinlock_t est_lock;
83784 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83785 index 8d4f588..2e37ad2 100644
83786 --- a/include/net/irda/ircomm_tty.h
83787 +++ b/include/net/irda/ircomm_tty.h
83788 @@ -33,6 +33,7 @@
83789 #include <linux/termios.h>
83790 #include <linux/timer.h>
83791 #include <linux/tty.h> /* struct tty_struct */
83792 +#include <asm/local.h>
83793
83794 #include <net/irda/irias_object.h>
83795 #include <net/irda/ircomm_core.h>
83796 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83797 index 714cc9a..ea05f3e 100644
83798 --- a/include/net/iucv/af_iucv.h
83799 +++ b/include/net/iucv/af_iucv.h
83800 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
83801 struct iucv_sock_list {
83802 struct hlist_head head;
83803 rwlock_t lock;
83804 - atomic_t autobind_name;
83805 + atomic_unchecked_t autobind_name;
83806 };
83807
83808 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83809 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83810 index f3be818..bf46196 100644
83811 --- a/include/net/llc_c_ac.h
83812 +++ b/include/net/llc_c_ac.h
83813 @@ -87,7 +87,7 @@
83814 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83815 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83816
83817 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83818 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83819
83820 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83821 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83822 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83823 index 3948cf1..83b28c4 100644
83824 --- a/include/net/llc_c_ev.h
83825 +++ b/include/net/llc_c_ev.h
83826 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83827 return (struct llc_conn_state_ev *)skb->cb;
83828 }
83829
83830 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83831 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83832 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83833 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83834
83835 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83836 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83837 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83838 index 0e79cfb..f46db31 100644
83839 --- a/include/net/llc_c_st.h
83840 +++ b/include/net/llc_c_st.h
83841 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83842 u8 next_state;
83843 llc_conn_ev_qfyr_t *ev_qualifiers;
83844 llc_conn_action_t *ev_actions;
83845 -};
83846 +} __do_const;
83847
83848 struct llc_conn_state {
83849 u8 current_state;
83850 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83851 index a61b98c..aade1eb 100644
83852 --- a/include/net/llc_s_ac.h
83853 +++ b/include/net/llc_s_ac.h
83854 @@ -23,7 +23,7 @@
83855 #define SAP_ACT_TEST_IND 9
83856
83857 /* All action functions must look like this */
83858 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83859 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83860
83861 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83862 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83863 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83864 index 567c681..cd73ac02 100644
83865 --- a/include/net/llc_s_st.h
83866 +++ b/include/net/llc_s_st.h
83867 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83868 llc_sap_ev_t ev;
83869 u8 next_state;
83870 llc_sap_action_t *ev_actions;
83871 -};
83872 +} __do_const;
83873
83874 struct llc_sap_state {
83875 u8 curr_state;
83876 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83877 index 8248e39..7610eec 100644
83878 --- a/include/net/mac80211.h
83879 +++ b/include/net/mac80211.h
83880 @@ -4467,7 +4467,7 @@ struct rate_control_ops {
83881 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83882 struct dentry *dir);
83883 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83884 -};
83885 +} __do_const;
83886
83887 static inline int rate_supported(struct ieee80211_sta *sta,
83888 enum ieee80211_band band,
83889 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83890 index 7277caf..fd095bc 100644
83891 --- a/include/net/neighbour.h
83892 +++ b/include/net/neighbour.h
83893 @@ -163,7 +163,7 @@ struct neigh_ops {
83894 void (*error_report)(struct neighbour *, struct sk_buff *);
83895 int (*output)(struct neighbour *, struct sk_buff *);
83896 int (*connected_output)(struct neighbour *, struct sk_buff *);
83897 -};
83898 +} __do_const;
83899
83900 struct pneigh_entry {
83901 struct pneigh_entry *next;
83902 @@ -203,7 +203,6 @@ struct neigh_table {
83903 void (*proxy_redo)(struct sk_buff *skb);
83904 char *id;
83905 struct neigh_parms parms;
83906 - /* HACK. gc_* should follow parms without a gap! */
83907 int gc_interval;
83908 int gc_thresh1;
83909 int gc_thresh2;
83910 @@ -218,7 +217,7 @@ struct neigh_table {
83911 struct neigh_statistics __percpu *stats;
83912 struct neigh_hash_table __rcu *nht;
83913 struct pneigh_entry **phash_buckets;
83914 -};
83915 +} __randomize_layout;
83916
83917 static inline int neigh_parms_family(struct neigh_parms *p)
83918 {
83919 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83920 index 5f9eb26..85699c4 100644
83921 --- a/include/net/net_namespace.h
83922 +++ b/include/net/net_namespace.h
83923 @@ -129,8 +129,8 @@ struct net {
83924 struct netns_ipvs *ipvs;
83925 #endif
83926 struct sock *diag_nlsk;
83927 - atomic_t fnhe_genid;
83928 -};
83929 + atomic_unchecked_t fnhe_genid;
83930 +} __randomize_layout;
83931
83932 #include <linux/seq_file_net.h>
83933
83934 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83935 #define __net_init __init
83936 #define __net_exit __exit_refok
83937 #define __net_initdata __initdata
83938 +#ifdef CONSTIFY_PLUGIN
83939 #define __net_initconst __initconst
83940 +#else
83941 +#define __net_initconst __initdata
83942 +#endif
83943 #endif
83944
83945 struct pernet_operations {
83946 @@ -296,7 +300,7 @@ struct pernet_operations {
83947 void (*exit_batch)(struct list_head *net_exit_list);
83948 int *id;
83949 size_t size;
83950 -};
83951 +} __do_const;
83952
83953 /*
83954 * Use these carefully. If you implement a network device and it
83955 @@ -344,23 +348,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83956
83957 static inline int rt_genid_ipv4(struct net *net)
83958 {
83959 - return atomic_read(&net->ipv4.rt_genid);
83960 + return atomic_read_unchecked(&net->ipv4.rt_genid);
83961 }
83962
83963 static inline void rt_genid_bump_ipv4(struct net *net)
83964 {
83965 - atomic_inc(&net->ipv4.rt_genid);
83966 + atomic_inc_unchecked(&net->ipv4.rt_genid);
83967 }
83968
83969 #if IS_ENABLED(CONFIG_IPV6)
83970 static inline int rt_genid_ipv6(struct net *net)
83971 {
83972 - return atomic_read(&net->ipv6.rt_genid);
83973 + return atomic_read_unchecked(&net->ipv6.rt_genid);
83974 }
83975
83976 static inline void rt_genid_bump_ipv6(struct net *net)
83977 {
83978 - atomic_inc(&net->ipv6.rt_genid);
83979 + atomic_inc_unchecked(&net->ipv6.rt_genid);
83980 }
83981 #else
83982 static inline int rt_genid_ipv6(struct net *net)
83983 @@ -382,12 +386,12 @@ static inline void rt_genid_bump_all(struct net *net)
83984
83985 static inline int fnhe_genid(struct net *net)
83986 {
83987 - return atomic_read(&net->fnhe_genid);
83988 + return atomic_read_unchecked(&net->fnhe_genid);
83989 }
83990
83991 static inline void fnhe_genid_bump(struct net *net)
83992 {
83993 - atomic_inc(&net->fnhe_genid);
83994 + atomic_inc_unchecked(&net->fnhe_genid);
83995 }
83996
83997 #endif /* __NET_NET_NAMESPACE_H */
83998 diff --git a/include/net/netdma.h b/include/net/netdma.h
83999 index 8ba8ce2..99b7fff 100644
84000 --- a/include/net/netdma.h
84001 +++ b/include/net/netdma.h
84002 @@ -24,7 +24,7 @@
84003 #include <linux/dmaengine.h>
84004 #include <linux/skbuff.h>
84005
84006 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
84007 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
84008 struct sk_buff *skb, int offset, struct iovec *to,
84009 size_t len, struct dma_pinned_list *pinned_list);
84010
84011 diff --git a/include/net/netlink.h b/include/net/netlink.h
84012 index 2b47eaa..6d5bcc2 100644
84013 --- a/include/net/netlink.h
84014 +++ b/include/net/netlink.h
84015 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
84016 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
84017 {
84018 if (mark)
84019 - skb_trim(skb, (unsigned char *) mark - skb->data);
84020 + skb_trim(skb, (const unsigned char *) mark - skb->data);
84021 }
84022
84023 /**
84024 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
84025 index 773cce3..6a11852 100644
84026 --- a/include/net/netns/conntrack.h
84027 +++ b/include/net/netns/conntrack.h
84028 @@ -13,10 +13,10 @@ struct nf_conntrack_ecache;
84029 struct nf_proto_net {
84030 #ifdef CONFIG_SYSCTL
84031 struct ctl_table_header *ctl_table_header;
84032 - struct ctl_table *ctl_table;
84033 + ctl_table_no_const *ctl_table;
84034 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
84035 struct ctl_table_header *ctl_compat_header;
84036 - struct ctl_table *ctl_compat_table;
84037 + ctl_table_no_const *ctl_compat_table;
84038 #endif
84039 #endif
84040 unsigned int users;
84041 @@ -59,7 +59,7 @@ struct nf_ip_net {
84042 struct nf_icmp_net icmpv6;
84043 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
84044 struct ctl_table_header *ctl_table_header;
84045 - struct ctl_table *ctl_table;
84046 + ctl_table_no_const *ctl_table;
84047 #endif
84048 };
84049
84050 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
84051 index b2704fd0..421d717 100644
84052 --- a/include/net/netns/ipv4.h
84053 +++ b/include/net/netns/ipv4.h
84054 @@ -79,7 +79,7 @@ struct netns_ipv4 {
84055
84056 struct ping_group_range ping_group_range;
84057
84058 - atomic_t dev_addr_genid;
84059 + atomic_unchecked_t dev_addr_genid;
84060
84061 #ifdef CONFIG_IP_MROUTE
84062 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
84063 @@ -89,6 +89,6 @@ struct netns_ipv4 {
84064 struct fib_rules_ops *mr_rules_ops;
84065 #endif
84066 #endif
84067 - atomic_t rt_genid;
84068 + atomic_unchecked_t rt_genid;
84069 };
84070 #endif
84071 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
84072 index 21edaf1..4c5faae 100644
84073 --- a/include/net/netns/ipv6.h
84074 +++ b/include/net/netns/ipv6.h
84075 @@ -73,8 +73,8 @@ struct netns_ipv6 {
84076 struct fib_rules_ops *mr6_rules_ops;
84077 #endif
84078 #endif
84079 - atomic_t dev_addr_genid;
84080 - atomic_t rt_genid;
84081 + atomic_unchecked_t dev_addr_genid;
84082 + atomic_unchecked_t rt_genid;
84083 };
84084
84085 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
84086 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
84087 index 3492434..209f58c 100644
84088 --- a/include/net/netns/xfrm.h
84089 +++ b/include/net/netns/xfrm.h
84090 @@ -64,7 +64,7 @@ struct netns_xfrm {
84091
84092 /* flow cache part */
84093 struct flow_cache flow_cache_global;
84094 - atomic_t flow_cache_genid;
84095 + atomic_unchecked_t flow_cache_genid;
84096 struct list_head flow_cache_gc_list;
84097 spinlock_t flow_cache_gc_lock;
84098 struct work_struct flow_cache_gc_work;
84099 diff --git a/include/net/ping.h b/include/net/ping.h
84100 index 026479b..d9b2829 100644
84101 --- a/include/net/ping.h
84102 +++ b/include/net/ping.h
84103 @@ -54,7 +54,7 @@ struct ping_iter_state {
84104
84105 extern struct proto ping_prot;
84106 #if IS_ENABLED(CONFIG_IPV6)
84107 -extern struct pingv6_ops pingv6_ops;
84108 +extern struct pingv6_ops *pingv6_ops;
84109 #endif
84110
84111 struct pingfakehdr {
84112 diff --git a/include/net/protocol.h b/include/net/protocol.h
84113 index a7e986b..dc67bce 100644
84114 --- a/include/net/protocol.h
84115 +++ b/include/net/protocol.h
84116 @@ -49,7 +49,7 @@ struct net_protocol {
84117 * socket lookup?
84118 */
84119 icmp_strict_tag_validation:1;
84120 -};
84121 +} __do_const;
84122
84123 #if IS_ENABLED(CONFIG_IPV6)
84124 struct inet6_protocol {
84125 @@ -62,7 +62,7 @@ struct inet6_protocol {
84126 u8 type, u8 code, int offset,
84127 __be32 info);
84128 unsigned int flags; /* INET6_PROTO_xxx */
84129 -};
84130 +} __do_const;
84131
84132 #define INET6_PROTO_NOPOLICY 0x1
84133 #define INET6_PROTO_FINAL 0x2
84134 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
84135 index 72240e5..8c14bef 100644
84136 --- a/include/net/rtnetlink.h
84137 +++ b/include/net/rtnetlink.h
84138 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
84139 int (*fill_slave_info)(struct sk_buff *skb,
84140 const struct net_device *dev,
84141 const struct net_device *slave_dev);
84142 -};
84143 +} __do_const;
84144
84145 int __rtnl_link_register(struct rtnl_link_ops *ops);
84146 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
84147 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
84148 index 4a5b9a3..ca27d73 100644
84149 --- a/include/net/sctp/checksum.h
84150 +++ b/include/net/sctp/checksum.h
84151 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
84152 unsigned int offset)
84153 {
84154 struct sctphdr *sh = sctp_hdr(skb);
84155 - __le32 ret, old = sh->checksum;
84156 - const struct skb_checksum_ops ops = {
84157 + __le32 ret, old = sh->checksum;
84158 + static const struct skb_checksum_ops ops = {
84159 .update = sctp_csum_update,
84160 .combine = sctp_csum_combine,
84161 };
84162 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
84163 index 7f4eeb3..37e8fe1 100644
84164 --- a/include/net/sctp/sm.h
84165 +++ b/include/net/sctp/sm.h
84166 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
84167 typedef struct {
84168 sctp_state_fn_t *fn;
84169 const char *name;
84170 -} sctp_sm_table_entry_t;
84171 +} __do_const sctp_sm_table_entry_t;
84172
84173 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
84174 * currently in use.
84175 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
84176 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
84177
84178 /* Extern declarations for major data structures. */
84179 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84180 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84181
84182
84183 /* Get the size of a DATA chunk payload. */
84184 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
84185 index 0dfcc92..7967849 100644
84186 --- a/include/net/sctp/structs.h
84187 +++ b/include/net/sctp/structs.h
84188 @@ -507,7 +507,7 @@ struct sctp_pf {
84189 struct sctp_association *asoc);
84190 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
84191 struct sctp_af *af;
84192 -};
84193 +} __do_const;
84194
84195
84196 /* Structure to track chunk fragments that have been acked, but peer
84197 diff --git a/include/net/sock.h b/include/net/sock.h
84198 index 21569cf..dd60300 100644
84199 --- a/include/net/sock.h
84200 +++ b/include/net/sock.h
84201 @@ -348,7 +348,7 @@ struct sock {
84202 unsigned int sk_napi_id;
84203 unsigned int sk_ll_usec;
84204 #endif
84205 - atomic_t sk_drops;
84206 + atomic_unchecked_t sk_drops;
84207 int sk_rcvbuf;
84208
84209 struct sk_filter __rcu *sk_filter;
84210 @@ -1036,7 +1036,7 @@ struct proto {
84211 void (*destroy_cgroup)(struct mem_cgroup *memcg);
84212 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
84213 #endif
84214 -};
84215 +} __randomize_layout;
84216
84217 /*
84218 * Bits in struct cg_proto.flags
84219 @@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
84220 return ret >> PAGE_SHIFT;
84221 }
84222
84223 -static inline long
84224 +static inline long __intentional_overflow(-1)
84225 sk_memory_allocated(const struct sock *sk)
84226 {
84227 struct proto *prot = sk->sk_prot;
84228 @@ -1368,7 +1368,7 @@ struct sock_iocb {
84229 struct scm_cookie *scm;
84230 struct msghdr *msg, async_msg;
84231 struct kiocb *kiocb;
84232 -};
84233 +} __randomize_layout;
84234
84235 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
84236 {
84237 @@ -1728,8 +1728,8 @@ sk_dst_get(struct sock *sk)
84238
84239 rcu_read_lock();
84240 dst = rcu_dereference(sk->sk_dst_cache);
84241 - if (dst)
84242 - dst_hold(dst);
84243 + if (dst && !atomic_inc_not_zero(&dst->__refcnt))
84244 + dst = NULL;
84245 rcu_read_unlock();
84246 return dst;
84247 }
84248 @@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
84249 }
84250
84251 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
84252 - char __user *from, char *to,
84253 + char __user *from, unsigned char *to,
84254 int copy, int offset)
84255 {
84256 if (skb->ip_summed == CHECKSUM_NONE) {
84257 @@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
84258 }
84259 }
84260
84261 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84262 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84263
84264 /**
84265 * sk_page_frag - return an appropriate page_frag
84266 diff --git a/include/net/tcp.h b/include/net/tcp.h
84267 index 87d8774..cf214f8 100644
84268 --- a/include/net/tcp.h
84269 +++ b/include/net/tcp.h
84270 @@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
84271 void tcp_xmit_retransmit_queue(struct sock *);
84272 void tcp_simple_retransmit(struct sock *);
84273 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
84274 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84275 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84276
84277 void tcp_send_probe0(struct sock *);
84278 void tcp_send_partial(struct sock *);
84279 @@ -715,8 +715,8 @@ struct tcp_skb_cb {
84280 struct inet6_skb_parm h6;
84281 #endif
84282 } header; /* For incoming frames */
84283 - __u32 seq; /* Starting sequence number */
84284 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
84285 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
84286 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
84287 __u32 when; /* used to compute rtt's */
84288 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
84289
84290 @@ -730,7 +730,7 @@ struct tcp_skb_cb {
84291
84292 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
84293 /* 1 byte hole */
84294 - __u32 ack_seq; /* Sequence number ACK'd */
84295 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
84296 };
84297
84298 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
84299 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
84300 index 116e9c7..3070537 100644
84301 --- a/include/net/xfrm.h
84302 +++ b/include/net/xfrm.h
84303 @@ -285,7 +285,6 @@ struct xfrm_dst;
84304 struct xfrm_policy_afinfo {
84305 unsigned short family;
84306 struct dst_ops *dst_ops;
84307 - void (*garbage_collect)(struct net *net);
84308 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
84309 const xfrm_address_t *saddr,
84310 const xfrm_address_t *daddr);
84311 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
84312 struct net_device *dev,
84313 const struct flowi *fl);
84314 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
84315 -};
84316 +} __do_const;
84317
84318 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
84319 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
84320 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
84321 int (*transport_finish)(struct sk_buff *skb,
84322 int async);
84323 void (*local_error)(struct sk_buff *skb, u32 mtu);
84324 -};
84325 +} __do_const;
84326
84327 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
84328 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
84329 @@ -437,7 +436,7 @@ struct xfrm_mode {
84330 struct module *owner;
84331 unsigned int encap;
84332 int flags;
84333 -};
84334 +} __do_const;
84335
84336 /* Flags for xfrm_mode. */
84337 enum {
84338 @@ -534,7 +533,7 @@ struct xfrm_policy {
84339 struct timer_list timer;
84340
84341 struct flow_cache_object flo;
84342 - atomic_t genid;
84343 + atomic_unchecked_t genid;
84344 u32 priority;
84345 u32 index;
84346 struct xfrm_mark mark;
84347 @@ -1180,6 +1179,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
84348 }
84349
84350 void xfrm_garbage_collect(struct net *net);
84351 +void xfrm_garbage_collect_deferred(struct net *net);
84352
84353 #else
84354
84355 @@ -1218,6 +1218,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
84356 static inline void xfrm_garbage_collect(struct net *net)
84357 {
84358 }
84359 +static inline void xfrm_garbage_collect_deferred(struct net *net)
84360 +{
84361 +}
84362 #endif
84363
84364 static __inline__
84365 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
84366 index 1017e0b..227aa4d 100644
84367 --- a/include/rdma/iw_cm.h
84368 +++ b/include/rdma/iw_cm.h
84369 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
84370 int backlog);
84371
84372 int (*destroy_listen)(struct iw_cm_id *cm_id);
84373 -};
84374 +} __no_const;
84375
84376 /**
84377 * iw_create_cm_id - Create an IW CM identifier.
84378 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84379 index 52beadf..598734c 100644
84380 --- a/include/scsi/libfc.h
84381 +++ b/include/scsi/libfc.h
84382 @@ -771,6 +771,7 @@ struct libfc_function_template {
84383 */
84384 void (*disc_stop_final) (struct fc_lport *);
84385 };
84386 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84387
84388 /**
84389 * struct fc_disc - Discovery context
84390 @@ -875,7 +876,7 @@ struct fc_lport {
84391 struct fc_vport *vport;
84392
84393 /* Operational Information */
84394 - struct libfc_function_template tt;
84395 + libfc_function_template_no_const tt;
84396 u8 link_up;
84397 u8 qfull;
84398 enum fc_lport_state state;
84399 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84400 index 27ab310..60dc245 100644
84401 --- a/include/scsi/scsi_device.h
84402 +++ b/include/scsi/scsi_device.h
84403 @@ -187,9 +187,9 @@ struct scsi_device {
84404 unsigned int max_device_blocked; /* what device_blocked counts down from */
84405 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84406
84407 - atomic_t iorequest_cnt;
84408 - atomic_t iodone_cnt;
84409 - atomic_t ioerr_cnt;
84410 + atomic_unchecked_t iorequest_cnt;
84411 + atomic_unchecked_t iodone_cnt;
84412 + atomic_unchecked_t ioerr_cnt;
84413
84414 struct device sdev_gendev,
84415 sdev_dev;
84416 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84417 index 8c79980..723f6f9 100644
84418 --- a/include/scsi/scsi_transport_fc.h
84419 +++ b/include/scsi/scsi_transport_fc.h
84420 @@ -752,7 +752,8 @@ struct fc_function_template {
84421 unsigned long show_host_system_hostname:1;
84422
84423 unsigned long disable_target_scan:1;
84424 -};
84425 +} __do_const;
84426 +typedef struct fc_function_template __no_const fc_function_template_no_const;
84427
84428
84429 /**
84430 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84431 index ae6c3b8..fd748ac 100644
84432 --- a/include/sound/compress_driver.h
84433 +++ b/include/sound/compress_driver.h
84434 @@ -128,7 +128,7 @@ struct snd_compr_ops {
84435 struct snd_compr_caps *caps);
84436 int (*get_codec_caps) (struct snd_compr_stream *stream,
84437 struct snd_compr_codec_caps *codec);
84438 -};
84439 +} __no_const;
84440
84441 /**
84442 * struct snd_compr: Compressed device
84443 diff --git a/include/sound/soc.h b/include/sound/soc.h
84444 index 0b83168..d67280a 100644
84445 --- a/include/sound/soc.h
84446 +++ b/include/sound/soc.h
84447 @@ -782,7 +782,7 @@ struct snd_soc_codec_driver {
84448 /* probe ordering - for components with runtime dependencies */
84449 int probe_order;
84450 int remove_order;
84451 -};
84452 +} __do_const;
84453
84454 /* SoC platform interface */
84455 struct snd_soc_platform_driver {
84456 @@ -828,7 +828,7 @@ struct snd_soc_platform_driver {
84457 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84458 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84459 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84460 -};
84461 +} __do_const;
84462
84463 struct snd_soc_platform {
84464 const char *name;
84465 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84466 index 9ec9864..e2ee1ee 100644
84467 --- a/include/target/target_core_base.h
84468 +++ b/include/target/target_core_base.h
84469 @@ -761,7 +761,7 @@ struct se_device {
84470 atomic_long_t write_bytes;
84471 /* Active commands on this virtual SE device */
84472 atomic_t simple_cmds;
84473 - atomic_t dev_ordered_id;
84474 + atomic_unchecked_t dev_ordered_id;
84475 atomic_t dev_ordered_sync;
84476 atomic_t dev_qf_count;
84477 int export_count;
84478 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84479 new file mode 100644
84480 index 0000000..fb634b7
84481 --- /dev/null
84482 +++ b/include/trace/events/fs.h
84483 @@ -0,0 +1,53 @@
84484 +#undef TRACE_SYSTEM
84485 +#define TRACE_SYSTEM fs
84486 +
84487 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84488 +#define _TRACE_FS_H
84489 +
84490 +#include <linux/fs.h>
84491 +#include <linux/tracepoint.h>
84492 +
84493 +TRACE_EVENT(do_sys_open,
84494 +
84495 + TP_PROTO(const char *filename, int flags, int mode),
84496 +
84497 + TP_ARGS(filename, flags, mode),
84498 +
84499 + TP_STRUCT__entry(
84500 + __string( filename, filename )
84501 + __field( int, flags )
84502 + __field( int, mode )
84503 + ),
84504 +
84505 + TP_fast_assign(
84506 + __assign_str(filename, filename);
84507 + __entry->flags = flags;
84508 + __entry->mode = mode;
84509 + ),
84510 +
84511 + TP_printk("\"%s\" %x %o",
84512 + __get_str(filename), __entry->flags, __entry->mode)
84513 +);
84514 +
84515 +TRACE_EVENT(open_exec,
84516 +
84517 + TP_PROTO(const char *filename),
84518 +
84519 + TP_ARGS(filename),
84520 +
84521 + TP_STRUCT__entry(
84522 + __string( filename, filename )
84523 + ),
84524 +
84525 + TP_fast_assign(
84526 + __assign_str(filename, filename);
84527 + ),
84528 +
84529 + TP_printk("\"%s\"",
84530 + __get_str(filename))
84531 +);
84532 +
84533 +#endif /* _TRACE_FS_H */
84534 +
84535 +/* This part must be outside protection */
84536 +#include <trace/define_trace.h>
84537 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84538 index 1c09820..7f5ec79 100644
84539 --- a/include/trace/events/irq.h
84540 +++ b/include/trace/events/irq.h
84541 @@ -36,7 +36,7 @@ struct softirq_action;
84542 */
84543 TRACE_EVENT(irq_handler_entry,
84544
84545 - TP_PROTO(int irq, struct irqaction *action),
84546 + TP_PROTO(int irq, const struct irqaction *action),
84547
84548 TP_ARGS(irq, action),
84549
84550 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84551 */
84552 TRACE_EVENT(irq_handler_exit,
84553
84554 - TP_PROTO(int irq, struct irqaction *action, int ret),
84555 + TP_PROTO(int irq, const struct irqaction *action, int ret),
84556
84557 TP_ARGS(irq, action, ret),
84558
84559 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84560 index 7caf44c..23c6f27 100644
84561 --- a/include/uapi/linux/a.out.h
84562 +++ b/include/uapi/linux/a.out.h
84563 @@ -39,6 +39,14 @@ enum machine_type {
84564 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84565 };
84566
84567 +/* Constants for the N_FLAGS field */
84568 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84569 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84570 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84571 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84572 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84573 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84574 +
84575 #if !defined (N_MAGIC)
84576 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84577 #endif
84578 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84579 index 22b6ad3..aeba37e 100644
84580 --- a/include/uapi/linux/bcache.h
84581 +++ b/include/uapi/linux/bcache.h
84582 @@ -5,6 +5,7 @@
84583 * Bcache on disk data structures
84584 */
84585
84586 +#include <linux/compiler.h>
84587 #include <asm/types.h>
84588
84589 #define BITMASK(name, type, field, offset, size) \
84590 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84591 /* Btree keys - all units are in sectors */
84592
84593 struct bkey {
84594 - __u64 high;
84595 - __u64 low;
84596 + __u64 high __intentional_overflow(-1);
84597 + __u64 low __intentional_overflow(-1);
84598 __u64 ptr[];
84599 };
84600
84601 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84602 index d876736..ccce5c0 100644
84603 --- a/include/uapi/linux/byteorder/little_endian.h
84604 +++ b/include/uapi/linux/byteorder/little_endian.h
84605 @@ -42,51 +42,51 @@
84606
84607 static inline __le64 __cpu_to_le64p(const __u64 *p)
84608 {
84609 - return (__force __le64)*p;
84610 + return (__force const __le64)*p;
84611 }
84612 -static inline __u64 __le64_to_cpup(const __le64 *p)
84613 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84614 {
84615 - return (__force __u64)*p;
84616 + return (__force const __u64)*p;
84617 }
84618 static inline __le32 __cpu_to_le32p(const __u32 *p)
84619 {
84620 - return (__force __le32)*p;
84621 + return (__force const __le32)*p;
84622 }
84623 static inline __u32 __le32_to_cpup(const __le32 *p)
84624 {
84625 - return (__force __u32)*p;
84626 + return (__force const __u32)*p;
84627 }
84628 static inline __le16 __cpu_to_le16p(const __u16 *p)
84629 {
84630 - return (__force __le16)*p;
84631 + return (__force const __le16)*p;
84632 }
84633 static inline __u16 __le16_to_cpup(const __le16 *p)
84634 {
84635 - return (__force __u16)*p;
84636 + return (__force const __u16)*p;
84637 }
84638 static inline __be64 __cpu_to_be64p(const __u64 *p)
84639 {
84640 - return (__force __be64)__swab64p(p);
84641 + return (__force const __be64)__swab64p(p);
84642 }
84643 static inline __u64 __be64_to_cpup(const __be64 *p)
84644 {
84645 - return __swab64p((__u64 *)p);
84646 + return __swab64p((const __u64 *)p);
84647 }
84648 static inline __be32 __cpu_to_be32p(const __u32 *p)
84649 {
84650 - return (__force __be32)__swab32p(p);
84651 + return (__force const __be32)__swab32p(p);
84652 }
84653 -static inline __u32 __be32_to_cpup(const __be32 *p)
84654 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84655 {
84656 - return __swab32p((__u32 *)p);
84657 + return __swab32p((const __u32 *)p);
84658 }
84659 static inline __be16 __cpu_to_be16p(const __u16 *p)
84660 {
84661 - return (__force __be16)__swab16p(p);
84662 + return (__force const __be16)__swab16p(p);
84663 }
84664 static inline __u16 __be16_to_cpup(const __be16 *p)
84665 {
84666 - return __swab16p((__u16 *)p);
84667 + return __swab16p((const __u16 *)p);
84668 }
84669 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84670 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84671 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84672 index ef6103b..d4e65dd 100644
84673 --- a/include/uapi/linux/elf.h
84674 +++ b/include/uapi/linux/elf.h
84675 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84676 #define PT_GNU_EH_FRAME 0x6474e550
84677
84678 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84679 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84680 +
84681 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84682 +
84683 +/* Constants for the e_flags field */
84684 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84685 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84686 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84687 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84688 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84689 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84690
84691 /*
84692 * Extended Numbering
84693 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84694 #define DT_DEBUG 21
84695 #define DT_TEXTREL 22
84696 #define DT_JMPREL 23
84697 +#define DT_FLAGS 30
84698 + #define DF_TEXTREL 0x00000004
84699 #define DT_ENCODING 32
84700 #define OLD_DT_LOOS 0x60000000
84701 #define DT_LOOS 0x6000000d
84702 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84703 #define PF_W 0x2
84704 #define PF_X 0x1
84705
84706 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84707 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84708 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84709 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84710 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84711 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84712 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84713 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84714 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84715 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84716 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84717 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84718 +
84719 typedef struct elf32_phdr{
84720 Elf32_Word p_type;
84721 Elf32_Off p_offset;
84722 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84723 #define EI_OSABI 7
84724 #define EI_PAD 8
84725
84726 +#define EI_PAX 14
84727 +
84728 #define ELFMAG0 0x7f /* EI_MAG */
84729 #define ELFMAG1 'E'
84730 #define ELFMAG2 'L'
84731 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84732 index aa169c4..6a2771d 100644
84733 --- a/include/uapi/linux/personality.h
84734 +++ b/include/uapi/linux/personality.h
84735 @@ -30,6 +30,7 @@ enum {
84736 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84737 ADDR_NO_RANDOMIZE | \
84738 ADDR_COMPAT_LAYOUT | \
84739 + ADDR_LIMIT_3GB | \
84740 MMAP_PAGE_ZERO)
84741
84742 /*
84743 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84744 index 7530e74..e714828 100644
84745 --- a/include/uapi/linux/screen_info.h
84746 +++ b/include/uapi/linux/screen_info.h
84747 @@ -43,7 +43,8 @@ struct screen_info {
84748 __u16 pages; /* 0x32 */
84749 __u16 vesa_attributes; /* 0x34 */
84750 __u32 capabilities; /* 0x36 */
84751 - __u8 _reserved[6]; /* 0x3a */
84752 + __u16 vesapm_size; /* 0x3a */
84753 + __u8 _reserved[4]; /* 0x3c */
84754 } __attribute__((packed));
84755
84756 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84757 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84758 index 0e011eb..82681b1 100644
84759 --- a/include/uapi/linux/swab.h
84760 +++ b/include/uapi/linux/swab.h
84761 @@ -43,7 +43,7 @@
84762 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84763 */
84764
84765 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
84766 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84767 {
84768 #ifdef __HAVE_BUILTIN_BSWAP16__
84769 return __builtin_bswap16(val);
84770 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84771 #endif
84772 }
84773
84774 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
84775 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84776 {
84777 #ifdef __HAVE_BUILTIN_BSWAP32__
84778 return __builtin_bswap32(val);
84779 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84780 #endif
84781 }
84782
84783 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
84784 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84785 {
84786 #ifdef __HAVE_BUILTIN_BSWAP64__
84787 return __builtin_bswap64(val);
84788 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84789 index 6d67213..552fdd9 100644
84790 --- a/include/uapi/linux/sysctl.h
84791 +++ b/include/uapi/linux/sysctl.h
84792 @@ -155,8 +155,6 @@ enum
84793 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84794 };
84795
84796 -
84797 -
84798 /* CTL_VM names: */
84799 enum
84800 {
84801 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84802 index ea468ee..4d367a5 100644
84803 --- a/include/uapi/linux/videodev2.h
84804 +++ b/include/uapi/linux/videodev2.h
84805 @@ -1248,7 +1248,7 @@ struct v4l2_ext_control {
84806 union {
84807 __s32 value;
84808 __s64 value64;
84809 - char *string;
84810 + char __user *string;
84811 };
84812 } __attribute__ ((packed));
84813
84814 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84815 index c38355c..17a57bc 100644
84816 --- a/include/uapi/linux/xattr.h
84817 +++ b/include/uapi/linux/xattr.h
84818 @@ -73,5 +73,9 @@
84819 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84820 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84821
84822 +/* User namespace */
84823 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84824 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
84825 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84826
84827 #endif /* _UAPI_LINUX_XATTR_H */
84828 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84829 index f9466fa..f4e2b81 100644
84830 --- a/include/video/udlfb.h
84831 +++ b/include/video/udlfb.h
84832 @@ -53,10 +53,10 @@ struct dlfb_data {
84833 u32 pseudo_palette[256];
84834 int blank_mode; /*one of FB_BLANK_ */
84835 /* blit-only rendering path metrics, exposed through sysfs */
84836 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84837 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84838 - atomic_t bytes_sent; /* to usb, after compression including overhead */
84839 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84840 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84841 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84842 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84843 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84844 };
84845
84846 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84847 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84848 index 30f5362..8ed8ac9 100644
84849 --- a/include/video/uvesafb.h
84850 +++ b/include/video/uvesafb.h
84851 @@ -122,6 +122,7 @@ struct uvesafb_par {
84852 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84853 u8 pmi_setpal; /* PMI for palette changes */
84854 u16 *pmi_base; /* protected mode interface location */
84855 + u8 *pmi_code; /* protected mode code location */
84856 void *pmi_start;
84857 void *pmi_pal;
84858 u8 *vbe_state_orig; /*
84859 diff --git a/init/Kconfig b/init/Kconfig
84860 index 9d3585b..ad45d34 100644
84861 --- a/init/Kconfig
84862 +++ b/init/Kconfig
84863 @@ -1093,6 +1093,7 @@ endif # CGROUPS
84864
84865 config CHECKPOINT_RESTORE
84866 bool "Checkpoint/restore support" if EXPERT
84867 + depends on !GRKERNSEC
84868 default n
84869 help
84870 Enables additional kernel features in a sake of checkpoint/restore.
84871 @@ -1570,7 +1571,7 @@ config SLUB_DEBUG
84872
84873 config COMPAT_BRK
84874 bool "Disable heap randomization"
84875 - default y
84876 + default n
84877 help
84878 Randomizing heap placement makes heap exploits harder, but it
84879 also breaks ancient binaries (including anything libc5 based).
84880 @@ -1858,7 +1859,7 @@ config INIT_ALL_POSSIBLE
84881 config STOP_MACHINE
84882 bool
84883 default y
84884 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84885 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84886 help
84887 Need stop_machine() primitive.
84888
84889 diff --git a/init/Makefile b/init/Makefile
84890 index 7bc47ee..6da2dc7 100644
84891 --- a/init/Makefile
84892 +++ b/init/Makefile
84893 @@ -2,6 +2,9 @@
84894 # Makefile for the linux kernel.
84895 #
84896
84897 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
84898 +asflags-y := $(GCC_PLUGINS_AFLAGS)
84899 +
84900 obj-y := main.o version.o mounts.o
84901 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84902 obj-y += noinitramfs.o
84903 diff --git a/init/do_mounts.c b/init/do_mounts.c
84904 index 82f2288..ea1430a 100644
84905 --- a/init/do_mounts.c
84906 +++ b/init/do_mounts.c
84907 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84908 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84909 {
84910 struct super_block *s;
84911 - int err = sys_mount(name, "/root", fs, flags, data);
84912 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84913 if (err)
84914 return err;
84915
84916 - sys_chdir("/root");
84917 + sys_chdir((const char __force_user *)"/root");
84918 s = current->fs->pwd.dentry->d_sb;
84919 ROOT_DEV = s->s_dev;
84920 printk(KERN_INFO
84921 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84922 va_start(args, fmt);
84923 vsprintf(buf, fmt, args);
84924 va_end(args);
84925 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84926 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84927 if (fd >= 0) {
84928 sys_ioctl(fd, FDEJECT, 0);
84929 sys_close(fd);
84930 }
84931 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84932 - fd = sys_open("/dev/console", O_RDWR, 0);
84933 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84934 if (fd >= 0) {
84935 sys_ioctl(fd, TCGETS, (long)&termios);
84936 termios.c_lflag &= ~ICANON;
84937 sys_ioctl(fd, TCSETSF, (long)&termios);
84938 - sys_read(fd, &c, 1);
84939 + sys_read(fd, (char __user *)&c, 1);
84940 termios.c_lflag |= ICANON;
84941 sys_ioctl(fd, TCSETSF, (long)&termios);
84942 sys_close(fd);
84943 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84944 mount_root();
84945 out:
84946 devtmpfs_mount("dev");
84947 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
84948 - sys_chroot(".");
84949 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84950 + sys_chroot((const char __force_user *)".");
84951 }
84952
84953 static bool is_tmpfs;
84954 diff --git a/init/do_mounts.h b/init/do_mounts.h
84955 index f5b978a..69dbfe8 100644
84956 --- a/init/do_mounts.h
84957 +++ b/init/do_mounts.h
84958 @@ -15,15 +15,15 @@ extern int root_mountflags;
84959
84960 static inline int create_dev(char *name, dev_t dev)
84961 {
84962 - sys_unlink(name);
84963 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84964 + sys_unlink((char __force_user *)name);
84965 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84966 }
84967
84968 #if BITS_PER_LONG == 32
84969 static inline u32 bstat(char *name)
84970 {
84971 struct stat64 stat;
84972 - if (sys_stat64(name, &stat) != 0)
84973 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84974 return 0;
84975 if (!S_ISBLK(stat.st_mode))
84976 return 0;
84977 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84978 static inline u32 bstat(char *name)
84979 {
84980 struct stat stat;
84981 - if (sys_newstat(name, &stat) != 0)
84982 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84983 return 0;
84984 if (!S_ISBLK(stat.st_mode))
84985 return 0;
84986 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84987 index 3e0878e..8a9d7a0 100644
84988 --- a/init/do_mounts_initrd.c
84989 +++ b/init/do_mounts_initrd.c
84990 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84991 {
84992 sys_unshare(CLONE_FS | CLONE_FILES);
84993 /* stdin/stdout/stderr for /linuxrc */
84994 - sys_open("/dev/console", O_RDWR, 0);
84995 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84996 sys_dup(0);
84997 sys_dup(0);
84998 /* move initrd over / and chdir/chroot in initrd root */
84999 - sys_chdir("/root");
85000 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
85001 - sys_chroot(".");
85002 + sys_chdir((const char __force_user *)"/root");
85003 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
85004 + sys_chroot((const char __force_user *)".");
85005 sys_setsid();
85006 return 0;
85007 }
85008 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
85009 create_dev("/dev/root.old", Root_RAM0);
85010 /* mount initrd on rootfs' /root */
85011 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
85012 - sys_mkdir("/old", 0700);
85013 - sys_chdir("/old");
85014 + sys_mkdir((const char __force_user *)"/old", 0700);
85015 + sys_chdir((const char __force_user *)"/old");
85016
85017 /* try loading default modules from initrd */
85018 load_default_modules();
85019 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
85020 current->flags &= ~PF_FREEZER_SKIP;
85021
85022 /* move initrd to rootfs' /old */
85023 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
85024 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
85025 /* switch root and cwd back to / of rootfs */
85026 - sys_chroot("..");
85027 + sys_chroot((const char __force_user *)"..");
85028
85029 if (new_decode_dev(real_root_dev) == Root_RAM0) {
85030 - sys_chdir("/old");
85031 + sys_chdir((const char __force_user *)"/old");
85032 return;
85033 }
85034
85035 - sys_chdir("/");
85036 + sys_chdir((const char __force_user *)"/");
85037 ROOT_DEV = new_decode_dev(real_root_dev);
85038 mount_root();
85039
85040 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
85041 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
85042 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
85043 if (!error)
85044 printk("okay\n");
85045 else {
85046 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
85047 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
85048 if (error == -ENOENT)
85049 printk("/initrd does not exist. Ignored.\n");
85050 else
85051 printk("failed\n");
85052 printk(KERN_NOTICE "Unmounting old root\n");
85053 - sys_umount("/old", MNT_DETACH);
85054 + sys_umount((char __force_user *)"/old", MNT_DETACH);
85055 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
85056 if (fd < 0) {
85057 error = fd;
85058 @@ -127,11 +127,11 @@ int __init initrd_load(void)
85059 * mounted in the normal path.
85060 */
85061 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
85062 - sys_unlink("/initrd.image");
85063 + sys_unlink((const char __force_user *)"/initrd.image");
85064 handle_initrd();
85065 return 1;
85066 }
85067 }
85068 - sys_unlink("/initrd.image");
85069 + sys_unlink((const char __force_user *)"/initrd.image");
85070 return 0;
85071 }
85072 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
85073 index 8cb6db5..d729f50 100644
85074 --- a/init/do_mounts_md.c
85075 +++ b/init/do_mounts_md.c
85076 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
85077 partitioned ? "_d" : "", minor,
85078 md_setup_args[ent].device_names);
85079
85080 - fd = sys_open(name, 0, 0);
85081 + fd = sys_open((char __force_user *)name, 0, 0);
85082 if (fd < 0) {
85083 printk(KERN_ERR "md: open failed - cannot start "
85084 "array %s\n", name);
85085 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
85086 * array without it
85087 */
85088 sys_close(fd);
85089 - fd = sys_open(name, 0, 0);
85090 + fd = sys_open((char __force_user *)name, 0, 0);
85091 sys_ioctl(fd, BLKRRPART, 0);
85092 }
85093 sys_close(fd);
85094 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
85095
85096 wait_for_device_probe();
85097
85098 - fd = sys_open("/dev/md0", 0, 0);
85099 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
85100 if (fd >= 0) {
85101 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
85102 sys_close(fd);
85103 diff --git a/init/init_task.c b/init/init_task.c
85104 index ba0a7f36..2bcf1d5 100644
85105 --- a/init/init_task.c
85106 +++ b/init/init_task.c
85107 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
85108 * Initial thread structure. Alignment of this is handled by a special
85109 * linker map entry.
85110 */
85111 +#ifdef CONFIG_X86
85112 +union thread_union init_thread_union __init_task_data;
85113 +#else
85114 union thread_union init_thread_union __init_task_data =
85115 { INIT_THREAD_INFO(init_task) };
85116 +#endif
85117 diff --git a/init/initramfs.c b/init/initramfs.c
85118 index a8497fa..35b3c90 100644
85119 --- a/init/initramfs.c
85120 +++ b/init/initramfs.c
85121 @@ -84,7 +84,7 @@ static void __init free_hash(void)
85122 }
85123 }
85124
85125 -static long __init do_utime(char *filename, time_t mtime)
85126 +static long __init do_utime(char __force_user *filename, time_t mtime)
85127 {
85128 struct timespec t[2];
85129
85130 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
85131 struct dir_entry *de, *tmp;
85132 list_for_each_entry_safe(de, tmp, &dir_list, list) {
85133 list_del(&de->list);
85134 - do_utime(de->name, de->mtime);
85135 + do_utime((char __force_user *)de->name, de->mtime);
85136 kfree(de->name);
85137 kfree(de);
85138 }
85139 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
85140 if (nlink >= 2) {
85141 char *old = find_link(major, minor, ino, mode, collected);
85142 if (old)
85143 - return (sys_link(old, collected) < 0) ? -1 : 1;
85144 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
85145 }
85146 return 0;
85147 }
85148 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
85149 {
85150 struct stat st;
85151
85152 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
85153 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
85154 if (S_ISDIR(st.st_mode))
85155 - sys_rmdir(path);
85156 + sys_rmdir((char __force_user *)path);
85157 else
85158 - sys_unlink(path);
85159 + sys_unlink((char __force_user *)path);
85160 }
85161 }
85162
85163 @@ -315,7 +315,7 @@ static int __init do_name(void)
85164 int openflags = O_WRONLY|O_CREAT;
85165 if (ml != 1)
85166 openflags |= O_TRUNC;
85167 - wfd = sys_open(collected, openflags, mode);
85168 + wfd = sys_open((char __force_user *)collected, openflags, mode);
85169
85170 if (wfd >= 0) {
85171 sys_fchown(wfd, uid, gid);
85172 @@ -327,17 +327,17 @@ static int __init do_name(void)
85173 }
85174 }
85175 } else if (S_ISDIR(mode)) {
85176 - sys_mkdir(collected, mode);
85177 - sys_chown(collected, uid, gid);
85178 - sys_chmod(collected, mode);
85179 + sys_mkdir((char __force_user *)collected, mode);
85180 + sys_chown((char __force_user *)collected, uid, gid);
85181 + sys_chmod((char __force_user *)collected, mode);
85182 dir_add(collected, mtime);
85183 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
85184 S_ISFIFO(mode) || S_ISSOCK(mode)) {
85185 if (maybe_link() == 0) {
85186 - sys_mknod(collected, mode, rdev);
85187 - sys_chown(collected, uid, gid);
85188 - sys_chmod(collected, mode);
85189 - do_utime(collected, mtime);
85190 + sys_mknod((char __force_user *)collected, mode, rdev);
85191 + sys_chown((char __force_user *)collected, uid, gid);
85192 + sys_chmod((char __force_user *)collected, mode);
85193 + do_utime((char __force_user *)collected, mtime);
85194 }
85195 }
85196 return 0;
85197 @@ -346,15 +346,15 @@ static int __init do_name(void)
85198 static int __init do_copy(void)
85199 {
85200 if (count >= body_len) {
85201 - sys_write(wfd, victim, body_len);
85202 + sys_write(wfd, (char __force_user *)victim, body_len);
85203 sys_close(wfd);
85204 - do_utime(vcollected, mtime);
85205 + do_utime((char __force_user *)vcollected, mtime);
85206 kfree(vcollected);
85207 eat(body_len);
85208 state = SkipIt;
85209 return 0;
85210 } else {
85211 - sys_write(wfd, victim, count);
85212 + sys_write(wfd, (char __force_user *)victim, count);
85213 body_len -= count;
85214 eat(count);
85215 return 1;
85216 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
85217 {
85218 collected[N_ALIGN(name_len) + body_len] = '\0';
85219 clean_path(collected, 0);
85220 - sys_symlink(collected + N_ALIGN(name_len), collected);
85221 - sys_lchown(collected, uid, gid);
85222 - do_utime(collected, mtime);
85223 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
85224 + sys_lchown((char __force_user *)collected, uid, gid);
85225 + do_utime((char __force_user *)collected, mtime);
85226 state = SkipIt;
85227 next_state = Reset;
85228 return 0;
85229 diff --git a/init/main.c b/init/main.c
85230 index 48655ce..d0113e4 100644
85231 --- a/init/main.c
85232 +++ b/init/main.c
85233 @@ -97,6 +97,8 @@ extern void radix_tree_init(void);
85234 static inline void mark_rodata_ro(void) { }
85235 #endif
85236
85237 +extern void grsecurity_init(void);
85238 +
85239 /*
85240 * Debug helper: via this flag we know that we are in 'early bootup code'
85241 * where only the boot processor is running with IRQ disabled. This means
85242 @@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
85243
85244 __setup("reset_devices", set_reset_devices);
85245
85246 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85247 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
85248 +static int __init setup_grsec_proc_gid(char *str)
85249 +{
85250 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
85251 + return 1;
85252 +}
85253 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
85254 +#endif
85255 +
85256 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
85257 +unsigned long pax_user_shadow_base __read_only;
85258 +EXPORT_SYMBOL(pax_user_shadow_base);
85259 +extern char pax_enter_kernel_user[];
85260 +extern char pax_exit_kernel_user[];
85261 +#endif
85262 +
85263 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
85264 +static int __init setup_pax_nouderef(char *str)
85265 +{
85266 +#ifdef CONFIG_X86_32
85267 + unsigned int cpu;
85268 + struct desc_struct *gdt;
85269 +
85270 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
85271 + gdt = get_cpu_gdt_table(cpu);
85272 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
85273 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
85274 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
85275 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
85276 + }
85277 + loadsegment(ds, __KERNEL_DS);
85278 + loadsegment(es, __KERNEL_DS);
85279 + loadsegment(ss, __KERNEL_DS);
85280 +#else
85281 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
85282 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
85283 + clone_pgd_mask = ~(pgdval_t)0UL;
85284 + pax_user_shadow_base = 0UL;
85285 + setup_clear_cpu_cap(X86_FEATURE_PCID);
85286 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
85287 +#endif
85288 +
85289 + return 0;
85290 +}
85291 +early_param("pax_nouderef", setup_pax_nouderef);
85292 +
85293 +#ifdef CONFIG_X86_64
85294 +static int __init setup_pax_weakuderef(char *str)
85295 +{
85296 + if (clone_pgd_mask != ~(pgdval_t)0UL)
85297 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
85298 + return 1;
85299 +}
85300 +__setup("pax_weakuderef", setup_pax_weakuderef);
85301 +#endif
85302 +#endif
85303 +
85304 +#ifdef CONFIG_PAX_SOFTMODE
85305 +int pax_softmode;
85306 +
85307 +static int __init setup_pax_softmode(char *str)
85308 +{
85309 + get_option(&str, &pax_softmode);
85310 + return 1;
85311 +}
85312 +__setup("pax_softmode=", setup_pax_softmode);
85313 +#endif
85314 +
85315 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
85316 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
85317 static const char *panic_later, *panic_param;
85318 @@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
85319 {
85320 int count = preempt_count();
85321 int ret;
85322 - char msgbuf[64];
85323 + const char *msg1 = "", *msg2 = "";
85324
85325 if (initcall_debug)
85326 ret = do_one_initcall_debug(fn);
85327 else
85328 ret = fn();
85329
85330 - msgbuf[0] = 0;
85331 -
85332 if (preempt_count() != count) {
85333 - sprintf(msgbuf, "preemption imbalance ");
85334 + msg1 = " preemption imbalance";
85335 preempt_count_set(count);
85336 }
85337 if (irqs_disabled()) {
85338 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
85339 + msg2 = " disabled interrupts";
85340 local_irq_enable();
85341 }
85342 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
85343 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
85344
85345 + add_latent_entropy();
85346 return ret;
85347 }
85348
85349 @@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
85350 {
85351 argv_init[0] = init_filename;
85352 return do_execve(getname_kernel(init_filename),
85353 - (const char __user *const __user *)argv_init,
85354 - (const char __user *const __user *)envp_init);
85355 + (const char __user *const __force_user *)argv_init,
85356 + (const char __user *const __force_user *)envp_init);
85357 }
85358
85359 static int try_to_run_init_process(const char *init_filename)
85360 @@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
85361 return ret;
85362 }
85363
85364 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85365 +extern int gr_init_ran;
85366 +#endif
85367 +
85368 static noinline void __init kernel_init_freeable(void);
85369
85370 static int __ref kernel_init(void *unused)
85371 @@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
85372 ramdisk_execute_command, ret);
85373 }
85374
85375 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85376 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
85377 + gr_init_ran = 1;
85378 +#endif
85379 +
85380 /*
85381 * We try each of these until one succeeds.
85382 *
85383 @@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
85384 do_basic_setup();
85385
85386 /* Open the /dev/console on the rootfs, this should never fail */
85387 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85388 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85389 pr_err("Warning: unable to open an initial console.\n");
85390
85391 (void) sys_dup(0);
85392 @@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
85393 if (!ramdisk_execute_command)
85394 ramdisk_execute_command = "/init";
85395
85396 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85397 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85398 ramdisk_execute_command = NULL;
85399 prepare_namespace();
85400 }
85401
85402 + grsecurity_init();
85403 +
85404 /*
85405 * Ok, we have completed the initial bootup, and
85406 * we're essentially up and running. Get rid of the
85407 diff --git a/ipc/compat.c b/ipc/compat.c
85408 index 45d035d..e4a7f99 100644
85409 --- a/ipc/compat.c
85410 +++ b/ipc/compat.c
85411 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85412 COMPAT_SHMLBA);
85413 if (err < 0)
85414 return err;
85415 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85416 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85417 }
85418 case SHMDT:
85419 return sys_shmdt(compat_ptr(ptr));
85420 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85421 index 998d31b..30c24df 100644
85422 --- a/ipc/ipc_sysctl.c
85423 +++ b/ipc/ipc_sysctl.c
85424 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85425 static int proc_ipc_dointvec(ctl_table *table, int write,
85426 void __user *buffer, size_t *lenp, loff_t *ppos)
85427 {
85428 - struct ctl_table ipc_table;
85429 + ctl_table_no_const ipc_table;
85430
85431 memcpy(&ipc_table, table, sizeof(ipc_table));
85432 ipc_table.data = get_ipc(table);
85433 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85434 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85435 void __user *buffer, size_t *lenp, loff_t *ppos)
85436 {
85437 - struct ctl_table ipc_table;
85438 + ctl_table_no_const ipc_table;
85439
85440 memcpy(&ipc_table, table, sizeof(ipc_table));
85441 ipc_table.data = get_ipc(table);
85442 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85443 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85444 void __user *buffer, size_t *lenp, loff_t *ppos)
85445 {
85446 - struct ctl_table ipc_table;
85447 + ctl_table_no_const ipc_table;
85448 size_t lenp_bef = *lenp;
85449 int rc;
85450
85451 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85452 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85453 void __user *buffer, size_t *lenp, loff_t *ppos)
85454 {
85455 - struct ctl_table ipc_table;
85456 + ctl_table_no_const ipc_table;
85457 memcpy(&ipc_table, table, sizeof(ipc_table));
85458 ipc_table.data = get_ipc(table);
85459
85460 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85461 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85462 void __user *buffer, size_t *lenp, loff_t *ppos)
85463 {
85464 - struct ctl_table ipc_table;
85465 + ctl_table_no_const ipc_table;
85466 size_t lenp_bef = *lenp;
85467 int oldval;
85468 int rc;
85469 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85470 index 5bb8bfe..a38ec05 100644
85471 --- a/ipc/mq_sysctl.c
85472 +++ b/ipc/mq_sysctl.c
85473 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85474 static int proc_mq_dointvec(ctl_table *table, int write,
85475 void __user *buffer, size_t *lenp, loff_t *ppos)
85476 {
85477 - struct ctl_table mq_table;
85478 + ctl_table_no_const mq_table;
85479 memcpy(&mq_table, table, sizeof(mq_table));
85480 mq_table.data = get_mq(table);
85481
85482 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85483 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85484 void __user *buffer, size_t *lenp, loff_t *ppos)
85485 {
85486 - struct ctl_table mq_table;
85487 + ctl_table_no_const mq_table;
85488 memcpy(&mq_table, table, sizeof(mq_table));
85489 mq_table.data = get_mq(table);
85490
85491 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85492 index 4fcf39a..d3cc2ec 100644
85493 --- a/ipc/mqueue.c
85494 +++ b/ipc/mqueue.c
85495 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85496 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85497 info->attr.mq_msgsize);
85498
85499 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85500 spin_lock(&mq_lock);
85501 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85502 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85503 diff --git a/ipc/msg.c b/ipc/msg.c
85504 index 6498531..b0ff3c8 100644
85505 --- a/ipc/msg.c
85506 +++ b/ipc/msg.c
85507 @@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85508 return security_msg_queue_associate(msq, msgflg);
85509 }
85510
85511 +static struct ipc_ops msg_ops = {
85512 + .getnew = newque,
85513 + .associate = msg_security,
85514 + .more_checks = NULL
85515 +};
85516 +
85517 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85518 {
85519 struct ipc_namespace *ns;
85520 - struct ipc_ops msg_ops;
85521 struct ipc_params msg_params;
85522
85523 ns = current->nsproxy->ipc_ns;
85524
85525 - msg_ops.getnew = newque;
85526 - msg_ops.associate = msg_security;
85527 - msg_ops.more_checks = NULL;
85528 -
85529 msg_params.key = key;
85530 msg_params.flg = msgflg;
85531
85532 diff --git a/ipc/sem.c b/ipc/sem.c
85533 index bee5554..e9af81dd 100644
85534 --- a/ipc/sem.c
85535 +++ b/ipc/sem.c
85536 @@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85537 return 0;
85538 }
85539
85540 +static struct ipc_ops sem_ops = {
85541 + .getnew = newary,
85542 + .associate = sem_security,
85543 + .more_checks = sem_more_checks
85544 +};
85545 +
85546 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85547 {
85548 struct ipc_namespace *ns;
85549 - struct ipc_ops sem_ops;
85550 struct ipc_params sem_params;
85551
85552 ns = current->nsproxy->ipc_ns;
85553 @@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85554 if (nsems < 0 || nsems > ns->sc_semmsl)
85555 return -EINVAL;
85556
85557 - sem_ops.getnew = newary;
85558 - sem_ops.associate = sem_security;
85559 - sem_ops.more_checks = sem_more_checks;
85560 -
85561 sem_params.key = key;
85562 sem_params.flg = semflg;
85563 sem_params.u.nsems = nsems;
85564 diff --git a/ipc/shm.c b/ipc/shm.c
85565 index 7645961..afc7f02 100644
85566 --- a/ipc/shm.c
85567 +++ b/ipc/shm.c
85568 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85569 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85570 #endif
85571
85572 +#ifdef CONFIG_GRKERNSEC
85573 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85574 + const time_t shm_createtime, const kuid_t cuid,
85575 + const int shmid);
85576 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85577 + const time_t shm_createtime);
85578 +#endif
85579 +
85580 void shm_init_ns(struct ipc_namespace *ns)
85581 {
85582 ns->shm_ctlmax = SHMMAX;
85583 @@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85584 shp->shm_lprid = 0;
85585 shp->shm_atim = shp->shm_dtim = 0;
85586 shp->shm_ctim = get_seconds();
85587 +#ifdef CONFIG_GRKERNSEC
85588 + {
85589 + struct timespec timeval;
85590 + do_posix_clock_monotonic_gettime(&timeval);
85591 +
85592 + shp->shm_createtime = timeval.tv_sec;
85593 + }
85594 +#endif
85595 shp->shm_segsz = size;
85596 shp->shm_nattch = 0;
85597 shp->shm_file = file;
85598 @@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85599 return 0;
85600 }
85601
85602 +static struct ipc_ops shm_ops = {
85603 + .getnew = newseg,
85604 + .associate = shm_security,
85605 + .more_checks = shm_more_checks
85606 +};
85607 +
85608 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85609 {
85610 struct ipc_namespace *ns;
85611 - struct ipc_ops shm_ops;
85612 struct ipc_params shm_params;
85613
85614 ns = current->nsproxy->ipc_ns;
85615
85616 - shm_ops.getnew = newseg;
85617 - shm_ops.associate = shm_security;
85618 - shm_ops.more_checks = shm_more_checks;
85619 -
85620 shm_params.key = key;
85621 shm_params.flg = shmflg;
85622 shm_params.u.size = size;
85623 @@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85624 f_mode = FMODE_READ | FMODE_WRITE;
85625 }
85626 if (shmflg & SHM_EXEC) {
85627 +
85628 +#ifdef CONFIG_PAX_MPROTECT
85629 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
85630 + goto out;
85631 +#endif
85632 +
85633 prot |= PROT_EXEC;
85634 acc_mode |= S_IXUGO;
85635 }
85636 @@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85637 if (err)
85638 goto out_unlock;
85639
85640 +#ifdef CONFIG_GRKERNSEC
85641 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85642 + shp->shm_perm.cuid, shmid) ||
85643 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85644 + err = -EACCES;
85645 + goto out_unlock;
85646 + }
85647 +#endif
85648 +
85649 ipc_lock_object(&shp->shm_perm);
85650
85651 /* check if shm_destroy() is tearing down shp */
85652 @@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85653 path = shp->shm_file->f_path;
85654 path_get(&path);
85655 shp->shm_nattch++;
85656 +#ifdef CONFIG_GRKERNSEC
85657 + shp->shm_lapid = current->pid;
85658 +#endif
85659 size = i_size_read(path.dentry->d_inode);
85660 ipc_unlock_object(&shp->shm_perm);
85661 rcu_read_unlock();
85662 diff --git a/ipc/util.c b/ipc/util.c
85663 index 2eb0d1e..0308564 100644
85664 --- a/ipc/util.c
85665 +++ b/ipc/util.c
85666 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
85667 int (*show)(struct seq_file *, void *);
85668 };
85669
85670 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85671 +
85672 static void ipc_memory_notifier(struct work_struct *work)
85673 {
85674 ipcns_notify(IPCNS_MEMCHANGED);
85675 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85676 granted_mode >>= 6;
85677 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85678 granted_mode >>= 3;
85679 +
85680 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85681 + return -1;
85682 +
85683 /* is there some bit set in requested_mode but not in granted_mode? */
85684 if ((requested_mode & ~granted_mode & 0007) &&
85685 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85686 diff --git a/kernel/acct.c b/kernel/acct.c
85687 index 8d6e145..33e0b1e 100644
85688 --- a/kernel/acct.c
85689 +++ b/kernel/acct.c
85690 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85691 */
85692 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85693 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85694 - file->f_op->write(file, (char *)&ac,
85695 + file->f_op->write(file, (char __force_user *)&ac,
85696 sizeof(acct_t), &file->f_pos);
85697 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85698 set_fs(fs);
85699 diff --git a/kernel/audit.c b/kernel/audit.c
85700 index 47845c5..bd9dd5b 100644
85701 --- a/kernel/audit.c
85702 +++ b/kernel/audit.c
85703 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85704 3) suppressed due to audit_rate_limit
85705 4) suppressed due to audit_backlog_limit
85706 */
85707 -static atomic_t audit_lost = ATOMIC_INIT(0);
85708 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85709
85710 /* The netlink socket. */
85711 static struct sock *audit_sock;
85712 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85713 unsigned long now;
85714 int print;
85715
85716 - atomic_inc(&audit_lost);
85717 + atomic_inc_unchecked(&audit_lost);
85718
85719 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85720
85721 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85722 if (print) {
85723 if (printk_ratelimit())
85724 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85725 - atomic_read(&audit_lost),
85726 + atomic_read_unchecked(&audit_lost),
85727 audit_rate_limit,
85728 audit_backlog_limit);
85729 audit_panic(message);
85730 @@ -808,7 +808,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85731 s.pid = audit_pid;
85732 s.rate_limit = audit_rate_limit;
85733 s.backlog_limit = audit_backlog_limit;
85734 - s.lost = atomic_read(&audit_lost);
85735 + s.lost = atomic_read_unchecked(&audit_lost);
85736 s.backlog = skb_queue_len(&audit_skb_queue);
85737 s.version = AUDIT_VERSION_LATEST;
85738 s.backlog_wait_time = audit_backlog_wait_time;
85739 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85740 index 21eae3c..66db239 100644
85741 --- a/kernel/auditsc.c
85742 +++ b/kernel/auditsc.c
85743 @@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85744 }
85745
85746 /* global counter which is incremented every time something logs in */
85747 -static atomic_t session_id = ATOMIC_INIT(0);
85748 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85749
85750 static int audit_set_loginuid_perm(kuid_t loginuid)
85751 {
85752 @@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
85753
85754 /* are we setting or clearing? */
85755 if (uid_valid(loginuid))
85756 - sessionid = (unsigned int)atomic_inc_return(&session_id);
85757 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85758
85759 task->sessionid = sessionid;
85760 task->loginuid = loginuid;
85761 diff --git a/kernel/capability.c b/kernel/capability.c
85762 index 24663b3..b926ae1 100644
85763 --- a/kernel/capability.c
85764 +++ b/kernel/capability.c
85765 @@ -193,6 +193,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85766 * before modification is attempted and the application
85767 * fails.
85768 */
85769 + if (tocopy > ARRAY_SIZE(kdata))
85770 + return -EFAULT;
85771 +
85772 if (copy_to_user(dataptr, kdata, tocopy
85773 * sizeof(struct __user_cap_data_struct))) {
85774 return -EFAULT;
85775 @@ -294,10 +297,11 @@ bool has_ns_capability(struct task_struct *t,
85776 int ret;
85777
85778 rcu_read_lock();
85779 - ret = security_capable(__task_cred(t), ns, cap);
85780 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85781 + gr_task_is_capable(t, __task_cred(t), cap);
85782 rcu_read_unlock();
85783
85784 - return (ret == 0);
85785 + return ret;
85786 }
85787
85788 /**
85789 @@ -334,10 +338,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85790 int ret;
85791
85792 rcu_read_lock();
85793 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
85794 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85795 rcu_read_unlock();
85796
85797 - return (ret == 0);
85798 + return ret;
85799 }
85800
85801 /**
85802 @@ -375,7 +379,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85803 BUG();
85804 }
85805
85806 - if (security_capable(current_cred(), ns, cap) == 0) {
85807 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85808 current->flags |= PF_SUPERPRIV;
85809 return true;
85810 }
85811 @@ -383,6 +387,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85812 }
85813 EXPORT_SYMBOL(ns_capable);
85814
85815 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
85816 +{
85817 + if (unlikely(!cap_valid(cap))) {
85818 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85819 + BUG();
85820 + }
85821 +
85822 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85823 + current->flags |= PF_SUPERPRIV;
85824 + return true;
85825 + }
85826 + return false;
85827 +}
85828 +EXPORT_SYMBOL(ns_capable_nolog);
85829 +
85830 /**
85831 * file_ns_capable - Determine if the file's opener had a capability in effect
85832 * @file: The file we want to check
85833 @@ -423,6 +442,12 @@ bool capable(int cap)
85834 }
85835 EXPORT_SYMBOL(capable);
85836
85837 +bool capable_nolog(int cap)
85838 +{
85839 + return ns_capable_nolog(&init_user_ns, cap);
85840 +}
85841 +EXPORT_SYMBOL(capable_nolog);
85842 +
85843 /**
85844 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
85845 * @inode: The inode in question
85846 @@ -440,3 +465,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
85847 kgid_has_mapping(ns, inode->i_gid);
85848 }
85849 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
85850 +
85851 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
85852 +{
85853 + struct user_namespace *ns = current_user_ns();
85854 +
85855 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
85856 + kgid_has_mapping(ns, inode->i_gid);
85857 +}
85858 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
85859 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85860 index 073226b..969c746 100644
85861 --- a/kernel/cgroup.c
85862 +++ b/kernel/cgroup.c
85863 @@ -4808,7 +4808,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85864 struct task_struct *task;
85865 int count = 0;
85866
85867 - seq_printf(seq, "css_set %p\n", cset);
85868 + seq_printf(seq, "css_set %pK\n", cset);
85869
85870 list_for_each_entry(task, &cset->tasks, cg_list) {
85871 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
85872 diff --git a/kernel/compat.c b/kernel/compat.c
85873 index e40b043..3da8f51 100644
85874 --- a/kernel/compat.c
85875 +++ b/kernel/compat.c
85876 @@ -13,6 +13,7 @@
85877
85878 #include <linux/linkage.h>
85879 #include <linux/compat.h>
85880 +#include <linux/module.h>
85881 #include <linux/errno.h>
85882 #include <linux/time.h>
85883 #include <linux/signal.h>
85884 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85885 mm_segment_t oldfs;
85886 long ret;
85887
85888 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85889 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85890 oldfs = get_fs();
85891 set_fs(KERNEL_DS);
85892 ret = hrtimer_nanosleep_restart(restart);
85893 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
85894 oldfs = get_fs();
85895 set_fs(KERNEL_DS);
85896 ret = hrtimer_nanosleep(&tu,
85897 - rmtp ? (struct timespec __user *)&rmt : NULL,
85898 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
85899 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85900 set_fs(oldfs);
85901
85902 @@ -361,7 +362,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
85903 mm_segment_t old_fs = get_fs();
85904
85905 set_fs(KERNEL_DS);
85906 - ret = sys_sigpending((old_sigset_t __user *) &s);
85907 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
85908 set_fs(old_fs);
85909 if (ret == 0)
85910 ret = put_user(s, set);
85911 @@ -451,7 +452,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
85912 mm_segment_t old_fs = get_fs();
85913
85914 set_fs(KERNEL_DS);
85915 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
85916 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85917 set_fs(old_fs);
85918
85919 if (!ret) {
85920 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85921 set_fs (KERNEL_DS);
85922 ret = sys_wait4(pid,
85923 (stat_addr ?
85924 - (unsigned int __user *) &status : NULL),
85925 - options, (struct rusage __user *) &r);
85926 + (unsigned int __force_user *) &status : NULL),
85927 + options, (struct rusage __force_user *) &r);
85928 set_fs (old_fs);
85929
85930 if (ret > 0) {
85931 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85932 memset(&info, 0, sizeof(info));
85933
85934 set_fs(KERNEL_DS);
85935 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85936 - uru ? (struct rusage __user *)&ru : NULL);
85937 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85938 + uru ? (struct rusage __force_user *)&ru : NULL);
85939 set_fs(old_fs);
85940
85941 if ((ret < 0) || (info.si_signo == 0))
85942 @@ -695,8 +696,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
85943 oldfs = get_fs();
85944 set_fs(KERNEL_DS);
85945 err = sys_timer_settime(timer_id, flags,
85946 - (struct itimerspec __user *) &newts,
85947 - (struct itimerspec __user *) &oldts);
85948 + (struct itimerspec __force_user *) &newts,
85949 + (struct itimerspec __force_user *) &oldts);
85950 set_fs(oldfs);
85951 if (!err && old && put_compat_itimerspec(old, &oldts))
85952 return -EFAULT;
85953 @@ -713,7 +714,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
85954 oldfs = get_fs();
85955 set_fs(KERNEL_DS);
85956 err = sys_timer_gettime(timer_id,
85957 - (struct itimerspec __user *) &ts);
85958 + (struct itimerspec __force_user *) &ts);
85959 set_fs(oldfs);
85960 if (!err && put_compat_itimerspec(setting, &ts))
85961 return -EFAULT;
85962 @@ -732,7 +733,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
85963 oldfs = get_fs();
85964 set_fs(KERNEL_DS);
85965 err = sys_clock_settime(which_clock,
85966 - (struct timespec __user *) &ts);
85967 + (struct timespec __force_user *) &ts);
85968 set_fs(oldfs);
85969 return err;
85970 }
85971 @@ -747,7 +748,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
85972 oldfs = get_fs();
85973 set_fs(KERNEL_DS);
85974 err = sys_clock_gettime(which_clock,
85975 - (struct timespec __user *) &ts);
85976 + (struct timespec __force_user *) &ts);
85977 set_fs(oldfs);
85978 if (!err && compat_put_timespec(&ts, tp))
85979 return -EFAULT;
85980 @@ -767,7 +768,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
85981
85982 oldfs = get_fs();
85983 set_fs(KERNEL_DS);
85984 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85985 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85986 set_fs(oldfs);
85987
85988 err = compat_put_timex(utp, &txc);
85989 @@ -787,7 +788,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
85990 oldfs = get_fs();
85991 set_fs(KERNEL_DS);
85992 err = sys_clock_getres(which_clock,
85993 - (struct timespec __user *) &ts);
85994 + (struct timespec __force_user *) &ts);
85995 set_fs(oldfs);
85996 if (!err && tp && compat_put_timespec(&ts, tp))
85997 return -EFAULT;
85998 @@ -801,7 +802,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85999 struct timespec tu;
86000 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
86001
86002 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
86003 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
86004 oldfs = get_fs();
86005 set_fs(KERNEL_DS);
86006 err = clock_nanosleep_restart(restart);
86007 @@ -833,8 +834,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
86008 oldfs = get_fs();
86009 set_fs(KERNEL_DS);
86010 err = sys_clock_nanosleep(which_clock, flags,
86011 - (struct timespec __user *) &in,
86012 - (struct timespec __user *) &out);
86013 + (struct timespec __force_user *) &in,
86014 + (struct timespec __force_user *) &out);
86015 set_fs(oldfs);
86016
86017 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
86018 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
86019 mm_segment_t old_fs = get_fs();
86020
86021 set_fs(KERNEL_DS);
86022 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
86023 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
86024 set_fs(old_fs);
86025 if (compat_put_timespec(&t, interval))
86026 return -EFAULT;
86027 diff --git a/kernel/configs.c b/kernel/configs.c
86028 index c18b1f1..b9a0132 100644
86029 --- a/kernel/configs.c
86030 +++ b/kernel/configs.c
86031 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
86032 struct proc_dir_entry *entry;
86033
86034 /* create the current config file */
86035 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
86036 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
86037 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
86038 + &ikconfig_file_ops);
86039 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
86040 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
86041 + &ikconfig_file_ops);
86042 +#endif
86043 +#else
86044 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
86045 &ikconfig_file_ops);
86046 +#endif
86047 +
86048 if (!entry)
86049 return -ENOMEM;
86050
86051 diff --git a/kernel/cred.c b/kernel/cred.c
86052 index e0573a4..26c0fd3 100644
86053 --- a/kernel/cred.c
86054 +++ b/kernel/cred.c
86055 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
86056 validate_creds(cred);
86057 alter_cred_subscribers(cred, -1);
86058 put_cred(cred);
86059 +
86060 +#ifdef CONFIG_GRKERNSEC_SETXID
86061 + cred = (struct cred *) tsk->delayed_cred;
86062 + if (cred != NULL) {
86063 + tsk->delayed_cred = NULL;
86064 + validate_creds(cred);
86065 + alter_cred_subscribers(cred, -1);
86066 + put_cred(cred);
86067 + }
86068 +#endif
86069 }
86070
86071 /**
86072 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
86073 * Always returns 0 thus allowing this function to be tail-called at the end
86074 * of, say, sys_setgid().
86075 */
86076 -int commit_creds(struct cred *new)
86077 +static int __commit_creds(struct cred *new)
86078 {
86079 struct task_struct *task = current;
86080 const struct cred *old = task->real_cred;
86081 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
86082
86083 get_cred(new); /* we will require a ref for the subj creds too */
86084
86085 + gr_set_role_label(task, new->uid, new->gid);
86086 +
86087 /* dumpability changes */
86088 if (!uid_eq(old->euid, new->euid) ||
86089 !gid_eq(old->egid, new->egid) ||
86090 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
86091 put_cred(old);
86092 return 0;
86093 }
86094 +#ifdef CONFIG_GRKERNSEC_SETXID
86095 +extern int set_user(struct cred *new);
86096 +
86097 +void gr_delayed_cred_worker(void)
86098 +{
86099 + const struct cred *new = current->delayed_cred;
86100 + struct cred *ncred;
86101 +
86102 + current->delayed_cred = NULL;
86103 +
86104 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
86105 + // from doing get_cred on it when queueing this
86106 + put_cred(new);
86107 + return;
86108 + } else if (new == NULL)
86109 + return;
86110 +
86111 + ncred = prepare_creds();
86112 + if (!ncred)
86113 + goto die;
86114 + // uids
86115 + ncred->uid = new->uid;
86116 + ncred->euid = new->euid;
86117 + ncred->suid = new->suid;
86118 + ncred->fsuid = new->fsuid;
86119 + // gids
86120 + ncred->gid = new->gid;
86121 + ncred->egid = new->egid;
86122 + ncred->sgid = new->sgid;
86123 + ncred->fsgid = new->fsgid;
86124 + // groups
86125 + set_groups(ncred, new->group_info);
86126 + // caps
86127 + ncred->securebits = new->securebits;
86128 + ncred->cap_inheritable = new->cap_inheritable;
86129 + ncred->cap_permitted = new->cap_permitted;
86130 + ncred->cap_effective = new->cap_effective;
86131 + ncred->cap_bset = new->cap_bset;
86132 +
86133 + if (set_user(ncred)) {
86134 + abort_creds(ncred);
86135 + goto die;
86136 + }
86137 +
86138 + // from doing get_cred on it when queueing this
86139 + put_cred(new);
86140 +
86141 + __commit_creds(ncred);
86142 + return;
86143 +die:
86144 + // from doing get_cred on it when queueing this
86145 + put_cred(new);
86146 + do_group_exit(SIGKILL);
86147 +}
86148 +#endif
86149 +
86150 +int commit_creds(struct cred *new)
86151 +{
86152 +#ifdef CONFIG_GRKERNSEC_SETXID
86153 + int ret;
86154 + int schedule_it = 0;
86155 + struct task_struct *t;
86156 + unsigned oldsecurebits = current_cred()->securebits;
86157 +
86158 + /* we won't get called with tasklist_lock held for writing
86159 + and interrupts disabled as the cred struct in that case is
86160 + init_cred
86161 + */
86162 + if (grsec_enable_setxid && !current_is_single_threaded() &&
86163 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
86164 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
86165 + schedule_it = 1;
86166 + }
86167 + ret = __commit_creds(new);
86168 + if (schedule_it) {
86169 + rcu_read_lock();
86170 + read_lock(&tasklist_lock);
86171 + for (t = next_thread(current); t != current;
86172 + t = next_thread(t)) {
86173 + /* we'll check if the thread has uid 0 in
86174 + * the delayed worker routine
86175 + */
86176 + if (task_securebits(t) == oldsecurebits &&
86177 + t->delayed_cred == NULL) {
86178 + t->delayed_cred = get_cred(new);
86179 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
86180 + set_tsk_need_resched(t);
86181 + }
86182 + }
86183 + read_unlock(&tasklist_lock);
86184 + rcu_read_unlock();
86185 + }
86186 +
86187 + return ret;
86188 +#else
86189 + return __commit_creds(new);
86190 +#endif
86191 +}
86192 +
86193 EXPORT_SYMBOL(commit_creds);
86194
86195 /**
86196 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
86197 index 2956c8d..cfe1e2e 100644
86198 --- a/kernel/debug/debug_core.c
86199 +++ b/kernel/debug/debug_core.c
86200 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
86201 */
86202 static atomic_t masters_in_kgdb;
86203 static atomic_t slaves_in_kgdb;
86204 -static atomic_t kgdb_break_tasklet_var;
86205 +static atomic_unchecked_t kgdb_break_tasklet_var;
86206 atomic_t kgdb_setting_breakpoint;
86207
86208 struct task_struct *kgdb_usethread;
86209 @@ -134,7 +134,7 @@ int kgdb_single_step;
86210 static pid_t kgdb_sstep_pid;
86211
86212 /* to keep track of the CPU which is doing the single stepping*/
86213 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86214 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86215
86216 /*
86217 * If you are debugging a problem where roundup (the collection of
86218 @@ -549,7 +549,7 @@ return_normal:
86219 * kernel will only try for the value of sstep_tries before
86220 * giving up and continuing on.
86221 */
86222 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
86223 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
86224 (kgdb_info[cpu].task &&
86225 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
86226 atomic_set(&kgdb_active, -1);
86227 @@ -647,8 +647,8 @@ cpu_master_loop:
86228 }
86229
86230 kgdb_restore:
86231 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
86232 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
86233 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
86234 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
86235 if (kgdb_info[sstep_cpu].task)
86236 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
86237 else
86238 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
86239 static void kgdb_tasklet_bpt(unsigned long ing)
86240 {
86241 kgdb_breakpoint();
86242 - atomic_set(&kgdb_break_tasklet_var, 0);
86243 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
86244 }
86245
86246 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
86247
86248 void kgdb_schedule_breakpoint(void)
86249 {
86250 - if (atomic_read(&kgdb_break_tasklet_var) ||
86251 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
86252 atomic_read(&kgdb_active) != -1 ||
86253 atomic_read(&kgdb_setting_breakpoint))
86254 return;
86255 - atomic_inc(&kgdb_break_tasklet_var);
86256 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
86257 tasklet_schedule(&kgdb_tasklet_breakpoint);
86258 }
86259 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
86260 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
86261 index 0b097c8..11dd5c5 100644
86262 --- a/kernel/debug/kdb/kdb_main.c
86263 +++ b/kernel/debug/kdb/kdb_main.c
86264 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
86265 continue;
86266
86267 kdb_printf("%-20s%8u 0x%p ", mod->name,
86268 - mod->core_size, (void *)mod);
86269 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
86270 #ifdef CONFIG_MODULE_UNLOAD
86271 kdb_printf("%4ld ", module_refcount(mod));
86272 #endif
86273 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
86274 kdb_printf(" (Loading)");
86275 else
86276 kdb_printf(" (Live)");
86277 - kdb_printf(" 0x%p", mod->module_core);
86278 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
86279
86280 #ifdef CONFIG_MODULE_UNLOAD
86281 {
86282 diff --git a/kernel/events/core.c b/kernel/events/core.c
86283 index 440eefc..0909f02 100644
86284 --- a/kernel/events/core.c
86285 +++ b/kernel/events/core.c
86286 @@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
86287 * 0 - disallow raw tracepoint access for unpriv
86288 * 1 - disallow cpu events for unpriv
86289 * 2 - disallow kernel profiling for unpriv
86290 + * 3 - disallow all unpriv perf event use
86291 */
86292 -int sysctl_perf_event_paranoid __read_mostly = 1;
86293 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86294 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
86295 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
86296 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
86297 +#else
86298 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
86299 +#endif
86300
86301 /* Minimum for 512 kiB + 1 user control page */
86302 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
86303 @@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
86304
86305 tmp *= sysctl_perf_cpu_time_max_percent;
86306 do_div(tmp, 100);
86307 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
86308 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
86309 }
86310
86311 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
86312 @@ -291,7 +298,7 @@ void perf_sample_event_took(u64 sample_len_ns)
86313 }
86314 }
86315
86316 -static atomic64_t perf_event_id;
86317 +static atomic64_unchecked_t perf_event_id;
86318
86319 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
86320 enum event_type_t event_type);
86321 @@ -3002,7 +3009,7 @@ static void __perf_event_read(void *info)
86322
86323 static inline u64 perf_event_count(struct perf_event *event)
86324 {
86325 - return local64_read(&event->count) + atomic64_read(&event->child_count);
86326 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
86327 }
86328
86329 static u64 perf_event_read(struct perf_event *event)
86330 @@ -3361,9 +3368,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
86331 mutex_lock(&event->child_mutex);
86332 total += perf_event_read(event);
86333 *enabled += event->total_time_enabled +
86334 - atomic64_read(&event->child_total_time_enabled);
86335 + atomic64_read_unchecked(&event->child_total_time_enabled);
86336 *running += event->total_time_running +
86337 - atomic64_read(&event->child_total_time_running);
86338 + atomic64_read_unchecked(&event->child_total_time_running);
86339
86340 list_for_each_entry(child, &event->child_list, child_list) {
86341 total += perf_event_read(child);
86342 @@ -3792,10 +3799,10 @@ void perf_event_update_userpage(struct perf_event *event)
86343 userpg->offset -= local64_read(&event->hw.prev_count);
86344
86345 userpg->time_enabled = enabled +
86346 - atomic64_read(&event->child_total_time_enabled);
86347 + atomic64_read_unchecked(&event->child_total_time_enabled);
86348
86349 userpg->time_running = running +
86350 - atomic64_read(&event->child_total_time_running);
86351 + atomic64_read_unchecked(&event->child_total_time_running);
86352
86353 arch_perf_update_userpage(userpg, now);
86354
86355 @@ -4359,7 +4366,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
86356
86357 /* Data. */
86358 sp = perf_user_stack_pointer(regs);
86359 - rem = __output_copy_user(handle, (void *) sp, dump_size);
86360 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
86361 dyn_size = dump_size - rem;
86362
86363 perf_output_skip(handle, rem);
86364 @@ -4450,11 +4457,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
86365 values[n++] = perf_event_count(event);
86366 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
86367 values[n++] = enabled +
86368 - atomic64_read(&event->child_total_time_enabled);
86369 + atomic64_read_unchecked(&event->child_total_time_enabled);
86370 }
86371 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86372 values[n++] = running +
86373 - atomic64_read(&event->child_total_time_running);
86374 + atomic64_read_unchecked(&event->child_total_time_running);
86375 }
86376 if (read_format & PERF_FORMAT_ID)
86377 values[n++] = primary_event_id(event);
86378 @@ -6733,7 +6740,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86379 event->parent = parent_event;
86380
86381 event->ns = get_pid_ns(task_active_pid_ns(current));
86382 - event->id = atomic64_inc_return(&perf_event_id);
86383 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
86384
86385 event->state = PERF_EVENT_STATE_INACTIVE;
86386
86387 @@ -7015,6 +7022,11 @@ SYSCALL_DEFINE5(perf_event_open,
86388 if (flags & ~PERF_FLAG_ALL)
86389 return -EINVAL;
86390
86391 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86392 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86393 + return -EACCES;
86394 +#endif
86395 +
86396 err = perf_copy_attr(attr_uptr, &attr);
86397 if (err)
86398 return err;
86399 @@ -7353,10 +7365,10 @@ static void sync_child_event(struct perf_event *child_event,
86400 /*
86401 * Add back the child's count to the parent's count:
86402 */
86403 - atomic64_add(child_val, &parent_event->child_count);
86404 - atomic64_add(child_event->total_time_enabled,
86405 + atomic64_add_unchecked(child_val, &parent_event->child_count);
86406 + atomic64_add_unchecked(child_event->total_time_enabled,
86407 &parent_event->child_total_time_enabled);
86408 - atomic64_add(child_event->total_time_running,
86409 + atomic64_add_unchecked(child_event->total_time_running,
86410 &parent_event->child_total_time_running);
86411
86412 /*
86413 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86414 index 569b2187..19940d9 100644
86415 --- a/kernel/events/internal.h
86416 +++ b/kernel/events/internal.h
86417 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86418 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86419 }
86420
86421 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86422 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86423 static inline unsigned long \
86424 func_name(struct perf_output_handle *handle, \
86425 - const void *buf, unsigned long len) \
86426 + const void user *buf, unsigned long len) \
86427 { \
86428 unsigned long size, written; \
86429 \
86430 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86431 return 0;
86432 }
86433
86434 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86435 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86436
86437 static inline unsigned long
86438 memcpy_skip(void *dst, const void *src, unsigned long n)
86439 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86440 return 0;
86441 }
86442
86443 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86444 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86445
86446 #ifndef arch_perf_out_copy_user
86447 #define arch_perf_out_copy_user arch_perf_out_copy_user
86448 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86449 }
86450 #endif
86451
86452 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86453 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86454
86455 /* Callchain handling */
86456 extern struct perf_callchain_entry *
86457 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86458 index 04709b6..d330828 100644
86459 --- a/kernel/events/uprobes.c
86460 +++ b/kernel/events/uprobes.c
86461 @@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86462 {
86463 struct page *page;
86464 uprobe_opcode_t opcode;
86465 - int result;
86466 + long result;
86467
86468 pagefault_disable();
86469 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86470 diff --git a/kernel/exit.c b/kernel/exit.c
86471 index 6ed6a1d..edecb0e 100644
86472 --- a/kernel/exit.c
86473 +++ b/kernel/exit.c
86474 @@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86475 struct task_struct *leader;
86476 int zap_leader;
86477 repeat:
86478 +#ifdef CONFIG_NET
86479 + gr_del_task_from_ip_table(p);
86480 +#endif
86481 +
86482 /* don't need to get the RCU readlock here - the process is dead and
86483 * can't be modifying its own credentials. But shut RCU-lockdep up */
86484 rcu_read_lock();
86485 @@ -330,7 +334,7 @@ int allow_signal(int sig)
86486 * know it'll be handled, so that they don't get converted to
86487 * SIGKILL or just silently dropped.
86488 */
86489 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86490 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86491 recalc_sigpending();
86492 spin_unlock_irq(&current->sighand->siglock);
86493 return 0;
86494 @@ -699,6 +703,8 @@ void do_exit(long code)
86495 struct task_struct *tsk = current;
86496 int group_dead;
86497
86498 + set_fs(USER_DS);
86499 +
86500 profile_task_exit(tsk);
86501
86502 WARN_ON(blk_needs_flush_plug(tsk));
86503 @@ -715,7 +721,6 @@ void do_exit(long code)
86504 * mm_release()->clear_child_tid() from writing to a user-controlled
86505 * kernel address.
86506 */
86507 - set_fs(USER_DS);
86508
86509 ptrace_event(PTRACE_EVENT_EXIT, code);
86510
86511 @@ -774,6 +779,9 @@ void do_exit(long code)
86512 tsk->exit_code = code;
86513 taskstats_exit(tsk, group_dead);
86514
86515 + gr_acl_handle_psacct(tsk, code);
86516 + gr_acl_handle_exit();
86517 +
86518 exit_mm(tsk);
86519
86520 if (group_dead)
86521 @@ -893,7 +901,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86522 * Take down every thread in the group. This is called by fatal signals
86523 * as well as by sys_exit_group (below).
86524 */
86525 -void
86526 +__noreturn void
86527 do_group_exit(int exit_code)
86528 {
86529 struct signal_struct *sig = current->signal;
86530 diff --git a/kernel/fork.c b/kernel/fork.c
86531 index 68b9226..0700bf6 100644
86532 --- a/kernel/fork.c
86533 +++ b/kernel/fork.c
86534 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
86535 # endif
86536 #endif
86537
86538 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86539 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86540 + int node, void **lowmem_stack)
86541 +{
86542 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
86543 + void *ret = NULL;
86544 + unsigned int i;
86545 +
86546 + *lowmem_stack = alloc_thread_info_node(tsk, node);
86547 + if (*lowmem_stack == NULL)
86548 + goto out;
86549 +
86550 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
86551 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
86552 +
86553 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
86554 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
86555 + if (ret == NULL) {
86556 + free_thread_info(*lowmem_stack);
86557 + *lowmem_stack = NULL;
86558 + }
86559 +
86560 +out:
86561 + return ret;
86562 +}
86563 +
86564 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86565 +{
86566 + unmap_process_stacks(tsk);
86567 +}
86568 +#else
86569 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86570 + int node, void **lowmem_stack)
86571 +{
86572 + return alloc_thread_info_node(tsk, node);
86573 +}
86574 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86575 +{
86576 + free_thread_info(ti);
86577 +}
86578 +#endif
86579 +
86580 /* SLAB cache for signal_struct structures (tsk->signal) */
86581 static struct kmem_cache *signal_cachep;
86582
86583 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
86584 /* SLAB cache for mm_struct structures (tsk->mm) */
86585 static struct kmem_cache *mm_cachep;
86586
86587 -static void account_kernel_stack(struct thread_info *ti, int account)
86588 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
86589 {
86590 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86591 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
86592 +#else
86593 struct zone *zone = page_zone(virt_to_page(ti));
86594 +#endif
86595
86596 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
86597 }
86598
86599 void free_task(struct task_struct *tsk)
86600 {
86601 - account_kernel_stack(tsk->stack, -1);
86602 + account_kernel_stack(tsk, tsk->stack, -1);
86603 arch_release_thread_info(tsk->stack);
86604 - free_thread_info(tsk->stack);
86605 + gr_free_thread_info(tsk, tsk->stack);
86606 rt_mutex_debug_task_free(tsk);
86607 ftrace_graph_exit_task(tsk);
86608 put_seccomp_filter(tsk);
86609 @@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86610 struct task_struct *tsk;
86611 struct thread_info *ti;
86612 unsigned long *stackend;
86613 + void *lowmem_stack;
86614 int node = tsk_fork_get_node(orig);
86615 int err;
86616
86617 @@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86618 if (!tsk)
86619 return NULL;
86620
86621 - ti = alloc_thread_info_node(tsk, node);
86622 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
86623 if (!ti)
86624 goto free_tsk;
86625
86626 @@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86627 goto free_ti;
86628
86629 tsk->stack = ti;
86630 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86631 + tsk->lowmem_stack = lowmem_stack;
86632 +#endif
86633
86634 setup_thread_stack(tsk, orig);
86635 clear_user_return_notifier(tsk);
86636 @@ -323,7 +373,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86637 *stackend = STACK_END_MAGIC; /* for overflow detection */
86638
86639 #ifdef CONFIG_CC_STACKPROTECTOR
86640 - tsk->stack_canary = get_random_int();
86641 + tsk->stack_canary = pax_get_random_long();
86642 #endif
86643
86644 /*
86645 @@ -337,24 +387,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86646 tsk->splice_pipe = NULL;
86647 tsk->task_frag.page = NULL;
86648
86649 - account_kernel_stack(ti, 1);
86650 + account_kernel_stack(tsk, ti, 1);
86651
86652 return tsk;
86653
86654 free_ti:
86655 - free_thread_info(ti);
86656 + gr_free_thread_info(tsk, ti);
86657 free_tsk:
86658 free_task_struct(tsk);
86659 return NULL;
86660 }
86661
86662 #ifdef CONFIG_MMU
86663 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86664 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86665 +{
86666 + struct vm_area_struct *tmp;
86667 + unsigned long charge;
86668 + struct file *file;
86669 + int retval;
86670 +
86671 + charge = 0;
86672 + if (mpnt->vm_flags & VM_ACCOUNT) {
86673 + unsigned long len = vma_pages(mpnt);
86674 +
86675 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86676 + goto fail_nomem;
86677 + charge = len;
86678 + }
86679 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86680 + if (!tmp)
86681 + goto fail_nomem;
86682 + *tmp = *mpnt;
86683 + tmp->vm_mm = mm;
86684 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
86685 + retval = vma_dup_policy(mpnt, tmp);
86686 + if (retval)
86687 + goto fail_nomem_policy;
86688 + if (anon_vma_fork(tmp, mpnt))
86689 + goto fail_nomem_anon_vma_fork;
86690 + tmp->vm_flags &= ~VM_LOCKED;
86691 + tmp->vm_next = tmp->vm_prev = NULL;
86692 + tmp->vm_mirror = NULL;
86693 + file = tmp->vm_file;
86694 + if (file) {
86695 + struct inode *inode = file_inode(file);
86696 + struct address_space *mapping = file->f_mapping;
86697 +
86698 + get_file(file);
86699 + if (tmp->vm_flags & VM_DENYWRITE)
86700 + atomic_dec(&inode->i_writecount);
86701 + mutex_lock(&mapping->i_mmap_mutex);
86702 + if (tmp->vm_flags & VM_SHARED)
86703 + mapping->i_mmap_writable++;
86704 + flush_dcache_mmap_lock(mapping);
86705 + /* insert tmp into the share list, just after mpnt */
86706 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86707 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86708 + else
86709 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86710 + flush_dcache_mmap_unlock(mapping);
86711 + mutex_unlock(&mapping->i_mmap_mutex);
86712 + }
86713 +
86714 + /*
86715 + * Clear hugetlb-related page reserves for children. This only
86716 + * affects MAP_PRIVATE mappings. Faults generated by the child
86717 + * are not guaranteed to succeed, even if read-only
86718 + */
86719 + if (is_vm_hugetlb_page(tmp))
86720 + reset_vma_resv_huge_pages(tmp);
86721 +
86722 + return tmp;
86723 +
86724 +fail_nomem_anon_vma_fork:
86725 + mpol_put(vma_policy(tmp));
86726 +fail_nomem_policy:
86727 + kmem_cache_free(vm_area_cachep, tmp);
86728 +fail_nomem:
86729 + vm_unacct_memory(charge);
86730 + return NULL;
86731 +}
86732 +
86733 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86734 {
86735 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86736 struct rb_node **rb_link, *rb_parent;
86737 int retval;
86738 - unsigned long charge;
86739
86740 uprobe_start_dup_mmap();
86741 down_write(&oldmm->mmap_sem);
86742 @@ -383,55 +501,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86743
86744 prev = NULL;
86745 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86746 - struct file *file;
86747 -
86748 if (mpnt->vm_flags & VM_DONTCOPY) {
86749 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86750 -vma_pages(mpnt));
86751 continue;
86752 }
86753 - charge = 0;
86754 - if (mpnt->vm_flags & VM_ACCOUNT) {
86755 - unsigned long len = vma_pages(mpnt);
86756 -
86757 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86758 - goto fail_nomem;
86759 - charge = len;
86760 - }
86761 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86762 - if (!tmp)
86763 - goto fail_nomem;
86764 - *tmp = *mpnt;
86765 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
86766 - retval = vma_dup_policy(mpnt, tmp);
86767 - if (retval)
86768 - goto fail_nomem_policy;
86769 - tmp->vm_mm = mm;
86770 - if (anon_vma_fork(tmp, mpnt))
86771 - goto fail_nomem_anon_vma_fork;
86772 - tmp->vm_flags &= ~VM_LOCKED;
86773 - tmp->vm_next = tmp->vm_prev = NULL;
86774 - file = tmp->vm_file;
86775 - if (file) {
86776 - struct inode *inode = file_inode(file);
86777 - struct address_space *mapping = file->f_mapping;
86778 -
86779 - get_file(file);
86780 - if (tmp->vm_flags & VM_DENYWRITE)
86781 - atomic_dec(&inode->i_writecount);
86782 - mutex_lock(&mapping->i_mmap_mutex);
86783 - if (tmp->vm_flags & VM_SHARED)
86784 - mapping->i_mmap_writable++;
86785 - flush_dcache_mmap_lock(mapping);
86786 - /* insert tmp into the share list, just after mpnt */
86787 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86788 - vma_nonlinear_insert(tmp,
86789 - &mapping->i_mmap_nonlinear);
86790 - else
86791 - vma_interval_tree_insert_after(tmp, mpnt,
86792 - &mapping->i_mmap);
86793 - flush_dcache_mmap_unlock(mapping);
86794 - mutex_unlock(&mapping->i_mmap_mutex);
86795 + tmp = dup_vma(mm, oldmm, mpnt);
86796 + if (!tmp) {
86797 + retval = -ENOMEM;
86798 + goto out;
86799 }
86800
86801 /*
86802 @@ -463,6 +541,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86803 if (retval)
86804 goto out;
86805 }
86806 +
86807 +#ifdef CONFIG_PAX_SEGMEXEC
86808 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86809 + struct vm_area_struct *mpnt_m;
86810 +
86811 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86812 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86813 +
86814 + if (!mpnt->vm_mirror)
86815 + continue;
86816 +
86817 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86818 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86819 + mpnt->vm_mirror = mpnt_m;
86820 + } else {
86821 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86822 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86823 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86824 + mpnt->vm_mirror->vm_mirror = mpnt;
86825 + }
86826 + }
86827 + BUG_ON(mpnt_m);
86828 + }
86829 +#endif
86830 +
86831 /* a new mm has just been created */
86832 arch_dup_mmap(oldmm, mm);
86833 retval = 0;
86834 @@ -472,14 +575,6 @@ out:
86835 up_write(&oldmm->mmap_sem);
86836 uprobe_end_dup_mmap();
86837 return retval;
86838 -fail_nomem_anon_vma_fork:
86839 - mpol_put(vma_policy(tmp));
86840 -fail_nomem_policy:
86841 - kmem_cache_free(vm_area_cachep, tmp);
86842 -fail_nomem:
86843 - retval = -ENOMEM;
86844 - vm_unacct_memory(charge);
86845 - goto out;
86846 }
86847
86848 static inline int mm_alloc_pgd(struct mm_struct *mm)
86849 @@ -698,8 +793,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86850 return ERR_PTR(err);
86851
86852 mm = get_task_mm(task);
86853 - if (mm && mm != current->mm &&
86854 - !ptrace_may_access(task, mode)) {
86855 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86856 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86857 mmput(mm);
86858 mm = ERR_PTR(-EACCES);
86859 }
86860 @@ -918,13 +1013,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86861 spin_unlock(&fs->lock);
86862 return -EAGAIN;
86863 }
86864 - fs->users++;
86865 + atomic_inc(&fs->users);
86866 spin_unlock(&fs->lock);
86867 return 0;
86868 }
86869 tsk->fs = copy_fs_struct(fs);
86870 if (!tsk->fs)
86871 return -ENOMEM;
86872 + /* Carry through gr_chroot_dentry and is_chrooted instead
86873 + of recomputing it here. Already copied when the task struct
86874 + is duplicated. This allows pivot_root to not be treated as
86875 + a chroot
86876 + */
86877 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
86878 +
86879 return 0;
86880 }
86881
86882 @@ -1133,7 +1235,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86883 * parts of the process environment (as per the clone
86884 * flags). The actual kick-off is left to the caller.
86885 */
86886 -static struct task_struct *copy_process(unsigned long clone_flags,
86887 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86888 unsigned long stack_start,
86889 unsigned long stack_size,
86890 int __user *child_tidptr,
86891 @@ -1205,6 +1307,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86892 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86893 #endif
86894 retval = -EAGAIN;
86895 +
86896 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86897 +
86898 if (atomic_read(&p->real_cred->user->processes) >=
86899 task_rlimit(p, RLIMIT_NPROC)) {
86900 if (p->real_cred->user != INIT_USER &&
86901 @@ -1452,6 +1557,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86902 goto bad_fork_free_pid;
86903 }
86904
86905 + /* synchronizes with gr_set_acls()
86906 + we need to call this past the point of no return for fork()
86907 + */
86908 + gr_copy_label(p);
86909 +
86910 if (likely(p->pid)) {
86911 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86912
86913 @@ -1541,6 +1651,8 @@ bad_fork_cleanup_count:
86914 bad_fork_free:
86915 free_task(p);
86916 fork_out:
86917 + gr_log_forkfail(retval);
86918 +
86919 return ERR_PTR(retval);
86920 }
86921
86922 @@ -1602,6 +1714,7 @@ long do_fork(unsigned long clone_flags,
86923
86924 p = copy_process(clone_flags, stack_start, stack_size,
86925 child_tidptr, NULL, trace);
86926 + add_latent_entropy();
86927 /*
86928 * Do this prior waking up the new thread - the thread pointer
86929 * might get invalid after that point, if the thread exits quickly.
86930 @@ -1618,6 +1731,8 @@ long do_fork(unsigned long clone_flags,
86931 if (clone_flags & CLONE_PARENT_SETTID)
86932 put_user(nr, parent_tidptr);
86933
86934 + gr_handle_brute_check();
86935 +
86936 if (clone_flags & CLONE_VFORK) {
86937 p->vfork_done = &vfork;
86938 init_completion(&vfork);
86939 @@ -1736,7 +1851,7 @@ void __init proc_caches_init(void)
86940 mm_cachep = kmem_cache_create("mm_struct",
86941 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86942 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86943 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86944 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86945 mmap_init();
86946 nsproxy_cache_init();
86947 }
86948 @@ -1776,7 +1891,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86949 return 0;
86950
86951 /* don't need lock here; in the worst case we'll do useless copy */
86952 - if (fs->users == 1)
86953 + if (atomic_read(&fs->users) == 1)
86954 return 0;
86955
86956 *new_fsp = copy_fs_struct(fs);
86957 @@ -1883,7 +1998,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86958 fs = current->fs;
86959 spin_lock(&fs->lock);
86960 current->fs = new_fs;
86961 - if (--fs->users)
86962 + gr_set_chroot_entries(current, &current->fs->root);
86963 + if (atomic_dec_return(&fs->users))
86964 new_fs = NULL;
86965 else
86966 new_fs = fs;
86967 diff --git a/kernel/futex.c b/kernel/futex.c
86968 index de938d2..c566038 100644
86969 --- a/kernel/futex.c
86970 +++ b/kernel/futex.c
86971 @@ -202,7 +202,7 @@ struct futex_pi_state {
86972 atomic_t refcount;
86973
86974 union futex_key key;
86975 -};
86976 +} __randomize_layout;
86977
86978 /**
86979 * struct futex_q - The hashed futex queue entry, one per waiting task
86980 @@ -236,7 +236,7 @@ struct futex_q {
86981 struct rt_mutex_waiter *rt_waiter;
86982 union futex_key *requeue_pi_key;
86983 u32 bitset;
86984 -};
86985 +} __randomize_layout;
86986
86987 static const struct futex_q futex_q_init = {
86988 /* list gets initialized in queue_me()*/
86989 @@ -394,6 +394,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86990 struct page *page, *page_head;
86991 int err, ro = 0;
86992
86993 +#ifdef CONFIG_PAX_SEGMEXEC
86994 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86995 + return -EFAULT;
86996 +#endif
86997 +
86998 /*
86999 * The futex address must be "naturally" aligned.
87000 */
87001 @@ -593,7 +598,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
87002
87003 static int get_futex_value_locked(u32 *dest, u32 __user *from)
87004 {
87005 - int ret;
87006 + unsigned long ret;
87007
87008 pagefault_disable();
87009 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
87010 @@ -3033,6 +3038,7 @@ static void __init futex_detect_cmpxchg(void)
87011 {
87012 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
87013 u32 curval;
87014 + mm_segment_t oldfs;
87015
87016 /*
87017 * This will fail and we want it. Some arch implementations do
87018 @@ -3044,8 +3050,11 @@ static void __init futex_detect_cmpxchg(void)
87019 * implementation, the non-functional ones will return
87020 * -ENOSYS.
87021 */
87022 + oldfs = get_fs();
87023 + set_fs(USER_DS);
87024 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
87025 futex_cmpxchg_enabled = 1;
87026 + set_fs(oldfs);
87027 #endif
87028 }
87029
87030 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
87031 index 55c8c93..9ba7ad6 100644
87032 --- a/kernel/futex_compat.c
87033 +++ b/kernel/futex_compat.c
87034 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
87035 return 0;
87036 }
87037
87038 -static void __user *futex_uaddr(struct robust_list __user *entry,
87039 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
87040 compat_long_t futex_offset)
87041 {
87042 compat_uptr_t base = ptr_to_compat(entry);
87043 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
87044 index f45b75b..bfac6d5 100644
87045 --- a/kernel/gcov/base.c
87046 +++ b/kernel/gcov/base.c
87047 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
87048 }
87049
87050 #ifdef CONFIG_MODULES
87051 -static inline int within(void *addr, void *start, unsigned long size)
87052 -{
87053 - return ((addr >= start) && (addr < start + size));
87054 -}
87055 -
87056 /* Update list and generate events when modules are unloaded. */
87057 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
87058 void *data)
87059 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
87060
87061 /* Remove entries located in module from linked list. */
87062 while ((info = gcov_info_next(info))) {
87063 - if (within(info, mod->module_core, mod->core_size)) {
87064 + if (within_module_core_rw((unsigned long)info, mod)) {
87065 gcov_info_unlink(prev, info);
87066 if (gcov_events_enabled)
87067 gcov_event(GCOV_REMOVE, info);
87068 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
87069 index e0501fe..312edd6 100644
87070 --- a/kernel/hrtimer.c
87071 +++ b/kernel/hrtimer.c
87072 @@ -1448,7 +1448,7 @@ void hrtimer_peek_ahead_timers(void)
87073 local_irq_restore(flags);
87074 }
87075
87076 -static void run_hrtimer_softirq(struct softirq_action *h)
87077 +static __latent_entropy void run_hrtimer_softirq(void)
87078 {
87079 hrtimer_peek_ahead_timers();
87080 }
87081 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
87082 index a82170e..5b01e7f 100644
87083 --- a/kernel/irq_work.c
87084 +++ b/kernel/irq_work.c
87085 @@ -191,12 +191,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
87086 return NOTIFY_OK;
87087 }
87088
87089 -static struct notifier_block cpu_notify;
87090 +static struct notifier_block cpu_notify = {
87091 + .notifier_call = irq_work_cpu_notify,
87092 + .priority = 0,
87093 +};
87094
87095 static __init int irq_work_init_cpu_notifier(void)
87096 {
87097 - cpu_notify.notifier_call = irq_work_cpu_notify;
87098 - cpu_notify.priority = 0;
87099 register_cpu_notifier(&cpu_notify);
87100 return 0;
87101 }
87102 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
87103 index 9019f15..9a3c42e 100644
87104 --- a/kernel/jump_label.c
87105 +++ b/kernel/jump_label.c
87106 @@ -14,6 +14,7 @@
87107 #include <linux/err.h>
87108 #include <linux/static_key.h>
87109 #include <linux/jump_label_ratelimit.h>
87110 +#include <linux/mm.h>
87111
87112 #ifdef HAVE_JUMP_LABEL
87113
87114 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
87115
87116 size = (((unsigned long)stop - (unsigned long)start)
87117 / sizeof(struct jump_entry));
87118 + pax_open_kernel();
87119 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
87120 + pax_close_kernel();
87121 }
87122
87123 static void jump_label_update(struct static_key *key, int enable);
87124 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
87125 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
87126 struct jump_entry *iter;
87127
87128 + pax_open_kernel();
87129 for (iter = iter_start; iter < iter_stop; iter++) {
87130 if (within_module_init(iter->code, mod))
87131 iter->code = 0;
87132 }
87133 + pax_close_kernel();
87134 }
87135
87136 static int
87137 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
87138 index cb0cf37..b69e161 100644
87139 --- a/kernel/kallsyms.c
87140 +++ b/kernel/kallsyms.c
87141 @@ -11,6 +11,9 @@
87142 * Changed the compression method from stem compression to "table lookup"
87143 * compression (see scripts/kallsyms.c for a more complete description)
87144 */
87145 +#ifdef CONFIG_GRKERNSEC_HIDESYM
87146 +#define __INCLUDED_BY_HIDESYM 1
87147 +#endif
87148 #include <linux/kallsyms.h>
87149 #include <linux/module.h>
87150 #include <linux/init.h>
87151 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
87152
87153 static inline int is_kernel_inittext(unsigned long addr)
87154 {
87155 + if (system_state != SYSTEM_BOOTING)
87156 + return 0;
87157 +
87158 if (addr >= (unsigned long)_sinittext
87159 && addr <= (unsigned long)_einittext)
87160 return 1;
87161 return 0;
87162 }
87163
87164 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87165 +#ifdef CONFIG_MODULES
87166 +static inline int is_module_text(unsigned long addr)
87167 +{
87168 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
87169 + return 1;
87170 +
87171 + addr = ktla_ktva(addr);
87172 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
87173 +}
87174 +#else
87175 +static inline int is_module_text(unsigned long addr)
87176 +{
87177 + return 0;
87178 +}
87179 +#endif
87180 +#endif
87181 +
87182 static inline int is_kernel_text(unsigned long addr)
87183 {
87184 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
87185 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
87186
87187 static inline int is_kernel(unsigned long addr)
87188 {
87189 +
87190 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87191 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
87192 + return 1;
87193 +
87194 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
87195 +#else
87196 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
87197 +#endif
87198 +
87199 return 1;
87200 return in_gate_area_no_mm(addr);
87201 }
87202
87203 static int is_ksym_addr(unsigned long addr)
87204 {
87205 +
87206 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87207 + if (is_module_text(addr))
87208 + return 0;
87209 +#endif
87210 +
87211 if (all_var)
87212 return is_kernel(addr);
87213
87214 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
87215
87216 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
87217 {
87218 - iter->name[0] = '\0';
87219 iter->nameoff = get_symbol_offset(new_pos);
87220 iter->pos = new_pos;
87221 }
87222 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
87223 {
87224 struct kallsym_iter *iter = m->private;
87225
87226 +#ifdef CONFIG_GRKERNSEC_HIDESYM
87227 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
87228 + return 0;
87229 +#endif
87230 +
87231 /* Some debugging symbols have no name. Ignore them. */
87232 if (!iter->name[0])
87233 return 0;
87234 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
87235 */
87236 type = iter->exported ? toupper(iter->type) :
87237 tolower(iter->type);
87238 +
87239 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
87240 type, iter->name, iter->module_name);
87241 } else
87242 @@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
87243 struct kallsym_iter *iter;
87244 int ret;
87245
87246 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
87247 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
87248 if (!iter)
87249 return -ENOMEM;
87250 reset_iter(iter, 0);
87251 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
87252 index e30ac0f..3528cac 100644
87253 --- a/kernel/kcmp.c
87254 +++ b/kernel/kcmp.c
87255 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
87256 struct task_struct *task1, *task2;
87257 int ret;
87258
87259 +#ifdef CONFIG_GRKERNSEC
87260 + return -ENOSYS;
87261 +#endif
87262 +
87263 rcu_read_lock();
87264
87265 /*
87266 diff --git a/kernel/kexec.c b/kernel/kexec.c
87267 index 28c5706..bfc8388 100644
87268 --- a/kernel/kexec.c
87269 +++ b/kernel/kexec.c
87270 @@ -1046,7 +1046,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
87271 compat_ulong_t, flags)
87272 {
87273 struct compat_kexec_segment in;
87274 - struct kexec_segment out, __user *ksegments;
87275 + struct kexec_segment out;
87276 + struct kexec_segment __user *ksegments;
87277 unsigned long i, result;
87278
87279 /* Don't allow clients that don't understand the native
87280 diff --git a/kernel/kmod.c b/kernel/kmod.c
87281 index 6b375af..eaff670 100644
87282 --- a/kernel/kmod.c
87283 +++ b/kernel/kmod.c
87284 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
87285 kfree(info->argv);
87286 }
87287
87288 -static int call_modprobe(char *module_name, int wait)
87289 +static int call_modprobe(char *module_name, char *module_param, int wait)
87290 {
87291 struct subprocess_info *info;
87292 static char *envp[] = {
87293 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
87294 NULL
87295 };
87296
87297 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
87298 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
87299 if (!argv)
87300 goto out;
87301
87302 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
87303 argv[1] = "-q";
87304 argv[2] = "--";
87305 argv[3] = module_name; /* check free_modprobe_argv() */
87306 - argv[4] = NULL;
87307 + argv[4] = module_param;
87308 + argv[5] = NULL;
87309
87310 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
87311 NULL, free_modprobe_argv, NULL);
87312 @@ -129,9 +130,8 @@ out:
87313 * If module auto-loading support is disabled then this function
87314 * becomes a no-operation.
87315 */
87316 -int __request_module(bool wait, const char *fmt, ...)
87317 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
87318 {
87319 - va_list args;
87320 char module_name[MODULE_NAME_LEN];
87321 unsigned int max_modprobes;
87322 int ret;
87323 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
87324 if (!modprobe_path[0])
87325 return 0;
87326
87327 - va_start(args, fmt);
87328 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
87329 - va_end(args);
87330 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
87331 if (ret >= MODULE_NAME_LEN)
87332 return -ENAMETOOLONG;
87333
87334 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
87335 if (ret)
87336 return ret;
87337
87338 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87339 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87340 + /* hack to workaround consolekit/udisks stupidity */
87341 + read_lock(&tasklist_lock);
87342 + if (!strcmp(current->comm, "mount") &&
87343 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
87344 + read_unlock(&tasklist_lock);
87345 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
87346 + return -EPERM;
87347 + }
87348 + read_unlock(&tasklist_lock);
87349 + }
87350 +#endif
87351 +
87352 /* If modprobe needs a service that is in a module, we get a recursive
87353 * loop. Limit the number of running kmod threads to max_threads/2 or
87354 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
87355 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
87356
87357 trace_module_request(module_name, wait, _RET_IP_);
87358
87359 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87360 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87361
87362 atomic_dec(&kmod_concurrent);
87363 return ret;
87364 }
87365 +
87366 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
87367 +{
87368 + va_list args;
87369 + int ret;
87370 +
87371 + va_start(args, fmt);
87372 + ret = ____request_module(wait, module_param, fmt, args);
87373 + va_end(args);
87374 +
87375 + return ret;
87376 +}
87377 +
87378 +int __request_module(bool wait, const char *fmt, ...)
87379 +{
87380 + va_list args;
87381 + int ret;
87382 +
87383 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87384 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87385 + char module_param[MODULE_NAME_LEN];
87386 +
87387 + memset(module_param, 0, sizeof(module_param));
87388 +
87389 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87390 +
87391 + va_start(args, fmt);
87392 + ret = ____request_module(wait, module_param, fmt, args);
87393 + va_end(args);
87394 +
87395 + return ret;
87396 + }
87397 +#endif
87398 +
87399 + va_start(args, fmt);
87400 + ret = ____request_module(wait, NULL, fmt, args);
87401 + va_end(args);
87402 +
87403 + return ret;
87404 +}
87405 +
87406 EXPORT_SYMBOL(__request_module);
87407 #endif /* CONFIG_MODULES */
87408
87409 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87410 */
87411 set_user_nice(current, 0);
87412
87413 +#ifdef CONFIG_GRKERNSEC
87414 + /* this is race-free as far as userland is concerned as we copied
87415 + out the path to be used prior to this point and are now operating
87416 + on that copy
87417 + */
87418 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87419 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87420 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87421 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87422 + retval = -EPERM;
87423 + goto fail;
87424 + }
87425 +#endif
87426 +
87427 retval = -ENOMEM;
87428 new = prepare_kernel_cred(current);
87429 if (!new)
87430 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87431 commit_creds(new);
87432
87433 retval = do_execve(getname_kernel(sub_info->path),
87434 - (const char __user *const __user *)sub_info->argv,
87435 - (const char __user *const __user *)sub_info->envp);
87436 + (const char __user *const __force_user *)sub_info->argv,
87437 + (const char __user *const __force_user *)sub_info->envp);
87438 if (!retval)
87439 return 0;
87440
87441 @@ -260,6 +327,10 @@ static int call_helper(void *data)
87442
87443 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87444 {
87445 +#ifdef CONFIG_GRKERNSEC
87446 + kfree(info->path);
87447 + info->path = info->origpath;
87448 +#endif
87449 if (info->cleanup)
87450 (*info->cleanup)(info);
87451 kfree(info);
87452 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87453 *
87454 * Thus the __user pointer cast is valid here.
87455 */
87456 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
87457 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87458
87459 /*
87460 * If ret is 0, either ____call_usermodehelper failed and the
87461 @@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87462 goto out;
87463
87464 INIT_WORK(&sub_info->work, __call_usermodehelper);
87465 +#ifdef CONFIG_GRKERNSEC
87466 + sub_info->origpath = path;
87467 + sub_info->path = kstrdup(path, gfp_mask);
87468 +#else
87469 sub_info->path = path;
87470 +#endif
87471 sub_info->argv = argv;
87472 sub_info->envp = envp;
87473
87474 @@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87475 static int proc_cap_handler(struct ctl_table *table, int write,
87476 void __user *buffer, size_t *lenp, loff_t *ppos)
87477 {
87478 - struct ctl_table t;
87479 + ctl_table_no_const t;
87480 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87481 kernel_cap_t new_cap;
87482 int err, i;
87483 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87484 index ceeadfc..11c18b6 100644
87485 --- a/kernel/kprobes.c
87486 +++ b/kernel/kprobes.c
87487 @@ -31,6 +31,9 @@
87488 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87489 * <prasanna@in.ibm.com> added function-return probes.
87490 */
87491 +#ifdef CONFIG_GRKERNSEC_HIDESYM
87492 +#define __INCLUDED_BY_HIDESYM 1
87493 +#endif
87494 #include <linux/kprobes.h>
87495 #include <linux/hash.h>
87496 #include <linux/init.h>
87497 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
87498
87499 static void *alloc_insn_page(void)
87500 {
87501 - return module_alloc(PAGE_SIZE);
87502 + return module_alloc_exec(PAGE_SIZE);
87503 }
87504
87505 static void free_insn_page(void *page)
87506 {
87507 - module_free(NULL, page);
87508 + module_free_exec(NULL, page);
87509 }
87510
87511 struct kprobe_insn_cache kprobe_insn_slots = {
87512 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87513 kprobe_type = "k";
87514
87515 if (sym)
87516 - seq_printf(pi, "%p %s %s+0x%x %s ",
87517 + seq_printf(pi, "%pK %s %s+0x%x %s ",
87518 p->addr, kprobe_type, sym, offset,
87519 (modname ? modname : " "));
87520 else
87521 - seq_printf(pi, "%p %s %p ",
87522 + seq_printf(pi, "%pK %s %pK ",
87523 p->addr, kprobe_type, p->addr);
87524
87525 if (!pp)
87526 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87527 index 2495a9b..071b906 100644
87528 --- a/kernel/ksysfs.c
87529 +++ b/kernel/ksysfs.c
87530 @@ -49,6 +49,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87531 {
87532 if (count+1 > UEVENT_HELPER_PATH_LEN)
87533 return -ENOENT;
87534 + if (!capable(CAP_SYS_ADMIN))
87535 + return -EPERM;
87536 memcpy(uevent_helper, buf, count);
87537 uevent_helper[count] = '\0';
87538 if (count && uevent_helper[count-1] == '\n')
87539 @@ -175,7 +177,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87540 return count;
87541 }
87542
87543 -static struct bin_attribute notes_attr = {
87544 +static bin_attribute_no_const notes_attr __read_only = {
87545 .attr = {
87546 .name = "notes",
87547 .mode = S_IRUGO,
87548 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87549 index d24e433..fa04fb8 100644
87550 --- a/kernel/locking/lockdep.c
87551 +++ b/kernel/locking/lockdep.c
87552 @@ -597,6 +597,10 @@ static int static_obj(void *obj)
87553 end = (unsigned long) &_end,
87554 addr = (unsigned long) obj;
87555
87556 +#ifdef CONFIG_PAX_KERNEXEC
87557 + start = ktla_ktva(start);
87558 +#endif
87559 +
87560 /*
87561 * static variable?
87562 */
87563 @@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87564 if (!static_obj(lock->key)) {
87565 debug_locks_off();
87566 printk("INFO: trying to register non-static key.\n");
87567 + printk("lock:%pS key:%pS.\n", lock, lock->key);
87568 printk("the code is fine but needs lockdep annotation.\n");
87569 printk("turning off the locking correctness validator.\n");
87570 dump_stack();
87571 @@ -3079,7 +3084,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87572 if (!class)
87573 return 0;
87574 }
87575 - atomic_inc((atomic_t *)&class->ops);
87576 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87577 if (very_verbose(class)) {
87578 printk("\nacquire class [%p] %s", class->key, class->name);
87579 if (class->name_version > 1)
87580 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87581 index ef43ac4..2720dfa 100644
87582 --- a/kernel/locking/lockdep_proc.c
87583 +++ b/kernel/locking/lockdep_proc.c
87584 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87585 return 0;
87586 }
87587
87588 - seq_printf(m, "%p", class->key);
87589 + seq_printf(m, "%pK", class->key);
87590 #ifdef CONFIG_DEBUG_LOCKDEP
87591 seq_printf(m, " OPS:%8ld", class->ops);
87592 #endif
87593 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87594
87595 list_for_each_entry(entry, &class->locks_after, entry) {
87596 if (entry->distance == 1) {
87597 - seq_printf(m, " -> [%p] ", entry->class->key);
87598 + seq_printf(m, " -> [%pK] ", entry->class->key);
87599 print_name(m, entry->class);
87600 seq_puts(m, "\n");
87601 }
87602 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87603 if (!class->key)
87604 continue;
87605
87606 - seq_printf(m, "[%p] ", class->key);
87607 + seq_printf(m, "[%pK] ", class->key);
87608 print_name(m, class);
87609 seq_puts(m, "\n");
87610 }
87611 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87612 if (!i)
87613 seq_line(m, '-', 40-namelen, namelen);
87614
87615 - snprintf(ip, sizeof(ip), "[<%p>]",
87616 + snprintf(ip, sizeof(ip), "[<%pK>]",
87617 (void *)class->contention_point[i]);
87618 seq_printf(m, "%40s %14lu %29s %pS\n",
87619 name, stats->contention_point[i],
87620 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87621 if (!i)
87622 seq_line(m, '-', 40-namelen, namelen);
87623
87624 - snprintf(ip, sizeof(ip), "[<%p>]",
87625 + snprintf(ip, sizeof(ip), "[<%pK>]",
87626 (void *)class->contending_point[i]);
87627 seq_printf(m, "%40s %14lu %29s %pS\n",
87628 name, stats->contending_point[i],
87629 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
87630 index 838dc9e..760e158 100644
87631 --- a/kernel/locking/mcs_spinlock.c
87632 +++ b/kernel/locking/mcs_spinlock.c
87633 @@ -71,7 +71,7 @@ bool osq_lock(struct optimistic_spin_queue **lock)
87634 if (likely(prev == NULL))
87635 return true;
87636
87637 - ACCESS_ONCE(prev->next) = node;
87638 + ACCESS_ONCE_RW(prev->next) = node;
87639
87640 /*
87641 * Normally @prev is untouchable after the above store; because at that
87642 @@ -143,8 +143,8 @@ unqueue:
87643 * it will wait in Step-A.
87644 */
87645
87646 - ACCESS_ONCE(next->prev) = prev;
87647 - ACCESS_ONCE(prev->next) = next;
87648 + ACCESS_ONCE_RW(next->prev) = prev;
87649 + ACCESS_ONCE_RW(prev->next) = next;
87650
87651 return false;
87652 }
87653 @@ -165,13 +165,13 @@ void osq_unlock(struct optimistic_spin_queue **lock)
87654 */
87655 next = xchg(&node->next, NULL);
87656 if (next) {
87657 - ACCESS_ONCE(next->locked) = 1;
87658 + ACCESS_ONCE_RW(next->locked) = 1;
87659 return;
87660 }
87661
87662 next = osq_wait_next(lock, node, NULL);
87663 if (next)
87664 - ACCESS_ONCE(next->locked) = 1;
87665 + ACCESS_ONCE_RW(next->locked) = 1;
87666 }
87667
87668 #endif
87669 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
87670 index a2dbac4..e02a34a 100644
87671 --- a/kernel/locking/mcs_spinlock.h
87672 +++ b/kernel/locking/mcs_spinlock.h
87673 @@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
87674 */
87675 return;
87676 }
87677 - ACCESS_ONCE(prev->next) = node;
87678 + ACCESS_ONCE_RW(prev->next) = node;
87679
87680 /* Wait until the lock holder passes the lock down. */
87681 arch_mcs_spin_lock_contended(&node->locked);
87682 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87683 index 5cf6731..ce3bc5a 100644
87684 --- a/kernel/locking/mutex-debug.c
87685 +++ b/kernel/locking/mutex-debug.c
87686 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87687 }
87688
87689 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87690 - struct thread_info *ti)
87691 + struct task_struct *task)
87692 {
87693 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87694
87695 /* Mark the current thread as blocked on the lock: */
87696 - ti->task->blocked_on = waiter;
87697 + task->blocked_on = waiter;
87698 }
87699
87700 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87701 - struct thread_info *ti)
87702 + struct task_struct *task)
87703 {
87704 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87705 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87706 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87707 - ti->task->blocked_on = NULL;
87708 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
87709 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87710 + task->blocked_on = NULL;
87711
87712 list_del_init(&waiter->list);
87713 waiter->task = NULL;
87714 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87715 index 0799fd3..d06ae3b 100644
87716 --- a/kernel/locking/mutex-debug.h
87717 +++ b/kernel/locking/mutex-debug.h
87718 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87719 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87720 extern void debug_mutex_add_waiter(struct mutex *lock,
87721 struct mutex_waiter *waiter,
87722 - struct thread_info *ti);
87723 + struct task_struct *task);
87724 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87725 - struct thread_info *ti);
87726 + struct task_struct *task);
87727 extern void debug_mutex_unlock(struct mutex *lock);
87728 extern void debug_mutex_init(struct mutex *lock, const char *name,
87729 struct lock_class_key *key);
87730 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87731 index bc73d33..6f308aa 100644
87732 --- a/kernel/locking/mutex.c
87733 +++ b/kernel/locking/mutex.c
87734 @@ -490,7 +490,7 @@ slowpath:
87735 goto skip_wait;
87736
87737 debug_mutex_lock_common(lock, &waiter);
87738 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87739 + debug_mutex_add_waiter(lock, &waiter, task);
87740
87741 /* add waiting tasks to the end of the waitqueue (FIFO): */
87742 list_add_tail(&waiter.list, &lock->wait_list);
87743 @@ -534,7 +534,7 @@ slowpath:
87744 schedule_preempt_disabled();
87745 spin_lock_mutex(&lock->wait_lock, flags);
87746 }
87747 - mutex_remove_waiter(lock, &waiter, current_thread_info());
87748 + mutex_remove_waiter(lock, &waiter, task);
87749 /* set it to 0 if there are no waiters left: */
87750 if (likely(list_empty(&lock->wait_list)))
87751 atomic_set(&lock->count, 0);
87752 @@ -571,7 +571,7 @@ skip_wait:
87753 return 0;
87754
87755 err:
87756 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87757 + mutex_remove_waiter(lock, &waiter, task);
87758 spin_unlock_mutex(&lock->wait_lock, flags);
87759 debug_mutex_free_waiter(&waiter);
87760 mutex_release(&lock->dep_map, 1, ip);
87761 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87762 index 1d96dd0..994ff19 100644
87763 --- a/kernel/locking/rtmutex-tester.c
87764 +++ b/kernel/locking/rtmutex-tester.c
87765 @@ -22,7 +22,7 @@
87766 #define MAX_RT_TEST_MUTEXES 8
87767
87768 static spinlock_t rttest_lock;
87769 -static atomic_t rttest_event;
87770 +static atomic_unchecked_t rttest_event;
87771
87772 struct test_thread_data {
87773 int opcode;
87774 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87775
87776 case RTTEST_LOCKCONT:
87777 td->mutexes[td->opdata] = 1;
87778 - td->event = atomic_add_return(1, &rttest_event);
87779 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87780 return 0;
87781
87782 case RTTEST_RESET:
87783 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87784 return 0;
87785
87786 case RTTEST_RESETEVENT:
87787 - atomic_set(&rttest_event, 0);
87788 + atomic_set_unchecked(&rttest_event, 0);
87789 return 0;
87790
87791 default:
87792 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87793 return ret;
87794
87795 td->mutexes[id] = 1;
87796 - td->event = atomic_add_return(1, &rttest_event);
87797 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87798 rt_mutex_lock(&mutexes[id]);
87799 - td->event = atomic_add_return(1, &rttest_event);
87800 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87801 td->mutexes[id] = 4;
87802 return 0;
87803
87804 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87805 return ret;
87806
87807 td->mutexes[id] = 1;
87808 - td->event = atomic_add_return(1, &rttest_event);
87809 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87810 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87811 - td->event = atomic_add_return(1, &rttest_event);
87812 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87813 td->mutexes[id] = ret ? 0 : 4;
87814 return ret ? -EINTR : 0;
87815
87816 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87817 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87818 return ret;
87819
87820 - td->event = atomic_add_return(1, &rttest_event);
87821 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87822 rt_mutex_unlock(&mutexes[id]);
87823 - td->event = atomic_add_return(1, &rttest_event);
87824 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87825 td->mutexes[id] = 0;
87826 return 0;
87827
87828 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87829 break;
87830
87831 td->mutexes[dat] = 2;
87832 - td->event = atomic_add_return(1, &rttest_event);
87833 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87834 break;
87835
87836 default:
87837 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87838 return;
87839
87840 td->mutexes[dat] = 3;
87841 - td->event = atomic_add_return(1, &rttest_event);
87842 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87843 break;
87844
87845 case RTTEST_LOCKNOWAIT:
87846 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87847 return;
87848
87849 td->mutexes[dat] = 1;
87850 - td->event = atomic_add_return(1, &rttest_event);
87851 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87852 return;
87853
87854 default:
87855 diff --git a/kernel/module.c b/kernel/module.c
87856 index 079c461..741f79c 100644
87857 --- a/kernel/module.c
87858 +++ b/kernel/module.c
87859 @@ -61,6 +61,7 @@
87860 #include <linux/pfn.h>
87861 #include <linux/bsearch.h>
87862 #include <linux/fips.h>
87863 +#include <linux/grsecurity.h>
87864 #include <uapi/linux/module.h>
87865 #include "module-internal.h"
87866
87867 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87868
87869 /* Bounds of module allocation, for speeding __module_address.
87870 * Protected by module_mutex. */
87871 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87872 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87873 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87874
87875 int register_module_notifier(struct notifier_block * nb)
87876 {
87877 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87878 return true;
87879
87880 list_for_each_entry_rcu(mod, &modules, list) {
87881 - struct symsearch arr[] = {
87882 + struct symsearch modarr[] = {
87883 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87884 NOT_GPL_ONLY, false },
87885 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87886 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87887 if (mod->state == MODULE_STATE_UNFORMED)
87888 continue;
87889
87890 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87891 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87892 return true;
87893 }
87894 return false;
87895 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87896 if (!pcpusec->sh_size)
87897 return 0;
87898
87899 - if (align > PAGE_SIZE) {
87900 + if (align-1 >= PAGE_SIZE) {
87901 pr_warn("%s: per-cpu alignment %li > %li\n",
87902 mod->name, align, PAGE_SIZE);
87903 align = PAGE_SIZE;
87904 @@ -1061,7 +1063,7 @@ struct module_attribute module_uevent =
87905 static ssize_t show_coresize(struct module_attribute *mattr,
87906 struct module_kobject *mk, char *buffer)
87907 {
87908 - return sprintf(buffer, "%u\n", mk->mod->core_size);
87909 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87910 }
87911
87912 static struct module_attribute modinfo_coresize =
87913 @@ -1070,7 +1072,7 @@ static struct module_attribute modinfo_coresize =
87914 static ssize_t show_initsize(struct module_attribute *mattr,
87915 struct module_kobject *mk, char *buffer)
87916 {
87917 - return sprintf(buffer, "%u\n", mk->mod->init_size);
87918 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87919 }
87920
87921 static struct module_attribute modinfo_initsize =
87922 @@ -1162,12 +1164,29 @@ static int check_version(Elf_Shdr *sechdrs,
87923 goto bad_version;
87924 }
87925
87926 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87927 + /*
87928 + * avoid potentially printing jibberish on attempted load
87929 + * of a module randomized with a different seed
87930 + */
87931 + pr_warn("no symbol version for %s\n", symname);
87932 +#else
87933 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87934 +#endif
87935 return 0;
87936
87937 bad_version:
87938 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87939 + /*
87940 + * avoid potentially printing jibberish on attempted load
87941 + * of a module randomized with a different seed
87942 + */
87943 + printk("attempted module disagrees about version of symbol %s\n",
87944 + symname);
87945 +#else
87946 printk("%s: disagrees about version of symbol %s\n",
87947 mod->name, symname);
87948 +#endif
87949 return 0;
87950 }
87951
87952 @@ -1283,7 +1302,7 @@ resolve_symbol_wait(struct module *mod,
87953 */
87954 #ifdef CONFIG_SYSFS
87955
87956 -#ifdef CONFIG_KALLSYMS
87957 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87958 static inline bool sect_empty(const Elf_Shdr *sect)
87959 {
87960 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87961 @@ -1423,7 +1442,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87962 {
87963 unsigned int notes, loaded, i;
87964 struct module_notes_attrs *notes_attrs;
87965 - struct bin_attribute *nattr;
87966 + bin_attribute_no_const *nattr;
87967
87968 /* failed to create section attributes, so can't create notes */
87969 if (!mod->sect_attrs)
87970 @@ -1535,7 +1554,7 @@ static void del_usage_links(struct module *mod)
87971 static int module_add_modinfo_attrs(struct module *mod)
87972 {
87973 struct module_attribute *attr;
87974 - struct module_attribute *temp_attr;
87975 + module_attribute_no_const *temp_attr;
87976 int error = 0;
87977 int i;
87978
87979 @@ -1756,21 +1775,21 @@ static void set_section_ro_nx(void *base,
87980
87981 static void unset_module_core_ro_nx(struct module *mod)
87982 {
87983 - set_page_attributes(mod->module_core + mod->core_text_size,
87984 - mod->module_core + mod->core_size,
87985 + set_page_attributes(mod->module_core_rw,
87986 + mod->module_core_rw + mod->core_size_rw,
87987 set_memory_x);
87988 - set_page_attributes(mod->module_core,
87989 - mod->module_core + mod->core_ro_size,
87990 + set_page_attributes(mod->module_core_rx,
87991 + mod->module_core_rx + mod->core_size_rx,
87992 set_memory_rw);
87993 }
87994
87995 static void unset_module_init_ro_nx(struct module *mod)
87996 {
87997 - set_page_attributes(mod->module_init + mod->init_text_size,
87998 - mod->module_init + mod->init_size,
87999 + set_page_attributes(mod->module_init_rw,
88000 + mod->module_init_rw + mod->init_size_rw,
88001 set_memory_x);
88002 - set_page_attributes(mod->module_init,
88003 - mod->module_init + mod->init_ro_size,
88004 + set_page_attributes(mod->module_init_rx,
88005 + mod->module_init_rx + mod->init_size_rx,
88006 set_memory_rw);
88007 }
88008
88009 @@ -1783,14 +1802,14 @@ void set_all_modules_text_rw(void)
88010 list_for_each_entry_rcu(mod, &modules, list) {
88011 if (mod->state == MODULE_STATE_UNFORMED)
88012 continue;
88013 - if ((mod->module_core) && (mod->core_text_size)) {
88014 - set_page_attributes(mod->module_core,
88015 - mod->module_core + mod->core_text_size,
88016 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
88017 + set_page_attributes(mod->module_core_rx,
88018 + mod->module_core_rx + mod->core_size_rx,
88019 set_memory_rw);
88020 }
88021 - if ((mod->module_init) && (mod->init_text_size)) {
88022 - set_page_attributes(mod->module_init,
88023 - mod->module_init + mod->init_text_size,
88024 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
88025 + set_page_attributes(mod->module_init_rx,
88026 + mod->module_init_rx + mod->init_size_rx,
88027 set_memory_rw);
88028 }
88029 }
88030 @@ -1806,14 +1825,14 @@ void set_all_modules_text_ro(void)
88031 list_for_each_entry_rcu(mod, &modules, list) {
88032 if (mod->state == MODULE_STATE_UNFORMED)
88033 continue;
88034 - if ((mod->module_core) && (mod->core_text_size)) {
88035 - set_page_attributes(mod->module_core,
88036 - mod->module_core + mod->core_text_size,
88037 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
88038 + set_page_attributes(mod->module_core_rx,
88039 + mod->module_core_rx + mod->core_size_rx,
88040 set_memory_ro);
88041 }
88042 - if ((mod->module_init) && (mod->init_text_size)) {
88043 - set_page_attributes(mod->module_init,
88044 - mod->module_init + mod->init_text_size,
88045 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
88046 + set_page_attributes(mod->module_init_rx,
88047 + mod->module_init_rx + mod->init_size_rx,
88048 set_memory_ro);
88049 }
88050 }
88051 @@ -1864,16 +1883,19 @@ static void free_module(struct module *mod)
88052
88053 /* This may be NULL, but that's OK */
88054 unset_module_init_ro_nx(mod);
88055 - module_free(mod, mod->module_init);
88056 + module_free(mod, mod->module_init_rw);
88057 + module_free_exec(mod, mod->module_init_rx);
88058 kfree(mod->args);
88059 percpu_modfree(mod);
88060
88061 /* Free lock-classes: */
88062 - lockdep_free_key_range(mod->module_core, mod->core_size);
88063 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
88064 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
88065
88066 /* Finally, free the core (containing the module structure) */
88067 unset_module_core_ro_nx(mod);
88068 - module_free(mod, mod->module_core);
88069 + module_free_exec(mod, mod->module_core_rx);
88070 + module_free(mod, mod->module_core_rw);
88071
88072 #ifdef CONFIG_MPU
88073 update_protections(current->mm);
88074 @@ -1942,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88075 int ret = 0;
88076 const struct kernel_symbol *ksym;
88077
88078 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88079 + int is_fs_load = 0;
88080 + int register_filesystem_found = 0;
88081 + char *p;
88082 +
88083 + p = strstr(mod->args, "grsec_modharden_fs");
88084 + if (p) {
88085 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
88086 + /* copy \0 as well */
88087 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
88088 + is_fs_load = 1;
88089 + }
88090 +#endif
88091 +
88092 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
88093 const char *name = info->strtab + sym[i].st_name;
88094
88095 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88096 + /* it's a real shame this will never get ripped and copied
88097 + upstream! ;(
88098 + */
88099 + if (is_fs_load && !strcmp(name, "register_filesystem"))
88100 + register_filesystem_found = 1;
88101 +#endif
88102 +
88103 switch (sym[i].st_shndx) {
88104 case SHN_COMMON:
88105 /* Ignore common symbols */
88106 @@ -1969,7 +2013,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88107 ksym = resolve_symbol_wait(mod, info, name);
88108 /* Ok if resolved. */
88109 if (ksym && !IS_ERR(ksym)) {
88110 + pax_open_kernel();
88111 sym[i].st_value = ksym->value;
88112 + pax_close_kernel();
88113 break;
88114 }
88115
88116 @@ -1988,11 +2034,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88117 secbase = (unsigned long)mod_percpu(mod);
88118 else
88119 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
88120 + pax_open_kernel();
88121 sym[i].st_value += secbase;
88122 + pax_close_kernel();
88123 break;
88124 }
88125 }
88126
88127 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88128 + if (is_fs_load && !register_filesystem_found) {
88129 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
88130 + ret = -EPERM;
88131 + }
88132 +#endif
88133 +
88134 return ret;
88135 }
88136
88137 @@ -2076,22 +2131,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
88138 || s->sh_entsize != ~0UL
88139 || strstarts(sname, ".init"))
88140 continue;
88141 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
88142 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
88143 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
88144 + else
88145 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
88146 pr_debug("\t%s\n", sname);
88147 }
88148 - switch (m) {
88149 - case 0: /* executable */
88150 - mod->core_size = debug_align(mod->core_size);
88151 - mod->core_text_size = mod->core_size;
88152 - break;
88153 - case 1: /* RO: text and ro-data */
88154 - mod->core_size = debug_align(mod->core_size);
88155 - mod->core_ro_size = mod->core_size;
88156 - break;
88157 - case 3: /* whole core */
88158 - mod->core_size = debug_align(mod->core_size);
88159 - break;
88160 - }
88161 }
88162
88163 pr_debug("Init section allocation order:\n");
88164 @@ -2105,23 +2150,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
88165 || s->sh_entsize != ~0UL
88166 || !strstarts(sname, ".init"))
88167 continue;
88168 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
88169 - | INIT_OFFSET_MASK);
88170 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
88171 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
88172 + else
88173 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
88174 + s->sh_entsize |= INIT_OFFSET_MASK;
88175 pr_debug("\t%s\n", sname);
88176 }
88177 - switch (m) {
88178 - case 0: /* executable */
88179 - mod->init_size = debug_align(mod->init_size);
88180 - mod->init_text_size = mod->init_size;
88181 - break;
88182 - case 1: /* RO: text and ro-data */
88183 - mod->init_size = debug_align(mod->init_size);
88184 - mod->init_ro_size = mod->init_size;
88185 - break;
88186 - case 3: /* whole init */
88187 - mod->init_size = debug_align(mod->init_size);
88188 - break;
88189 - }
88190 }
88191 }
88192
88193 @@ -2294,7 +2329,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88194
88195 /* Put symbol section at end of init part of module. */
88196 symsect->sh_flags |= SHF_ALLOC;
88197 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
88198 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
88199 info->index.sym) | INIT_OFFSET_MASK;
88200 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
88201
88202 @@ -2311,13 +2346,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88203 }
88204
88205 /* Append room for core symbols at end of core part. */
88206 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
88207 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
88208 - mod->core_size += strtab_size;
88209 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
88210 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
88211 + mod->core_size_rx += strtab_size;
88212
88213 /* Put string table section at end of init part of module. */
88214 strsect->sh_flags |= SHF_ALLOC;
88215 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
88216 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
88217 info->index.str) | INIT_OFFSET_MASK;
88218 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
88219 }
88220 @@ -2335,12 +2370,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88221 /* Make sure we get permanent strtab: don't use info->strtab. */
88222 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
88223
88224 + pax_open_kernel();
88225 +
88226 /* Set types up while we still have access to sections. */
88227 for (i = 0; i < mod->num_symtab; i++)
88228 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
88229
88230 - mod->core_symtab = dst = mod->module_core + info->symoffs;
88231 - mod->core_strtab = s = mod->module_core + info->stroffs;
88232 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
88233 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
88234 src = mod->symtab;
88235 for (ndst = i = 0; i < mod->num_symtab; i++) {
88236 if (i == 0 ||
88237 @@ -2352,6 +2389,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88238 }
88239 }
88240 mod->core_num_syms = ndst;
88241 +
88242 + pax_close_kernel();
88243 }
88244 #else
88245 static inline void layout_symtab(struct module *mod, struct load_info *info)
88246 @@ -2385,17 +2424,33 @@ void * __weak module_alloc(unsigned long size)
88247 return vmalloc_exec(size);
88248 }
88249
88250 -static void *module_alloc_update_bounds(unsigned long size)
88251 +static void *module_alloc_update_bounds_rw(unsigned long size)
88252 {
88253 void *ret = module_alloc(size);
88254
88255 if (ret) {
88256 mutex_lock(&module_mutex);
88257 /* Update module bounds. */
88258 - if ((unsigned long)ret < module_addr_min)
88259 - module_addr_min = (unsigned long)ret;
88260 - if ((unsigned long)ret + size > module_addr_max)
88261 - module_addr_max = (unsigned long)ret + size;
88262 + if ((unsigned long)ret < module_addr_min_rw)
88263 + module_addr_min_rw = (unsigned long)ret;
88264 + if ((unsigned long)ret + size > module_addr_max_rw)
88265 + module_addr_max_rw = (unsigned long)ret + size;
88266 + mutex_unlock(&module_mutex);
88267 + }
88268 + return ret;
88269 +}
88270 +
88271 +static void *module_alloc_update_bounds_rx(unsigned long size)
88272 +{
88273 + void *ret = module_alloc_exec(size);
88274 +
88275 + if (ret) {
88276 + mutex_lock(&module_mutex);
88277 + /* Update module bounds. */
88278 + if ((unsigned long)ret < module_addr_min_rx)
88279 + module_addr_min_rx = (unsigned long)ret;
88280 + if ((unsigned long)ret + size > module_addr_max_rx)
88281 + module_addr_max_rx = (unsigned long)ret + size;
88282 mutex_unlock(&module_mutex);
88283 }
88284 return ret;
88285 @@ -2652,7 +2707,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88286 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
88287
88288 if (info->index.sym == 0) {
88289 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88290 + /*
88291 + * avoid potentially printing jibberish on attempted load
88292 + * of a module randomized with a different seed
88293 + */
88294 + pr_warn("module has no symbols (stripped?)\n");
88295 +#else
88296 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
88297 +#endif
88298 return ERR_PTR(-ENOEXEC);
88299 }
88300
88301 @@ -2668,8 +2731,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88302 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88303 {
88304 const char *modmagic = get_modinfo(info, "vermagic");
88305 + const char *license = get_modinfo(info, "license");
88306 int err;
88307
88308 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
88309 + if (!license || !license_is_gpl_compatible(license))
88310 + return -ENOEXEC;
88311 +#endif
88312 +
88313 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
88314 modmagic = NULL;
88315
88316 @@ -2694,7 +2763,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88317 }
88318
88319 /* Set up license info based on the info section */
88320 - set_license(mod, get_modinfo(info, "license"));
88321 + set_license(mod, license);
88322
88323 return 0;
88324 }
88325 @@ -2788,7 +2857,7 @@ static int move_module(struct module *mod, struct load_info *info)
88326 void *ptr;
88327
88328 /* Do the allocs. */
88329 - ptr = module_alloc_update_bounds(mod->core_size);
88330 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
88331 /*
88332 * The pointer to this block is stored in the module structure
88333 * which is inside the block. Just mark it as not being a
88334 @@ -2798,11 +2867,11 @@ static int move_module(struct module *mod, struct load_info *info)
88335 if (!ptr)
88336 return -ENOMEM;
88337
88338 - memset(ptr, 0, mod->core_size);
88339 - mod->module_core = ptr;
88340 + memset(ptr, 0, mod->core_size_rw);
88341 + mod->module_core_rw = ptr;
88342
88343 - if (mod->init_size) {
88344 - ptr = module_alloc_update_bounds(mod->init_size);
88345 + if (mod->init_size_rw) {
88346 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
88347 /*
88348 * The pointer to this block is stored in the module structure
88349 * which is inside the block. This block doesn't need to be
88350 @@ -2811,13 +2880,45 @@ static int move_module(struct module *mod, struct load_info *info)
88351 */
88352 kmemleak_ignore(ptr);
88353 if (!ptr) {
88354 - module_free(mod, mod->module_core);
88355 + module_free(mod, mod->module_core_rw);
88356 return -ENOMEM;
88357 }
88358 - memset(ptr, 0, mod->init_size);
88359 - mod->module_init = ptr;
88360 + memset(ptr, 0, mod->init_size_rw);
88361 + mod->module_init_rw = ptr;
88362 } else
88363 - mod->module_init = NULL;
88364 + mod->module_init_rw = NULL;
88365 +
88366 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
88367 + kmemleak_not_leak(ptr);
88368 + if (!ptr) {
88369 + if (mod->module_init_rw)
88370 + module_free(mod, mod->module_init_rw);
88371 + module_free(mod, mod->module_core_rw);
88372 + return -ENOMEM;
88373 + }
88374 +
88375 + pax_open_kernel();
88376 + memset(ptr, 0, mod->core_size_rx);
88377 + pax_close_kernel();
88378 + mod->module_core_rx = ptr;
88379 +
88380 + if (mod->init_size_rx) {
88381 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88382 + kmemleak_ignore(ptr);
88383 + if (!ptr && mod->init_size_rx) {
88384 + module_free_exec(mod, mod->module_core_rx);
88385 + if (mod->module_init_rw)
88386 + module_free(mod, mod->module_init_rw);
88387 + module_free(mod, mod->module_core_rw);
88388 + return -ENOMEM;
88389 + }
88390 +
88391 + pax_open_kernel();
88392 + memset(ptr, 0, mod->init_size_rx);
88393 + pax_close_kernel();
88394 + mod->module_init_rx = ptr;
88395 + } else
88396 + mod->module_init_rx = NULL;
88397
88398 /* Transfer each section which specifies SHF_ALLOC */
88399 pr_debug("final section addresses:\n");
88400 @@ -2828,16 +2929,45 @@ static int move_module(struct module *mod, struct load_info *info)
88401 if (!(shdr->sh_flags & SHF_ALLOC))
88402 continue;
88403
88404 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
88405 - dest = mod->module_init
88406 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88407 - else
88408 - dest = mod->module_core + shdr->sh_entsize;
88409 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88410 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88411 + dest = mod->module_init_rw
88412 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88413 + else
88414 + dest = mod->module_init_rx
88415 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88416 + } else {
88417 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88418 + dest = mod->module_core_rw + shdr->sh_entsize;
88419 + else
88420 + dest = mod->module_core_rx + shdr->sh_entsize;
88421 + }
88422 +
88423 + if (shdr->sh_type != SHT_NOBITS) {
88424 +
88425 +#ifdef CONFIG_PAX_KERNEXEC
88426 +#ifdef CONFIG_X86_64
88427 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88428 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88429 +#endif
88430 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88431 + pax_open_kernel();
88432 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88433 + pax_close_kernel();
88434 + } else
88435 +#endif
88436
88437 - if (shdr->sh_type != SHT_NOBITS)
88438 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88439 + }
88440 /* Update sh_addr to point to copy in image. */
88441 - shdr->sh_addr = (unsigned long)dest;
88442 +
88443 +#ifdef CONFIG_PAX_KERNEXEC
88444 + if (shdr->sh_flags & SHF_EXECINSTR)
88445 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
88446 + else
88447 +#endif
88448 +
88449 + shdr->sh_addr = (unsigned long)dest;
88450 pr_debug("\t0x%lx %s\n",
88451 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88452 }
88453 @@ -2894,12 +3024,12 @@ static void flush_module_icache(const struct module *mod)
88454 * Do it before processing of module parameters, so the module
88455 * can provide parameter accessor functions of its own.
88456 */
88457 - if (mod->module_init)
88458 - flush_icache_range((unsigned long)mod->module_init,
88459 - (unsigned long)mod->module_init
88460 - + mod->init_size);
88461 - flush_icache_range((unsigned long)mod->module_core,
88462 - (unsigned long)mod->module_core + mod->core_size);
88463 + if (mod->module_init_rx)
88464 + flush_icache_range((unsigned long)mod->module_init_rx,
88465 + (unsigned long)mod->module_init_rx
88466 + + mod->init_size_rx);
88467 + flush_icache_range((unsigned long)mod->module_core_rx,
88468 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
88469
88470 set_fs(old_fs);
88471 }
88472 @@ -2956,8 +3086,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88473 static void module_deallocate(struct module *mod, struct load_info *info)
88474 {
88475 percpu_modfree(mod);
88476 - module_free(mod, mod->module_init);
88477 - module_free(mod, mod->module_core);
88478 + module_free_exec(mod, mod->module_init_rx);
88479 + module_free_exec(mod, mod->module_core_rx);
88480 + module_free(mod, mod->module_init_rw);
88481 + module_free(mod, mod->module_core_rw);
88482 }
88483
88484 int __weak module_finalize(const Elf_Ehdr *hdr,
88485 @@ -2970,7 +3102,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88486 static int post_relocation(struct module *mod, const struct load_info *info)
88487 {
88488 /* Sort exception table now relocations are done. */
88489 + pax_open_kernel();
88490 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88491 + pax_close_kernel();
88492
88493 /* Copy relocated percpu area over. */
88494 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88495 @@ -3024,16 +3158,16 @@ static int do_init_module(struct module *mod)
88496 MODULE_STATE_COMING, mod);
88497
88498 /* Set RO and NX regions for core */
88499 - set_section_ro_nx(mod->module_core,
88500 - mod->core_text_size,
88501 - mod->core_ro_size,
88502 - mod->core_size);
88503 + set_section_ro_nx(mod->module_core_rx,
88504 + mod->core_size_rx,
88505 + mod->core_size_rx,
88506 + mod->core_size_rx);
88507
88508 /* Set RO and NX regions for init */
88509 - set_section_ro_nx(mod->module_init,
88510 - mod->init_text_size,
88511 - mod->init_ro_size,
88512 - mod->init_size);
88513 + set_section_ro_nx(mod->module_init_rx,
88514 + mod->init_size_rx,
88515 + mod->init_size_rx,
88516 + mod->init_size_rx);
88517
88518 do_mod_ctors(mod);
88519 /* Start the module */
88520 @@ -3094,11 +3228,12 @@ static int do_init_module(struct module *mod)
88521 mod->strtab = mod->core_strtab;
88522 #endif
88523 unset_module_init_ro_nx(mod);
88524 - module_free(mod, mod->module_init);
88525 - mod->module_init = NULL;
88526 - mod->init_size = 0;
88527 - mod->init_ro_size = 0;
88528 - mod->init_text_size = 0;
88529 + module_free(mod, mod->module_init_rw);
88530 + module_free_exec(mod, mod->module_init_rx);
88531 + mod->module_init_rw = NULL;
88532 + mod->module_init_rx = NULL;
88533 + mod->init_size_rw = 0;
88534 + mod->init_size_rx = 0;
88535 mutex_unlock(&module_mutex);
88536 wake_up_all(&module_wq);
88537
88538 @@ -3241,9 +3376,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88539 if (err)
88540 goto free_unload;
88541
88542 + /* Now copy in args */
88543 + mod->args = strndup_user(uargs, ~0UL >> 1);
88544 + if (IS_ERR(mod->args)) {
88545 + err = PTR_ERR(mod->args);
88546 + goto free_unload;
88547 + }
88548 +
88549 /* Set up MODINFO_ATTR fields */
88550 setup_modinfo(mod, info);
88551
88552 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88553 + {
88554 + char *p, *p2;
88555 +
88556 + if (strstr(mod->args, "grsec_modharden_netdev")) {
88557 + 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);
88558 + err = -EPERM;
88559 + goto free_modinfo;
88560 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88561 + p += sizeof("grsec_modharden_normal") - 1;
88562 + p2 = strstr(p, "_");
88563 + if (p2) {
88564 + *p2 = '\0';
88565 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88566 + *p2 = '_';
88567 + }
88568 + err = -EPERM;
88569 + goto free_modinfo;
88570 + }
88571 + }
88572 +#endif
88573 +
88574 /* Fix up syms, so that st_value is a pointer to location. */
88575 err = simplify_symbols(mod, info);
88576 if (err < 0)
88577 @@ -3259,13 +3423,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88578
88579 flush_module_icache(mod);
88580
88581 - /* Now copy in args */
88582 - mod->args = strndup_user(uargs, ~0UL >> 1);
88583 - if (IS_ERR(mod->args)) {
88584 - err = PTR_ERR(mod->args);
88585 - goto free_arch_cleanup;
88586 - }
88587 -
88588 dynamic_debug_setup(info->debug, info->num_debug);
88589
88590 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
88591 @@ -3303,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88592 ddebug_cleanup:
88593 dynamic_debug_remove(info->debug);
88594 synchronize_sched();
88595 - kfree(mod->args);
88596 - free_arch_cleanup:
88597 module_arch_cleanup(mod);
88598 free_modinfo:
88599 free_modinfo(mod);
88600 + kfree(mod->args);
88601 free_unload:
88602 module_unload_free(mod);
88603 unlink_mod:
88604 @@ -3390,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
88605 unsigned long nextval;
88606
88607 /* At worse, next value is at end of module */
88608 - if (within_module_init(addr, mod))
88609 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
88610 + if (within_module_init_rx(addr, mod))
88611 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88612 + else if (within_module_init_rw(addr, mod))
88613 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88614 + else if (within_module_core_rx(addr, mod))
88615 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88616 + else if (within_module_core_rw(addr, mod))
88617 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88618 else
88619 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
88620 + return NULL;
88621
88622 /* Scan for closest preceding symbol, and next symbol. (ELF
88623 starts real symbols at 1). */
88624 @@ -3644,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
88625 return 0;
88626
88627 seq_printf(m, "%s %u",
88628 - mod->name, mod->init_size + mod->core_size);
88629 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88630 print_unload_info(m, mod);
88631
88632 /* Informative for users. */
88633 @@ -3653,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
88634 mod->state == MODULE_STATE_COMING ? "Loading":
88635 "Live");
88636 /* Used by oprofile and other similar tools. */
88637 - seq_printf(m, " 0x%pK", mod->module_core);
88638 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88639
88640 /* Taints info */
88641 if (mod->taints)
88642 @@ -3689,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
88643
88644 static int __init proc_modules_init(void)
88645 {
88646 +#ifndef CONFIG_GRKERNSEC_HIDESYM
88647 +#ifdef CONFIG_GRKERNSEC_PROC_USER
88648 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88649 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88650 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88651 +#else
88652 proc_create("modules", 0, NULL, &proc_modules_operations);
88653 +#endif
88654 +#else
88655 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88656 +#endif
88657 return 0;
88658 }
88659 module_init(proc_modules_init);
88660 @@ -3750,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
88661 {
88662 struct module *mod;
88663
88664 - if (addr < module_addr_min || addr > module_addr_max)
88665 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88666 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
88667 return NULL;
88668
88669 list_for_each_entry_rcu(mod, &modules, list) {
88670 if (mod->state == MODULE_STATE_UNFORMED)
88671 continue;
88672 - if (within_module_core(addr, mod)
88673 - || within_module_init(addr, mod))
88674 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
88675 return mod;
88676 }
88677 return NULL;
88678 @@ -3792,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
88679 */
88680 struct module *__module_text_address(unsigned long addr)
88681 {
88682 - struct module *mod = __module_address(addr);
88683 + struct module *mod;
88684 +
88685 +#ifdef CONFIG_X86_32
88686 + addr = ktla_ktva(addr);
88687 +#endif
88688 +
88689 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88690 + return NULL;
88691 +
88692 + mod = __module_address(addr);
88693 +
88694 if (mod) {
88695 /* Make sure it's within the text section. */
88696 - if (!within(addr, mod->module_init, mod->init_text_size)
88697 - && !within(addr, mod->module_core, mod->core_text_size))
88698 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88699 mod = NULL;
88700 }
88701 return mod;
88702 diff --git a/kernel/notifier.c b/kernel/notifier.c
88703 index db4c8b0..ad011c5 100644
88704 --- a/kernel/notifier.c
88705 +++ b/kernel/notifier.c
88706 @@ -5,6 +5,7 @@
88707 #include <linux/rcupdate.h>
88708 #include <linux/vmalloc.h>
88709 #include <linux/reboot.h>
88710 +#include <linux/mm.h>
88711
88712 /*
88713 * Notifier list for kernel code which wants to be called
88714 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88715 while ((*nl) != NULL) {
88716 if (n->priority > (*nl)->priority)
88717 break;
88718 - nl = &((*nl)->next);
88719 + nl = (struct notifier_block **)&((*nl)->next);
88720 }
88721 - n->next = *nl;
88722 + pax_open_kernel();
88723 + *(const void **)&n->next = *nl;
88724 rcu_assign_pointer(*nl, n);
88725 + pax_close_kernel();
88726 return 0;
88727 }
88728
88729 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88730 return 0;
88731 if (n->priority > (*nl)->priority)
88732 break;
88733 - nl = &((*nl)->next);
88734 + nl = (struct notifier_block **)&((*nl)->next);
88735 }
88736 - n->next = *nl;
88737 + pax_open_kernel();
88738 + *(const void **)&n->next = *nl;
88739 rcu_assign_pointer(*nl, n);
88740 + pax_close_kernel();
88741 return 0;
88742 }
88743
88744 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88745 {
88746 while ((*nl) != NULL) {
88747 if ((*nl) == n) {
88748 + pax_open_kernel();
88749 rcu_assign_pointer(*nl, n->next);
88750 + pax_close_kernel();
88751 return 0;
88752 }
88753 - nl = &((*nl)->next);
88754 + nl = (struct notifier_block **)&((*nl)->next);
88755 }
88756 return -ENOENT;
88757 }
88758 diff --git a/kernel/padata.c b/kernel/padata.c
88759 index 161402f..598814c 100644
88760 --- a/kernel/padata.c
88761 +++ b/kernel/padata.c
88762 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88763 * seq_nr mod. number of cpus in use.
88764 */
88765
88766 - seq_nr = atomic_inc_return(&pd->seq_nr);
88767 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88768 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88769
88770 return padata_index_to_cpu(pd, cpu_index);
88771 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88772 padata_init_pqueues(pd);
88773 padata_init_squeues(pd);
88774 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88775 - atomic_set(&pd->seq_nr, -1);
88776 + atomic_set_unchecked(&pd->seq_nr, -1);
88777 atomic_set(&pd->reorder_objects, 0);
88778 atomic_set(&pd->refcnt, 0);
88779 pd->pinst = pinst;
88780 diff --git a/kernel/panic.c b/kernel/panic.c
88781 index d02fa9f..9faec0a 100644
88782 --- a/kernel/panic.c
88783 +++ b/kernel/panic.c
88784 @@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88785 /*
88786 * Stop ourself in panic -- architecture code may override this
88787 */
88788 -void __weak panic_smp_self_stop(void)
88789 +void __weak __noreturn panic_smp_self_stop(void)
88790 {
88791 while (1)
88792 cpu_relax();
88793 @@ -408,7 +408,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88794 disable_trace_on_warning();
88795
88796 pr_warn("------------[ cut here ]------------\n");
88797 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88798 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88799 raw_smp_processor_id(), current->pid, file, line, caller);
88800
88801 if (args)
88802 @@ -462,7 +462,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88803 */
88804 __visible void __stack_chk_fail(void)
88805 {
88806 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
88807 + dump_stack();
88808 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88809 __builtin_return_address(0));
88810 }
88811 EXPORT_SYMBOL(__stack_chk_fail);
88812 diff --git a/kernel/pid.c b/kernel/pid.c
88813 index 9b9a266..c20ef80 100644
88814 --- a/kernel/pid.c
88815 +++ b/kernel/pid.c
88816 @@ -33,6 +33,7 @@
88817 #include <linux/rculist.h>
88818 #include <linux/bootmem.h>
88819 #include <linux/hash.h>
88820 +#include <linux/security.h>
88821 #include <linux/pid_namespace.h>
88822 #include <linux/init_task.h>
88823 #include <linux/syscalls.h>
88824 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88825
88826 int pid_max = PID_MAX_DEFAULT;
88827
88828 -#define RESERVED_PIDS 300
88829 +#define RESERVED_PIDS 500
88830
88831 int pid_max_min = RESERVED_PIDS + 1;
88832 int pid_max_max = PID_MAX_LIMIT;
88833 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88834 */
88835 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88836 {
88837 + struct task_struct *task;
88838 +
88839 rcu_lockdep_assert(rcu_read_lock_held(),
88840 "find_task_by_pid_ns() needs rcu_read_lock()"
88841 " protection");
88842 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88843 +
88844 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88845 +
88846 + if (gr_pid_is_chrooted(task))
88847 + return NULL;
88848 +
88849 + return task;
88850 }
88851
88852 struct task_struct *find_task_by_vpid(pid_t vnr)
88853 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88854 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88855 }
88856
88857 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88858 +{
88859 + rcu_lockdep_assert(rcu_read_lock_held(),
88860 + "find_task_by_pid_ns() needs rcu_read_lock()"
88861 + " protection");
88862 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88863 +}
88864 +
88865 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88866 {
88867 struct pid *pid;
88868 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88869 index db95d8e..a0ca23f 100644
88870 --- a/kernel/pid_namespace.c
88871 +++ b/kernel/pid_namespace.c
88872 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88873 void __user *buffer, size_t *lenp, loff_t *ppos)
88874 {
88875 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88876 - struct ctl_table tmp = *table;
88877 + ctl_table_no_const tmp = *table;
88878
88879 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88880 return -EPERM;
88881 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88882 index 3b89464..5e38379 100644
88883 --- a/kernel/posix-cpu-timers.c
88884 +++ b/kernel/posix-cpu-timers.c
88885 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88886
88887 static __init int init_posix_cpu_timers(void)
88888 {
88889 - struct k_clock process = {
88890 + static struct k_clock process = {
88891 .clock_getres = process_cpu_clock_getres,
88892 .clock_get = process_cpu_clock_get,
88893 .timer_create = process_cpu_timer_create,
88894 .nsleep = process_cpu_nsleep,
88895 .nsleep_restart = process_cpu_nsleep_restart,
88896 };
88897 - struct k_clock thread = {
88898 + static struct k_clock thread = {
88899 .clock_getres = thread_cpu_clock_getres,
88900 .clock_get = thread_cpu_clock_get,
88901 .timer_create = thread_cpu_timer_create,
88902 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88903 index 424c2d4..679242f 100644
88904 --- a/kernel/posix-timers.c
88905 +++ b/kernel/posix-timers.c
88906 @@ -43,6 +43,7 @@
88907 #include <linux/hash.h>
88908 #include <linux/posix-clock.h>
88909 #include <linux/posix-timers.h>
88910 +#include <linux/grsecurity.h>
88911 #include <linux/syscalls.h>
88912 #include <linux/wait.h>
88913 #include <linux/workqueue.h>
88914 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88915 * which we beg off on and pass to do_sys_settimeofday().
88916 */
88917
88918 -static struct k_clock posix_clocks[MAX_CLOCKS];
88919 +static struct k_clock *posix_clocks[MAX_CLOCKS];
88920
88921 /*
88922 * These ones are defined below.
88923 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88924 */
88925 static __init int init_posix_timers(void)
88926 {
88927 - struct k_clock clock_realtime = {
88928 + static struct k_clock clock_realtime = {
88929 .clock_getres = hrtimer_get_res,
88930 .clock_get = posix_clock_realtime_get,
88931 .clock_set = posix_clock_realtime_set,
88932 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88933 .timer_get = common_timer_get,
88934 .timer_del = common_timer_del,
88935 };
88936 - struct k_clock clock_monotonic = {
88937 + static struct k_clock clock_monotonic = {
88938 .clock_getres = hrtimer_get_res,
88939 .clock_get = posix_ktime_get_ts,
88940 .nsleep = common_nsleep,
88941 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88942 .timer_get = common_timer_get,
88943 .timer_del = common_timer_del,
88944 };
88945 - struct k_clock clock_monotonic_raw = {
88946 + static struct k_clock clock_monotonic_raw = {
88947 .clock_getres = hrtimer_get_res,
88948 .clock_get = posix_get_monotonic_raw,
88949 };
88950 - struct k_clock clock_realtime_coarse = {
88951 + static struct k_clock clock_realtime_coarse = {
88952 .clock_getres = posix_get_coarse_res,
88953 .clock_get = posix_get_realtime_coarse,
88954 };
88955 - struct k_clock clock_monotonic_coarse = {
88956 + static struct k_clock clock_monotonic_coarse = {
88957 .clock_getres = posix_get_coarse_res,
88958 .clock_get = posix_get_monotonic_coarse,
88959 };
88960 - struct k_clock clock_tai = {
88961 + static struct k_clock clock_tai = {
88962 .clock_getres = hrtimer_get_res,
88963 .clock_get = posix_get_tai,
88964 .nsleep = common_nsleep,
88965 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88966 .timer_get = common_timer_get,
88967 .timer_del = common_timer_del,
88968 };
88969 - struct k_clock clock_boottime = {
88970 + static struct k_clock clock_boottime = {
88971 .clock_getres = hrtimer_get_res,
88972 .clock_get = posix_get_boottime,
88973 .nsleep = common_nsleep,
88974 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88975 return;
88976 }
88977
88978 - posix_clocks[clock_id] = *new_clock;
88979 + posix_clocks[clock_id] = new_clock;
88980 }
88981 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88982
88983 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88984 return (id & CLOCKFD_MASK) == CLOCKFD ?
88985 &clock_posix_dynamic : &clock_posix_cpu;
88986
88987 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88988 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88989 return NULL;
88990 - return &posix_clocks[id];
88991 + return posix_clocks[id];
88992 }
88993
88994 static int common_timer_create(struct k_itimer *new_timer)
88995 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88996 struct k_clock *kc = clockid_to_kclock(which_clock);
88997 struct k_itimer *new_timer;
88998 int error, new_timer_id;
88999 - sigevent_t event;
89000 + sigevent_t event = { };
89001 int it_id_set = IT_ID_NOT_SET;
89002
89003 if (!kc)
89004 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
89005 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
89006 return -EFAULT;
89007
89008 + /* only the CLOCK_REALTIME clock can be set, all other clocks
89009 + have their clock_set fptr set to a nosettime dummy function
89010 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
89011 + call common_clock_set, which calls do_sys_settimeofday, which
89012 + we hook
89013 + */
89014 +
89015 return kc->clock_set(which_clock, &new_tp);
89016 }
89017
89018 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
89019 index 2fac9cc..56fef29 100644
89020 --- a/kernel/power/Kconfig
89021 +++ b/kernel/power/Kconfig
89022 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
89023 config HIBERNATION
89024 bool "Hibernation (aka 'suspend to disk')"
89025 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
89026 + depends on !GRKERNSEC_KMEM
89027 + depends on !PAX_MEMORY_SANITIZE
89028 select HIBERNATE_CALLBACKS
89029 select LZO_COMPRESS
89030 select LZO_DECOMPRESS
89031 diff --git a/kernel/power/process.c b/kernel/power/process.c
89032 index 06ec886..9dba35e 100644
89033 --- a/kernel/power/process.c
89034 +++ b/kernel/power/process.c
89035 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
89036 unsigned int elapsed_msecs;
89037 bool wakeup = false;
89038 int sleep_usecs = USEC_PER_MSEC;
89039 + bool timedout = false;
89040
89041 do_gettimeofday(&start);
89042
89043 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
89044
89045 while (true) {
89046 todo = 0;
89047 + if (time_after(jiffies, end_time))
89048 + timedout = true;
89049 read_lock(&tasklist_lock);
89050 do_each_thread(g, p) {
89051 if (p == current || !freeze_task(p))
89052 continue;
89053
89054 - if (!freezer_should_skip(p))
89055 + if (!freezer_should_skip(p)) {
89056 todo++;
89057 + if (timedout) {
89058 + printk(KERN_ERR "Task refusing to freeze:\n");
89059 + sched_show_task(p);
89060 + }
89061 + }
89062 } while_each_thread(g, p);
89063 read_unlock(&tasklist_lock);
89064
89065 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
89066 todo += wq_busy;
89067 }
89068
89069 - if (!todo || time_after(jiffies, end_time))
89070 + if (!todo || timedout)
89071 break;
89072
89073 if (pm_wakeup_pending()) {
89074 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
89075 index 221229c..c76ca0a 100644
89076 --- a/kernel/printk/printk.c
89077 +++ b/kernel/printk/printk.c
89078 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
89079 if (from_file && type != SYSLOG_ACTION_OPEN)
89080 return 0;
89081
89082 +#ifdef CONFIG_GRKERNSEC_DMESG
89083 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
89084 + return -EPERM;
89085 +#endif
89086 +
89087 if (syslog_action_restricted(type)) {
89088 if (capable(CAP_SYSLOG))
89089 return 0;
89090 diff --git a/kernel/profile.c b/kernel/profile.c
89091 index cb980f0..ccd8782 100644
89092 --- a/kernel/profile.c
89093 +++ b/kernel/profile.c
89094 @@ -37,7 +37,7 @@ struct profile_hit {
89095 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
89096 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
89097
89098 -static atomic_t *prof_buffer;
89099 +static atomic_unchecked_t *prof_buffer;
89100 static unsigned long prof_len, prof_shift;
89101
89102 int prof_on __read_mostly;
89103 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
89104 hits[i].pc = 0;
89105 continue;
89106 }
89107 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
89108 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
89109 hits[i].hits = hits[i].pc = 0;
89110 }
89111 }
89112 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
89113 * Add the current hit(s) and flush the write-queue out
89114 * to the global buffer:
89115 */
89116 - atomic_add(nr_hits, &prof_buffer[pc]);
89117 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
89118 for (i = 0; i < NR_PROFILE_HIT; ++i) {
89119 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
89120 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
89121 hits[i].pc = hits[i].hits = 0;
89122 }
89123 out:
89124 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
89125 {
89126 unsigned long pc;
89127 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
89128 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
89129 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
89130 }
89131 #endif /* !CONFIG_SMP */
89132
89133 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
89134 return -EFAULT;
89135 buf++; p++; count--; read++;
89136 }
89137 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
89138 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
89139 if (copy_to_user(buf, (void *)pnt, count))
89140 return -EFAULT;
89141 read += count;
89142 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
89143 }
89144 #endif
89145 profile_discard_flip_buffers();
89146 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
89147 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
89148 return count;
89149 }
89150
89151 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
89152 index adf9862..9d86345 100644
89153 --- a/kernel/ptrace.c
89154 +++ b/kernel/ptrace.c
89155 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
89156 if (seize)
89157 flags |= PT_SEIZED;
89158 rcu_read_lock();
89159 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
89160 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
89161 flags |= PT_PTRACE_CAP;
89162 rcu_read_unlock();
89163 task->ptrace = flags;
89164 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
89165 break;
89166 return -EIO;
89167 }
89168 - if (copy_to_user(dst, buf, retval))
89169 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
89170 return -EFAULT;
89171 copied += retval;
89172 src += retval;
89173 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
89174 bool seized = child->ptrace & PT_SEIZED;
89175 int ret = -EIO;
89176 siginfo_t siginfo, *si;
89177 - void __user *datavp = (void __user *) data;
89178 + void __user *datavp = (__force void __user *) data;
89179 unsigned long __user *datalp = datavp;
89180 unsigned long flags;
89181
89182 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
89183 goto out;
89184 }
89185
89186 + if (gr_handle_ptrace(child, request)) {
89187 + ret = -EPERM;
89188 + goto out_put_task_struct;
89189 + }
89190 +
89191 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89192 ret = ptrace_attach(child, request, addr, data);
89193 /*
89194 * Some architectures need to do book-keeping after
89195 * a ptrace attach.
89196 */
89197 - if (!ret)
89198 + if (!ret) {
89199 arch_ptrace_attach(child);
89200 + gr_audit_ptrace(child);
89201 + }
89202 goto out_put_task_struct;
89203 }
89204
89205 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
89206 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
89207 if (copied != sizeof(tmp))
89208 return -EIO;
89209 - return put_user(tmp, (unsigned long __user *)data);
89210 + return put_user(tmp, (__force unsigned long __user *)data);
89211 }
89212
89213 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
89214 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
89215 }
89216
89217 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
89218 - compat_long_t, addr, compat_long_t, data)
89219 + compat_ulong_t, addr, compat_ulong_t, data)
89220 {
89221 struct task_struct *child;
89222 long ret;
89223 @@ -1197,14 +1204,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
89224 goto out;
89225 }
89226
89227 + if (gr_handle_ptrace(child, request)) {
89228 + ret = -EPERM;
89229 + goto out_put_task_struct;
89230 + }
89231 +
89232 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89233 ret = ptrace_attach(child, request, addr, data);
89234 /*
89235 * Some architectures need to do book-keeping after
89236 * a ptrace attach.
89237 */
89238 - if (!ret)
89239 + if (!ret) {
89240 arch_ptrace_attach(child);
89241 + gr_audit_ptrace(child);
89242 + }
89243 goto out_put_task_struct;
89244 }
89245
89246 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
89247 index bd30bc6..dce23da 100644
89248 --- a/kernel/rcu/rcutorture.c
89249 +++ b/kernel/rcu/rcutorture.c
89250 @@ -122,12 +122,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
89251 rcu_torture_count) = { 0 };
89252 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
89253 rcu_torture_batch) = { 0 };
89254 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89255 -static atomic_t n_rcu_torture_alloc;
89256 -static atomic_t n_rcu_torture_alloc_fail;
89257 -static atomic_t n_rcu_torture_free;
89258 -static atomic_t n_rcu_torture_mberror;
89259 -static atomic_t n_rcu_torture_error;
89260 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89261 +static atomic_unchecked_t n_rcu_torture_alloc;
89262 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
89263 +static atomic_unchecked_t n_rcu_torture_free;
89264 +static atomic_unchecked_t n_rcu_torture_mberror;
89265 +static atomic_unchecked_t n_rcu_torture_error;
89266 static long n_rcu_torture_barrier_error;
89267 static long n_rcu_torture_boost_ktrerror;
89268 static long n_rcu_torture_boost_rterror;
89269 @@ -186,11 +186,11 @@ rcu_torture_alloc(void)
89270
89271 spin_lock_bh(&rcu_torture_lock);
89272 if (list_empty(&rcu_torture_freelist)) {
89273 - atomic_inc(&n_rcu_torture_alloc_fail);
89274 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
89275 spin_unlock_bh(&rcu_torture_lock);
89276 return NULL;
89277 }
89278 - atomic_inc(&n_rcu_torture_alloc);
89279 + atomic_inc_unchecked(&n_rcu_torture_alloc);
89280 p = rcu_torture_freelist.next;
89281 list_del_init(p);
89282 spin_unlock_bh(&rcu_torture_lock);
89283 @@ -203,7 +203,7 @@ rcu_torture_alloc(void)
89284 static void
89285 rcu_torture_free(struct rcu_torture *p)
89286 {
89287 - atomic_inc(&n_rcu_torture_free);
89288 + atomic_inc_unchecked(&n_rcu_torture_free);
89289 spin_lock_bh(&rcu_torture_lock);
89290 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
89291 spin_unlock_bh(&rcu_torture_lock);
89292 @@ -287,7 +287,7 @@ rcu_torture_cb(struct rcu_head *p)
89293 i = rp->rtort_pipe_count;
89294 if (i > RCU_TORTURE_PIPE_LEN)
89295 i = RCU_TORTURE_PIPE_LEN;
89296 - atomic_inc(&rcu_torture_wcount[i]);
89297 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89298 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
89299 rp->rtort_mbtest = 0;
89300 rcu_torture_free(rp);
89301 @@ -714,7 +714,7 @@ rcu_torture_writer(void *arg)
89302 i = old_rp->rtort_pipe_count;
89303 if (i > RCU_TORTURE_PIPE_LEN)
89304 i = RCU_TORTURE_PIPE_LEN;
89305 - atomic_inc(&rcu_torture_wcount[i]);
89306 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89307 old_rp->rtort_pipe_count++;
89308 if (gp_normal == gp_exp)
89309 exp = !!(torture_random(&rand) & 0x80);
89310 @@ -732,7 +732,7 @@ rcu_torture_writer(void *arg)
89311 i = rp->rtort_pipe_count;
89312 if (i > RCU_TORTURE_PIPE_LEN)
89313 i = RCU_TORTURE_PIPE_LEN;
89314 - atomic_inc(&rcu_torture_wcount[i]);
89315 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89316 if (++rp->rtort_pipe_count >=
89317 RCU_TORTURE_PIPE_LEN) {
89318 rp->rtort_mbtest = 0;
89319 @@ -825,7 +825,7 @@ static void rcu_torture_timer(unsigned long unused)
89320 return;
89321 }
89322 if (p->rtort_mbtest == 0)
89323 - atomic_inc(&n_rcu_torture_mberror);
89324 + atomic_inc_unchecked(&n_rcu_torture_mberror);
89325 spin_lock(&rand_lock);
89326 cur_ops->read_delay(&rand);
89327 n_rcu_torture_timers++;
89328 @@ -895,7 +895,7 @@ rcu_torture_reader(void *arg)
89329 continue;
89330 }
89331 if (p->rtort_mbtest == 0)
89332 - atomic_inc(&n_rcu_torture_mberror);
89333 + atomic_inc_unchecked(&n_rcu_torture_mberror);
89334 cur_ops->read_delay(&rand);
89335 preempt_disable();
89336 pipe_count = p->rtort_pipe_count;
89337 @@ -950,15 +950,15 @@ rcu_torture_printk(char *page)
89338 }
89339 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
89340 page += sprintf(page,
89341 - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89342 + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89343 rcu_torture_current,
89344 rcu_torture_current_version,
89345 list_empty(&rcu_torture_freelist),
89346 - atomic_read(&n_rcu_torture_alloc),
89347 - atomic_read(&n_rcu_torture_alloc_fail),
89348 - atomic_read(&n_rcu_torture_free));
89349 + atomic_read_unchecked(&n_rcu_torture_alloc),
89350 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
89351 + atomic_read_unchecked(&n_rcu_torture_free));
89352 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
89353 - atomic_read(&n_rcu_torture_mberror),
89354 + atomic_read_unchecked(&n_rcu_torture_mberror),
89355 n_rcu_torture_boost_ktrerror,
89356 n_rcu_torture_boost_rterror);
89357 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
89358 @@ -971,14 +971,14 @@ rcu_torture_printk(char *page)
89359 n_barrier_attempts,
89360 n_rcu_torture_barrier_error);
89361 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
89362 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
89363 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
89364 n_rcu_torture_barrier_error != 0 ||
89365 n_rcu_torture_boost_ktrerror != 0 ||
89366 n_rcu_torture_boost_rterror != 0 ||
89367 n_rcu_torture_boost_failure != 0 ||
89368 i > 1) {
89369 page += sprintf(page, "!!! ");
89370 - atomic_inc(&n_rcu_torture_error);
89371 + atomic_inc_unchecked(&n_rcu_torture_error);
89372 WARN_ON_ONCE(1);
89373 }
89374 page += sprintf(page, "Reader Pipe: ");
89375 @@ -992,7 +992,7 @@ rcu_torture_printk(char *page)
89376 page += sprintf(page, "Free-Block Circulation: ");
89377 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89378 page += sprintf(page, " %d",
89379 - atomic_read(&rcu_torture_wcount[i]));
89380 + atomic_read_unchecked(&rcu_torture_wcount[i]));
89381 }
89382 page += sprintf(page, "\n");
89383 if (cur_ops->stats)
89384 @@ -1341,7 +1341,7 @@ rcu_torture_cleanup(void)
89385
89386 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89387
89388 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89389 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89390 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89391 else if (torture_onoff_failures())
89392 rcu_torture_print_module_parms(cur_ops,
89393 @@ -1460,18 +1460,18 @@ rcu_torture_init(void)
89394
89395 rcu_torture_current = NULL;
89396 rcu_torture_current_version = 0;
89397 - atomic_set(&n_rcu_torture_alloc, 0);
89398 - atomic_set(&n_rcu_torture_alloc_fail, 0);
89399 - atomic_set(&n_rcu_torture_free, 0);
89400 - atomic_set(&n_rcu_torture_mberror, 0);
89401 - atomic_set(&n_rcu_torture_error, 0);
89402 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89403 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89404 + atomic_set_unchecked(&n_rcu_torture_free, 0);
89405 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89406 + atomic_set_unchecked(&n_rcu_torture_error, 0);
89407 n_rcu_torture_barrier_error = 0;
89408 n_rcu_torture_boost_ktrerror = 0;
89409 n_rcu_torture_boost_rterror = 0;
89410 n_rcu_torture_boost_failure = 0;
89411 n_rcu_torture_boosts = 0;
89412 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89413 - atomic_set(&rcu_torture_wcount[i], 0);
89414 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89415 for_each_possible_cpu(cpu) {
89416 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89417 per_cpu(rcu_torture_count, cpu)[i] = 0;
89418 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
89419 index c639556..cf0a0d5 100644
89420 --- a/kernel/rcu/srcu.c
89421 +++ b/kernel/rcu/srcu.c
89422 @@ -298,9 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
89423
89424 idx = ACCESS_ONCE(sp->completed) & 0x1;
89425 preempt_disable();
89426 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89427 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89428 smp_mb(); /* B */ /* Avoid leaking the critical section. */
89429 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89430 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89431 preempt_enable();
89432 return idx;
89433 }
89434 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
89435 index d9efcc1..ea543e9 100644
89436 --- a/kernel/rcu/tiny.c
89437 +++ b/kernel/rcu/tiny.c
89438 @@ -42,7 +42,7 @@
89439 /* Forward declarations for tiny_plugin.h. */
89440 struct rcu_ctrlblk;
89441 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
89442 -static void rcu_process_callbacks(struct softirq_action *unused);
89443 +static void rcu_process_callbacks(void);
89444 static void __call_rcu(struct rcu_head *head,
89445 void (*func)(struct rcu_head *rcu),
89446 struct rcu_ctrlblk *rcp);
89447 @@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
89448 false));
89449 }
89450
89451 -static void rcu_process_callbacks(struct softirq_action *unused)
89452 +static __latent_entropy void rcu_process_callbacks(void)
89453 {
89454 __rcu_process_callbacks(&rcu_sched_ctrlblk);
89455 __rcu_process_callbacks(&rcu_bh_ctrlblk);
89456 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89457 index 0c47e30..a084591 100644
89458 --- a/kernel/rcu/tree.c
89459 +++ b/kernel/rcu/tree.c
89460 @@ -388,9 +388,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89461 rcu_prepare_for_idle(smp_processor_id());
89462 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89463 smp_mb__before_atomic_inc(); /* See above. */
89464 - atomic_inc(&rdtp->dynticks);
89465 + atomic_inc_unchecked(&rdtp->dynticks);
89466 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89467 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89468 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89469
89470 /*
89471 * It is illegal to enter an extended quiescent state while
89472 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89473 int user)
89474 {
89475 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89476 - atomic_inc(&rdtp->dynticks);
89477 + atomic_inc_unchecked(&rdtp->dynticks);
89478 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89479 smp_mb__after_atomic_inc(); /* See above. */
89480 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89481 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89482 rcu_cleanup_after_idle(smp_processor_id());
89483 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89484 if (!user && !is_idle_task(current)) {
89485 @@ -632,14 +632,14 @@ void rcu_nmi_enter(void)
89486 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89487
89488 if (rdtp->dynticks_nmi_nesting == 0 &&
89489 - (atomic_read(&rdtp->dynticks) & 0x1))
89490 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89491 return;
89492 rdtp->dynticks_nmi_nesting++;
89493 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89494 - atomic_inc(&rdtp->dynticks);
89495 + atomic_inc_unchecked(&rdtp->dynticks);
89496 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89497 smp_mb__after_atomic_inc(); /* See above. */
89498 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89499 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89500 }
89501
89502 /**
89503 @@ -658,9 +658,9 @@ void rcu_nmi_exit(void)
89504 return;
89505 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89506 smp_mb__before_atomic_inc(); /* See above. */
89507 - atomic_inc(&rdtp->dynticks);
89508 + atomic_inc_unchecked(&rdtp->dynticks);
89509 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89510 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89511 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89512 }
89513
89514 /**
89515 @@ -673,7 +673,7 @@ void rcu_nmi_exit(void)
89516 */
89517 bool notrace __rcu_is_watching(void)
89518 {
89519 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89520 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89521 }
89522
89523 /**
89524 @@ -756,7 +756,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89525 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89526 bool *isidle, unsigned long *maxj)
89527 {
89528 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89529 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89530 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89531 return (rdp->dynticks_snap & 0x1) == 0;
89532 }
89533 @@ -779,7 +779,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89534 unsigned int curr;
89535 unsigned int snap;
89536
89537 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89538 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89539 snap = (unsigned int)rdp->dynticks_snap;
89540
89541 /*
89542 @@ -1449,9 +1449,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89543 rdp = this_cpu_ptr(rsp->rda);
89544 rcu_preempt_check_blocked_tasks(rnp);
89545 rnp->qsmask = rnp->qsmaskinit;
89546 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89547 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89548 WARN_ON_ONCE(rnp->completed != rsp->completed);
89549 - ACCESS_ONCE(rnp->completed) = rsp->completed;
89550 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89551 if (rnp == rdp->mynode)
89552 __note_gp_changes(rsp, rnp, rdp);
89553 rcu_preempt_boost_start_gp(rnp);
89554 @@ -1545,7 +1545,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89555 rcu_for_each_node_breadth_first(rsp, rnp) {
89556 raw_spin_lock_irq(&rnp->lock);
89557 smp_mb__after_unlock_lock();
89558 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89559 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89560 rdp = this_cpu_ptr(rsp->rda);
89561 if (rnp == rdp->mynode)
89562 __note_gp_changes(rsp, rnp, rdp);
89563 @@ -1560,7 +1560,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89564 rcu_nocb_gp_set(rnp, nocb);
89565
89566 /* Declare grace period done. */
89567 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
89568 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
89569 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
89570 rsp->fqs_state = RCU_GP_IDLE;
89571 rdp = this_cpu_ptr(rsp->rda);
89572 @@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89573 rsp->qlen += rdp->qlen;
89574 rdp->n_cbs_orphaned += rdp->qlen;
89575 rdp->qlen_lazy = 0;
89576 - ACCESS_ONCE(rdp->qlen) = 0;
89577 + ACCESS_ONCE_RW(rdp->qlen) = 0;
89578 }
89579
89580 /*
89581 @@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89582 }
89583 smp_mb(); /* List handling before counting for rcu_barrier(). */
89584 rdp->qlen_lazy -= count_lazy;
89585 - ACCESS_ONCE(rdp->qlen) -= count;
89586 + ACCESS_ONCE_RW(rdp->qlen) -= count;
89587 rdp->n_cbs_invoked += count;
89588
89589 /* Reinstate batch limit if we have worked down the excess. */
89590 @@ -2304,7 +2304,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89591 if (rnp_old != NULL)
89592 raw_spin_unlock(&rnp_old->fqslock);
89593 if (ret) {
89594 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
89595 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89596 return;
89597 }
89598 rnp_old = rnp;
89599 @@ -2316,7 +2316,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89600 smp_mb__after_unlock_lock();
89601 raw_spin_unlock(&rnp_old->fqslock);
89602 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
89603 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
89604 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89605 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
89606 return; /* Someone beat us to it. */
89607 }
89608 @@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89609 /*
89610 * Do RCU core processing for the current CPU.
89611 */
89612 -static void rcu_process_callbacks(struct softirq_action *unused)
89613 +static void rcu_process_callbacks(void)
89614 {
89615 struct rcu_state *rsp;
89616
89617 @@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89618 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89619 if (debug_rcu_head_queue(head)) {
89620 /* Probable double call_rcu(), so leak the callback. */
89621 - ACCESS_ONCE(head->func) = rcu_leak_callback;
89622 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89623 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89624 return;
89625 }
89626 @@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89627 local_irq_restore(flags);
89628 return;
89629 }
89630 - ACCESS_ONCE(rdp->qlen)++;
89631 + ACCESS_ONCE_RW(rdp->qlen)++;
89632 if (lazy)
89633 rdp->qlen_lazy++;
89634 else
89635 @@ -2759,11 +2759,11 @@ void synchronize_sched_expedited(void)
89636 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89637 * course be required on a 64-bit system.
89638 */
89639 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89640 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89641 (ulong)atomic_long_read(&rsp->expedited_done) +
89642 ULONG_MAX / 8)) {
89643 synchronize_sched();
89644 - atomic_long_inc(&rsp->expedited_wrap);
89645 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
89646 return;
89647 }
89648
89649 @@ -2771,7 +2771,7 @@ void synchronize_sched_expedited(void)
89650 * Take a ticket. Note that atomic_inc_return() implies a
89651 * full memory barrier.
89652 */
89653 - snap = atomic_long_inc_return(&rsp->expedited_start);
89654 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
89655 firstsnap = snap;
89656 get_online_cpus();
89657 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
89658 @@ -2784,14 +2784,14 @@ void synchronize_sched_expedited(void)
89659 synchronize_sched_expedited_cpu_stop,
89660 NULL) == -EAGAIN) {
89661 put_online_cpus();
89662 - atomic_long_inc(&rsp->expedited_tryfail);
89663 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
89664
89665 /* Check to see if someone else did our work for us. */
89666 s = atomic_long_read(&rsp->expedited_done);
89667 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89668 /* ensure test happens before caller kfree */
89669 smp_mb__before_atomic_inc(); /* ^^^ */
89670 - atomic_long_inc(&rsp->expedited_workdone1);
89671 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89672 return;
89673 }
89674
89675 @@ -2800,7 +2800,7 @@ void synchronize_sched_expedited(void)
89676 udelay(trycount * num_online_cpus());
89677 } else {
89678 wait_rcu_gp(call_rcu_sched);
89679 - atomic_long_inc(&rsp->expedited_normal);
89680 + atomic_long_inc_unchecked(&rsp->expedited_normal);
89681 return;
89682 }
89683
89684 @@ -2809,7 +2809,7 @@ void synchronize_sched_expedited(void)
89685 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89686 /* ensure test happens before caller kfree */
89687 smp_mb__before_atomic_inc(); /* ^^^ */
89688 - atomic_long_inc(&rsp->expedited_workdone2);
89689 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89690 return;
89691 }
89692
89693 @@ -2821,10 +2821,10 @@ void synchronize_sched_expedited(void)
89694 * period works for us.
89695 */
89696 get_online_cpus();
89697 - snap = atomic_long_read(&rsp->expedited_start);
89698 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
89699 smp_mb(); /* ensure read is before try_stop_cpus(). */
89700 }
89701 - atomic_long_inc(&rsp->expedited_stoppedcpus);
89702 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89703
89704 /*
89705 * Everyone up to our most recent fetch is covered by our grace
89706 @@ -2833,16 +2833,16 @@ void synchronize_sched_expedited(void)
89707 * than we did already did their update.
89708 */
89709 do {
89710 - atomic_long_inc(&rsp->expedited_done_tries);
89711 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89712 s = atomic_long_read(&rsp->expedited_done);
89713 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89714 /* ensure test happens before caller kfree */
89715 smp_mb__before_atomic_inc(); /* ^^^ */
89716 - atomic_long_inc(&rsp->expedited_done_lost);
89717 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89718 break;
89719 }
89720 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89721 - atomic_long_inc(&rsp->expedited_done_exit);
89722 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89723
89724 put_online_cpus();
89725 }
89726 @@ -3048,7 +3048,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89727 * ACCESS_ONCE() to prevent the compiler from speculating
89728 * the increment to precede the early-exit check.
89729 */
89730 - ACCESS_ONCE(rsp->n_barrier_done)++;
89731 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89732 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89733 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89734 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89735 @@ -3098,7 +3098,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89736
89737 /* Increment ->n_barrier_done to prevent duplicate work. */
89738 smp_mb(); /* Keep increment after above mechanism. */
89739 - ACCESS_ONCE(rsp->n_barrier_done)++;
89740 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89741 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89742 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89743 smp_mb(); /* Keep increment before caller's subsequent code. */
89744 @@ -3143,10 +3143,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89745 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89746 init_callback_list(rdp);
89747 rdp->qlen_lazy = 0;
89748 - ACCESS_ONCE(rdp->qlen) = 0;
89749 + ACCESS_ONCE_RW(rdp->qlen) = 0;
89750 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89751 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89752 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89753 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89754 rdp->cpu = cpu;
89755 rdp->rsp = rsp;
89756 rcu_boot_init_nocb_percpu_data(rdp);
89757 @@ -3180,8 +3180,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89758 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89759 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89760 rcu_sysidle_init_percpu_data(rdp->dynticks);
89761 - atomic_set(&rdp->dynticks->dynticks,
89762 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89763 + atomic_set_unchecked(&rdp->dynticks->dynticks,
89764 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89765 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89766
89767 /* Add CPU to rcu_node bitmasks. */
89768 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89769 index 75dc3c3..b95d624 100644
89770 --- a/kernel/rcu/tree.h
89771 +++ b/kernel/rcu/tree.h
89772 @@ -87,11 +87,11 @@ struct rcu_dynticks {
89773 long long dynticks_nesting; /* Track irq/process nesting level. */
89774 /* Process level is worth LLONG_MAX/2. */
89775 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89776 - atomic_t dynticks; /* Even value for idle, else odd. */
89777 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89778 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89779 long long dynticks_idle_nesting;
89780 /* irq/process nesting level from idle. */
89781 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
89782 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89783 /* "Idle" excludes userspace execution. */
89784 unsigned long dynticks_idle_jiffies;
89785 /* End of last non-NMI non-idle period. */
89786 @@ -431,17 +431,17 @@ struct rcu_state {
89787 /* _rcu_barrier(). */
89788 /* End of fields guarded by barrier_mutex. */
89789
89790 - atomic_long_t expedited_start; /* Starting ticket. */
89791 - atomic_long_t expedited_done; /* Done ticket. */
89792 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89793 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
89794 - atomic_long_t expedited_workdone1; /* # done by others #1. */
89795 - atomic_long_t expedited_workdone2; /* # done by others #2. */
89796 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
89797 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89798 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
89799 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89800 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89801 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89802 + atomic_long_t expedited_done; /* Done ticket. */
89803 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89804 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89805 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89806 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89807 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89808 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89809 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89810 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89811 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89812
89813 unsigned long jiffies_force_qs; /* Time at which to invoke */
89814 /* force_quiescent_state(). */
89815 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89816 index 962d1d5..c6c62d12d 100644
89817 --- a/kernel/rcu/tree_plugin.h
89818 +++ b/kernel/rcu/tree_plugin.h
89819 @@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89820 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89821 {
89822 return !rcu_preempted_readers_exp(rnp) &&
89823 - ACCESS_ONCE(rnp->expmask) == 0;
89824 + ACCESS_ONCE_RW(rnp->expmask) == 0;
89825 }
89826
89827 /*
89828 @@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89829
89830 /* Clean up and exit. */
89831 smp_mb(); /* ensure expedited GP seen before counter increment. */
89832 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89833 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89834 unlock_mb_ret:
89835 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89836 mb_ret:
89837 @@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89838 free_cpumask_var(cm);
89839 }
89840
89841 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89842 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89843 .store = &rcu_cpu_kthread_task,
89844 .thread_should_run = rcu_cpu_kthread_should_run,
89845 .thread_fn = rcu_cpu_kthread,
89846 @@ -1972,7 +1972,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89847 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89848 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89849 cpu, ticks_value, ticks_title,
89850 - atomic_read(&rdtp->dynticks) & 0xfff,
89851 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89852 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89853 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89854 fast_no_hz);
89855 @@ -2138,7 +2138,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89856
89857 /* Enqueue the callback on the nocb list and update counts. */
89858 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89859 - ACCESS_ONCE(*old_rhpp) = rhp;
89860 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
89861 atomic_long_add(rhcount, &rdp->nocb_q_count);
89862 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89863
89864 @@ -2311,12 +2311,12 @@ static int rcu_nocb_kthread(void *arg)
89865 * Extract queued callbacks, update counts, and wait
89866 * for a grace period to elapse.
89867 */
89868 - ACCESS_ONCE(rdp->nocb_head) = NULL;
89869 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89870 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89871 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89872 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89873 - ACCESS_ONCE(rdp->nocb_p_count) += c;
89874 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89875 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89876 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89877 rcu_nocb_wait_gp(rdp);
89878
89879 /* Each pass through the following loop invokes a callback. */
89880 @@ -2342,8 +2342,8 @@ static int rcu_nocb_kthread(void *arg)
89881 list = next;
89882 }
89883 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89884 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
89885 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89886 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89887 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89888 rdp->n_nocbs_invoked += c;
89889 }
89890 return 0;
89891 @@ -2360,7 +2360,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89892 {
89893 if (!rcu_nocb_need_deferred_wakeup(rdp))
89894 return;
89895 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89896 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89897 wake_up(&rdp->nocb_wq);
89898 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89899 }
89900 @@ -2386,7 +2386,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89901 t = kthread_run(rcu_nocb_kthread, rdp,
89902 "rcuo%c/%d", rsp->abbr, cpu);
89903 BUG_ON(IS_ERR(t));
89904 - ACCESS_ONCE(rdp->nocb_kthread) = t;
89905 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89906 }
89907 }
89908
89909 @@ -2522,11 +2522,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89910
89911 /* Record start of fully idle period. */
89912 j = jiffies;
89913 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89914 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89915 smp_mb__before_atomic_inc();
89916 - atomic_inc(&rdtp->dynticks_idle);
89917 + atomic_inc_unchecked(&rdtp->dynticks_idle);
89918 smp_mb__after_atomic_inc();
89919 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89920 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89921 }
89922
89923 /*
89924 @@ -2591,9 +2591,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89925
89926 /* Record end of idle period. */
89927 smp_mb__before_atomic_inc();
89928 - atomic_inc(&rdtp->dynticks_idle);
89929 + atomic_inc_unchecked(&rdtp->dynticks_idle);
89930 smp_mb__after_atomic_inc();
89931 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89932 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89933
89934 /*
89935 * If we are the timekeeping CPU, we are permitted to be non-idle
89936 @@ -2634,7 +2634,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89937 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89938
89939 /* Pick up current idle and NMI-nesting counter and check. */
89940 - cur = atomic_read(&rdtp->dynticks_idle);
89941 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89942 if (cur & 0x1) {
89943 *isidle = false; /* We are not idle! */
89944 return;
89945 @@ -2697,7 +2697,7 @@ static void rcu_sysidle(unsigned long j)
89946 case RCU_SYSIDLE_NOT:
89947
89948 /* First time all are idle, so note a short idle period. */
89949 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89950 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89951 break;
89952
89953 case RCU_SYSIDLE_SHORT:
89954 @@ -2734,7 +2734,7 @@ static void rcu_sysidle(unsigned long j)
89955 static void rcu_sysidle_cancel(void)
89956 {
89957 smp_mb();
89958 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89959 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89960 }
89961
89962 /*
89963 @@ -2782,7 +2782,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89964 smp_mb(); /* grace period precedes setting inuse. */
89965
89966 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89967 - ACCESS_ONCE(rshp->inuse) = 0;
89968 + ACCESS_ONCE_RW(rshp->inuse) = 0;
89969 }
89970
89971 /*
89972 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89973 index 5cdc62e..cc52e88 100644
89974 --- a/kernel/rcu/tree_trace.c
89975 +++ b/kernel/rcu/tree_trace.c
89976 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89977 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89978 rdp->passed_quiesce, rdp->qs_pending);
89979 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89980 - atomic_read(&rdp->dynticks->dynticks),
89981 + atomic_read_unchecked(&rdp->dynticks->dynticks),
89982 rdp->dynticks->dynticks_nesting,
89983 rdp->dynticks->dynticks_nmi_nesting,
89984 rdp->dynticks_fqs);
89985 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89986 struct rcu_state *rsp = (struct rcu_state *)m->private;
89987
89988 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",
89989 - atomic_long_read(&rsp->expedited_start),
89990 + atomic_long_read_unchecked(&rsp->expedited_start),
89991 atomic_long_read(&rsp->expedited_done),
89992 - atomic_long_read(&rsp->expedited_wrap),
89993 - atomic_long_read(&rsp->expedited_tryfail),
89994 - atomic_long_read(&rsp->expedited_workdone1),
89995 - atomic_long_read(&rsp->expedited_workdone2),
89996 - atomic_long_read(&rsp->expedited_normal),
89997 - atomic_long_read(&rsp->expedited_stoppedcpus),
89998 - atomic_long_read(&rsp->expedited_done_tries),
89999 - atomic_long_read(&rsp->expedited_done_lost),
90000 - atomic_long_read(&rsp->expedited_done_exit));
90001 + atomic_long_read_unchecked(&rsp->expedited_wrap),
90002 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
90003 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
90004 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
90005 + atomic_long_read_unchecked(&rsp->expedited_normal),
90006 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
90007 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
90008 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
90009 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
90010 return 0;
90011 }
90012
90013 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
90014 index 4c0a9b0..7e81362 100644
90015 --- a/kernel/rcu/update.c
90016 +++ b/kernel/rcu/update.c
90017 @@ -311,10 +311,10 @@ int rcu_jiffies_till_stall_check(void)
90018 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
90019 */
90020 if (till_stall_check < 3) {
90021 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
90022 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
90023 till_stall_check = 3;
90024 } else if (till_stall_check > 300) {
90025 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
90026 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
90027 till_stall_check = 300;
90028 }
90029 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
90030 diff --git a/kernel/resource.c b/kernel/resource.c
90031 index 8957d68..770cbe4 100644
90032 --- a/kernel/resource.c
90033 +++ b/kernel/resource.c
90034 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
90035
90036 static int __init ioresources_init(void)
90037 {
90038 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
90039 +#ifdef CONFIG_GRKERNSEC_PROC_USER
90040 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
90041 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
90042 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
90043 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
90044 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
90045 +#endif
90046 +#else
90047 proc_create("ioports", 0, NULL, &proc_ioports_operations);
90048 proc_create("iomem", 0, NULL, &proc_iomem_operations);
90049 +#endif
90050 return 0;
90051 }
90052 __initcall(ioresources_init);
90053 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
90054 index e73efba..c9bfbd4 100644
90055 --- a/kernel/sched/auto_group.c
90056 +++ b/kernel/sched/auto_group.c
90057 @@ -11,7 +11,7 @@
90058
90059 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
90060 static struct autogroup autogroup_default;
90061 -static atomic_t autogroup_seq_nr;
90062 +static atomic_unchecked_t autogroup_seq_nr;
90063
90064 void __init autogroup_init(struct task_struct *init_task)
90065 {
90066 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
90067
90068 kref_init(&ag->kref);
90069 init_rwsem(&ag->lock);
90070 - ag->id = atomic_inc_return(&autogroup_seq_nr);
90071 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
90072 ag->tg = tg;
90073 #ifdef CONFIG_RT_GROUP_SCHED
90074 /*
90075 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
90076 index a63f4dc..349bbb0 100644
90077 --- a/kernel/sched/completion.c
90078 +++ b/kernel/sched/completion.c
90079 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
90080 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
90081 * or number of jiffies left till timeout) if completed.
90082 */
90083 -long __sched
90084 +long __sched __intentional_overflow(-1)
90085 wait_for_completion_interruptible_timeout(struct completion *x,
90086 unsigned long timeout)
90087 {
90088 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
90089 *
90090 * Return: -ERESTARTSYS if interrupted, 0 if completed.
90091 */
90092 -int __sched wait_for_completion_killable(struct completion *x)
90093 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
90094 {
90095 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
90096 if (t == -ERESTARTSYS)
90097 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
90098 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
90099 * or number of jiffies left till timeout) if completed.
90100 */
90101 -long __sched
90102 +long __sched __intentional_overflow(-1)
90103 wait_for_completion_killable_timeout(struct completion *x,
90104 unsigned long timeout)
90105 {
90106 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
90107 index 084d17f..e416b9f 100644
90108 --- a/kernel/sched/core.c
90109 +++ b/kernel/sched/core.c
90110 @@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
90111 int sysctl_numa_balancing(struct ctl_table *table, int write,
90112 void __user *buffer, size_t *lenp, loff_t *ppos)
90113 {
90114 - struct ctl_table t;
90115 + ctl_table_no_const t;
90116 int err;
90117 int state = numabalancing_enabled;
90118
90119 @@ -2238,8 +2238,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
90120 next->active_mm = oldmm;
90121 atomic_inc(&oldmm->mm_count);
90122 enter_lazy_tlb(oldmm, next);
90123 - } else
90124 + } else {
90125 switch_mm(oldmm, mm, next);
90126 + populate_stack();
90127 + }
90128
90129 if (!prev->mm) {
90130 prev->active_mm = NULL;
90131 @@ -3004,6 +3006,8 @@ int can_nice(const struct task_struct *p, const int nice)
90132 /* convert nice value [19,-20] to rlimit style value [1,40] */
90133 int nice_rlim = 20 - nice;
90134
90135 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
90136 +
90137 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
90138 capable(CAP_SYS_NICE));
90139 }
90140 @@ -3037,7 +3041,8 @@ SYSCALL_DEFINE1(nice, int, increment)
90141 if (nice > MAX_NICE)
90142 nice = MAX_NICE;
90143
90144 - if (increment < 0 && !can_nice(current, nice))
90145 + if (increment < 0 && (!can_nice(current, nice) ||
90146 + gr_handle_chroot_nice()))
90147 return -EPERM;
90148
90149 retval = security_task_setnice(current, nice);
90150 @@ -3310,6 +3315,7 @@ recheck:
90151 if (policy != p->policy && !rlim_rtprio)
90152 return -EPERM;
90153
90154 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
90155 /* can't increase priority */
90156 if (attr->sched_priority > p->rt_priority &&
90157 attr->sched_priority > rlim_rtprio)
90158 @@ -4708,6 +4714,7 @@ void idle_task_exit(void)
90159
90160 if (mm != &init_mm) {
90161 switch_mm(mm, &init_mm, current);
90162 + populate_stack();
90163 finish_arch_post_lock_switch();
90164 }
90165 mmdrop(mm);
90166 @@ -4803,7 +4810,7 @@ static void migrate_tasks(unsigned int dead_cpu)
90167
90168 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
90169
90170 -static struct ctl_table sd_ctl_dir[] = {
90171 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
90172 {
90173 .procname = "sched_domain",
90174 .mode = 0555,
90175 @@ -4820,17 +4827,17 @@ static struct ctl_table sd_ctl_root[] = {
90176 {}
90177 };
90178
90179 -static struct ctl_table *sd_alloc_ctl_entry(int n)
90180 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
90181 {
90182 - struct ctl_table *entry =
90183 + ctl_table_no_const *entry =
90184 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
90185
90186 return entry;
90187 }
90188
90189 -static void sd_free_ctl_entry(struct ctl_table **tablep)
90190 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
90191 {
90192 - struct ctl_table *entry;
90193 + ctl_table_no_const *entry;
90194
90195 /*
90196 * In the intermediate directories, both the child directory and
90197 @@ -4838,22 +4845,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
90198 * will always be set. In the lowest directory the names are
90199 * static strings and all have proc handlers.
90200 */
90201 - for (entry = *tablep; entry->mode; entry++) {
90202 - if (entry->child)
90203 - sd_free_ctl_entry(&entry->child);
90204 + for (entry = tablep; entry->mode; entry++) {
90205 + if (entry->child) {
90206 + sd_free_ctl_entry(entry->child);
90207 + pax_open_kernel();
90208 + entry->child = NULL;
90209 + pax_close_kernel();
90210 + }
90211 if (entry->proc_handler == NULL)
90212 kfree(entry->procname);
90213 }
90214
90215 - kfree(*tablep);
90216 - *tablep = NULL;
90217 + kfree(tablep);
90218 }
90219
90220 static int min_load_idx = 0;
90221 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
90222
90223 static void
90224 -set_table_entry(struct ctl_table *entry,
90225 +set_table_entry(ctl_table_no_const *entry,
90226 const char *procname, void *data, int maxlen,
90227 umode_t mode, proc_handler *proc_handler,
90228 bool load_idx)
90229 @@ -4873,7 +4883,7 @@ set_table_entry(struct ctl_table *entry,
90230 static struct ctl_table *
90231 sd_alloc_ctl_domain_table(struct sched_domain *sd)
90232 {
90233 - struct ctl_table *table = sd_alloc_ctl_entry(14);
90234 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
90235
90236 if (table == NULL)
90237 return NULL;
90238 @@ -4911,9 +4921,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
90239 return table;
90240 }
90241
90242 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
90243 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
90244 {
90245 - struct ctl_table *entry, *table;
90246 + ctl_table_no_const *entry, *table;
90247 struct sched_domain *sd;
90248 int domain_num = 0, i;
90249 char buf[32];
90250 @@ -4940,11 +4950,13 @@ static struct ctl_table_header *sd_sysctl_header;
90251 static void register_sched_domain_sysctl(void)
90252 {
90253 int i, cpu_num = num_possible_cpus();
90254 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
90255 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
90256 char buf[32];
90257
90258 WARN_ON(sd_ctl_dir[0].child);
90259 + pax_open_kernel();
90260 sd_ctl_dir[0].child = entry;
90261 + pax_close_kernel();
90262
90263 if (entry == NULL)
90264 return;
90265 @@ -4967,8 +4979,12 @@ static void unregister_sched_domain_sysctl(void)
90266 if (sd_sysctl_header)
90267 unregister_sysctl_table(sd_sysctl_header);
90268 sd_sysctl_header = NULL;
90269 - if (sd_ctl_dir[0].child)
90270 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
90271 + if (sd_ctl_dir[0].child) {
90272 + sd_free_ctl_entry(sd_ctl_dir[0].child);
90273 + pax_open_kernel();
90274 + sd_ctl_dir[0].child = NULL;
90275 + pax_close_kernel();
90276 + }
90277 }
90278 #else
90279 static void register_sched_domain_sysctl(void)
90280 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
90281 index 8cbe2d2..61f20a1 100644
90282 --- a/kernel/sched/fair.c
90283 +++ b/kernel/sched/fair.c
90284 @@ -1806,7 +1806,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
90285
90286 static void reset_ptenuma_scan(struct task_struct *p)
90287 {
90288 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
90289 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
90290 p->mm->numa_scan_offset = 0;
90291 }
90292
90293 @@ -7181,7 +7181,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
90294 * run_rebalance_domains is triggered when needed from the scheduler tick.
90295 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
90296 */
90297 -static void run_rebalance_domains(struct softirq_action *h)
90298 +static __latent_entropy void run_rebalance_domains(void)
90299 {
90300 struct rq *this_rq = this_rq();
90301 enum cpu_idle_type idle = this_rq->idle_balance ?
90302 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
90303 index 369b4d6..fa4eb3b 100644
90304 --- a/kernel/sched/sched.h
90305 +++ b/kernel/sched/sched.h
90306 @@ -1157,7 +1157,7 @@ struct sched_class {
90307 #ifdef CONFIG_FAIR_GROUP_SCHED
90308 void (*task_move_group) (struct task_struct *p, int on_rq);
90309 #endif
90310 -};
90311 +} __do_const;
90312
90313 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
90314 {
90315 diff --git a/kernel/signal.c b/kernel/signal.c
90316 index 6ea13c0..31e3b25 100644
90317 --- a/kernel/signal.c
90318 +++ b/kernel/signal.c
90319 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
90320
90321 int print_fatal_signals __read_mostly;
90322
90323 -static void __user *sig_handler(struct task_struct *t, int sig)
90324 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
90325 {
90326 return t->sighand->action[sig - 1].sa.sa_handler;
90327 }
90328
90329 -static int sig_handler_ignored(void __user *handler, int sig)
90330 +static int sig_handler_ignored(__sighandler_t handler, int sig)
90331 {
90332 /* Is it explicitly or implicitly ignored? */
90333 return handler == SIG_IGN ||
90334 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
90335
90336 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
90337 {
90338 - void __user *handler;
90339 + __sighandler_t handler;
90340
90341 handler = sig_handler(t, sig);
90342
90343 @@ -371,6 +371,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
90344 atomic_inc(&user->sigpending);
90345 rcu_read_unlock();
90346
90347 + if (!override_rlimit)
90348 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
90349 +
90350 if (override_rlimit ||
90351 atomic_read(&user->sigpending) <=
90352 task_rlimit(t, RLIMIT_SIGPENDING)) {
90353 @@ -498,7 +501,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
90354
90355 int unhandled_signal(struct task_struct *tsk, int sig)
90356 {
90357 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
90358 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
90359 if (is_global_init(tsk))
90360 return 1;
90361 if (handler != SIG_IGN && handler != SIG_DFL)
90362 @@ -818,6 +821,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
90363 }
90364 }
90365
90366 + /* allow glibc communication via tgkill to other threads in our
90367 + thread group */
90368 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
90369 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
90370 + && gr_handle_signal(t, sig))
90371 + return -EPERM;
90372 +
90373 return security_task_kill(t, info, sig, 0);
90374 }
90375
90376 @@ -1201,7 +1211,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90377 return send_signal(sig, info, p, 1);
90378 }
90379
90380 -static int
90381 +int
90382 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90383 {
90384 return send_signal(sig, info, t, 0);
90385 @@ -1238,6 +1248,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90386 unsigned long int flags;
90387 int ret, blocked, ignored;
90388 struct k_sigaction *action;
90389 + int is_unhandled = 0;
90390
90391 spin_lock_irqsave(&t->sighand->siglock, flags);
90392 action = &t->sighand->action[sig-1];
90393 @@ -1252,9 +1263,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90394 }
90395 if (action->sa.sa_handler == SIG_DFL)
90396 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90397 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90398 + is_unhandled = 1;
90399 ret = specific_send_sig_info(sig, info, t);
90400 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90401
90402 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
90403 + normal operation */
90404 + if (is_unhandled) {
90405 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90406 + gr_handle_crash(t, sig);
90407 + }
90408 +
90409 return ret;
90410 }
90411
90412 @@ -1321,8 +1341,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90413 ret = check_kill_permission(sig, info, p);
90414 rcu_read_unlock();
90415
90416 - if (!ret && sig)
90417 + if (!ret && sig) {
90418 ret = do_send_sig_info(sig, info, p, true);
90419 + if (!ret)
90420 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90421 + }
90422
90423 return ret;
90424 }
90425 @@ -2928,7 +2951,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90426 int error = -ESRCH;
90427
90428 rcu_read_lock();
90429 - p = find_task_by_vpid(pid);
90430 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90431 + /* allow glibc communication via tgkill to other threads in our
90432 + thread group */
90433 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90434 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
90435 + p = find_task_by_vpid_unrestricted(pid);
90436 + else
90437 +#endif
90438 + p = find_task_by_vpid(pid);
90439 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90440 error = check_kill_permission(sig, info, p);
90441 /*
90442 @@ -3241,8 +3272,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90443 }
90444 seg = get_fs();
90445 set_fs(KERNEL_DS);
90446 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90447 - (stack_t __force __user *) &uoss,
90448 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90449 + (stack_t __force_user *) &uoss,
90450 compat_user_stack_pointer());
90451 set_fs(seg);
90452 if (ret >= 0 && uoss_ptr) {
90453 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90454 index eb89e18..a4e6792 100644
90455 --- a/kernel/smpboot.c
90456 +++ b/kernel/smpboot.c
90457 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90458 }
90459 smpboot_unpark_thread(plug_thread, cpu);
90460 }
90461 - list_add(&plug_thread->list, &hotplug_threads);
90462 + pax_list_add(&plug_thread->list, &hotplug_threads);
90463 out:
90464 mutex_unlock(&smpboot_threads_lock);
90465 return ret;
90466 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90467 {
90468 get_online_cpus();
90469 mutex_lock(&smpboot_threads_lock);
90470 - list_del(&plug_thread->list);
90471 + pax_list_del(&plug_thread->list);
90472 smpboot_destroy_threads(plug_thread);
90473 mutex_unlock(&smpboot_threads_lock);
90474 put_online_cpus();
90475 diff --git a/kernel/softirq.c b/kernel/softirq.c
90476 index 92f24f5..db41501 100644
90477 --- a/kernel/softirq.c
90478 +++ b/kernel/softirq.c
90479 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90480 EXPORT_SYMBOL(irq_stat);
90481 #endif
90482
90483 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90484 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90485
90486 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90487
90488 @@ -268,7 +268,7 @@ restart:
90489 kstat_incr_softirqs_this_cpu(vec_nr);
90490
90491 trace_softirq_entry(vec_nr);
90492 - h->action(h);
90493 + h->action();
90494 trace_softirq_exit(vec_nr);
90495 if (unlikely(prev_count != preempt_count())) {
90496 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90497 @@ -428,7 +428,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90498 or_softirq_pending(1UL << nr);
90499 }
90500
90501 -void open_softirq(int nr, void (*action)(struct softirq_action *))
90502 +void __init open_softirq(int nr, void (*action)(void))
90503 {
90504 softirq_vec[nr].action = action;
90505 }
90506 @@ -480,7 +480,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90507 }
90508 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90509
90510 -static void tasklet_action(struct softirq_action *a)
90511 +static void tasklet_action(void)
90512 {
90513 struct tasklet_struct *list;
90514
90515 @@ -516,7 +516,7 @@ static void tasklet_action(struct softirq_action *a)
90516 }
90517 }
90518
90519 -static void tasklet_hi_action(struct softirq_action *a)
90520 +static __latent_entropy void tasklet_hi_action(void)
90521 {
90522 struct tasklet_struct *list;
90523
90524 @@ -743,7 +743,7 @@ static struct notifier_block cpu_nfb = {
90525 .notifier_call = cpu_callback
90526 };
90527
90528 -static struct smp_hotplug_thread softirq_threads = {
90529 +static struct smp_hotplug_thread softirq_threads __read_only = {
90530 .store = &ksoftirqd,
90531 .thread_should_run = ksoftirqd_should_run,
90532 .thread_fn = run_ksoftirqd,
90533 diff --git a/kernel/sys.c b/kernel/sys.c
90534 index fba0f29..84400e2 100644
90535 --- a/kernel/sys.c
90536 +++ b/kernel/sys.c
90537 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90538 error = -EACCES;
90539 goto out;
90540 }
90541 +
90542 + if (gr_handle_chroot_setpriority(p, niceval)) {
90543 + error = -EACCES;
90544 + goto out;
90545 + }
90546 +
90547 no_nice = security_task_setnice(p, niceval);
90548 if (no_nice) {
90549 error = no_nice;
90550 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90551 goto error;
90552 }
90553
90554 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90555 + goto error;
90556 +
90557 if (rgid != (gid_t) -1 ||
90558 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90559 new->sgid = new->egid;
90560 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90561 old = current_cred();
90562
90563 retval = -EPERM;
90564 +
90565 + if (gr_check_group_change(kgid, kgid, kgid))
90566 + goto error;
90567 +
90568 if (ns_capable(old->user_ns, CAP_SETGID))
90569 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90570 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90571 @@ -403,7 +416,7 @@ error:
90572 /*
90573 * change the user struct in a credentials set to match the new UID
90574 */
90575 -static int set_user(struct cred *new)
90576 +int set_user(struct cred *new)
90577 {
90578 struct user_struct *new_user;
90579
90580 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90581 goto error;
90582 }
90583
90584 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90585 + goto error;
90586 +
90587 if (!uid_eq(new->uid, old->uid)) {
90588 retval = set_user(new);
90589 if (retval < 0)
90590 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90591 old = current_cred();
90592
90593 retval = -EPERM;
90594 +
90595 + if (gr_check_crash_uid(kuid))
90596 + goto error;
90597 + if (gr_check_user_change(kuid, kuid, kuid))
90598 + goto error;
90599 +
90600 if (ns_capable(old->user_ns, CAP_SETUID)) {
90601 new->suid = new->uid = kuid;
90602 if (!uid_eq(kuid, old->uid)) {
90603 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90604 goto error;
90605 }
90606
90607 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
90608 + goto error;
90609 +
90610 if (ruid != (uid_t) -1) {
90611 new->uid = kruid;
90612 if (!uid_eq(kruid, old->uid)) {
90613 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90614 goto error;
90615 }
90616
90617 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
90618 + goto error;
90619 +
90620 if (rgid != (gid_t) -1)
90621 new->gid = krgid;
90622 if (egid != (gid_t) -1)
90623 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90624 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90625 ns_capable(old->user_ns, CAP_SETUID)) {
90626 if (!uid_eq(kuid, old->fsuid)) {
90627 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90628 + goto error;
90629 +
90630 new->fsuid = kuid;
90631 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90632 goto change_okay;
90633 }
90634 }
90635
90636 +error:
90637 abort_creds(new);
90638 return old_fsuid;
90639
90640 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90641 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90642 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
90643 ns_capable(old->user_ns, CAP_SETGID)) {
90644 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
90645 + goto error;
90646 +
90647 if (!gid_eq(kgid, old->fsgid)) {
90648 new->fsgid = kgid;
90649 goto change_okay;
90650 }
90651 }
90652
90653 +error:
90654 abort_creds(new);
90655 return old_fsgid;
90656
90657 @@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
90658 return -EFAULT;
90659
90660 down_read(&uts_sem);
90661 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
90662 + error = __copy_to_user(name->sysname, &utsname()->sysname,
90663 __OLD_UTS_LEN);
90664 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
90665 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
90666 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
90667 __OLD_UTS_LEN);
90668 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
90669 - error |= __copy_to_user(&name->release, &utsname()->release,
90670 + error |= __copy_to_user(name->release, &utsname()->release,
90671 __OLD_UTS_LEN);
90672 error |= __put_user(0, name->release + __OLD_UTS_LEN);
90673 - error |= __copy_to_user(&name->version, &utsname()->version,
90674 + error |= __copy_to_user(name->version, &utsname()->version,
90675 __OLD_UTS_LEN);
90676 error |= __put_user(0, name->version + __OLD_UTS_LEN);
90677 - error |= __copy_to_user(&name->machine, &utsname()->machine,
90678 + error |= __copy_to_user(name->machine, &utsname()->machine,
90679 __OLD_UTS_LEN);
90680 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
90681 up_read(&uts_sem);
90682 @@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
90683 */
90684 new_rlim->rlim_cur = 1;
90685 }
90686 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
90687 + is changed to a lower value. Since tasks can be created by the same
90688 + user in between this limit change and an execve by this task, force
90689 + a recheck only for this task by setting PF_NPROC_EXCEEDED
90690 + */
90691 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90692 + tsk->flags |= PF_NPROC_EXCEEDED;
90693 }
90694 if (!retval) {
90695 if (old_rlim)
90696 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90697 index 0e0373f..69f5181 100644
90698 --- a/kernel/sysctl.c
90699 +++ b/kernel/sysctl.c
90700 @@ -94,7 +94,6 @@
90701
90702
90703 #if defined(CONFIG_SYSCTL)
90704 -
90705 /* External variables not in a header file. */
90706 extern int max_threads;
90707 extern int suid_dumpable;
90708 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
90709
90710 /* Constants used for minimum and maximum */
90711 #ifdef CONFIG_LOCKUP_DETECTOR
90712 -static int sixty = 60;
90713 +static int sixty __read_only = 60;
90714 #endif
90715
90716 -static int __maybe_unused neg_one = -1;
90717 +static int __maybe_unused neg_one __read_only = -1;
90718
90719 -static int zero;
90720 -static int __maybe_unused one = 1;
90721 -static int __maybe_unused two = 2;
90722 -static int __maybe_unused four = 4;
90723 -static unsigned long one_ul = 1;
90724 -static int one_hundred = 100;
90725 +static int zero __read_only = 0;
90726 +static int __maybe_unused one __read_only = 1;
90727 +static int __maybe_unused two __read_only = 2;
90728 +static int __maybe_unused three __read_only = 3;
90729 +static int __maybe_unused four __read_only = 4;
90730 +static unsigned long one_ul __read_only = 1;
90731 +static int one_hundred __read_only = 100;
90732 #ifdef CONFIG_PRINTK
90733 -static int ten_thousand = 10000;
90734 +static int ten_thousand __read_only = 10000;
90735 #endif
90736
90737 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90738 @@ -178,10 +178,8 @@ static int proc_taint(struct ctl_table *table, int write,
90739 void __user *buffer, size_t *lenp, loff_t *ppos);
90740 #endif
90741
90742 -#ifdef CONFIG_PRINTK
90743 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90744 void __user *buffer, size_t *lenp, loff_t *ppos);
90745 -#endif
90746
90747 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90748 void __user *buffer, size_t *lenp, loff_t *ppos);
90749 @@ -212,6 +210,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90750
90751 #endif
90752
90753 +extern struct ctl_table grsecurity_table[];
90754 +
90755 static struct ctl_table kern_table[];
90756 static struct ctl_table vm_table[];
90757 static struct ctl_table fs_table[];
90758 @@ -226,6 +226,20 @@ extern struct ctl_table epoll_table[];
90759 int sysctl_legacy_va_layout;
90760 #endif
90761
90762 +#ifdef CONFIG_PAX_SOFTMODE
90763 +static ctl_table pax_table[] = {
90764 + {
90765 + .procname = "softmode",
90766 + .data = &pax_softmode,
90767 + .maxlen = sizeof(unsigned int),
90768 + .mode = 0600,
90769 + .proc_handler = &proc_dointvec,
90770 + },
90771 +
90772 + { }
90773 +};
90774 +#endif
90775 +
90776 /* The default sysctl tables: */
90777
90778 static struct ctl_table sysctl_base_table[] = {
90779 @@ -274,6 +288,22 @@ static int max_extfrag_threshold = 1000;
90780 #endif
90781
90782 static struct ctl_table kern_table[] = {
90783 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90784 + {
90785 + .procname = "grsecurity",
90786 + .mode = 0500,
90787 + .child = grsecurity_table,
90788 + },
90789 +#endif
90790 +
90791 +#ifdef CONFIG_PAX_SOFTMODE
90792 + {
90793 + .procname = "pax",
90794 + .mode = 0500,
90795 + .child = pax_table,
90796 + },
90797 +#endif
90798 +
90799 {
90800 .procname = "sched_child_runs_first",
90801 .data = &sysctl_sched_child_runs_first,
90802 @@ -629,7 +659,7 @@ static struct ctl_table kern_table[] = {
90803 .data = &modprobe_path,
90804 .maxlen = KMOD_PATH_LEN,
90805 .mode = 0644,
90806 - .proc_handler = proc_dostring,
90807 + .proc_handler = proc_dostring_modpriv,
90808 },
90809 {
90810 .procname = "modules_disabled",
90811 @@ -796,16 +826,20 @@ static struct ctl_table kern_table[] = {
90812 .extra1 = &zero,
90813 .extra2 = &one,
90814 },
90815 +#endif
90816 {
90817 .procname = "kptr_restrict",
90818 .data = &kptr_restrict,
90819 .maxlen = sizeof(int),
90820 .mode = 0644,
90821 .proc_handler = proc_dointvec_minmax_sysadmin,
90822 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90823 + .extra1 = &two,
90824 +#else
90825 .extra1 = &zero,
90826 +#endif
90827 .extra2 = &two,
90828 },
90829 -#endif
90830 {
90831 .procname = "ngroups_max",
90832 .data = &ngroups_max,
90833 @@ -1050,10 +1084,17 @@ static struct ctl_table kern_table[] = {
90834 */
90835 {
90836 .procname = "perf_event_paranoid",
90837 - .data = &sysctl_perf_event_paranoid,
90838 - .maxlen = sizeof(sysctl_perf_event_paranoid),
90839 + .data = &sysctl_perf_event_legitimately_concerned,
90840 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90841 .mode = 0644,
90842 - .proc_handler = proc_dointvec,
90843 + /* go ahead, be a hero */
90844 + .proc_handler = proc_dointvec_minmax_sysadmin,
90845 + .extra1 = &neg_one,
90846 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90847 + .extra2 = &three,
90848 +#else
90849 + .extra2 = &two,
90850 +#endif
90851 },
90852 {
90853 .procname = "perf_event_mlock_kb",
90854 @@ -1315,6 +1356,13 @@ static struct ctl_table vm_table[] = {
90855 .proc_handler = proc_dointvec_minmax,
90856 .extra1 = &zero,
90857 },
90858 + {
90859 + .procname = "heap_stack_gap",
90860 + .data = &sysctl_heap_stack_gap,
90861 + .maxlen = sizeof(sysctl_heap_stack_gap),
90862 + .mode = 0644,
90863 + .proc_handler = proc_doulongvec_minmax,
90864 + },
90865 #else
90866 {
90867 .procname = "nr_trim_pages",
90868 @@ -1779,6 +1827,16 @@ int proc_dostring(struct ctl_table *table, int write,
90869 buffer, lenp, ppos);
90870 }
90871
90872 +int proc_dostring_modpriv(struct ctl_table *table, int write,
90873 + void __user *buffer, size_t *lenp, loff_t *ppos)
90874 +{
90875 + if (write && !capable(CAP_SYS_MODULE))
90876 + return -EPERM;
90877 +
90878 + return _proc_do_string(table->data, table->maxlen, write,
90879 + buffer, lenp, ppos);
90880 +}
90881 +
90882 static size_t proc_skip_spaces(char **buf)
90883 {
90884 size_t ret;
90885 @@ -1884,6 +1942,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90886 len = strlen(tmp);
90887 if (len > *size)
90888 len = *size;
90889 + if (len > sizeof(tmp))
90890 + len = sizeof(tmp);
90891 if (copy_to_user(*buf, tmp, len))
90892 return -EFAULT;
90893 *size -= len;
90894 @@ -2048,7 +2108,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90895 static int proc_taint(struct ctl_table *table, int write,
90896 void __user *buffer, size_t *lenp, loff_t *ppos)
90897 {
90898 - struct ctl_table t;
90899 + ctl_table_no_const t;
90900 unsigned long tmptaint = get_taint();
90901 int err;
90902
90903 @@ -2076,7 +2136,6 @@ static int proc_taint(struct ctl_table *table, int write,
90904 return err;
90905 }
90906
90907 -#ifdef CONFIG_PRINTK
90908 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90909 void __user *buffer, size_t *lenp, loff_t *ppos)
90910 {
90911 @@ -2085,7 +2144,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90912
90913 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90914 }
90915 -#endif
90916
90917 struct do_proc_dointvec_minmax_conv_param {
90918 int *min;
90919 @@ -2632,6 +2690,12 @@ int proc_dostring(struct ctl_table *table, int write,
90920 return -ENOSYS;
90921 }
90922
90923 +int proc_dostring_modpriv(struct ctl_table *table, int write,
90924 + void __user *buffer, size_t *lenp, loff_t *ppos)
90925 +{
90926 + return -ENOSYS;
90927 +}
90928 +
90929 int proc_dointvec(struct ctl_table *table, int write,
90930 void __user *buffer, size_t *lenp, loff_t *ppos)
90931 {
90932 @@ -2688,5 +2752,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90933 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90934 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90935 EXPORT_SYMBOL(proc_dostring);
90936 +EXPORT_SYMBOL(proc_dostring_modpriv);
90937 EXPORT_SYMBOL(proc_doulongvec_minmax);
90938 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90939 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90940 index 13d2f7c..c93d0b0 100644
90941 --- a/kernel/taskstats.c
90942 +++ b/kernel/taskstats.c
90943 @@ -28,9 +28,12 @@
90944 #include <linux/fs.h>
90945 #include <linux/file.h>
90946 #include <linux/pid_namespace.h>
90947 +#include <linux/grsecurity.h>
90948 #include <net/genetlink.h>
90949 #include <linux/atomic.h>
90950
90951 +extern int gr_is_taskstats_denied(int pid);
90952 +
90953 /*
90954 * Maximum length of a cpumask that can be specified in
90955 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90956 @@ -576,6 +579,9 @@ err:
90957
90958 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90959 {
90960 + if (gr_is_taskstats_denied(current->pid))
90961 + return -EACCES;
90962 +
90963 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90964 return cmd_attr_register_cpumask(info);
90965 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90966 diff --git a/kernel/time.c b/kernel/time.c
90967 index 7c7964c..2a0d412 100644
90968 --- a/kernel/time.c
90969 +++ b/kernel/time.c
90970 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90971 return error;
90972
90973 if (tz) {
90974 + /* we log in do_settimeofday called below, so don't log twice
90975 + */
90976 + if (!tv)
90977 + gr_log_timechange();
90978 +
90979 sys_tz = *tz;
90980 update_vsyscall_tz();
90981 if (firsttime) {
90982 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90983 index 88c9c65..7497ebc 100644
90984 --- a/kernel/time/alarmtimer.c
90985 +++ b/kernel/time/alarmtimer.c
90986 @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90987 struct platform_device *pdev;
90988 int error = 0;
90989 int i;
90990 - struct k_clock alarm_clock = {
90991 + static struct k_clock alarm_clock = {
90992 .clock_getres = alarm_clock_getres,
90993 .clock_get = alarm_clock_get,
90994 .timer_create = alarm_timer_create,
90995 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90996 index f7df8ea..0810193 100644
90997 --- a/kernel/time/timekeeping.c
90998 +++ b/kernel/time/timekeeping.c
90999 @@ -15,6 +15,7 @@
91000 #include <linux/init.h>
91001 #include <linux/mm.h>
91002 #include <linux/sched.h>
91003 +#include <linux/grsecurity.h>
91004 #include <linux/syscore_ops.h>
91005 #include <linux/clocksource.h>
91006 #include <linux/jiffies.h>
91007 @@ -502,6 +503,8 @@ int do_settimeofday(const struct timespec *tv)
91008 if (!timespec_valid_strict(tv))
91009 return -EINVAL;
91010
91011 + gr_log_timechange();
91012 +
91013 raw_spin_lock_irqsave(&timekeeper_lock, flags);
91014 write_seqcount_begin(&timekeeper_seq);
91015
91016 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
91017 index 61ed862..3b52c65 100644
91018 --- a/kernel/time/timer_list.c
91019 +++ b/kernel/time/timer_list.c
91020 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
91021
91022 static void print_name_offset(struct seq_file *m, void *sym)
91023 {
91024 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91025 + SEQ_printf(m, "<%p>", NULL);
91026 +#else
91027 char symname[KSYM_NAME_LEN];
91028
91029 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
91030 SEQ_printf(m, "<%pK>", sym);
91031 else
91032 SEQ_printf(m, "%s", symname);
91033 +#endif
91034 }
91035
91036 static void
91037 @@ -119,7 +123,11 @@ next_one:
91038 static void
91039 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
91040 {
91041 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91042 + SEQ_printf(m, " .base: %p\n", NULL);
91043 +#else
91044 SEQ_printf(m, " .base: %pK\n", base);
91045 +#endif
91046 SEQ_printf(m, " .index: %d\n",
91047 base->index);
91048 SEQ_printf(m, " .resolution: %Lu nsecs\n",
91049 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
91050 {
91051 struct proc_dir_entry *pe;
91052
91053 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
91054 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
91055 +#else
91056 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
91057 +#endif
91058 if (!pe)
91059 return -ENOMEM;
91060 return 0;
91061 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
91062 index 1fb08f2..ca4bb1e 100644
91063 --- a/kernel/time/timer_stats.c
91064 +++ b/kernel/time/timer_stats.c
91065 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
91066 static unsigned long nr_entries;
91067 static struct entry entries[MAX_ENTRIES];
91068
91069 -static atomic_t overflow_count;
91070 +static atomic_unchecked_t overflow_count;
91071
91072 /*
91073 * The entries are in a hash-table, for fast lookup:
91074 @@ -140,7 +140,7 @@ static void reset_entries(void)
91075 nr_entries = 0;
91076 memset(entries, 0, sizeof(entries));
91077 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
91078 - atomic_set(&overflow_count, 0);
91079 + atomic_set_unchecked(&overflow_count, 0);
91080 }
91081
91082 static struct entry *alloc_entry(void)
91083 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
91084 if (likely(entry))
91085 entry->count++;
91086 else
91087 - atomic_inc(&overflow_count);
91088 + atomic_inc_unchecked(&overflow_count);
91089
91090 out_unlock:
91091 raw_spin_unlock_irqrestore(lock, flags);
91092 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
91093
91094 static void print_name_offset(struct seq_file *m, unsigned long addr)
91095 {
91096 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91097 + seq_printf(m, "<%p>", NULL);
91098 +#else
91099 char symname[KSYM_NAME_LEN];
91100
91101 if (lookup_symbol_name(addr, symname) < 0)
91102 - seq_printf(m, "<%p>", (void *)addr);
91103 + seq_printf(m, "<%pK>", (void *)addr);
91104 else
91105 seq_printf(m, "%s", symname);
91106 +#endif
91107 }
91108
91109 static int tstats_show(struct seq_file *m, void *v)
91110 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
91111
91112 seq_puts(m, "Timer Stats Version: v0.3\n");
91113 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
91114 - if (atomic_read(&overflow_count))
91115 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
91116 + if (atomic_read_unchecked(&overflow_count))
91117 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
91118 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
91119
91120 for (i = 0; i < nr_entries; i++) {
91121 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
91122 {
91123 struct proc_dir_entry *pe;
91124
91125 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
91126 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
91127 +#else
91128 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
91129 +#endif
91130 if (!pe)
91131 return -ENOMEM;
91132 return 0;
91133 diff --git a/kernel/timer.c b/kernel/timer.c
91134 index 3bb01a3..0e7760e 100644
91135 --- a/kernel/timer.c
91136 +++ b/kernel/timer.c
91137 @@ -1393,7 +1393,7 @@ void update_process_times(int user_tick)
91138 /*
91139 * This function runs timers and the timer-tq in bottom half context.
91140 */
91141 -static void run_timer_softirq(struct softirq_action *h)
91142 +static __latent_entropy void run_timer_softirq(void)
91143 {
91144 struct tvec_base *base = __this_cpu_read(tvec_bases);
91145
91146 @@ -1456,7 +1456,7 @@ static void process_timeout(unsigned long __data)
91147 *
91148 * In all cases the return value is guaranteed to be non-negative.
91149 */
91150 -signed long __sched schedule_timeout(signed long timeout)
91151 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
91152 {
91153 struct timer_list timer;
91154 unsigned long expire;
91155 diff --git a/kernel/torture.c b/kernel/torture.c
91156 index acc9afc..4f9eb49 100644
91157 --- a/kernel/torture.c
91158 +++ b/kernel/torture.c
91159 @@ -489,7 +489,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
91160 mutex_lock(&fullstop_mutex);
91161 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
91162 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
91163 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
91164 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
91165 } else {
91166 pr_warn("Concurrent rmmod and shutdown illegal!\n");
91167 }
91168 @@ -551,11 +551,11 @@ static int torture_stutter(void *arg)
91169 do {
91170 if (!torture_must_stop()) {
91171 schedule_timeout_interruptible(stutter);
91172 - ACCESS_ONCE(stutter_pause_test) = 1;
91173 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
91174 }
91175 if (!torture_must_stop())
91176 schedule_timeout_interruptible(stutter);
91177 - ACCESS_ONCE(stutter_pause_test) = 0;
91178 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
91179 torture_shutdown_absorb("torture_stutter");
91180 } while (!torture_must_stop());
91181 torture_kthread_stopping("torture_stutter");
91182 @@ -636,7 +636,7 @@ bool torture_cleanup(void)
91183 schedule_timeout_uninterruptible(10);
91184 return true;
91185 }
91186 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
91187 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
91188 mutex_unlock(&fullstop_mutex);
91189 torture_shutdown_cleanup();
91190 torture_shuffle_cleanup();
91191 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
91192 index c1bd4ad..4b861dc 100644
91193 --- a/kernel/trace/blktrace.c
91194 +++ b/kernel/trace/blktrace.c
91195 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
91196 struct blk_trace *bt = filp->private_data;
91197 char buf[16];
91198
91199 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
91200 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
91201
91202 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
91203 }
91204 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
91205 return 1;
91206
91207 bt = buf->chan->private_data;
91208 - atomic_inc(&bt->dropped);
91209 + atomic_inc_unchecked(&bt->dropped);
91210 return 0;
91211 }
91212
91213 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
91214
91215 bt->dir = dir;
91216 bt->dev = dev;
91217 - atomic_set(&bt->dropped, 0);
91218 + atomic_set_unchecked(&bt->dropped, 0);
91219 INIT_LIST_HEAD(&bt->running_list);
91220
91221 ret = -EIO;
91222 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
91223 index 4a54a25..7ca9c89 100644
91224 --- a/kernel/trace/ftrace.c
91225 +++ b/kernel/trace/ftrace.c
91226 @@ -1960,12 +1960,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
91227 if (unlikely(ftrace_disabled))
91228 return 0;
91229
91230 + ret = ftrace_arch_code_modify_prepare();
91231 + FTRACE_WARN_ON(ret);
91232 + if (ret)
91233 + return 0;
91234 +
91235 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
91236 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
91237 if (ret) {
91238 ftrace_bug(ret, ip);
91239 - return 0;
91240 }
91241 - return 1;
91242 + return ret ? 0 : 1;
91243 }
91244
91245 /*
91246 @@ -4195,8 +4200,10 @@ static int ftrace_process_locs(struct module *mod,
91247 if (!count)
91248 return 0;
91249
91250 + pax_open_kernel();
91251 sort(start, count, sizeof(*start),
91252 ftrace_cmp_ips, ftrace_swap_ips);
91253 + pax_close_kernel();
91254
91255 start_pg = ftrace_allocate_pages(count);
91256 if (!start_pg)
91257 @@ -4908,8 +4915,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
91258 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
91259
91260 static int ftrace_graph_active;
91261 -static struct notifier_block ftrace_suspend_notifier;
91262 -
91263 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
91264 {
91265 return 0;
91266 @@ -5085,6 +5090,10 @@ static void update_function_graph_func(void)
91267 ftrace_graph_entry = ftrace_graph_entry_test;
91268 }
91269
91270 +static struct notifier_block ftrace_suspend_notifier = {
91271 + .notifier_call = ftrace_suspend_notifier_call
91272 +};
91273 +
91274 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91275 trace_func_graph_ent_t entryfunc)
91276 {
91277 @@ -5098,7 +5107,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91278 goto out;
91279 }
91280
91281 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
91282 register_pm_notifier(&ftrace_suspend_notifier);
91283
91284 ftrace_graph_active++;
91285 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
91286 index 7c56c3d..9980576 100644
91287 --- a/kernel/trace/ring_buffer.c
91288 +++ b/kernel/trace/ring_buffer.c
91289 @@ -352,9 +352,9 @@ struct buffer_data_page {
91290 */
91291 struct buffer_page {
91292 struct list_head list; /* list of buffer pages */
91293 - local_t write; /* index for next write */
91294 + local_unchecked_t write; /* index for next write */
91295 unsigned read; /* index for next read */
91296 - local_t entries; /* entries on this page */
91297 + local_unchecked_t entries; /* entries on this page */
91298 unsigned long real_end; /* real end of data */
91299 struct buffer_data_page *page; /* Actual data page */
91300 };
91301 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
91302 unsigned long last_overrun;
91303 local_t entries_bytes;
91304 local_t entries;
91305 - local_t overrun;
91306 - local_t commit_overrun;
91307 + local_unchecked_t overrun;
91308 + local_unchecked_t commit_overrun;
91309 local_t dropped_events;
91310 local_t committing;
91311 local_t commits;
91312 @@ -995,8 +995,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91313 *
91314 * We add a counter to the write field to denote this.
91315 */
91316 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
91317 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
91318 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
91319 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
91320
91321 /*
91322 * Just make sure we have seen our old_write and synchronize
91323 @@ -1024,8 +1024,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91324 * cmpxchg to only update if an interrupt did not already
91325 * do it for us. If the cmpxchg fails, we don't care.
91326 */
91327 - (void)local_cmpxchg(&next_page->write, old_write, val);
91328 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
91329 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
91330 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
91331
91332 /*
91333 * No need to worry about races with clearing out the commit.
91334 @@ -1392,12 +1392,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
91335
91336 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
91337 {
91338 - return local_read(&bpage->entries) & RB_WRITE_MASK;
91339 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
91340 }
91341
91342 static inline unsigned long rb_page_write(struct buffer_page *bpage)
91343 {
91344 - return local_read(&bpage->write) & RB_WRITE_MASK;
91345 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
91346 }
91347
91348 static int
91349 @@ -1492,7 +1492,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
91350 * bytes consumed in ring buffer from here.
91351 * Increment overrun to account for the lost events.
91352 */
91353 - local_add(page_entries, &cpu_buffer->overrun);
91354 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
91355 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91356 }
91357
91358 @@ -2070,7 +2070,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
91359 * it is our responsibility to update
91360 * the counters.
91361 */
91362 - local_add(entries, &cpu_buffer->overrun);
91363 + local_add_unchecked(entries, &cpu_buffer->overrun);
91364 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91365
91366 /*
91367 @@ -2220,7 +2220,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91368 if (tail == BUF_PAGE_SIZE)
91369 tail_page->real_end = 0;
91370
91371 - local_sub(length, &tail_page->write);
91372 + local_sub_unchecked(length, &tail_page->write);
91373 return;
91374 }
91375
91376 @@ -2255,7 +2255,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91377 rb_event_set_padding(event);
91378
91379 /* Set the write back to the previous setting */
91380 - local_sub(length, &tail_page->write);
91381 + local_sub_unchecked(length, &tail_page->write);
91382 return;
91383 }
91384
91385 @@ -2267,7 +2267,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91386
91387 /* Set write to end of buffer */
91388 length = (tail + length) - BUF_PAGE_SIZE;
91389 - local_sub(length, &tail_page->write);
91390 + local_sub_unchecked(length, &tail_page->write);
91391 }
91392
91393 /*
91394 @@ -2293,7 +2293,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91395 * about it.
91396 */
91397 if (unlikely(next_page == commit_page)) {
91398 - local_inc(&cpu_buffer->commit_overrun);
91399 + local_inc_unchecked(&cpu_buffer->commit_overrun);
91400 goto out_reset;
91401 }
91402
91403 @@ -2349,7 +2349,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91404 cpu_buffer->tail_page) &&
91405 (cpu_buffer->commit_page ==
91406 cpu_buffer->reader_page))) {
91407 - local_inc(&cpu_buffer->commit_overrun);
91408 + local_inc_unchecked(&cpu_buffer->commit_overrun);
91409 goto out_reset;
91410 }
91411 }
91412 @@ -2397,7 +2397,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91413 length += RB_LEN_TIME_EXTEND;
91414
91415 tail_page = cpu_buffer->tail_page;
91416 - write = local_add_return(length, &tail_page->write);
91417 + write = local_add_return_unchecked(length, &tail_page->write);
91418
91419 /* set write to only the index of the write */
91420 write &= RB_WRITE_MASK;
91421 @@ -2421,7 +2421,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91422 kmemcheck_annotate_bitfield(event, bitfield);
91423 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
91424
91425 - local_inc(&tail_page->entries);
91426 + local_inc_unchecked(&tail_page->entries);
91427
91428 /*
91429 * If this is the first commit on the page, then update
91430 @@ -2454,7 +2454,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91431
91432 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91433 unsigned long write_mask =
91434 - local_read(&bpage->write) & ~RB_WRITE_MASK;
91435 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91436 unsigned long event_length = rb_event_length(event);
91437 /*
91438 * This is on the tail page. It is possible that
91439 @@ -2464,7 +2464,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91440 */
91441 old_index += write_mask;
91442 new_index += write_mask;
91443 - index = local_cmpxchg(&bpage->write, old_index, new_index);
91444 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91445 if (index == old_index) {
91446 /* update counters */
91447 local_sub(event_length, &cpu_buffer->entries_bytes);
91448 @@ -2856,7 +2856,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91449
91450 /* Do the likely case first */
91451 if (likely(bpage->page == (void *)addr)) {
91452 - local_dec(&bpage->entries);
91453 + local_dec_unchecked(&bpage->entries);
91454 return;
91455 }
91456
91457 @@ -2868,7 +2868,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91458 start = bpage;
91459 do {
91460 if (bpage->page == (void *)addr) {
91461 - local_dec(&bpage->entries);
91462 + local_dec_unchecked(&bpage->entries);
91463 return;
91464 }
91465 rb_inc_page(cpu_buffer, &bpage);
91466 @@ -3152,7 +3152,7 @@ static inline unsigned long
91467 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91468 {
91469 return local_read(&cpu_buffer->entries) -
91470 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91471 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91472 }
91473
91474 /**
91475 @@ -3241,7 +3241,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91476 return 0;
91477
91478 cpu_buffer = buffer->buffers[cpu];
91479 - ret = local_read(&cpu_buffer->overrun);
91480 + ret = local_read_unchecked(&cpu_buffer->overrun);
91481
91482 return ret;
91483 }
91484 @@ -3264,7 +3264,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91485 return 0;
91486
91487 cpu_buffer = buffer->buffers[cpu];
91488 - ret = local_read(&cpu_buffer->commit_overrun);
91489 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91490
91491 return ret;
91492 }
91493 @@ -3349,7 +3349,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91494 /* if you care about this being correct, lock the buffer */
91495 for_each_buffer_cpu(buffer, cpu) {
91496 cpu_buffer = buffer->buffers[cpu];
91497 - overruns += local_read(&cpu_buffer->overrun);
91498 + overruns += local_read_unchecked(&cpu_buffer->overrun);
91499 }
91500
91501 return overruns;
91502 @@ -3525,8 +3525,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91503 /*
91504 * Reset the reader page to size zero.
91505 */
91506 - local_set(&cpu_buffer->reader_page->write, 0);
91507 - local_set(&cpu_buffer->reader_page->entries, 0);
91508 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91509 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91510 local_set(&cpu_buffer->reader_page->page->commit, 0);
91511 cpu_buffer->reader_page->real_end = 0;
91512
91513 @@ -3560,7 +3560,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91514 * want to compare with the last_overrun.
91515 */
91516 smp_mb();
91517 - overwrite = local_read(&(cpu_buffer->overrun));
91518 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91519
91520 /*
91521 * Here's the tricky part.
91522 @@ -4130,8 +4130,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91523
91524 cpu_buffer->head_page
91525 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91526 - local_set(&cpu_buffer->head_page->write, 0);
91527 - local_set(&cpu_buffer->head_page->entries, 0);
91528 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
91529 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91530 local_set(&cpu_buffer->head_page->page->commit, 0);
91531
91532 cpu_buffer->head_page->read = 0;
91533 @@ -4141,14 +4141,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91534
91535 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91536 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91537 - local_set(&cpu_buffer->reader_page->write, 0);
91538 - local_set(&cpu_buffer->reader_page->entries, 0);
91539 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91540 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91541 local_set(&cpu_buffer->reader_page->page->commit, 0);
91542 cpu_buffer->reader_page->read = 0;
91543
91544 local_set(&cpu_buffer->entries_bytes, 0);
91545 - local_set(&cpu_buffer->overrun, 0);
91546 - local_set(&cpu_buffer->commit_overrun, 0);
91547 + local_set_unchecked(&cpu_buffer->overrun, 0);
91548 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91549 local_set(&cpu_buffer->dropped_events, 0);
91550 local_set(&cpu_buffer->entries, 0);
91551 local_set(&cpu_buffer->committing, 0);
91552 @@ -4553,8 +4553,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91553 rb_init_page(bpage);
91554 bpage = reader->page;
91555 reader->page = *data_page;
91556 - local_set(&reader->write, 0);
91557 - local_set(&reader->entries, 0);
91558 + local_set_unchecked(&reader->write, 0);
91559 + local_set_unchecked(&reader->entries, 0);
91560 reader->read = 0;
91561 *data_page = bpage;
91562
91563 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91564 index 39a1226..2dc2b43 100644
91565 --- a/kernel/trace/trace.c
91566 +++ b/kernel/trace/trace.c
91567 @@ -3447,7 +3447,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91568 return 0;
91569 }
91570
91571 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91572 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91573 {
91574 /* do nothing if flag is already set */
91575 if (!!(trace_flags & mask) == !!enabled)
91576 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91577 index 99676cd..670b9e8 100644
91578 --- a/kernel/trace/trace.h
91579 +++ b/kernel/trace/trace.h
91580 @@ -1264,7 +1264,7 @@ extern const char *__stop___tracepoint_str[];
91581 void trace_printk_init_buffers(void);
91582 void trace_printk_start_comm(void);
91583 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91584 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91585 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91586
91587 /*
91588 * Normal trace_printk() and friends allocates special buffers
91589 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91590 index 26dc348..8708ca7 100644
91591 --- a/kernel/trace/trace_clock.c
91592 +++ b/kernel/trace/trace_clock.c
91593 @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
91594 return now;
91595 }
91596
91597 -static atomic64_t trace_counter;
91598 +static atomic64_unchecked_t trace_counter;
91599
91600 /*
91601 * trace_clock_counter(): simply an atomic counter.
91602 @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
91603 */
91604 u64 notrace trace_clock_counter(void)
91605 {
91606 - return atomic64_add_return(1, &trace_counter);
91607 + return atomic64_inc_return_unchecked(&trace_counter);
91608 }
91609 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91610 index 3ddfd8f..41a10fe 100644
91611 --- a/kernel/trace/trace_events.c
91612 +++ b/kernel/trace/trace_events.c
91613 @@ -1718,7 +1718,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91614 return 0;
91615 }
91616
91617 -struct ftrace_module_file_ops;
91618 static void __add_event_to_tracers(struct ftrace_event_call *call);
91619
91620 /* Add an additional event_call dynamically */
91621 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91622 index 0abd9b8..6a663a2 100644
91623 --- a/kernel/trace/trace_mmiotrace.c
91624 +++ b/kernel/trace/trace_mmiotrace.c
91625 @@ -24,7 +24,7 @@ struct header_iter {
91626 static struct trace_array *mmio_trace_array;
91627 static bool overrun_detected;
91628 static unsigned long prev_overruns;
91629 -static atomic_t dropped_count;
91630 +static atomic_unchecked_t dropped_count;
91631
91632 static void mmio_reset_data(struct trace_array *tr)
91633 {
91634 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91635
91636 static unsigned long count_overruns(struct trace_iterator *iter)
91637 {
91638 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
91639 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91640 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91641
91642 if (over > prev_overruns)
91643 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
91644 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
91645 sizeof(*entry), 0, pc);
91646 if (!event) {
91647 - atomic_inc(&dropped_count);
91648 + atomic_inc_unchecked(&dropped_count);
91649 return;
91650 }
91651 entry = ring_buffer_event_data(event);
91652 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
91653 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
91654 sizeof(*entry), 0, pc);
91655 if (!event) {
91656 - atomic_inc(&dropped_count);
91657 + atomic_inc_unchecked(&dropped_count);
91658 return;
91659 }
91660 entry = ring_buffer_event_data(event);
91661 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
91662 index a436de1..f64dde2 100644
91663 --- a/kernel/trace/trace_output.c
91664 +++ b/kernel/trace/trace_output.c
91665 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
91666
91667 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
91668 if (!IS_ERR(p)) {
91669 - p = mangle_path(s->buffer + s->len, p, "\n");
91670 + p = mangle_path(s->buffer + s->len, p, "\n\\");
91671 if (p) {
91672 s->len = p - s->buffer;
91673 return 1;
91674 @@ -939,14 +939,16 @@ int register_ftrace_event(struct trace_event *event)
91675 goto out;
91676 }
91677
91678 + pax_open_kernel();
91679 if (event->funcs->trace == NULL)
91680 - event->funcs->trace = trace_nop_print;
91681 + *(void **)&event->funcs->trace = trace_nop_print;
91682 if (event->funcs->raw == NULL)
91683 - event->funcs->raw = trace_nop_print;
91684 + *(void **)&event->funcs->raw = trace_nop_print;
91685 if (event->funcs->hex == NULL)
91686 - event->funcs->hex = trace_nop_print;
91687 + *(void **)&event->funcs->hex = trace_nop_print;
91688 if (event->funcs->binary == NULL)
91689 - event->funcs->binary = trace_nop_print;
91690 + *(void **)&event->funcs->binary = trace_nop_print;
91691 + pax_close_kernel();
91692
91693 key = event->type & (EVENT_HASHSIZE - 1);
91694
91695 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
91696 index 21b320e..40607bc 100644
91697 --- a/kernel/trace/trace_stack.c
91698 +++ b/kernel/trace/trace_stack.c
91699 @@ -69,7 +69,7 @@ check_stack(unsigned long ip, unsigned long *stack)
91700 return;
91701
91702 /* we do not handle interrupt stacks yet */
91703 - if (!object_is_on_stack(stack))
91704 + if (!object_starts_on_stack(stack))
91705 return;
91706
91707 local_irq_save(flags);
91708 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
91709 index bf71b4b..04dee68 100644
91710 --- a/kernel/user_namespace.c
91711 +++ b/kernel/user_namespace.c
91712 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
91713 !kgid_has_mapping(parent_ns, group))
91714 return -EPERM;
91715
91716 +#ifdef CONFIG_GRKERNSEC
91717 + /*
91718 + * This doesn't really inspire confidence:
91719 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
91720 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
91721 + * Increases kernel attack surface in areas developers
91722 + * previously cared little about ("low importance due
91723 + * to requiring "root" capability")
91724 + * To be removed when this code receives *proper* review
91725 + */
91726 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91727 + !capable(CAP_SETGID))
91728 + return -EPERM;
91729 +#endif
91730 +
91731 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91732 if (!ns)
91733 return -ENOMEM;
91734 @@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91735 if (atomic_read(&current->mm->mm_users) > 1)
91736 return -EINVAL;
91737
91738 - if (current->fs->users != 1)
91739 + if (atomic_read(&current->fs->users) != 1)
91740 return -EINVAL;
91741
91742 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91743 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91744 index 4f69f9a..7c6f8f8 100644
91745 --- a/kernel/utsname_sysctl.c
91746 +++ b/kernel/utsname_sysctl.c
91747 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91748 static int proc_do_uts_string(ctl_table *table, int write,
91749 void __user *buffer, size_t *lenp, loff_t *ppos)
91750 {
91751 - struct ctl_table uts_table;
91752 + ctl_table_no_const uts_table;
91753 int r;
91754 memcpy(&uts_table, table, sizeof(uts_table));
91755 uts_table.data = get_uts(table, write);
91756 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91757 index 30e4822..dd2b854 100644
91758 --- a/kernel/watchdog.c
91759 +++ b/kernel/watchdog.c
91760 @@ -479,7 +479,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91761 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91762 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91763
91764 -static struct smp_hotplug_thread watchdog_threads = {
91765 +static struct smp_hotplug_thread watchdog_threads __read_only = {
91766 .store = &softlockup_watchdog,
91767 .thread_should_run = watchdog_should_run,
91768 .thread_fn = watchdog,
91769 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91770 index 7ba5897..c8ed1f2 100644
91771 --- a/kernel/workqueue.c
91772 +++ b/kernel/workqueue.c
91773 @@ -4710,7 +4710,7 @@ static void rebind_workers(struct worker_pool *pool)
91774 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91775 worker_flags |= WORKER_REBOUND;
91776 worker_flags &= ~WORKER_UNBOUND;
91777 - ACCESS_ONCE(worker->flags) = worker_flags;
91778 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
91779 }
91780
91781 spin_unlock_irq(&pool->lock);
91782 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91783 index 819ac51..1c8a65e 100644
91784 --- a/lib/Kconfig.debug
91785 +++ b/lib/Kconfig.debug
91786 @@ -853,7 +853,7 @@ config DEBUG_MUTEXES
91787
91788 config DEBUG_WW_MUTEX_SLOWPATH
91789 bool "Wait/wound mutex debugging: Slowpath testing"
91790 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91791 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91792 select DEBUG_LOCK_ALLOC
91793 select DEBUG_SPINLOCK
91794 select DEBUG_MUTEXES
91795 @@ -866,7 +866,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91796
91797 config DEBUG_LOCK_ALLOC
91798 bool "Lock debugging: detect incorrect freeing of live locks"
91799 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91800 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91801 select DEBUG_SPINLOCK
91802 select DEBUG_MUTEXES
91803 select LOCKDEP
91804 @@ -880,7 +880,7 @@ config DEBUG_LOCK_ALLOC
91805
91806 config PROVE_LOCKING
91807 bool "Lock debugging: prove locking correctness"
91808 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91809 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91810 select LOCKDEP
91811 select DEBUG_SPINLOCK
91812 select DEBUG_MUTEXES
91813 @@ -931,7 +931,7 @@ config LOCKDEP
91814
91815 config LOCK_STAT
91816 bool "Lock usage statistics"
91817 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91818 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91819 select LOCKDEP
91820 select DEBUG_SPINLOCK
91821 select DEBUG_MUTEXES
91822 @@ -1403,6 +1403,7 @@ config LATENCYTOP
91823 depends on DEBUG_KERNEL
91824 depends on STACKTRACE_SUPPORT
91825 depends on PROC_FS
91826 + depends on !GRKERNSEC_HIDESYM
91827 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91828 select KALLSYMS
91829 select KALLSYMS_ALL
91830 @@ -1419,7 +1420,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91831 config DEBUG_STRICT_USER_COPY_CHECKS
91832 bool "Strict user copy size checks"
91833 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91834 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91835 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91836 help
91837 Enabling this option turns a certain set of sanity checks for user
91838 copy operations into compile time failures.
91839 @@ -1538,7 +1539,7 @@ endmenu # runtime tests
91840
91841 config PROVIDE_OHCI1394_DMA_INIT
91842 bool "Remote debugging over FireWire early on boot"
91843 - depends on PCI && X86
91844 + depends on PCI && X86 && !GRKERNSEC
91845 help
91846 If you want to debug problems which hang or crash the kernel early
91847 on boot and the crashing machine has a FireWire port, you can use
91848 diff --git a/lib/Makefile b/lib/Makefile
91849 index 0cd7b68..e149e37 100644
91850 --- a/lib/Makefile
91851 +++ b/lib/Makefile
91852 @@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91853 obj-$(CONFIG_BTREE) += btree.o
91854 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91855 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91856 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91857 +obj-y += list_debug.o
91858 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91859
91860 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91861 diff --git a/lib/average.c b/lib/average.c
91862 index 114d1be..ab0350c 100644
91863 --- a/lib/average.c
91864 +++ b/lib/average.c
91865 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91866 {
91867 unsigned long internal = ACCESS_ONCE(avg->internal);
91868
91869 - ACCESS_ONCE(avg->internal) = internal ?
91870 + ACCESS_ONCE_RW(avg->internal) = internal ?
91871 (((internal << avg->weight) - internal) +
91872 (val << avg->factor)) >> avg->weight :
91873 (val << avg->factor);
91874 diff --git a/lib/bitmap.c b/lib/bitmap.c
91875 index 06f7e4f..f3cf2b0 100644
91876 --- a/lib/bitmap.c
91877 +++ b/lib/bitmap.c
91878 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91879 {
91880 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91881 u32 chunk;
91882 - const char __user __force *ubuf = (const char __user __force *)buf;
91883 + const char __user *ubuf = (const char __force_user *)buf;
91884
91885 bitmap_zero(maskp, nmaskbits);
91886
91887 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91888 {
91889 if (!access_ok(VERIFY_READ, ubuf, ulen))
91890 return -EFAULT;
91891 - return __bitmap_parse((const char __force *)ubuf,
91892 + return __bitmap_parse((const char __force_kernel *)ubuf,
91893 ulen, 1, maskp, nmaskbits);
91894
91895 }
91896 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91897 {
91898 unsigned a, b;
91899 int c, old_c, totaldigits;
91900 - const char __user __force *ubuf = (const char __user __force *)buf;
91901 + const char __user *ubuf = (const char __force_user *)buf;
91902 int exp_digit, in_range;
91903
91904 totaldigits = c = 0;
91905 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91906 {
91907 if (!access_ok(VERIFY_READ, ubuf, ulen))
91908 return -EFAULT;
91909 - return __bitmap_parselist((const char __force *)ubuf,
91910 + return __bitmap_parselist((const char __force_kernel *)ubuf,
91911 ulen, 1, maskp, nmaskbits);
91912 }
91913 EXPORT_SYMBOL(bitmap_parselist_user);
91914 diff --git a/lib/bug.c b/lib/bug.c
91915 index 1686034..a9c00c8 100644
91916 --- a/lib/bug.c
91917 +++ b/lib/bug.c
91918 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91919 return BUG_TRAP_TYPE_NONE;
91920
91921 bug = find_bug(bugaddr);
91922 + if (!bug)
91923 + return BUG_TRAP_TYPE_NONE;
91924
91925 file = NULL;
91926 line = 0;
91927 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
91928 index e0731c3..ad66444 100644
91929 --- a/lib/debugobjects.c
91930 +++ b/lib/debugobjects.c
91931 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
91932 if (limit > 4)
91933 return;
91934
91935 - is_on_stack = object_is_on_stack(addr);
91936 + is_on_stack = object_starts_on_stack(addr);
91937 if (is_on_stack == onstack)
91938 return;
91939
91940 diff --git a/lib/div64.c b/lib/div64.c
91941 index 4382ad7..08aa558 100644
91942 --- a/lib/div64.c
91943 +++ b/lib/div64.c
91944 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91945 EXPORT_SYMBOL(__div64_32);
91946
91947 #ifndef div_s64_rem
91948 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91949 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91950 {
91951 u64 quotient;
91952
91953 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91954 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91955 */
91956 #ifndef div64_u64
91957 -u64 div64_u64(u64 dividend, u64 divisor)
91958 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91959 {
91960 u32 high = divisor >> 32;
91961 u64 quot;
91962 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91963 index 98f2d7e..899da5c 100644
91964 --- a/lib/dma-debug.c
91965 +++ b/lib/dma-debug.c
91966 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91967
91968 void dma_debug_add_bus(struct bus_type *bus)
91969 {
91970 - struct notifier_block *nb;
91971 + notifier_block_no_const *nb;
91972
91973 if (global_disable)
91974 return;
91975 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91976
91977 static void check_for_stack(struct device *dev, void *addr)
91978 {
91979 - if (object_is_on_stack(addr))
91980 + if (object_starts_on_stack(addr))
91981 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91982 "stack [addr=%p]\n", addr);
91983 }
91984 diff --git a/lib/hash.c b/lib/hash.c
91985 index fea973f..386626f 100644
91986 --- a/lib/hash.c
91987 +++ b/lib/hash.c
91988 @@ -14,7 +14,7 @@
91989 #include <linux/hash.h>
91990 #include <linux/cache.h>
91991
91992 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
91993 +static struct fast_hash_ops arch_hash_ops __read_only = {
91994 .hash = jhash,
91995 .hash2 = jhash2,
91996 };
91997 diff --git a/lib/inflate.c b/lib/inflate.c
91998 index 013a761..c28f3fc 100644
91999 --- a/lib/inflate.c
92000 +++ b/lib/inflate.c
92001 @@ -269,7 +269,7 @@ static void free(void *where)
92002 malloc_ptr = free_mem_ptr;
92003 }
92004 #else
92005 -#define malloc(a) kmalloc(a, GFP_KERNEL)
92006 +#define malloc(a) kmalloc((a), GFP_KERNEL)
92007 #define free(a) kfree(a)
92008 #endif
92009
92010 diff --git a/lib/ioremap.c b/lib/ioremap.c
92011 index 0c9216c..863bd89 100644
92012 --- a/lib/ioremap.c
92013 +++ b/lib/ioremap.c
92014 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
92015 unsigned long next;
92016
92017 phys_addr -= addr;
92018 - pmd = pmd_alloc(&init_mm, pud, addr);
92019 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
92020 if (!pmd)
92021 return -ENOMEM;
92022 do {
92023 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
92024 unsigned long next;
92025
92026 phys_addr -= addr;
92027 - pud = pud_alloc(&init_mm, pgd, addr);
92028 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
92029 if (!pud)
92030 return -ENOMEM;
92031 do {
92032 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
92033 index bd2bea9..6b3c95e 100644
92034 --- a/lib/is_single_threaded.c
92035 +++ b/lib/is_single_threaded.c
92036 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
92037 struct task_struct *p, *t;
92038 bool ret;
92039
92040 + if (!mm)
92041 + return true;
92042 +
92043 if (atomic_read(&task->signal->live) != 1)
92044 return false;
92045
92046 diff --git a/lib/kobject.c b/lib/kobject.c
92047 index 58751bb..93a1853 100644
92048 --- a/lib/kobject.c
92049 +++ b/lib/kobject.c
92050 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
92051
92052
92053 static DEFINE_SPINLOCK(kobj_ns_type_lock);
92054 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
92055 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
92056
92057 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
92058 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
92059 {
92060 enum kobj_ns_type type = ops->type;
92061 int error;
92062 diff --git a/lib/list_debug.c b/lib/list_debug.c
92063 index c24c2f7..f0296f4 100644
92064 --- a/lib/list_debug.c
92065 +++ b/lib/list_debug.c
92066 @@ -11,7 +11,9 @@
92067 #include <linux/bug.h>
92068 #include <linux/kernel.h>
92069 #include <linux/rculist.h>
92070 +#include <linux/mm.h>
92071
92072 +#ifdef CONFIG_DEBUG_LIST
92073 /*
92074 * Insert a new entry between two known consecutive entries.
92075 *
92076 @@ -19,21 +21,40 @@
92077 * the prev/next entries already!
92078 */
92079
92080 +static bool __list_add_debug(struct list_head *new,
92081 + struct list_head *prev,
92082 + struct list_head *next)
92083 +{
92084 + if (unlikely(next->prev != prev)) {
92085 + printk(KERN_ERR "list_add corruption. next->prev should be "
92086 + "prev (%p), but was %p. (next=%p).\n",
92087 + prev, next->prev, next);
92088 + BUG();
92089 + return false;
92090 + }
92091 + if (unlikely(prev->next != next)) {
92092 + printk(KERN_ERR "list_add corruption. prev->next should be "
92093 + "next (%p), but was %p. (prev=%p).\n",
92094 + next, prev->next, prev);
92095 + BUG();
92096 + return false;
92097 + }
92098 + if (unlikely(new == prev || new == next)) {
92099 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
92100 + new, prev, next);
92101 + BUG();
92102 + return false;
92103 + }
92104 + return true;
92105 +}
92106 +
92107 void __list_add(struct list_head *new,
92108 - struct list_head *prev,
92109 - struct list_head *next)
92110 + struct list_head *prev,
92111 + struct list_head *next)
92112 {
92113 - WARN(next->prev != prev,
92114 - "list_add corruption. next->prev should be "
92115 - "prev (%p), but was %p. (next=%p).\n",
92116 - prev, next->prev, next);
92117 - WARN(prev->next != next,
92118 - "list_add corruption. prev->next should be "
92119 - "next (%p), but was %p. (prev=%p).\n",
92120 - next, prev->next, prev);
92121 - WARN(new == prev || new == next,
92122 - "list_add double add: new=%p, prev=%p, next=%p.\n",
92123 - new, prev, next);
92124 + if (!__list_add_debug(new, prev, next))
92125 + return;
92126 +
92127 next->prev = new;
92128 new->next = next;
92129 new->prev = prev;
92130 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
92131 }
92132 EXPORT_SYMBOL(__list_add);
92133
92134 -void __list_del_entry(struct list_head *entry)
92135 +static bool __list_del_entry_debug(struct list_head *entry)
92136 {
92137 struct list_head *prev, *next;
92138
92139 prev = entry->prev;
92140 next = entry->next;
92141
92142 - if (WARN(next == LIST_POISON1,
92143 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
92144 - entry, LIST_POISON1) ||
92145 - WARN(prev == LIST_POISON2,
92146 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
92147 - entry, LIST_POISON2) ||
92148 - WARN(prev->next != entry,
92149 - "list_del corruption. prev->next should be %p, "
92150 - "but was %p\n", entry, prev->next) ||
92151 - WARN(next->prev != entry,
92152 - "list_del corruption. next->prev should be %p, "
92153 - "but was %p\n", entry, next->prev))
92154 + if (unlikely(next == LIST_POISON1)) {
92155 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
92156 + entry, LIST_POISON1);
92157 + BUG();
92158 + return false;
92159 + }
92160 + if (unlikely(prev == LIST_POISON2)) {
92161 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
92162 + entry, LIST_POISON2);
92163 + BUG();
92164 + return false;
92165 + }
92166 + if (unlikely(entry->prev->next != entry)) {
92167 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
92168 + "but was %p\n", entry, prev->next);
92169 + BUG();
92170 + return false;
92171 + }
92172 + if (unlikely(entry->next->prev != entry)) {
92173 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
92174 + "but was %p\n", entry, next->prev);
92175 + BUG();
92176 + return false;
92177 + }
92178 + return true;
92179 +}
92180 +
92181 +void __list_del_entry(struct list_head *entry)
92182 +{
92183 + if (!__list_del_entry_debug(entry))
92184 return;
92185
92186 - __list_del(prev, next);
92187 + __list_del(entry->prev, entry->next);
92188 }
92189 EXPORT_SYMBOL(__list_del_entry);
92190
92191 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
92192 void __list_add_rcu(struct list_head *new,
92193 struct list_head *prev, struct list_head *next)
92194 {
92195 - WARN(next->prev != prev,
92196 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
92197 - prev, next->prev, next);
92198 - WARN(prev->next != next,
92199 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
92200 - next, prev->next, prev);
92201 + if (!__list_add_debug(new, prev, next))
92202 + return;
92203 +
92204 new->next = next;
92205 new->prev = prev;
92206 rcu_assign_pointer(list_next_rcu(prev), new);
92207 next->prev = new;
92208 }
92209 EXPORT_SYMBOL(__list_add_rcu);
92210 +#endif
92211 +
92212 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
92213 +{
92214 +#ifdef CONFIG_DEBUG_LIST
92215 + if (!__list_add_debug(new, prev, next))
92216 + return;
92217 +#endif
92218 +
92219 + pax_open_kernel();
92220 + next->prev = new;
92221 + new->next = next;
92222 + new->prev = prev;
92223 + prev->next = new;
92224 + pax_close_kernel();
92225 +}
92226 +EXPORT_SYMBOL(__pax_list_add);
92227 +
92228 +void pax_list_del(struct list_head *entry)
92229 +{
92230 +#ifdef CONFIG_DEBUG_LIST
92231 + if (!__list_del_entry_debug(entry))
92232 + return;
92233 +#endif
92234 +
92235 + pax_open_kernel();
92236 + __list_del(entry->prev, entry->next);
92237 + entry->next = LIST_POISON1;
92238 + entry->prev = LIST_POISON2;
92239 + pax_close_kernel();
92240 +}
92241 +EXPORT_SYMBOL(pax_list_del);
92242 +
92243 +void pax_list_del_init(struct list_head *entry)
92244 +{
92245 + pax_open_kernel();
92246 + __list_del(entry->prev, entry->next);
92247 + INIT_LIST_HEAD(entry);
92248 + pax_close_kernel();
92249 +}
92250 +EXPORT_SYMBOL(pax_list_del_init);
92251 +
92252 +void __pax_list_add_rcu(struct list_head *new,
92253 + struct list_head *prev, struct list_head *next)
92254 +{
92255 +#ifdef CONFIG_DEBUG_LIST
92256 + if (!__list_add_debug(new, prev, next))
92257 + return;
92258 +#endif
92259 +
92260 + pax_open_kernel();
92261 + new->next = next;
92262 + new->prev = prev;
92263 + rcu_assign_pointer(list_next_rcu(prev), new);
92264 + next->prev = new;
92265 + pax_close_kernel();
92266 +}
92267 +EXPORT_SYMBOL(__pax_list_add_rcu);
92268 +
92269 +void pax_list_del_rcu(struct list_head *entry)
92270 +{
92271 +#ifdef CONFIG_DEBUG_LIST
92272 + if (!__list_del_entry_debug(entry))
92273 + return;
92274 +#endif
92275 +
92276 + pax_open_kernel();
92277 + __list_del(entry->prev, entry->next);
92278 + entry->next = LIST_POISON1;
92279 + entry->prev = LIST_POISON2;
92280 + pax_close_kernel();
92281 +}
92282 +EXPORT_SYMBOL(pax_list_del_rcu);
92283 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
92284 index 963b703..438bc51 100644
92285 --- a/lib/percpu-refcount.c
92286 +++ b/lib/percpu-refcount.c
92287 @@ -29,7 +29,7 @@
92288 * can't hit 0 before we've added up all the percpu refs.
92289 */
92290
92291 -#define PCPU_COUNT_BIAS (1U << 31)
92292 +#define PCPU_COUNT_BIAS (1U << 30)
92293
92294 /**
92295 * percpu_ref_init - initialize a percpu refcount
92296 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
92297 index 9599aa7..9cf6c72 100644
92298 --- a/lib/radix-tree.c
92299 +++ b/lib/radix-tree.c
92300 @@ -66,7 +66,7 @@ struct radix_tree_preload {
92301 int nr;
92302 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
92303 };
92304 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
92305 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
92306
92307 static inline void *ptr_to_indirect(void *ptr)
92308 {
92309 diff --git a/lib/random32.c b/lib/random32.c
92310 index fa5da61..35fe9af 100644
92311 --- a/lib/random32.c
92312 +++ b/lib/random32.c
92313 @@ -42,7 +42,7 @@
92314 static void __init prandom_state_selftest(void);
92315 #endif
92316
92317 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
92318 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
92319
92320 /**
92321 * prandom_u32_state - seeded pseudo-random number generator.
92322 diff --git a/lib/rbtree.c b/lib/rbtree.c
92323 index 65f4eff..2cfa167 100644
92324 --- a/lib/rbtree.c
92325 +++ b/lib/rbtree.c
92326 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
92327 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
92328
92329 static const struct rb_augment_callbacks dummy_callbacks = {
92330 - dummy_propagate, dummy_copy, dummy_rotate
92331 + .propagate = dummy_propagate,
92332 + .copy = dummy_copy,
92333 + .rotate = dummy_rotate
92334 };
92335
92336 void rb_insert_color(struct rb_node *node, struct rb_root *root)
92337 diff --git a/lib/show_mem.c b/lib/show_mem.c
92338 index 0922579..9d7adb9 100644
92339 --- a/lib/show_mem.c
92340 +++ b/lib/show_mem.c
92341 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
92342 quicklist_total_size());
92343 #endif
92344 #ifdef CONFIG_MEMORY_FAILURE
92345 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
92346 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
92347 #endif
92348 }
92349 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
92350 index bb2b201..46abaf9 100644
92351 --- a/lib/strncpy_from_user.c
92352 +++ b/lib/strncpy_from_user.c
92353 @@ -21,7 +21,7 @@
92354 */
92355 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
92356 {
92357 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92358 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92359 long res = 0;
92360
92361 /*
92362 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
92363 index a28df52..3d55877 100644
92364 --- a/lib/strnlen_user.c
92365 +++ b/lib/strnlen_user.c
92366 @@ -26,7 +26,7 @@
92367 */
92368 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
92369 {
92370 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92371 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92372 long align, res = 0;
92373 unsigned long c;
92374
92375 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
92376 index b604b83..c0547f6 100644
92377 --- a/lib/swiotlb.c
92378 +++ b/lib/swiotlb.c
92379 @@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
92380
92381 void
92382 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
92383 - dma_addr_t dev_addr)
92384 + dma_addr_t dev_addr, struct dma_attrs *attrs)
92385 {
92386 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
92387
92388 diff --git a/lib/usercopy.c b/lib/usercopy.c
92389 index 4f5b1dd..7cab418 100644
92390 --- a/lib/usercopy.c
92391 +++ b/lib/usercopy.c
92392 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
92393 WARN(1, "Buffer overflow detected!\n");
92394 }
92395 EXPORT_SYMBOL(copy_from_user_overflow);
92396 +
92397 +void copy_to_user_overflow(void)
92398 +{
92399 + WARN(1, "Buffer overflow detected!\n");
92400 +}
92401 +EXPORT_SYMBOL(copy_to_user_overflow);
92402 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
92403 index 0648291..42bf42b 100644
92404 --- a/lib/vsprintf.c
92405 +++ b/lib/vsprintf.c
92406 @@ -16,6 +16,9 @@
92407 * - scnprintf and vscnprintf
92408 */
92409
92410 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92411 +#define __INCLUDED_BY_HIDESYM 1
92412 +#endif
92413 #include <stdarg.h>
92414 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92415 #include <linux/types.h>
92416 @@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
92417 return number(buf, end, num, spec);
92418 }
92419
92420 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92421 +int kptr_restrict __read_mostly = 2;
92422 +#else
92423 int kptr_restrict __read_mostly;
92424 +#endif
92425
92426 /*
92427 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92428 @@ -1196,6 +1203,7 @@ int kptr_restrict __read_mostly;
92429 * - 'f' For simple symbolic function names without offset
92430 * - 'S' For symbolic direct pointers with offset
92431 * - 's' For symbolic direct pointers without offset
92432 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92433 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92434 * - 'B' For backtraced symbolic direct pointers with offset
92435 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92436 @@ -1263,12 +1271,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92437
92438 if (!ptr && *fmt != 'K') {
92439 /*
92440 - * Print (null) with the same width as a pointer so it makes
92441 + * Print (nil) with the same width as a pointer so it makes
92442 * tabular output look nice.
92443 */
92444 if (spec.field_width == -1)
92445 spec.field_width = default_width;
92446 - return string(buf, end, "(null)", spec);
92447 + return string(buf, end, "(nil)", spec);
92448 }
92449
92450 switch (*fmt) {
92451 @@ -1278,6 +1286,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92452 /* Fallthrough */
92453 case 'S':
92454 case 's':
92455 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92456 + break;
92457 +#else
92458 + return symbol_string(buf, end, ptr, spec, fmt);
92459 +#endif
92460 + case 'A':
92461 case 'B':
92462 return symbol_string(buf, end, ptr, spec, fmt);
92463 case 'R':
92464 @@ -1333,6 +1347,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92465 va_end(va);
92466 return buf;
92467 }
92468 + case 'P':
92469 + break;
92470 case 'K':
92471 /*
92472 * %pK cannot be used in IRQ context because its test
92473 @@ -1390,6 +1406,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92474 ((const struct file *)ptr)->f_path.dentry,
92475 spec, fmt);
92476 }
92477 +
92478 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92479 + /* 'P' = approved pointers to copy to userland,
92480 + as in the /proc/kallsyms case, as we make it display nothing
92481 + for non-root users, and the real contents for root users
92482 + Also ignore 'K' pointers, since we force their NULLing for non-root users
92483 + above
92484 + */
92485 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92486 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92487 + dump_stack();
92488 + ptr = NULL;
92489 + }
92490 +#endif
92491 +
92492 spec.flags |= SMALL;
92493 if (spec.field_width == -1) {
92494 spec.field_width = default_width;
92495 @@ -2089,11 +2120,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92496 typeof(type) value; \
92497 if (sizeof(type) == 8) { \
92498 args = PTR_ALIGN(args, sizeof(u32)); \
92499 - *(u32 *)&value = *(u32 *)args; \
92500 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92501 + *(u32 *)&value = *(const u32 *)args; \
92502 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92503 } else { \
92504 args = PTR_ALIGN(args, sizeof(type)); \
92505 - value = *(typeof(type) *)args; \
92506 + value = *(const typeof(type) *)args; \
92507 } \
92508 args += sizeof(type); \
92509 value; \
92510 @@ -2156,7 +2187,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92511 case FORMAT_TYPE_STR: {
92512 const char *str_arg = args;
92513 args += strlen(str_arg) + 1;
92514 - str = string(str, end, (char *)str_arg, spec);
92515 + str = string(str, end, str_arg, spec);
92516 break;
92517 }
92518
92519 diff --git a/localversion-grsec b/localversion-grsec
92520 new file mode 100644
92521 index 0000000..7cd6065
92522 --- /dev/null
92523 +++ b/localversion-grsec
92524 @@ -0,0 +1 @@
92525 +-grsec
92526 diff --git a/mm/Kconfig b/mm/Kconfig
92527 index 2f42b9c..6095e14 100644
92528 --- a/mm/Kconfig
92529 +++ b/mm/Kconfig
92530 @@ -330,10 +330,11 @@ config KSM
92531 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92532
92533 config DEFAULT_MMAP_MIN_ADDR
92534 - int "Low address space to protect from user allocation"
92535 + int "Low address space to protect from user allocation"
92536 depends on MMU
92537 - default 4096
92538 - help
92539 + default 32768 if ALPHA || ARM || PARISC || SPARC32
92540 + default 65536
92541 + help
92542 This is the portion of low virtual memory which should be protected
92543 from userspace allocation. Keeping a user from writing to low pages
92544 can help reduce the impact of kernel NULL pointer bugs.
92545 @@ -364,7 +365,7 @@ config MEMORY_FAILURE
92546
92547 config HWPOISON_INJECT
92548 tristate "HWPoison pages injector"
92549 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92550 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92551 select PROC_PAGE_MONITOR
92552
92553 config NOMMU_INITIAL_TRIM_EXCESS
92554 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92555 index 09d9591..165bb75 100644
92556 --- a/mm/backing-dev.c
92557 +++ b/mm/backing-dev.c
92558 @@ -12,7 +12,7 @@
92559 #include <linux/device.h>
92560 #include <trace/events/writeback.h>
92561
92562 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92563 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92564
92565 struct backing_dev_info default_backing_dev_info = {
92566 .name = "default",
92567 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92568 return err;
92569
92570 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92571 - atomic_long_inc_return(&bdi_seq));
92572 + atomic_long_inc_return_unchecked(&bdi_seq));
92573 if (err) {
92574 bdi_destroy(bdi);
92575 return err;
92576 diff --git a/mm/filemap.c b/mm/filemap.c
92577 index 088358c..bb415bf 100644
92578 --- a/mm/filemap.c
92579 +++ b/mm/filemap.c
92580 @@ -2125,7 +2125,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92581 struct address_space *mapping = file->f_mapping;
92582
92583 if (!mapping->a_ops->readpage)
92584 - return -ENOEXEC;
92585 + return -ENODEV;
92586 file_accessed(file);
92587 vma->vm_ops = &generic_file_vm_ops;
92588 return 0;
92589 @@ -2303,6 +2303,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92590 *pos = i_size_read(inode);
92591
92592 if (limit != RLIM_INFINITY) {
92593 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92594 if (*pos >= limit) {
92595 send_sig(SIGXFSZ, current, 0);
92596 return -EFBIG;
92597 diff --git a/mm/fremap.c b/mm/fremap.c
92598 index 34feba6..315fe78 100644
92599 --- a/mm/fremap.c
92600 +++ b/mm/fremap.c
92601 @@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92602 retry:
92603 vma = find_vma(mm, start);
92604
92605 +#ifdef CONFIG_PAX_SEGMEXEC
92606 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92607 + goto out;
92608 +#endif
92609 +
92610 /*
92611 * Make sure the vma is shared, that it supports prefaulting,
92612 * and that the remapped range is valid and fully within
92613 diff --git a/mm/highmem.c b/mm/highmem.c
92614 index b32b70c..e512eb0 100644
92615 --- a/mm/highmem.c
92616 +++ b/mm/highmem.c
92617 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92618 * So no dangers, even with speculative execution.
92619 */
92620 page = pte_page(pkmap_page_table[i]);
92621 + pax_open_kernel();
92622 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92623 -
92624 + pax_close_kernel();
92625 set_page_address(page, NULL);
92626 need_flush = 1;
92627 }
92628 @@ -198,9 +199,11 @@ start:
92629 }
92630 }
92631 vaddr = PKMAP_ADDR(last_pkmap_nr);
92632 +
92633 + pax_open_kernel();
92634 set_pte_at(&init_mm, vaddr,
92635 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92636 -
92637 + pax_close_kernel();
92638 pkmap_count[last_pkmap_nr] = 1;
92639 set_page_address(page, (void *)vaddr);
92640
92641 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92642 index a646f15..f55da4c 100644
92643 --- a/mm/hugetlb.c
92644 +++ b/mm/hugetlb.c
92645 @@ -2107,6 +2107,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92646 struct hstate *h = &default_hstate;
92647 unsigned long tmp;
92648 int ret;
92649 + ctl_table_no_const hugetlb_table;
92650
92651 if (!hugepages_supported())
92652 return -ENOTSUPP;
92653 @@ -2116,9 +2117,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92654 if (write && h->order >= MAX_ORDER)
92655 return -EINVAL;
92656
92657 - table->data = &tmp;
92658 - table->maxlen = sizeof(unsigned long);
92659 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92660 + hugetlb_table = *table;
92661 + hugetlb_table.data = &tmp;
92662 + hugetlb_table.maxlen = sizeof(unsigned long);
92663 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92664 if (ret)
92665 goto out;
92666
92667 @@ -2163,6 +2165,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92668 struct hstate *h = &default_hstate;
92669 unsigned long tmp;
92670 int ret;
92671 + ctl_table_no_const hugetlb_table;
92672
92673 if (!hugepages_supported())
92674 return -ENOTSUPP;
92675 @@ -2172,9 +2175,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92676 if (write && h->order >= MAX_ORDER)
92677 return -EINVAL;
92678
92679 - table->data = &tmp;
92680 - table->maxlen = sizeof(unsigned long);
92681 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92682 + hugetlb_table = *table;
92683 + hugetlb_table.data = &tmp;
92684 + hugetlb_table.maxlen = sizeof(unsigned long);
92685 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92686 if (ret)
92687 goto out;
92688
92689 @@ -2654,6 +2658,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92690 return 1;
92691 }
92692
92693 +#ifdef CONFIG_PAX_SEGMEXEC
92694 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92695 +{
92696 + struct mm_struct *mm = vma->vm_mm;
92697 + struct vm_area_struct *vma_m;
92698 + unsigned long address_m;
92699 + pte_t *ptep_m;
92700 +
92701 + vma_m = pax_find_mirror_vma(vma);
92702 + if (!vma_m)
92703 + return;
92704 +
92705 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92706 + address_m = address + SEGMEXEC_TASK_SIZE;
92707 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92708 + get_page(page_m);
92709 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
92710 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92711 +}
92712 +#endif
92713 +
92714 /*
92715 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92716 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92717 @@ -2771,6 +2796,11 @@ retry_avoidcopy:
92718 make_huge_pte(vma, new_page, 1));
92719 page_remove_rmap(old_page);
92720 hugepage_add_new_anon_rmap(new_page, vma, address);
92721 +
92722 +#ifdef CONFIG_PAX_SEGMEXEC
92723 + pax_mirror_huge_pte(vma, address, new_page);
92724 +#endif
92725 +
92726 /* Make the old page be freed below */
92727 new_page = old_page;
92728 }
92729 @@ -2930,6 +2960,10 @@ retry:
92730 && (vma->vm_flags & VM_SHARED)));
92731 set_huge_pte_at(mm, address, ptep, new_pte);
92732
92733 +#ifdef CONFIG_PAX_SEGMEXEC
92734 + pax_mirror_huge_pte(vma, address, page);
92735 +#endif
92736 +
92737 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92738 /* Optimization, do the COW without a second fault */
92739 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92740 @@ -2996,6 +3030,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92741 struct hstate *h = hstate_vma(vma);
92742 struct address_space *mapping;
92743
92744 +#ifdef CONFIG_PAX_SEGMEXEC
92745 + struct vm_area_struct *vma_m;
92746 +#endif
92747 +
92748 address &= huge_page_mask(h);
92749
92750 ptep = huge_pte_offset(mm, address);
92751 @@ -3009,6 +3047,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92752 VM_FAULT_SET_HINDEX(hstate_index(h));
92753 }
92754
92755 +#ifdef CONFIG_PAX_SEGMEXEC
92756 + vma_m = pax_find_mirror_vma(vma);
92757 + if (vma_m) {
92758 + unsigned long address_m;
92759 +
92760 + if (vma->vm_start > vma_m->vm_start) {
92761 + address_m = address;
92762 + address -= SEGMEXEC_TASK_SIZE;
92763 + vma = vma_m;
92764 + h = hstate_vma(vma);
92765 + } else
92766 + address_m = address + SEGMEXEC_TASK_SIZE;
92767 +
92768 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92769 + return VM_FAULT_OOM;
92770 + address_m &= HPAGE_MASK;
92771 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92772 + }
92773 +#endif
92774 +
92775 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92776 if (!ptep)
92777 return VM_FAULT_OOM;
92778 diff --git a/mm/internal.h b/mm/internal.h
92779 index 07b6736..ae8da20 100644
92780 --- a/mm/internal.h
92781 +++ b/mm/internal.h
92782 @@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92783 * in mm/page_alloc.c
92784 */
92785 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92786 +extern void free_compound_page(struct page *page);
92787 extern void prep_compound_page(struct page *page, unsigned long order);
92788 #ifdef CONFIG_MEMORY_FAILURE
92789 extern bool is_free_buddy_page(struct page *page);
92790 @@ -367,7 +368,7 @@ extern u32 hwpoison_filter_enable;
92791
92792 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92793 unsigned long, unsigned long,
92794 - unsigned long, unsigned long);
92795 + unsigned long, unsigned long) __intentional_overflow(-1);
92796
92797 extern void set_pageblock_order(void);
92798 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92799 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
92800 index 10e46cd..e3052f6 100644
92801 --- a/mm/iov_iter.c
92802 +++ b/mm/iov_iter.c
92803 @@ -87,7 +87,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
92804
92805 while (bytes) {
92806 char __user *buf = iov->iov_base + base;
92807 - int copy = min(bytes, iov->iov_len - base);
92808 + size_t copy = min(bytes, iov->iov_len - base);
92809
92810 base = 0;
92811 left = __copy_from_user_inatomic(vaddr, buf, copy);
92812 @@ -115,7 +115,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
92813
92814 kaddr = kmap_atomic(page);
92815 if (likely(i->nr_segs == 1)) {
92816 - int left;
92817 + size_t left;
92818 char __user *buf = i->iov->iov_base + i->iov_offset;
92819 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
92820 copied = bytes - left;
92821 @@ -143,7 +143,7 @@ size_t iov_iter_copy_from_user(struct page *page,
92822
92823 kaddr = kmap(page);
92824 if (likely(i->nr_segs == 1)) {
92825 - int left;
92826 + size_t left;
92827 char __user *buf = i->iov->iov_base + i->iov_offset;
92828 left = __copy_from_user(kaddr + offset, buf, bytes);
92829 copied = bytes - left;
92830 @@ -173,7 +173,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
92831 * zero-length segments (without overruning the iovec).
92832 */
92833 while (bytes || unlikely(i->count && !iov->iov_len)) {
92834 - int copy;
92835 + size_t copy;
92836
92837 copy = min(bytes, iov->iov_len - base);
92838 BUG_ON(!i->count || i->count < copy);
92839 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92840 index 8d2fcdf..6dd9f1a 100644
92841 --- a/mm/kmemleak.c
92842 +++ b/mm/kmemleak.c
92843 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
92844
92845 for (i = 0; i < object->trace_len; i++) {
92846 void *ptr = (void *)object->trace[i];
92847 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92848 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92849 }
92850 }
92851
92852 @@ -1871,7 +1871,7 @@ static int __init kmemleak_late_init(void)
92853 return -ENOMEM;
92854 }
92855
92856 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92857 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92858 &kmemleak_fops);
92859 if (!dentry)
92860 pr_warning("Failed to create the debugfs kmemleak file\n");
92861 diff --git a/mm/maccess.c b/mm/maccess.c
92862 index d53adf9..03a24bf 100644
92863 --- a/mm/maccess.c
92864 +++ b/mm/maccess.c
92865 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92866 set_fs(KERNEL_DS);
92867 pagefault_disable();
92868 ret = __copy_from_user_inatomic(dst,
92869 - (__force const void __user *)src, size);
92870 + (const void __force_user *)src, size);
92871 pagefault_enable();
92872 set_fs(old_fs);
92873
92874 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92875
92876 set_fs(KERNEL_DS);
92877 pagefault_disable();
92878 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92879 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92880 pagefault_enable();
92881 set_fs(old_fs);
92882
92883 diff --git a/mm/madvise.c b/mm/madvise.c
92884 index a402f8f..f5e5daa 100644
92885 --- a/mm/madvise.c
92886 +++ b/mm/madvise.c
92887 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92888 pgoff_t pgoff;
92889 unsigned long new_flags = vma->vm_flags;
92890
92891 +#ifdef CONFIG_PAX_SEGMEXEC
92892 + struct vm_area_struct *vma_m;
92893 +#endif
92894 +
92895 switch (behavior) {
92896 case MADV_NORMAL:
92897 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92898 @@ -126,6 +130,13 @@ success:
92899 /*
92900 * vm_flags is protected by the mmap_sem held in write mode.
92901 */
92902 +
92903 +#ifdef CONFIG_PAX_SEGMEXEC
92904 + vma_m = pax_find_mirror_vma(vma);
92905 + if (vma_m)
92906 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92907 +#endif
92908 +
92909 vma->vm_flags = new_flags;
92910
92911 out:
92912 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92913 struct vm_area_struct **prev,
92914 unsigned long start, unsigned long end)
92915 {
92916 +
92917 +#ifdef CONFIG_PAX_SEGMEXEC
92918 + struct vm_area_struct *vma_m;
92919 +#endif
92920 +
92921 *prev = vma;
92922 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92923 return -EINVAL;
92924 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92925 zap_page_range(vma, start, end - start, &details);
92926 } else
92927 zap_page_range(vma, start, end - start, NULL);
92928 +
92929 +#ifdef CONFIG_PAX_SEGMEXEC
92930 + vma_m = pax_find_mirror_vma(vma);
92931 + if (vma_m) {
92932 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92933 + struct zap_details details = {
92934 + .nonlinear_vma = vma_m,
92935 + .last_index = ULONG_MAX,
92936 + };
92937 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92938 + } else
92939 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92940 + }
92941 +#endif
92942 +
92943 return 0;
92944 }
92945
92946 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92947 if (end < start)
92948 return error;
92949
92950 +#ifdef CONFIG_PAX_SEGMEXEC
92951 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92952 + if (end > SEGMEXEC_TASK_SIZE)
92953 + return error;
92954 + } else
92955 +#endif
92956 +
92957 + if (end > TASK_SIZE)
92958 + return error;
92959 +
92960 error = 0;
92961 if (end == start)
92962 return error;
92963 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92964 index eb8fb72..ae36cf3 100644
92965 --- a/mm/memory-failure.c
92966 +++ b/mm/memory-failure.c
92967 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92968
92969 int sysctl_memory_failure_recovery __read_mostly = 1;
92970
92971 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92972 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92973
92974 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92975
92976 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92977 pfn, t->comm, t->pid);
92978 si.si_signo = SIGBUS;
92979 si.si_errno = 0;
92980 - si.si_addr = (void *)addr;
92981 + si.si_addr = (void __user *)addr;
92982 #ifdef __ARCH_SI_TRAPNO
92983 si.si_trapno = trapno;
92984 #endif
92985 @@ -791,7 +791,7 @@ static struct page_state {
92986 unsigned long res;
92987 char *msg;
92988 int (*action)(struct page *p, unsigned long pfn);
92989 -} error_states[] = {
92990 +} __do_const error_states[] = {
92991 { reserved, reserved, "reserved kernel", me_kernel },
92992 /*
92993 * free pages are specially detected outside this table:
92994 @@ -1091,7 +1091,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92995 nr_pages = 1 << compound_order(hpage);
92996 else /* normal page or thp */
92997 nr_pages = 1;
92998 - atomic_long_add(nr_pages, &num_poisoned_pages);
92999 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
93000
93001 /*
93002 * We need/can do nothing about count=0 pages.
93003 @@ -1120,7 +1120,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
93004 if (PageHWPoison(hpage)) {
93005 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
93006 || (p != hpage && TestSetPageHWPoison(hpage))) {
93007 - atomic_long_sub(nr_pages, &num_poisoned_pages);
93008 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93009 unlock_page(hpage);
93010 return 0;
93011 }
93012 @@ -1186,14 +1186,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
93013 */
93014 if (!PageHWPoison(p)) {
93015 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
93016 - atomic_long_sub(nr_pages, &num_poisoned_pages);
93017 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93018 put_page(hpage);
93019 res = 0;
93020 goto out;
93021 }
93022 if (hwpoison_filter(p)) {
93023 if (TestClearPageHWPoison(p))
93024 - atomic_long_sub(nr_pages, &num_poisoned_pages);
93025 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93026 unlock_page(hpage);
93027 put_page(hpage);
93028 return 0;
93029 @@ -1415,7 +1415,7 @@ int unpoison_memory(unsigned long pfn)
93030 return 0;
93031 }
93032 if (TestClearPageHWPoison(p))
93033 - atomic_long_dec(&num_poisoned_pages);
93034 + atomic_long_dec_unchecked(&num_poisoned_pages);
93035 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
93036 return 0;
93037 }
93038 @@ -1429,7 +1429,7 @@ int unpoison_memory(unsigned long pfn)
93039 */
93040 if (TestClearPageHWPoison(page)) {
93041 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
93042 - atomic_long_sub(nr_pages, &num_poisoned_pages);
93043 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93044 freeit = 1;
93045 if (PageHuge(page))
93046 clear_page_hwpoison_huge_page(page);
93047 @@ -1554,11 +1554,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
93048 if (PageHuge(page)) {
93049 set_page_hwpoison_huge_page(hpage);
93050 dequeue_hwpoisoned_huge_page(hpage);
93051 - atomic_long_add(1 << compound_order(hpage),
93052 + atomic_long_add_unchecked(1 << compound_order(hpage),
93053 &num_poisoned_pages);
93054 } else {
93055 SetPageHWPoison(page);
93056 - atomic_long_inc(&num_poisoned_pages);
93057 + atomic_long_inc_unchecked(&num_poisoned_pages);
93058 }
93059 }
93060 return ret;
93061 @@ -1597,7 +1597,7 @@ static int __soft_offline_page(struct page *page, int flags)
93062 put_page(page);
93063 pr_info("soft_offline: %#lx: invalidated\n", pfn);
93064 SetPageHWPoison(page);
93065 - atomic_long_inc(&num_poisoned_pages);
93066 + atomic_long_inc_unchecked(&num_poisoned_pages);
93067 return 0;
93068 }
93069
93070 @@ -1648,7 +1648,7 @@ static int __soft_offline_page(struct page *page, int flags)
93071 if (!is_free_buddy_page(page))
93072 pr_info("soft offline: %#lx: page leaked\n",
93073 pfn);
93074 - atomic_long_inc(&num_poisoned_pages);
93075 + atomic_long_inc_unchecked(&num_poisoned_pages);
93076 }
93077 } else {
93078 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
93079 @@ -1722,11 +1722,11 @@ int soft_offline_page(struct page *page, int flags)
93080 if (PageHuge(page)) {
93081 set_page_hwpoison_huge_page(hpage);
93082 dequeue_hwpoisoned_huge_page(hpage);
93083 - atomic_long_add(1 << compound_order(hpage),
93084 + atomic_long_add_unchecked(1 << compound_order(hpage),
93085 &num_poisoned_pages);
93086 } else {
93087 SetPageHWPoison(page);
93088 - atomic_long_inc(&num_poisoned_pages);
93089 + atomic_long_inc_unchecked(&num_poisoned_pages);
93090 }
93091 }
93092 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
93093 diff --git a/mm/memory.c b/mm/memory.c
93094 index e302ae1..779c7ce 100644
93095 --- a/mm/memory.c
93096 +++ b/mm/memory.c
93097 @@ -413,6 +413,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
93098 free_pte_range(tlb, pmd, addr);
93099 } while (pmd++, addr = next, addr != end);
93100
93101 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
93102 start &= PUD_MASK;
93103 if (start < floor)
93104 return;
93105 @@ -427,6 +428,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
93106 pmd = pmd_offset(pud, start);
93107 pud_clear(pud);
93108 pmd_free_tlb(tlb, pmd, start);
93109 +#endif
93110 +
93111 }
93112
93113 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93114 @@ -446,6 +449,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93115 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
93116 } while (pud++, addr = next, addr != end);
93117
93118 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
93119 start &= PGDIR_MASK;
93120 if (start < floor)
93121 return;
93122 @@ -460,6 +464,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93123 pud = pud_offset(pgd, start);
93124 pgd_clear(pgd);
93125 pud_free_tlb(tlb, pud, start);
93126 +#endif
93127 +
93128 }
93129
93130 /*
93131 @@ -1652,12 +1658,6 @@ no_page_table:
93132 return page;
93133 }
93134
93135 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
93136 -{
93137 - return stack_guard_page_start(vma, addr) ||
93138 - stack_guard_page_end(vma, addr+PAGE_SIZE);
93139 -}
93140 -
93141 /**
93142 * __get_user_pages() - pin user pages in memory
93143 * @tsk: task_struct of target task
93144 @@ -1735,10 +1735,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93145
93146 i = 0;
93147
93148 - do {
93149 + while (nr_pages) {
93150 struct vm_area_struct *vma;
93151
93152 - vma = find_extend_vma(mm, start);
93153 + vma = find_vma(mm, start);
93154 if (!vma && in_gate_area(mm, start)) {
93155 unsigned long pg = start & PAGE_MASK;
93156 pgd_t *pgd;
93157 @@ -1787,7 +1787,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93158 goto next_page;
93159 }
93160
93161 - if (!vma)
93162 + if (!vma || start < vma->vm_start)
93163 goto efault;
93164 vm_flags = vma->vm_flags;
93165 if (vm_flags & (VM_IO | VM_PFNMAP))
93166 @@ -1848,11 +1848,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93167 int ret;
93168 unsigned int fault_flags = 0;
93169
93170 - /* For mlock, just skip the stack guard page. */
93171 - if (foll_flags & FOLL_MLOCK) {
93172 - if (stack_guard_page(vma, start))
93173 - goto next_page;
93174 - }
93175 if (foll_flags & FOLL_WRITE)
93176 fault_flags |= FAULT_FLAG_WRITE;
93177 if (nonblocking)
93178 @@ -1932,7 +1927,7 @@ next_page:
93179 start += page_increm * PAGE_SIZE;
93180 nr_pages -= page_increm;
93181 } while (nr_pages && start < vma->vm_end);
93182 - } while (nr_pages);
93183 + }
93184 return i;
93185 efault:
93186 return i ? : -EFAULT;
93187 @@ -2145,6 +2140,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
93188 page_add_file_rmap(page);
93189 set_pte_at(mm, addr, pte, mk_pte(page, prot));
93190
93191 +#ifdef CONFIG_PAX_SEGMEXEC
93192 + pax_mirror_file_pte(vma, addr, page, ptl);
93193 +#endif
93194 +
93195 retval = 0;
93196 pte_unmap_unlock(pte, ptl);
93197 return retval;
93198 @@ -2189,9 +2188,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
93199 if (!page_count(page))
93200 return -EINVAL;
93201 if (!(vma->vm_flags & VM_MIXEDMAP)) {
93202 +
93203 +#ifdef CONFIG_PAX_SEGMEXEC
93204 + struct vm_area_struct *vma_m;
93205 +#endif
93206 +
93207 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
93208 BUG_ON(vma->vm_flags & VM_PFNMAP);
93209 vma->vm_flags |= VM_MIXEDMAP;
93210 +
93211 +#ifdef CONFIG_PAX_SEGMEXEC
93212 + vma_m = pax_find_mirror_vma(vma);
93213 + if (vma_m)
93214 + vma_m->vm_flags |= VM_MIXEDMAP;
93215 +#endif
93216 +
93217 }
93218 return insert_page(vma, addr, page, vma->vm_page_prot);
93219 }
93220 @@ -2274,6 +2285,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
93221 unsigned long pfn)
93222 {
93223 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
93224 + BUG_ON(vma->vm_mirror);
93225
93226 if (addr < vma->vm_start || addr >= vma->vm_end)
93227 return -EFAULT;
93228 @@ -2521,7 +2533,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
93229
93230 BUG_ON(pud_huge(*pud));
93231
93232 - pmd = pmd_alloc(mm, pud, addr);
93233 + pmd = (mm == &init_mm) ?
93234 + pmd_alloc_kernel(mm, pud, addr) :
93235 + pmd_alloc(mm, pud, addr);
93236 if (!pmd)
93237 return -ENOMEM;
93238 do {
93239 @@ -2541,7 +2555,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
93240 unsigned long next;
93241 int err;
93242
93243 - pud = pud_alloc(mm, pgd, addr);
93244 + pud = (mm == &init_mm) ?
93245 + pud_alloc_kernel(mm, pgd, addr) :
93246 + pud_alloc(mm, pgd, addr);
93247 if (!pud)
93248 return -ENOMEM;
93249 do {
93250 @@ -2663,6 +2679,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
93251 return ret;
93252 }
93253
93254 +#ifdef CONFIG_PAX_SEGMEXEC
93255 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
93256 +{
93257 + struct mm_struct *mm = vma->vm_mm;
93258 + spinlock_t *ptl;
93259 + pte_t *pte, entry;
93260 +
93261 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
93262 + entry = *pte;
93263 + if (!pte_present(entry)) {
93264 + if (!pte_none(entry)) {
93265 + BUG_ON(pte_file(entry));
93266 + free_swap_and_cache(pte_to_swp_entry(entry));
93267 + pte_clear_not_present_full(mm, address, pte, 0);
93268 + }
93269 + } else {
93270 + struct page *page;
93271 +
93272 + flush_cache_page(vma, address, pte_pfn(entry));
93273 + entry = ptep_clear_flush(vma, address, pte);
93274 + BUG_ON(pte_dirty(entry));
93275 + page = vm_normal_page(vma, address, entry);
93276 + if (page) {
93277 + update_hiwater_rss(mm);
93278 + if (PageAnon(page))
93279 + dec_mm_counter_fast(mm, MM_ANONPAGES);
93280 + else
93281 + dec_mm_counter_fast(mm, MM_FILEPAGES);
93282 + page_remove_rmap(page);
93283 + page_cache_release(page);
93284 + }
93285 + }
93286 + pte_unmap_unlock(pte, ptl);
93287 +}
93288 +
93289 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
93290 + *
93291 + * the ptl of the lower mapped page is held on entry and is not released on exit
93292 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
93293 + */
93294 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93295 +{
93296 + struct mm_struct *mm = vma->vm_mm;
93297 + unsigned long address_m;
93298 + spinlock_t *ptl_m;
93299 + struct vm_area_struct *vma_m;
93300 + pmd_t *pmd_m;
93301 + pte_t *pte_m, entry_m;
93302 +
93303 + BUG_ON(!page_m || !PageAnon(page_m));
93304 +
93305 + vma_m = pax_find_mirror_vma(vma);
93306 + if (!vma_m)
93307 + return;
93308 +
93309 + BUG_ON(!PageLocked(page_m));
93310 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93311 + address_m = address + SEGMEXEC_TASK_SIZE;
93312 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93313 + pte_m = pte_offset_map(pmd_m, address_m);
93314 + ptl_m = pte_lockptr(mm, pmd_m);
93315 + if (ptl != ptl_m) {
93316 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93317 + if (!pte_none(*pte_m))
93318 + goto out;
93319 + }
93320 +
93321 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93322 + page_cache_get(page_m);
93323 + page_add_anon_rmap(page_m, vma_m, address_m);
93324 + inc_mm_counter_fast(mm, MM_ANONPAGES);
93325 + set_pte_at(mm, address_m, pte_m, entry_m);
93326 + update_mmu_cache(vma_m, address_m, pte_m);
93327 +out:
93328 + if (ptl != ptl_m)
93329 + spin_unlock(ptl_m);
93330 + pte_unmap(pte_m);
93331 + unlock_page(page_m);
93332 +}
93333 +
93334 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93335 +{
93336 + struct mm_struct *mm = vma->vm_mm;
93337 + unsigned long address_m;
93338 + spinlock_t *ptl_m;
93339 + struct vm_area_struct *vma_m;
93340 + pmd_t *pmd_m;
93341 + pte_t *pte_m, entry_m;
93342 +
93343 + BUG_ON(!page_m || PageAnon(page_m));
93344 +
93345 + vma_m = pax_find_mirror_vma(vma);
93346 + if (!vma_m)
93347 + return;
93348 +
93349 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93350 + address_m = address + SEGMEXEC_TASK_SIZE;
93351 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93352 + pte_m = pte_offset_map(pmd_m, address_m);
93353 + ptl_m = pte_lockptr(mm, pmd_m);
93354 + if (ptl != ptl_m) {
93355 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93356 + if (!pte_none(*pte_m))
93357 + goto out;
93358 + }
93359 +
93360 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93361 + page_cache_get(page_m);
93362 + page_add_file_rmap(page_m);
93363 + inc_mm_counter_fast(mm, MM_FILEPAGES);
93364 + set_pte_at(mm, address_m, pte_m, entry_m);
93365 + update_mmu_cache(vma_m, address_m, pte_m);
93366 +out:
93367 + if (ptl != ptl_m)
93368 + spin_unlock(ptl_m);
93369 + pte_unmap(pte_m);
93370 +}
93371 +
93372 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
93373 +{
93374 + struct mm_struct *mm = vma->vm_mm;
93375 + unsigned long address_m;
93376 + spinlock_t *ptl_m;
93377 + struct vm_area_struct *vma_m;
93378 + pmd_t *pmd_m;
93379 + pte_t *pte_m, entry_m;
93380 +
93381 + vma_m = pax_find_mirror_vma(vma);
93382 + if (!vma_m)
93383 + return;
93384 +
93385 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93386 + address_m = address + SEGMEXEC_TASK_SIZE;
93387 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93388 + pte_m = pte_offset_map(pmd_m, address_m);
93389 + ptl_m = pte_lockptr(mm, pmd_m);
93390 + if (ptl != ptl_m) {
93391 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93392 + if (!pte_none(*pte_m))
93393 + goto out;
93394 + }
93395 +
93396 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
93397 + set_pte_at(mm, address_m, pte_m, entry_m);
93398 +out:
93399 + if (ptl != ptl_m)
93400 + spin_unlock(ptl_m);
93401 + pte_unmap(pte_m);
93402 +}
93403 +
93404 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93405 +{
93406 + struct page *page_m;
93407 + pte_t entry;
93408 +
93409 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93410 + goto out;
93411 +
93412 + entry = *pte;
93413 + page_m = vm_normal_page(vma, address, entry);
93414 + if (!page_m)
93415 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93416 + else if (PageAnon(page_m)) {
93417 + if (pax_find_mirror_vma(vma)) {
93418 + pte_unmap_unlock(pte, ptl);
93419 + lock_page(page_m);
93420 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93421 + if (pte_same(entry, *pte))
93422 + pax_mirror_anon_pte(vma, address, page_m, ptl);
93423 + else
93424 + unlock_page(page_m);
93425 + }
93426 + } else
93427 + pax_mirror_file_pte(vma, address, page_m, ptl);
93428 +
93429 +out:
93430 + pte_unmap_unlock(pte, ptl);
93431 +}
93432 +#endif
93433 +
93434 /*
93435 * This routine handles present pages, when users try to write
93436 * to a shared page. It is done by copying the page to a new address
93437 @@ -2860,6 +3056,12 @@ gotten:
93438 */
93439 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93440 if (likely(pte_same(*page_table, orig_pte))) {
93441 +
93442 +#ifdef CONFIG_PAX_SEGMEXEC
93443 + if (pax_find_mirror_vma(vma))
93444 + BUG_ON(!trylock_page(new_page));
93445 +#endif
93446 +
93447 if (old_page) {
93448 if (!PageAnon(old_page)) {
93449 dec_mm_counter_fast(mm, MM_FILEPAGES);
93450 @@ -2911,6 +3113,10 @@ gotten:
93451 page_remove_rmap(old_page);
93452 }
93453
93454 +#ifdef CONFIG_PAX_SEGMEXEC
93455 + pax_mirror_anon_pte(vma, address, new_page, ptl);
93456 +#endif
93457 +
93458 /* Free the old page.. */
93459 new_page = old_page;
93460 ret |= VM_FAULT_WRITE;
93461 @@ -3184,6 +3390,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93462 swap_free(entry);
93463 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93464 try_to_free_swap(page);
93465 +
93466 +#ifdef CONFIG_PAX_SEGMEXEC
93467 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93468 +#endif
93469 +
93470 unlock_page(page);
93471 if (page != swapcache) {
93472 /*
93473 @@ -3207,6 +3418,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93474
93475 /* No need to invalidate - it was non-present before */
93476 update_mmu_cache(vma, address, page_table);
93477 +
93478 +#ifdef CONFIG_PAX_SEGMEXEC
93479 + pax_mirror_anon_pte(vma, address, page, ptl);
93480 +#endif
93481 +
93482 unlock:
93483 pte_unmap_unlock(page_table, ptl);
93484 out:
93485 @@ -3226,40 +3442,6 @@ out_release:
93486 }
93487
93488 /*
93489 - * This is like a special single-page "expand_{down|up}wards()",
93490 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
93491 - * doesn't hit another vma.
93492 - */
93493 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93494 -{
93495 - address &= PAGE_MASK;
93496 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93497 - struct vm_area_struct *prev = vma->vm_prev;
93498 -
93499 - /*
93500 - * Is there a mapping abutting this one below?
93501 - *
93502 - * That's only ok if it's the same stack mapping
93503 - * that has gotten split..
93504 - */
93505 - if (prev && prev->vm_end == address)
93506 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93507 -
93508 - expand_downwards(vma, address - PAGE_SIZE);
93509 - }
93510 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93511 - struct vm_area_struct *next = vma->vm_next;
93512 -
93513 - /* As VM_GROWSDOWN but s/below/above/ */
93514 - if (next && next->vm_start == address + PAGE_SIZE)
93515 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93516 -
93517 - expand_upwards(vma, address + PAGE_SIZE);
93518 - }
93519 - return 0;
93520 -}
93521 -
93522 -/*
93523 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93524 * but allow concurrent faults), and pte mapped but not yet locked.
93525 * We return with mmap_sem still held, but pte unmapped and unlocked.
93526 @@ -3268,27 +3450,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93527 unsigned long address, pte_t *page_table, pmd_t *pmd,
93528 unsigned int flags)
93529 {
93530 - struct page *page;
93531 + struct page *page = NULL;
93532 spinlock_t *ptl;
93533 pte_t entry;
93534
93535 - pte_unmap(page_table);
93536 -
93537 - /* Check if we need to add a guard page to the stack */
93538 - if (check_stack_guard_page(vma, address) < 0)
93539 - return VM_FAULT_SIGBUS;
93540 -
93541 - /* Use the zero-page for reads */
93542 if (!(flags & FAULT_FLAG_WRITE)) {
93543 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93544 vma->vm_page_prot));
93545 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93546 + ptl = pte_lockptr(mm, pmd);
93547 + spin_lock(ptl);
93548 if (!pte_none(*page_table))
93549 goto unlock;
93550 goto setpte;
93551 }
93552
93553 /* Allocate our own private page. */
93554 + pte_unmap(page_table);
93555 +
93556 if (unlikely(anon_vma_prepare(vma)))
93557 goto oom;
93558 page = alloc_zeroed_user_highpage_movable(vma, address);
93559 @@ -3312,6 +3490,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93560 if (!pte_none(*page_table))
93561 goto release;
93562
93563 +#ifdef CONFIG_PAX_SEGMEXEC
93564 + if (pax_find_mirror_vma(vma))
93565 + BUG_ON(!trylock_page(page));
93566 +#endif
93567 +
93568 inc_mm_counter_fast(mm, MM_ANONPAGES);
93569 page_add_new_anon_rmap(page, vma, address);
93570 setpte:
93571 @@ -3319,6 +3502,12 @@ setpte:
93572
93573 /* No need to invalidate - it was non-present before */
93574 update_mmu_cache(vma, address, page_table);
93575 +
93576 +#ifdef CONFIG_PAX_SEGMEXEC
93577 + if (page)
93578 + pax_mirror_anon_pte(vma, address, page, ptl);
93579 +#endif
93580 +
93581 unlock:
93582 pte_unmap_unlock(page_table, ptl);
93583 return 0;
93584 @@ -3515,7 +3704,8 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93585 * if page by the offset is not ready to be mapped (cold cache or
93586 * something).
93587 */
93588 - if (vma->vm_ops->map_pages) {
93589 + if (vma->vm_ops->map_pages && !(flags & FAULT_FLAG_NONLINEAR) &&
93590 + fault_around_pages() > 1) {
93591 pte = pte_offset_map_lock(mm, pmd, address, &ptl);
93592 do_fault_around(vma, address, pte, pgoff, flags);
93593 if (!pte_same(*pte, orig_pte))
93594 @@ -3535,6 +3725,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93595 return ret;
93596 }
93597 do_set_pte(vma, address, fault_page, pte, false, false);
93598 +
93599 +#ifdef CONFIG_PAX_SEGMEXEC
93600 + pax_mirror_file_pte(vma, address, fault_page, ptl);
93601 +#endif
93602 +
93603 unlock_page(fault_page);
93604 unlock_out:
93605 pte_unmap_unlock(pte, ptl);
93606 @@ -3576,7 +3771,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93607 page_cache_release(fault_page);
93608 goto uncharge_out;
93609 }
93610 +
93611 +#ifdef CONFIG_PAX_SEGMEXEC
93612 + if (pax_find_mirror_vma(vma))
93613 + BUG_ON(!trylock_page(new_page));
93614 +#endif
93615 +
93616 do_set_pte(vma, address, new_page, pte, true, true);
93617 +
93618 +#ifdef CONFIG_PAX_SEGMEXEC
93619 + pax_mirror_anon_pte(vma, address, new_page, ptl);
93620 +#endif
93621 +
93622 pte_unmap_unlock(pte, ptl);
93623 unlock_page(fault_page);
93624 page_cache_release(fault_page);
93625 @@ -3624,6 +3830,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93626 return ret;
93627 }
93628 do_set_pte(vma, address, fault_page, pte, true, false);
93629 +
93630 +#ifdef CONFIG_PAX_SEGMEXEC
93631 + pax_mirror_file_pte(vma, address, fault_page, ptl);
93632 +#endif
93633 +
93634 pte_unmap_unlock(pte, ptl);
93635
93636 if (set_page_dirty(fault_page))
93637 @@ -3854,6 +4065,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93638 if (flags & FAULT_FLAG_WRITE)
93639 flush_tlb_fix_spurious_fault(vma, address);
93640 }
93641 +
93642 +#ifdef CONFIG_PAX_SEGMEXEC
93643 + pax_mirror_pte(vma, address, pte, pmd, ptl);
93644 + return 0;
93645 +#endif
93646 +
93647 unlock:
93648 pte_unmap_unlock(pte, ptl);
93649 return 0;
93650 @@ -3870,9 +4087,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93651 pmd_t *pmd;
93652 pte_t *pte;
93653
93654 +#ifdef CONFIG_PAX_SEGMEXEC
93655 + struct vm_area_struct *vma_m;
93656 +#endif
93657 +
93658 if (unlikely(is_vm_hugetlb_page(vma)))
93659 return hugetlb_fault(mm, vma, address, flags);
93660
93661 +#ifdef CONFIG_PAX_SEGMEXEC
93662 + vma_m = pax_find_mirror_vma(vma);
93663 + if (vma_m) {
93664 + unsigned long address_m;
93665 + pgd_t *pgd_m;
93666 + pud_t *pud_m;
93667 + pmd_t *pmd_m;
93668 +
93669 + if (vma->vm_start > vma_m->vm_start) {
93670 + address_m = address;
93671 + address -= SEGMEXEC_TASK_SIZE;
93672 + vma = vma_m;
93673 + } else
93674 + address_m = address + SEGMEXEC_TASK_SIZE;
93675 +
93676 + pgd_m = pgd_offset(mm, address_m);
93677 + pud_m = pud_alloc(mm, pgd_m, address_m);
93678 + if (!pud_m)
93679 + return VM_FAULT_OOM;
93680 + pmd_m = pmd_alloc(mm, pud_m, address_m);
93681 + if (!pmd_m)
93682 + return VM_FAULT_OOM;
93683 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
93684 + return VM_FAULT_OOM;
93685 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
93686 + }
93687 +#endif
93688 +
93689 pgd = pgd_offset(mm, address);
93690 pud = pud_alloc(mm, pgd, address);
93691 if (!pud)
93692 @@ -4000,6 +4249,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93693 spin_unlock(&mm->page_table_lock);
93694 return 0;
93695 }
93696 +
93697 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93698 +{
93699 + pud_t *new = pud_alloc_one(mm, address);
93700 + if (!new)
93701 + return -ENOMEM;
93702 +
93703 + smp_wmb(); /* See comment in __pte_alloc */
93704 +
93705 + spin_lock(&mm->page_table_lock);
93706 + if (pgd_present(*pgd)) /* Another has populated it */
93707 + pud_free(mm, new);
93708 + else
93709 + pgd_populate_kernel(mm, pgd, new);
93710 + spin_unlock(&mm->page_table_lock);
93711 + return 0;
93712 +}
93713 #endif /* __PAGETABLE_PUD_FOLDED */
93714
93715 #ifndef __PAGETABLE_PMD_FOLDED
93716 @@ -4030,6 +4296,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
93717 spin_unlock(&mm->page_table_lock);
93718 return 0;
93719 }
93720 +
93721 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
93722 +{
93723 + pmd_t *new = pmd_alloc_one(mm, address);
93724 + if (!new)
93725 + return -ENOMEM;
93726 +
93727 + smp_wmb(); /* See comment in __pte_alloc */
93728 +
93729 + spin_lock(&mm->page_table_lock);
93730 +#ifndef __ARCH_HAS_4LEVEL_HACK
93731 + if (pud_present(*pud)) /* Another has populated it */
93732 + pmd_free(mm, new);
93733 + else
93734 + pud_populate_kernel(mm, pud, new);
93735 +#else
93736 + if (pgd_present(*pud)) /* Another has populated it */
93737 + pmd_free(mm, new);
93738 + else
93739 + pgd_populate_kernel(mm, pud, new);
93740 +#endif /* __ARCH_HAS_4LEVEL_HACK */
93741 + spin_unlock(&mm->page_table_lock);
93742 + return 0;
93743 +}
93744 #endif /* __PAGETABLE_PMD_FOLDED */
93745
93746 #if !defined(__HAVE_ARCH_GATE_AREA)
93747 @@ -4043,7 +4333,7 @@ static int __init gate_vma_init(void)
93748 gate_vma.vm_start = FIXADDR_USER_START;
93749 gate_vma.vm_end = FIXADDR_USER_END;
93750 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93751 - gate_vma.vm_page_prot = __P101;
93752 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93753
93754 return 0;
93755 }
93756 @@ -4177,8 +4467,8 @@ out:
93757 return ret;
93758 }
93759
93760 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93761 - void *buf, int len, int write)
93762 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93763 + void *buf, size_t len, int write)
93764 {
93765 resource_size_t phys_addr;
93766 unsigned long prot = 0;
93767 @@ -4204,8 +4494,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93768 * Access another process' address space as given in mm. If non-NULL, use the
93769 * given task for page fault accounting.
93770 */
93771 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93772 - unsigned long addr, void *buf, int len, int write)
93773 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93774 + unsigned long addr, void *buf, size_t len, int write)
93775 {
93776 struct vm_area_struct *vma;
93777 void *old_buf = buf;
93778 @@ -4213,7 +4503,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93779 down_read(&mm->mmap_sem);
93780 /* ignore errors, just check how much was successfully transferred */
93781 while (len) {
93782 - int bytes, ret, offset;
93783 + ssize_t bytes, ret, offset;
93784 void *maddr;
93785 struct page *page = NULL;
93786
93787 @@ -4272,8 +4562,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93788 *
93789 * The caller must hold a reference on @mm.
93790 */
93791 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93792 - void *buf, int len, int write)
93793 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93794 + void *buf, size_t len, int write)
93795 {
93796 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93797 }
93798 @@ -4283,11 +4573,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93799 * Source/target buffer must be kernel space,
93800 * Do not walk the page table directly, use get_user_pages
93801 */
93802 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
93803 - void *buf, int len, int write)
93804 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93805 + void *buf, size_t len, int write)
93806 {
93807 struct mm_struct *mm;
93808 - int ret;
93809 + ssize_t ret;
93810
93811 mm = get_task_mm(tsk);
93812 if (!mm)
93813 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93814 index 6b65d10..e6f415a 100644
93815 --- a/mm/mempolicy.c
93816 +++ b/mm/mempolicy.c
93817 @@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93818 unsigned long vmstart;
93819 unsigned long vmend;
93820
93821 +#ifdef CONFIG_PAX_SEGMEXEC
93822 + struct vm_area_struct *vma_m;
93823 +#endif
93824 +
93825 vma = find_vma(mm, start);
93826 if (!vma || vma->vm_start > start)
93827 return -EFAULT;
93828 @@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93829 err = vma_replace_policy(vma, new_pol);
93830 if (err)
93831 goto out;
93832 +
93833 +#ifdef CONFIG_PAX_SEGMEXEC
93834 + vma_m = pax_find_mirror_vma(vma);
93835 + if (vma_m) {
93836 + err = vma_replace_policy(vma_m, new_pol);
93837 + if (err)
93838 + goto out;
93839 + }
93840 +#endif
93841 +
93842 }
93843
93844 out:
93845 @@ -1222,6 +1236,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93846
93847 if (end < start)
93848 return -EINVAL;
93849 +
93850 +#ifdef CONFIG_PAX_SEGMEXEC
93851 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93852 + if (end > SEGMEXEC_TASK_SIZE)
93853 + return -EINVAL;
93854 + } else
93855 +#endif
93856 +
93857 + if (end > TASK_SIZE)
93858 + return -EINVAL;
93859 +
93860 if (end == start)
93861 return 0;
93862
93863 @@ -1447,8 +1472,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93864 */
93865 tcred = __task_cred(task);
93866 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93867 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93868 - !capable(CAP_SYS_NICE)) {
93869 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93870 rcu_read_unlock();
93871 err = -EPERM;
93872 goto out_put;
93873 @@ -1479,6 +1503,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93874 goto out;
93875 }
93876
93877 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93878 + if (mm != current->mm &&
93879 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93880 + mmput(mm);
93881 + err = -EPERM;
93882 + goto out;
93883 + }
93884 +#endif
93885 +
93886 err = do_migrate_pages(mm, old, new,
93887 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93888
93889 diff --git a/mm/migrate.c b/mm/migrate.c
93890 index bed4880..a493f67 100644
93891 --- a/mm/migrate.c
93892 +++ b/mm/migrate.c
93893 @@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93894 */
93895 tcred = __task_cred(task);
93896 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93897 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93898 - !capable(CAP_SYS_NICE)) {
93899 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93900 rcu_read_unlock();
93901 err = -EPERM;
93902 goto out;
93903 diff --git a/mm/mlock.c b/mm/mlock.c
93904 index b1eb536..091d154 100644
93905 --- a/mm/mlock.c
93906 +++ b/mm/mlock.c
93907 @@ -14,6 +14,7 @@
93908 #include <linux/pagevec.h>
93909 #include <linux/mempolicy.h>
93910 #include <linux/syscalls.h>
93911 +#include <linux/security.h>
93912 #include <linux/sched.h>
93913 #include <linux/export.h>
93914 #include <linux/rmap.h>
93915 @@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93916 {
93917 unsigned long nstart, end, tmp;
93918 struct vm_area_struct * vma, * prev;
93919 - int error;
93920 + int error = 0;
93921
93922 VM_BUG_ON(start & ~PAGE_MASK);
93923 VM_BUG_ON(len != PAGE_ALIGN(len));
93924 @@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93925 return -EINVAL;
93926 if (end == start)
93927 return 0;
93928 + if (end > TASK_SIZE)
93929 + return -EINVAL;
93930 +
93931 vma = find_vma(current->mm, start);
93932 if (!vma || vma->vm_start > start)
93933 return -ENOMEM;
93934 @@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
93935 for (nstart = start ; ; ) {
93936 vm_flags_t newflags;
93937
93938 +#ifdef CONFIG_PAX_SEGMEXEC
93939 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93940 + break;
93941 +#endif
93942 +
93943 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
93944
93945 newflags = vma->vm_flags & ~VM_LOCKED;
93946 @@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93947 locked += current->mm->locked_vm;
93948
93949 /* check against resource limits */
93950 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93951 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93952 error = do_mlock(start, len, 1);
93953
93954 @@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93955 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93956 vm_flags_t newflags;
93957
93958 +#ifdef CONFIG_PAX_SEGMEXEC
93959 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93960 + break;
93961 +#endif
93962 +
93963 newflags = vma->vm_flags & ~VM_LOCKED;
93964 if (flags & MCL_CURRENT)
93965 newflags |= VM_LOCKED;
93966 @@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93967 lock_limit >>= PAGE_SHIFT;
93968
93969 ret = -ENOMEM;
93970 +
93971 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93972 +
93973 down_write(&current->mm->mmap_sem);
93974 -
93975 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93976 capable(CAP_IPC_LOCK))
93977 ret = do_mlockall(flags);
93978 diff --git a/mm/mmap.c b/mm/mmap.c
93979 index b1202cf..ee487f8 100644
93980 --- a/mm/mmap.c
93981 +++ b/mm/mmap.c
93982 @@ -37,6 +37,7 @@
93983 #include <linux/sched/sysctl.h>
93984 #include <linux/notifier.h>
93985 #include <linux/memory.h>
93986 +#include <linux/random.h>
93987
93988 #include <asm/uaccess.h>
93989 #include <asm/cacheflush.h>
93990 @@ -53,6 +54,16 @@
93991 #define arch_rebalance_pgtables(addr, len) (addr)
93992 #endif
93993
93994 +static inline void verify_mm_writelocked(struct mm_struct *mm)
93995 +{
93996 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93997 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93998 + up_read(&mm->mmap_sem);
93999 + BUG();
94000 + }
94001 +#endif
94002 +}
94003 +
94004 static void unmap_region(struct mm_struct *mm,
94005 struct vm_area_struct *vma, struct vm_area_struct *prev,
94006 unsigned long start, unsigned long end);
94007 @@ -72,16 +83,25 @@ static void unmap_region(struct mm_struct *mm,
94008 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
94009 *
94010 */
94011 -pgprot_t protection_map[16] = {
94012 +pgprot_t protection_map[16] __read_only = {
94013 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
94014 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
94015 };
94016
94017 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
94018 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
94019 {
94020 - return __pgprot(pgprot_val(protection_map[vm_flags &
94021 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
94022 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
94023 pgprot_val(arch_vm_get_page_prot(vm_flags)));
94024 +
94025 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94026 + if (!(__supported_pte_mask & _PAGE_NX) &&
94027 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
94028 + (vm_flags & (VM_READ | VM_WRITE)))
94029 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
94030 +#endif
94031 +
94032 + return prot;
94033 }
94034 EXPORT_SYMBOL(vm_get_page_prot);
94035
94036 @@ -91,6 +111,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
94037 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
94038 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94039 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94040 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
94041 /*
94042 * Make sure vm_committed_as in one cacheline and not cacheline shared with
94043 * other variables. It can be updated by several CPUs frequently.
94044 @@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
94045 struct vm_area_struct *next = vma->vm_next;
94046
94047 might_sleep();
94048 + BUG_ON(vma->vm_mirror);
94049 if (vma->vm_ops && vma->vm_ops->close)
94050 vma->vm_ops->close(vma);
94051 if (vma->vm_file)
94052 @@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
94053 * not page aligned -Ram Gupta
94054 */
94055 rlim = rlimit(RLIMIT_DATA);
94056 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
94057 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
94058 (mm->end_data - mm->start_data) > rlim)
94059 goto out;
94060 @@ -942,6 +965,12 @@ static int
94061 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
94062 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
94063 {
94064 +
94065 +#ifdef CONFIG_PAX_SEGMEXEC
94066 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
94067 + return 0;
94068 +#endif
94069 +
94070 if (is_mergeable_vma(vma, file, vm_flags) &&
94071 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
94072 if (vma->vm_pgoff == vm_pgoff)
94073 @@ -961,6 +990,12 @@ static int
94074 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
94075 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
94076 {
94077 +
94078 +#ifdef CONFIG_PAX_SEGMEXEC
94079 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
94080 + return 0;
94081 +#endif
94082 +
94083 if (is_mergeable_vma(vma, file, vm_flags) &&
94084 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
94085 pgoff_t vm_pglen;
94086 @@ -1003,13 +1038,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
94087 struct vm_area_struct *vma_merge(struct mm_struct *mm,
94088 struct vm_area_struct *prev, unsigned long addr,
94089 unsigned long end, unsigned long vm_flags,
94090 - struct anon_vma *anon_vma, struct file *file,
94091 + struct anon_vma *anon_vma, struct file *file,
94092 pgoff_t pgoff, struct mempolicy *policy)
94093 {
94094 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
94095 struct vm_area_struct *area, *next;
94096 int err;
94097
94098 +#ifdef CONFIG_PAX_SEGMEXEC
94099 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
94100 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
94101 +
94102 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
94103 +#endif
94104 +
94105 /*
94106 * We later require that vma->vm_flags == vm_flags,
94107 * so this tests vma->vm_flags & VM_SPECIAL, too.
94108 @@ -1025,6 +1067,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94109 if (next && next->vm_end == end) /* cases 6, 7, 8 */
94110 next = next->vm_next;
94111
94112 +#ifdef CONFIG_PAX_SEGMEXEC
94113 + if (prev)
94114 + prev_m = pax_find_mirror_vma(prev);
94115 + if (area)
94116 + area_m = pax_find_mirror_vma(area);
94117 + if (next)
94118 + next_m = pax_find_mirror_vma(next);
94119 +#endif
94120 +
94121 /*
94122 * Can it merge with the predecessor?
94123 */
94124 @@ -1044,9 +1095,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94125 /* cases 1, 6 */
94126 err = vma_adjust(prev, prev->vm_start,
94127 next->vm_end, prev->vm_pgoff, NULL);
94128 - } else /* cases 2, 5, 7 */
94129 +
94130 +#ifdef CONFIG_PAX_SEGMEXEC
94131 + if (!err && prev_m)
94132 + err = vma_adjust(prev_m, prev_m->vm_start,
94133 + next_m->vm_end, prev_m->vm_pgoff, NULL);
94134 +#endif
94135 +
94136 + } else { /* cases 2, 5, 7 */
94137 err = vma_adjust(prev, prev->vm_start,
94138 end, prev->vm_pgoff, NULL);
94139 +
94140 +#ifdef CONFIG_PAX_SEGMEXEC
94141 + if (!err && prev_m)
94142 + err = vma_adjust(prev_m, prev_m->vm_start,
94143 + end_m, prev_m->vm_pgoff, NULL);
94144 +#endif
94145 +
94146 + }
94147 if (err)
94148 return NULL;
94149 khugepaged_enter_vma_merge(prev);
94150 @@ -1060,12 +1126,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94151 mpol_equal(policy, vma_policy(next)) &&
94152 can_vma_merge_before(next, vm_flags,
94153 anon_vma, file, pgoff+pglen)) {
94154 - if (prev && addr < prev->vm_end) /* case 4 */
94155 + if (prev && addr < prev->vm_end) { /* case 4 */
94156 err = vma_adjust(prev, prev->vm_start,
94157 addr, prev->vm_pgoff, NULL);
94158 - else /* cases 3, 8 */
94159 +
94160 +#ifdef CONFIG_PAX_SEGMEXEC
94161 + if (!err && prev_m)
94162 + err = vma_adjust(prev_m, prev_m->vm_start,
94163 + addr_m, prev_m->vm_pgoff, NULL);
94164 +#endif
94165 +
94166 + } else { /* cases 3, 8 */
94167 err = vma_adjust(area, addr, next->vm_end,
94168 next->vm_pgoff - pglen, NULL);
94169 +
94170 +#ifdef CONFIG_PAX_SEGMEXEC
94171 + if (!err && area_m)
94172 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
94173 + next_m->vm_pgoff - pglen, NULL);
94174 +#endif
94175 +
94176 + }
94177 if (err)
94178 return NULL;
94179 khugepaged_enter_vma_merge(area);
94180 @@ -1174,8 +1255,10 @@ none:
94181 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
94182 struct file *file, long pages)
94183 {
94184 - const unsigned long stack_flags
94185 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
94186 +
94187 +#ifdef CONFIG_PAX_RANDMMAP
94188 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94189 +#endif
94190
94191 mm->total_vm += pages;
94192
94193 @@ -1183,7 +1266,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
94194 mm->shared_vm += pages;
94195 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
94196 mm->exec_vm += pages;
94197 - } else if (flags & stack_flags)
94198 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
94199 mm->stack_vm += pages;
94200 }
94201 #endif /* CONFIG_PROC_FS */
94202 @@ -1213,6 +1296,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
94203 locked += mm->locked_vm;
94204 lock_limit = rlimit(RLIMIT_MEMLOCK);
94205 lock_limit >>= PAGE_SHIFT;
94206 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94207 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
94208 return -EAGAIN;
94209 }
94210 @@ -1239,7 +1323,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94211 * (the exception is when the underlying filesystem is noexec
94212 * mounted, in which case we dont add PROT_EXEC.)
94213 */
94214 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94215 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94216 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
94217 prot |= PROT_EXEC;
94218
94219 @@ -1265,7 +1349,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94220 /* Obtain the address to map to. we verify (or select) it and ensure
94221 * that it represents a valid section of the address space.
94222 */
94223 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
94224 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
94225 if (addr & ~PAGE_MASK)
94226 return addr;
94227
94228 @@ -1276,6 +1360,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94229 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
94230 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
94231
94232 +#ifdef CONFIG_PAX_MPROTECT
94233 + if (mm->pax_flags & MF_PAX_MPROTECT) {
94234 +
94235 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
94236 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
94237 + mm->binfmt->handle_mmap)
94238 + mm->binfmt->handle_mmap(file);
94239 +#endif
94240 +
94241 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
94242 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
94243 + gr_log_rwxmmap(file);
94244 +
94245 +#ifdef CONFIG_PAX_EMUPLT
94246 + vm_flags &= ~VM_EXEC;
94247 +#else
94248 + return -EPERM;
94249 +#endif
94250 +
94251 + }
94252 +
94253 + if (!(vm_flags & VM_EXEC))
94254 + vm_flags &= ~VM_MAYEXEC;
94255 +#else
94256 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94257 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94258 +#endif
94259 + else
94260 + vm_flags &= ~VM_MAYWRITE;
94261 + }
94262 +#endif
94263 +
94264 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94265 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
94266 + vm_flags &= ~VM_PAGEEXEC;
94267 +#endif
94268 +
94269 if (flags & MAP_LOCKED)
94270 if (!can_do_mlock())
94271 return -EPERM;
94272 @@ -1363,6 +1484,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94273 vm_flags |= VM_NORESERVE;
94274 }
94275
94276 + if (!gr_acl_handle_mmap(file, prot))
94277 + return -EACCES;
94278 +
94279 addr = mmap_region(file, addr, len, vm_flags, pgoff);
94280 if (!IS_ERR_VALUE(addr) &&
94281 ((vm_flags & VM_LOCKED) ||
94282 @@ -1456,7 +1580,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
94283 vm_flags_t vm_flags = vma->vm_flags;
94284
94285 /* If it was private or non-writable, the write bit is already clear */
94286 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
94287 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
94288 return 0;
94289
94290 /* The backer wishes to know when pages are first written to? */
94291 @@ -1502,7 +1626,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94292 struct rb_node **rb_link, *rb_parent;
94293 unsigned long charged = 0;
94294
94295 +#ifdef CONFIG_PAX_SEGMEXEC
94296 + struct vm_area_struct *vma_m = NULL;
94297 +#endif
94298 +
94299 + /*
94300 + * mm->mmap_sem is required to protect against another thread
94301 + * changing the mappings in case we sleep.
94302 + */
94303 + verify_mm_writelocked(mm);
94304 +
94305 /* Check against address space limit. */
94306 +
94307 +#ifdef CONFIG_PAX_RANDMMAP
94308 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94309 +#endif
94310 +
94311 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
94312 unsigned long nr_pages;
94313
94314 @@ -1521,11 +1660,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94315
94316 /* Clear old maps */
94317 error = -ENOMEM;
94318 -munmap_back:
94319 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94320 if (do_munmap(mm, addr, len))
94321 return -ENOMEM;
94322 - goto munmap_back;
94323 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94324 }
94325
94326 /*
94327 @@ -1556,6 +1694,16 @@ munmap_back:
94328 goto unacct_error;
94329 }
94330
94331 +#ifdef CONFIG_PAX_SEGMEXEC
94332 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
94333 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94334 + if (!vma_m) {
94335 + error = -ENOMEM;
94336 + goto free_vma;
94337 + }
94338 + }
94339 +#endif
94340 +
94341 vma->vm_mm = mm;
94342 vma->vm_start = addr;
94343 vma->vm_end = addr + len;
94344 @@ -1575,6 +1723,13 @@ munmap_back:
94345 if (error)
94346 goto unmap_and_free_vma;
94347
94348 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94349 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
94350 + vma->vm_flags |= VM_PAGEEXEC;
94351 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94352 + }
94353 +#endif
94354 +
94355 /* Can addr have changed??
94356 *
94357 * Answer: Yes, several device drivers can do it in their
94358 @@ -1608,6 +1763,12 @@ munmap_back:
94359 }
94360
94361 vma_link(mm, vma, prev, rb_link, rb_parent);
94362 +
94363 +#ifdef CONFIG_PAX_SEGMEXEC
94364 + if (vma_m)
94365 + BUG_ON(pax_mirror_vma(vma_m, vma));
94366 +#endif
94367 +
94368 /* Once vma denies write, undo our temporary denial count */
94369 if (vm_flags & VM_DENYWRITE)
94370 allow_write_access(file);
94371 @@ -1616,6 +1777,7 @@ out:
94372 perf_event_mmap(vma);
94373
94374 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
94375 + track_exec_limit(mm, addr, addr + len, vm_flags);
94376 if (vm_flags & VM_LOCKED) {
94377 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
94378 vma == get_gate_vma(current->mm)))
94379 @@ -1648,6 +1810,12 @@ unmap_and_free_vma:
94380 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
94381 charged = 0;
94382 free_vma:
94383 +
94384 +#ifdef CONFIG_PAX_SEGMEXEC
94385 + if (vma_m)
94386 + kmem_cache_free(vm_area_cachep, vma_m);
94387 +#endif
94388 +
94389 kmem_cache_free(vm_area_cachep, vma);
94390 unacct_error:
94391 if (charged)
94392 @@ -1655,7 +1823,63 @@ unacct_error:
94393 return error;
94394 }
94395
94396 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94397 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
94398 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
94399 +{
94400 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
94401 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
94402 +
94403 + return 0;
94404 +}
94405 +#endif
94406 +
94407 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
94408 +{
94409 + if (!vma) {
94410 +#ifdef CONFIG_STACK_GROWSUP
94411 + if (addr > sysctl_heap_stack_gap)
94412 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
94413 + else
94414 + vma = find_vma(current->mm, 0);
94415 + if (vma && (vma->vm_flags & VM_GROWSUP))
94416 + return false;
94417 +#endif
94418 + return true;
94419 + }
94420 +
94421 + if (addr + len > vma->vm_start)
94422 + return false;
94423 +
94424 + if (vma->vm_flags & VM_GROWSDOWN)
94425 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94426 +#ifdef CONFIG_STACK_GROWSUP
94427 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94428 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94429 +#endif
94430 + else if (offset)
94431 + return offset <= vma->vm_start - addr - len;
94432 +
94433 + return true;
94434 +}
94435 +
94436 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94437 +{
94438 + if (vma->vm_start < len)
94439 + return -ENOMEM;
94440 +
94441 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
94442 + if (offset <= vma->vm_start - len)
94443 + return vma->vm_start - len - offset;
94444 + else
94445 + return -ENOMEM;
94446 + }
94447 +
94448 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
94449 + return vma->vm_start - len - sysctl_heap_stack_gap;
94450 + return -ENOMEM;
94451 +}
94452 +
94453 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94454 {
94455 /*
94456 * We implement the search by looking for an rbtree node that
94457 @@ -1703,11 +1927,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94458 }
94459 }
94460
94461 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94462 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94463 check_current:
94464 /* Check if current node has a suitable gap */
94465 if (gap_start > high_limit)
94466 return -ENOMEM;
94467 +
94468 + if (gap_end - gap_start > info->threadstack_offset)
94469 + gap_start += info->threadstack_offset;
94470 + else
94471 + gap_start = gap_end;
94472 +
94473 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94474 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94475 + gap_start += sysctl_heap_stack_gap;
94476 + else
94477 + gap_start = gap_end;
94478 + }
94479 + if (vma->vm_flags & VM_GROWSDOWN) {
94480 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94481 + gap_end -= sysctl_heap_stack_gap;
94482 + else
94483 + gap_end = gap_start;
94484 + }
94485 if (gap_end >= low_limit && gap_end - gap_start >= length)
94486 goto found;
94487
94488 @@ -1757,7 +1999,7 @@ found:
94489 return gap_start;
94490 }
94491
94492 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94493 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94494 {
94495 struct mm_struct *mm = current->mm;
94496 struct vm_area_struct *vma;
94497 @@ -1811,6 +2053,24 @@ check_current:
94498 gap_end = vma->vm_start;
94499 if (gap_end < low_limit)
94500 return -ENOMEM;
94501 +
94502 + if (gap_end - gap_start > info->threadstack_offset)
94503 + gap_end -= info->threadstack_offset;
94504 + else
94505 + gap_end = gap_start;
94506 +
94507 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94508 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94509 + gap_start += sysctl_heap_stack_gap;
94510 + else
94511 + gap_start = gap_end;
94512 + }
94513 + if (vma->vm_flags & VM_GROWSDOWN) {
94514 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94515 + gap_end -= sysctl_heap_stack_gap;
94516 + else
94517 + gap_end = gap_start;
94518 + }
94519 if (gap_start <= high_limit && gap_end - gap_start >= length)
94520 goto found;
94521
94522 @@ -1874,6 +2134,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94523 struct mm_struct *mm = current->mm;
94524 struct vm_area_struct *vma;
94525 struct vm_unmapped_area_info info;
94526 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94527
94528 if (len > TASK_SIZE - mmap_min_addr)
94529 return -ENOMEM;
94530 @@ -1881,11 +2142,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94531 if (flags & MAP_FIXED)
94532 return addr;
94533
94534 +#ifdef CONFIG_PAX_RANDMMAP
94535 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94536 +#endif
94537 +
94538 if (addr) {
94539 addr = PAGE_ALIGN(addr);
94540 vma = find_vma(mm, addr);
94541 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94542 - (!vma || addr + len <= vma->vm_start))
94543 + check_heap_stack_gap(vma, addr, len, offset))
94544 return addr;
94545 }
94546
94547 @@ -1894,6 +2159,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94548 info.low_limit = mm->mmap_base;
94549 info.high_limit = TASK_SIZE;
94550 info.align_mask = 0;
94551 + info.threadstack_offset = offset;
94552 return vm_unmapped_area(&info);
94553 }
94554 #endif
94555 @@ -1912,6 +2178,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94556 struct mm_struct *mm = current->mm;
94557 unsigned long addr = addr0;
94558 struct vm_unmapped_area_info info;
94559 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94560
94561 /* requested length too big for entire address space */
94562 if (len > TASK_SIZE - mmap_min_addr)
94563 @@ -1920,12 +2187,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94564 if (flags & MAP_FIXED)
94565 return addr;
94566
94567 +#ifdef CONFIG_PAX_RANDMMAP
94568 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94569 +#endif
94570 +
94571 /* requesting a specific address */
94572 if (addr) {
94573 addr = PAGE_ALIGN(addr);
94574 vma = find_vma(mm, addr);
94575 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94576 - (!vma || addr + len <= vma->vm_start))
94577 + check_heap_stack_gap(vma, addr, len, offset))
94578 return addr;
94579 }
94580
94581 @@ -1934,6 +2205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94582 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94583 info.high_limit = mm->mmap_base;
94584 info.align_mask = 0;
94585 + info.threadstack_offset = offset;
94586 addr = vm_unmapped_area(&info);
94587
94588 /*
94589 @@ -1946,6 +2218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94590 VM_BUG_ON(addr != -ENOMEM);
94591 info.flags = 0;
94592 info.low_limit = TASK_UNMAPPED_BASE;
94593 +
94594 +#ifdef CONFIG_PAX_RANDMMAP
94595 + if (mm->pax_flags & MF_PAX_RANDMMAP)
94596 + info.low_limit += mm->delta_mmap;
94597 +#endif
94598 +
94599 info.high_limit = TASK_SIZE;
94600 addr = vm_unmapped_area(&info);
94601 }
94602 @@ -2046,6 +2324,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94603 return vma;
94604 }
94605
94606 +#ifdef CONFIG_PAX_SEGMEXEC
94607 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94608 +{
94609 + struct vm_area_struct *vma_m;
94610 +
94611 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94612 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94613 + BUG_ON(vma->vm_mirror);
94614 + return NULL;
94615 + }
94616 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94617 + vma_m = vma->vm_mirror;
94618 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94619 + BUG_ON(vma->vm_file != vma_m->vm_file);
94620 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94621 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94622 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94623 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94624 + return vma_m;
94625 +}
94626 +#endif
94627 +
94628 /*
94629 * Verify that the stack growth is acceptable and
94630 * update accounting. This is shared with both the
94631 @@ -2062,6 +2362,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94632 return -ENOMEM;
94633
94634 /* Stack limit test */
94635 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
94636 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94637 return -ENOMEM;
94638
94639 @@ -2072,6 +2373,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94640 locked = mm->locked_vm + grow;
94641 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94642 limit >>= PAGE_SHIFT;
94643 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94644 if (locked > limit && !capable(CAP_IPC_LOCK))
94645 return -ENOMEM;
94646 }
94647 @@ -2101,37 +2403,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94648 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
94649 * vma is the last one with address > vma->vm_end. Have to extend vma.
94650 */
94651 +#ifndef CONFIG_IA64
94652 +static
94653 +#endif
94654 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94655 {
94656 int error;
94657 + bool locknext;
94658
94659 if (!(vma->vm_flags & VM_GROWSUP))
94660 return -EFAULT;
94661
94662 + /* Also guard against wrapping around to address 0. */
94663 + if (address < PAGE_ALIGN(address+1))
94664 + address = PAGE_ALIGN(address+1);
94665 + else
94666 + return -ENOMEM;
94667 +
94668 /*
94669 * We must make sure the anon_vma is allocated
94670 * so that the anon_vma locking is not a noop.
94671 */
94672 if (unlikely(anon_vma_prepare(vma)))
94673 return -ENOMEM;
94674 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
94675 + if (locknext && anon_vma_prepare(vma->vm_next))
94676 + return -ENOMEM;
94677 vma_lock_anon_vma(vma);
94678 + if (locknext)
94679 + vma_lock_anon_vma(vma->vm_next);
94680
94681 /*
94682 * vma->vm_start/vm_end cannot change under us because the caller
94683 * is required to hold the mmap_sem in read mode. We need the
94684 - * anon_vma lock to serialize against concurrent expand_stacks.
94685 - * Also guard against wrapping around to address 0.
94686 + * anon_vma locks to serialize against concurrent expand_stacks
94687 + * and expand_upwards.
94688 */
94689 - if (address < PAGE_ALIGN(address+4))
94690 - address = PAGE_ALIGN(address+4);
94691 - else {
94692 - vma_unlock_anon_vma(vma);
94693 - return -ENOMEM;
94694 - }
94695 error = 0;
94696
94697 /* Somebody else might have raced and expanded it already */
94698 - if (address > vma->vm_end) {
94699 + 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)
94700 + error = -ENOMEM;
94701 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
94702 unsigned long size, grow;
94703
94704 size = address - vma->vm_start;
94705 @@ -2166,6 +2479,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94706 }
94707 }
94708 }
94709 + if (locknext)
94710 + vma_unlock_anon_vma(vma->vm_next);
94711 vma_unlock_anon_vma(vma);
94712 khugepaged_enter_vma_merge(vma);
94713 validate_mm(vma->vm_mm);
94714 @@ -2180,6 +2495,8 @@ int expand_downwards(struct vm_area_struct *vma,
94715 unsigned long address)
94716 {
94717 int error;
94718 + bool lockprev = false;
94719 + struct vm_area_struct *prev;
94720
94721 /*
94722 * We must make sure the anon_vma is allocated
94723 @@ -2193,6 +2510,15 @@ int expand_downwards(struct vm_area_struct *vma,
94724 if (error)
94725 return error;
94726
94727 + prev = vma->vm_prev;
94728 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94729 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94730 +#endif
94731 + if (lockprev && anon_vma_prepare(prev))
94732 + return -ENOMEM;
94733 + if (lockprev)
94734 + vma_lock_anon_vma(prev);
94735 +
94736 vma_lock_anon_vma(vma);
94737
94738 /*
94739 @@ -2202,9 +2528,17 @@ int expand_downwards(struct vm_area_struct *vma,
94740 */
94741
94742 /* Somebody else might have raced and expanded it already */
94743 - if (address < vma->vm_start) {
94744 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94745 + error = -ENOMEM;
94746 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94747 unsigned long size, grow;
94748
94749 +#ifdef CONFIG_PAX_SEGMEXEC
94750 + struct vm_area_struct *vma_m;
94751 +
94752 + vma_m = pax_find_mirror_vma(vma);
94753 +#endif
94754 +
94755 size = vma->vm_end - address;
94756 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94757
94758 @@ -2229,13 +2563,27 @@ int expand_downwards(struct vm_area_struct *vma,
94759 vma->vm_pgoff -= grow;
94760 anon_vma_interval_tree_post_update_vma(vma);
94761 vma_gap_update(vma);
94762 +
94763 +#ifdef CONFIG_PAX_SEGMEXEC
94764 + if (vma_m) {
94765 + anon_vma_interval_tree_pre_update_vma(vma_m);
94766 + vma_m->vm_start -= grow << PAGE_SHIFT;
94767 + vma_m->vm_pgoff -= grow;
94768 + anon_vma_interval_tree_post_update_vma(vma_m);
94769 + vma_gap_update(vma_m);
94770 + }
94771 +#endif
94772 +
94773 spin_unlock(&vma->vm_mm->page_table_lock);
94774
94775 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94776 perf_event_mmap(vma);
94777 }
94778 }
94779 }
94780 vma_unlock_anon_vma(vma);
94781 + if (lockprev)
94782 + vma_unlock_anon_vma(prev);
94783 khugepaged_enter_vma_merge(vma);
94784 validate_mm(vma->vm_mm);
94785 return error;
94786 @@ -2333,6 +2681,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94787 do {
94788 long nrpages = vma_pages(vma);
94789
94790 +#ifdef CONFIG_PAX_SEGMEXEC
94791 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94792 + vma = remove_vma(vma);
94793 + continue;
94794 + }
94795 +#endif
94796 +
94797 if (vma->vm_flags & VM_ACCOUNT)
94798 nr_accounted += nrpages;
94799 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94800 @@ -2377,6 +2732,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94801 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94802 vma->vm_prev = NULL;
94803 do {
94804 +
94805 +#ifdef CONFIG_PAX_SEGMEXEC
94806 + if (vma->vm_mirror) {
94807 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94808 + vma->vm_mirror->vm_mirror = NULL;
94809 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
94810 + vma->vm_mirror = NULL;
94811 + }
94812 +#endif
94813 +
94814 vma_rb_erase(vma, &mm->mm_rb);
94815 mm->map_count--;
94816 tail_vma = vma;
94817 @@ -2404,14 +2769,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94818 struct vm_area_struct *new;
94819 int err = -ENOMEM;
94820
94821 +#ifdef CONFIG_PAX_SEGMEXEC
94822 + struct vm_area_struct *vma_m, *new_m = NULL;
94823 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94824 +#endif
94825 +
94826 if (is_vm_hugetlb_page(vma) && (addr &
94827 ~(huge_page_mask(hstate_vma(vma)))))
94828 return -EINVAL;
94829
94830 +#ifdef CONFIG_PAX_SEGMEXEC
94831 + vma_m = pax_find_mirror_vma(vma);
94832 +#endif
94833 +
94834 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94835 if (!new)
94836 goto out_err;
94837
94838 +#ifdef CONFIG_PAX_SEGMEXEC
94839 + if (vma_m) {
94840 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94841 + if (!new_m) {
94842 + kmem_cache_free(vm_area_cachep, new);
94843 + goto out_err;
94844 + }
94845 + }
94846 +#endif
94847 +
94848 /* most fields are the same, copy all, and then fixup */
94849 *new = *vma;
94850
94851 @@ -2424,6 +2808,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94852 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94853 }
94854
94855 +#ifdef CONFIG_PAX_SEGMEXEC
94856 + if (vma_m) {
94857 + *new_m = *vma_m;
94858 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
94859 + new_m->vm_mirror = new;
94860 + new->vm_mirror = new_m;
94861 +
94862 + if (new_below)
94863 + new_m->vm_end = addr_m;
94864 + else {
94865 + new_m->vm_start = addr_m;
94866 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94867 + }
94868 + }
94869 +#endif
94870 +
94871 err = vma_dup_policy(vma, new);
94872 if (err)
94873 goto out_free_vma;
94874 @@ -2443,6 +2843,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94875 else
94876 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94877
94878 +#ifdef CONFIG_PAX_SEGMEXEC
94879 + if (!err && vma_m) {
94880 + struct mempolicy *pol = vma_policy(new);
94881 +
94882 + if (anon_vma_clone(new_m, vma_m))
94883 + goto out_free_mpol;
94884 +
94885 + mpol_get(pol);
94886 + set_vma_policy(new_m, pol);
94887 +
94888 + if (new_m->vm_file)
94889 + get_file(new_m->vm_file);
94890 +
94891 + if (new_m->vm_ops && new_m->vm_ops->open)
94892 + new_m->vm_ops->open(new_m);
94893 +
94894 + if (new_below)
94895 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94896 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94897 + else
94898 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94899 +
94900 + if (err) {
94901 + if (new_m->vm_ops && new_m->vm_ops->close)
94902 + new_m->vm_ops->close(new_m);
94903 + if (new_m->vm_file)
94904 + fput(new_m->vm_file);
94905 + mpol_put(pol);
94906 + }
94907 + }
94908 +#endif
94909 +
94910 /* Success. */
94911 if (!err)
94912 return 0;
94913 @@ -2452,10 +2884,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94914 new->vm_ops->close(new);
94915 if (new->vm_file)
94916 fput(new->vm_file);
94917 - unlink_anon_vmas(new);
94918 out_free_mpol:
94919 mpol_put(vma_policy(new));
94920 out_free_vma:
94921 +
94922 +#ifdef CONFIG_PAX_SEGMEXEC
94923 + if (new_m) {
94924 + unlink_anon_vmas(new_m);
94925 + kmem_cache_free(vm_area_cachep, new_m);
94926 + }
94927 +#endif
94928 +
94929 + unlink_anon_vmas(new);
94930 kmem_cache_free(vm_area_cachep, new);
94931 out_err:
94932 return err;
94933 @@ -2468,6 +2908,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94934 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94935 unsigned long addr, int new_below)
94936 {
94937 +
94938 +#ifdef CONFIG_PAX_SEGMEXEC
94939 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94940 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
94941 + if (mm->map_count >= sysctl_max_map_count-1)
94942 + return -ENOMEM;
94943 + } else
94944 +#endif
94945 +
94946 if (mm->map_count >= sysctl_max_map_count)
94947 return -ENOMEM;
94948
94949 @@ -2479,11 +2928,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94950 * work. This now handles partial unmappings.
94951 * Jeremy Fitzhardinge <jeremy@goop.org>
94952 */
94953 +#ifdef CONFIG_PAX_SEGMEXEC
94954 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94955 {
94956 + int ret = __do_munmap(mm, start, len);
94957 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94958 + return ret;
94959 +
94960 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94961 +}
94962 +
94963 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94964 +#else
94965 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94966 +#endif
94967 +{
94968 unsigned long end;
94969 struct vm_area_struct *vma, *prev, *last;
94970
94971 + /*
94972 + * mm->mmap_sem is required to protect against another thread
94973 + * changing the mappings in case we sleep.
94974 + */
94975 + verify_mm_writelocked(mm);
94976 +
94977 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94978 return -EINVAL;
94979
94980 @@ -2558,6 +3026,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94981 /* Fix up all other VM information */
94982 remove_vma_list(mm, vma);
94983
94984 + track_exec_limit(mm, start, end, 0UL);
94985 +
94986 return 0;
94987 }
94988
94989 @@ -2566,6 +3036,13 @@ int vm_munmap(unsigned long start, size_t len)
94990 int ret;
94991 struct mm_struct *mm = current->mm;
94992
94993 +
94994 +#ifdef CONFIG_PAX_SEGMEXEC
94995 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94996 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94997 + return -EINVAL;
94998 +#endif
94999 +
95000 down_write(&mm->mmap_sem);
95001 ret = do_munmap(mm, start, len);
95002 up_write(&mm->mmap_sem);
95003 @@ -2579,16 +3056,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
95004 return vm_munmap(addr, len);
95005 }
95006
95007 -static inline void verify_mm_writelocked(struct mm_struct *mm)
95008 -{
95009 -#ifdef CONFIG_DEBUG_VM
95010 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
95011 - WARN_ON(1);
95012 - up_read(&mm->mmap_sem);
95013 - }
95014 -#endif
95015 -}
95016 -
95017 /*
95018 * this is really a simplified "do_mmap". it only handles
95019 * anonymous maps. eventually we may be able to do some
95020 @@ -2602,6 +3069,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95021 struct rb_node ** rb_link, * rb_parent;
95022 pgoff_t pgoff = addr >> PAGE_SHIFT;
95023 int error;
95024 + unsigned long charged;
95025
95026 len = PAGE_ALIGN(len);
95027 if (!len)
95028 @@ -2609,10 +3077,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95029
95030 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
95031
95032 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
95033 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
95034 + flags &= ~VM_EXEC;
95035 +
95036 +#ifdef CONFIG_PAX_MPROTECT
95037 + if (mm->pax_flags & MF_PAX_MPROTECT)
95038 + flags &= ~VM_MAYEXEC;
95039 +#endif
95040 +
95041 + }
95042 +#endif
95043 +
95044 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
95045 if (error & ~PAGE_MASK)
95046 return error;
95047
95048 + charged = len >> PAGE_SHIFT;
95049 +
95050 error = mlock_future_check(mm, mm->def_flags, len);
95051 if (error)
95052 return error;
95053 @@ -2626,21 +3108,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95054 /*
95055 * Clear old maps. this also does some error checking for us
95056 */
95057 - munmap_back:
95058 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
95059 if (do_munmap(mm, addr, len))
95060 return -ENOMEM;
95061 - goto munmap_back;
95062 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
95063 }
95064
95065 /* Check against address space limits *after* clearing old maps... */
95066 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
95067 + if (!may_expand_vm(mm, charged))
95068 return -ENOMEM;
95069
95070 if (mm->map_count > sysctl_max_map_count)
95071 return -ENOMEM;
95072
95073 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
95074 + if (security_vm_enough_memory_mm(mm, charged))
95075 return -ENOMEM;
95076
95077 /* Can we just expand an old private anonymous mapping? */
95078 @@ -2654,7 +3135,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95079 */
95080 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95081 if (!vma) {
95082 - vm_unacct_memory(len >> PAGE_SHIFT);
95083 + vm_unacct_memory(charged);
95084 return -ENOMEM;
95085 }
95086
95087 @@ -2668,10 +3149,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95088 vma_link(mm, vma, prev, rb_link, rb_parent);
95089 out:
95090 perf_event_mmap(vma);
95091 - mm->total_vm += len >> PAGE_SHIFT;
95092 + mm->total_vm += charged;
95093 if (flags & VM_LOCKED)
95094 - mm->locked_vm += (len >> PAGE_SHIFT);
95095 + mm->locked_vm += charged;
95096 vma->vm_flags |= VM_SOFTDIRTY;
95097 + track_exec_limit(mm, addr, addr + len, flags);
95098 return addr;
95099 }
95100
95101 @@ -2733,6 +3215,7 @@ void exit_mmap(struct mm_struct *mm)
95102 while (vma) {
95103 if (vma->vm_flags & VM_ACCOUNT)
95104 nr_accounted += vma_pages(vma);
95105 + vma->vm_mirror = NULL;
95106 vma = remove_vma(vma);
95107 }
95108 vm_unacct_memory(nr_accounted);
95109 @@ -2750,6 +3233,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
95110 struct vm_area_struct *prev;
95111 struct rb_node **rb_link, *rb_parent;
95112
95113 +#ifdef CONFIG_PAX_SEGMEXEC
95114 + struct vm_area_struct *vma_m = NULL;
95115 +#endif
95116 +
95117 + if (security_mmap_addr(vma->vm_start))
95118 + return -EPERM;
95119 +
95120 /*
95121 * The vm_pgoff of a purely anonymous vma should be irrelevant
95122 * until its first write fault, when page's anon_vma and index
95123 @@ -2773,7 +3263,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
95124 security_vm_enough_memory_mm(mm, vma_pages(vma)))
95125 return -ENOMEM;
95126
95127 +#ifdef CONFIG_PAX_SEGMEXEC
95128 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
95129 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95130 + if (!vma_m)
95131 + return -ENOMEM;
95132 + }
95133 +#endif
95134 +
95135 vma_link(mm, vma, prev, rb_link, rb_parent);
95136 +
95137 +#ifdef CONFIG_PAX_SEGMEXEC
95138 + if (vma_m)
95139 + BUG_ON(pax_mirror_vma(vma_m, vma));
95140 +#endif
95141 +
95142 return 0;
95143 }
95144
95145 @@ -2792,6 +3296,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
95146 struct rb_node **rb_link, *rb_parent;
95147 bool faulted_in_anon_vma = true;
95148
95149 + BUG_ON(vma->vm_mirror);
95150 +
95151 /*
95152 * If anonymous vma has not yet been faulted, update new pgoff
95153 * to match new location, to increase its chance of merging.
95154 @@ -2856,6 +3362,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
95155 return NULL;
95156 }
95157
95158 +#ifdef CONFIG_PAX_SEGMEXEC
95159 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
95160 +{
95161 + struct vm_area_struct *prev_m;
95162 + struct rb_node **rb_link_m, *rb_parent_m;
95163 + struct mempolicy *pol_m;
95164 +
95165 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
95166 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
95167 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
95168 + *vma_m = *vma;
95169 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
95170 + if (anon_vma_clone(vma_m, vma))
95171 + return -ENOMEM;
95172 + pol_m = vma_policy(vma_m);
95173 + mpol_get(pol_m);
95174 + set_vma_policy(vma_m, pol_m);
95175 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
95176 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
95177 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
95178 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
95179 + if (vma_m->vm_file)
95180 + get_file(vma_m->vm_file);
95181 + if (vma_m->vm_ops && vma_m->vm_ops->open)
95182 + vma_m->vm_ops->open(vma_m);
95183 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
95184 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
95185 + vma_m->vm_mirror = vma;
95186 + vma->vm_mirror = vma_m;
95187 + return 0;
95188 +}
95189 +#endif
95190 +
95191 /*
95192 * Return true if the calling process may expand its vm space by the passed
95193 * number of pages
95194 @@ -2867,6 +3406,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
95195
95196 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
95197
95198 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
95199 if (cur + npages > lim)
95200 return 0;
95201 return 1;
95202 @@ -2937,6 +3477,22 @@ struct vm_area_struct *_install_special_mapping(struct mm_struct *mm,
95203 vma->vm_start = addr;
95204 vma->vm_end = addr + len;
95205
95206 +#ifdef CONFIG_PAX_MPROTECT
95207 + if (mm->pax_flags & MF_PAX_MPROTECT) {
95208 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
95209 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
95210 + return ERR_PTR(-EPERM);
95211 + if (!(vm_flags & VM_EXEC))
95212 + vm_flags &= ~VM_MAYEXEC;
95213 +#else
95214 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
95215 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
95216 +#endif
95217 + else
95218 + vm_flags &= ~VM_MAYWRITE;
95219 + }
95220 +#endif
95221 +
95222 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
95223 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
95224
95225 diff --git a/mm/mprotect.c b/mm/mprotect.c
95226 index c43d557..0b7ccd2 100644
95227 --- a/mm/mprotect.c
95228 +++ b/mm/mprotect.c
95229 @@ -24,10 +24,18 @@
95230 #include <linux/migrate.h>
95231 #include <linux/perf_event.h>
95232 #include <linux/ksm.h>
95233 +#include <linux/sched/sysctl.h>
95234 +
95235 +#ifdef CONFIG_PAX_MPROTECT
95236 +#include <linux/elf.h>
95237 +#include <linux/binfmts.h>
95238 +#endif
95239 +
95240 #include <asm/uaccess.h>
95241 #include <asm/pgtable.h>
95242 #include <asm/cacheflush.h>
95243 #include <asm/tlbflush.h>
95244 +#include <asm/mmu_context.h>
95245
95246 #ifndef pgprot_modify
95247 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
95248 @@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
95249 return pages;
95250 }
95251
95252 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95253 +/* called while holding the mmap semaphor for writing except stack expansion */
95254 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
95255 +{
95256 + unsigned long oldlimit, newlimit = 0UL;
95257 +
95258 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
95259 + return;
95260 +
95261 + spin_lock(&mm->page_table_lock);
95262 + oldlimit = mm->context.user_cs_limit;
95263 + if ((prot & VM_EXEC) && oldlimit < end)
95264 + /* USER_CS limit moved up */
95265 + newlimit = end;
95266 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
95267 + /* USER_CS limit moved down */
95268 + newlimit = start;
95269 +
95270 + if (newlimit) {
95271 + mm->context.user_cs_limit = newlimit;
95272 +
95273 +#ifdef CONFIG_SMP
95274 + wmb();
95275 + cpus_clear(mm->context.cpu_user_cs_mask);
95276 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
95277 +#endif
95278 +
95279 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
95280 + }
95281 + spin_unlock(&mm->page_table_lock);
95282 + if (newlimit == end) {
95283 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
95284 +
95285 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
95286 + if (is_vm_hugetlb_page(vma))
95287 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
95288 + else
95289 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
95290 + }
95291 +}
95292 +#endif
95293 +
95294 int
95295 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95296 unsigned long start, unsigned long end, unsigned long newflags)
95297 @@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95298 int error;
95299 int dirty_accountable = 0;
95300
95301 +#ifdef CONFIG_PAX_SEGMEXEC
95302 + struct vm_area_struct *vma_m = NULL;
95303 + unsigned long start_m, end_m;
95304 +
95305 + start_m = start + SEGMEXEC_TASK_SIZE;
95306 + end_m = end + SEGMEXEC_TASK_SIZE;
95307 +#endif
95308 +
95309 if (newflags == oldflags) {
95310 *pprev = vma;
95311 return 0;
95312 }
95313
95314 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
95315 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
95316 +
95317 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
95318 + return -ENOMEM;
95319 +
95320 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
95321 + return -ENOMEM;
95322 + }
95323 +
95324 /*
95325 * If we make a private mapping writable we increase our commit;
95326 * but (without finer accounting) cannot reduce our commit if we
95327 @@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95328 }
95329 }
95330
95331 +#ifdef CONFIG_PAX_SEGMEXEC
95332 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
95333 + if (start != vma->vm_start) {
95334 + error = split_vma(mm, vma, start, 1);
95335 + if (error)
95336 + goto fail;
95337 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
95338 + *pprev = (*pprev)->vm_next;
95339 + }
95340 +
95341 + if (end != vma->vm_end) {
95342 + error = split_vma(mm, vma, end, 0);
95343 + if (error)
95344 + goto fail;
95345 + }
95346 +
95347 + if (pax_find_mirror_vma(vma)) {
95348 + error = __do_munmap(mm, start_m, end_m - start_m);
95349 + if (error)
95350 + goto fail;
95351 + } else {
95352 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95353 + if (!vma_m) {
95354 + error = -ENOMEM;
95355 + goto fail;
95356 + }
95357 + vma->vm_flags = newflags;
95358 + error = pax_mirror_vma(vma_m, vma);
95359 + if (error) {
95360 + vma->vm_flags = oldflags;
95361 + goto fail;
95362 + }
95363 + }
95364 + }
95365 +#endif
95366 +
95367 /*
95368 * First try to merge with previous and/or next vma.
95369 */
95370 @@ -319,9 +423,21 @@ success:
95371 * vm_flags and vm_page_prot are protected by the mmap_sem
95372 * held in write mode.
95373 */
95374 +
95375 +#ifdef CONFIG_PAX_SEGMEXEC
95376 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
95377 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
95378 +#endif
95379 +
95380 vma->vm_flags = newflags;
95381 +
95382 +#ifdef CONFIG_PAX_MPROTECT
95383 + if (mm->binfmt && mm->binfmt->handle_mprotect)
95384 + mm->binfmt->handle_mprotect(vma, newflags);
95385 +#endif
95386 +
95387 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
95388 - vm_get_page_prot(newflags));
95389 + vm_get_page_prot(vma->vm_flags));
95390
95391 if (vma_wants_writenotify(vma)) {
95392 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
95393 @@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95394 end = start + len;
95395 if (end <= start)
95396 return -ENOMEM;
95397 +
95398 +#ifdef CONFIG_PAX_SEGMEXEC
95399 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95400 + if (end > SEGMEXEC_TASK_SIZE)
95401 + return -EINVAL;
95402 + } else
95403 +#endif
95404 +
95405 + if (end > TASK_SIZE)
95406 + return -EINVAL;
95407 +
95408 if (!arch_validate_prot(prot))
95409 return -EINVAL;
95410
95411 @@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95412 /*
95413 * Does the application expect PROT_READ to imply PROT_EXEC:
95414 */
95415 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
95416 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
95417 prot |= PROT_EXEC;
95418
95419 vm_flags = calc_vm_prot_bits(prot);
95420 @@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95421 if (start > vma->vm_start)
95422 prev = vma;
95423
95424 +#ifdef CONFIG_PAX_MPROTECT
95425 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95426 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
95427 +#endif
95428 +
95429 for (nstart = start ; ; ) {
95430 unsigned long newflags;
95431
95432 @@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95433
95434 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95435 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95436 + if (prot & (PROT_WRITE | PROT_EXEC))
95437 + gr_log_rwxmprotect(vma);
95438 +
95439 + error = -EACCES;
95440 + goto out;
95441 + }
95442 +
95443 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95444 error = -EACCES;
95445 goto out;
95446 }
95447 @@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95448 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95449 if (error)
95450 goto out;
95451 +
95452 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
95453 +
95454 nstart = tmp;
95455
95456 if (nstart < prev->vm_end)
95457 diff --git a/mm/mremap.c b/mm/mremap.c
95458 index 05f1180..c3cde48 100644
95459 --- a/mm/mremap.c
95460 +++ b/mm/mremap.c
95461 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95462 continue;
95463 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95464 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95465 +
95466 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95467 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95468 + pte = pte_exprotect(pte);
95469 +#endif
95470 +
95471 pte = move_soft_dirty_pte(pte);
95472 set_pte_at(mm, new_addr, new_pte, pte);
95473 }
95474 @@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95475 if (is_vm_hugetlb_page(vma))
95476 goto Einval;
95477
95478 +#ifdef CONFIG_PAX_SEGMEXEC
95479 + if (pax_find_mirror_vma(vma))
95480 + goto Einval;
95481 +#endif
95482 +
95483 /* We can't remap across vm area boundaries */
95484 if (old_len > vma->vm_end - addr)
95485 goto Efault;
95486 @@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95487 unsigned long ret = -EINVAL;
95488 unsigned long charged = 0;
95489 unsigned long map_flags;
95490 + unsigned long pax_task_size = TASK_SIZE;
95491
95492 if (new_addr & ~PAGE_MASK)
95493 goto out;
95494
95495 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95496 +#ifdef CONFIG_PAX_SEGMEXEC
95497 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
95498 + pax_task_size = SEGMEXEC_TASK_SIZE;
95499 +#endif
95500 +
95501 + pax_task_size -= PAGE_SIZE;
95502 +
95503 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95504 goto out;
95505
95506 /* Check if the location we're moving into overlaps the
95507 * old location at all, and fail if it does.
95508 */
95509 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
95510 - goto out;
95511 -
95512 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
95513 + if (addr + old_len > new_addr && new_addr + new_len > addr)
95514 goto out;
95515
95516 ret = do_munmap(mm, new_addr, new_len);
95517 @@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95518 unsigned long ret = -EINVAL;
95519 unsigned long charged = 0;
95520 bool locked = false;
95521 + unsigned long pax_task_size = TASK_SIZE;
95522
95523 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95524 return ret;
95525 @@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95526 if (!new_len)
95527 return ret;
95528
95529 +#ifdef CONFIG_PAX_SEGMEXEC
95530 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
95531 + pax_task_size = SEGMEXEC_TASK_SIZE;
95532 +#endif
95533 +
95534 + pax_task_size -= PAGE_SIZE;
95535 +
95536 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95537 + old_len > pax_task_size || addr > pax_task_size-old_len)
95538 + return ret;
95539 +
95540 down_write(&current->mm->mmap_sem);
95541
95542 if (flags & MREMAP_FIXED) {
95543 @@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95544 new_addr = addr;
95545 }
95546 ret = addr;
95547 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95548 goto out;
95549 }
95550 }
95551 @@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95552 goto out;
95553 }
95554
95555 + map_flags = vma->vm_flags;
95556 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95557 + if (!(ret & ~PAGE_MASK)) {
95558 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95559 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95560 + }
95561 }
95562 out:
95563 if (ret & ~PAGE_MASK)
95564 diff --git a/mm/nommu.c b/mm/nommu.c
95565 index 431fd7c..8674512 100644
95566 --- a/mm/nommu.c
95567 +++ b/mm/nommu.c
95568 @@ -67,7 +67,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95569 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95570 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95571 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95572 -int heap_stack_gap = 0;
95573
95574 atomic_long_t mmap_pages_allocated;
95575
95576 @@ -854,15 +853,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95577 EXPORT_SYMBOL(find_vma);
95578
95579 /*
95580 - * find a VMA
95581 - * - we don't extend stack VMAs under NOMMU conditions
95582 - */
95583 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95584 -{
95585 - return find_vma(mm, addr);
95586 -}
95587 -
95588 -/*
95589 * expand a stack to a given address
95590 * - not supported under NOMMU conditions
95591 */
95592 @@ -1569,6 +1559,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95593
95594 /* most fields are the same, copy all, and then fixup */
95595 *new = *vma;
95596 + INIT_LIST_HEAD(&new->anon_vma_chain);
95597 *region = *vma->vm_region;
95598 new->vm_region = region;
95599
95600 @@ -2004,8 +1995,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95601 }
95602 EXPORT_SYMBOL(generic_file_remap_pages);
95603
95604 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95605 - unsigned long addr, void *buf, int len, int write)
95606 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95607 + unsigned long addr, void *buf, size_t len, int write)
95608 {
95609 struct vm_area_struct *vma;
95610
95611 @@ -2046,8 +2037,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95612 *
95613 * The caller must hold a reference on @mm.
95614 */
95615 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95616 - void *buf, int len, int write)
95617 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95618 + void *buf, size_t len, int write)
95619 {
95620 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95621 }
95622 @@ -2056,7 +2047,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95623 * Access another process' address space.
95624 * - source/target buffer must be kernel space
95625 */
95626 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95627 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95628 {
95629 struct mm_struct *mm;
95630
95631 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95632 index 154af21..86e447f 100644
95633 --- a/mm/page-writeback.c
95634 +++ b/mm/page-writeback.c
95635 @@ -685,7 +685,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
95636 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95637 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95638 */
95639 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95640 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95641 unsigned long thresh,
95642 unsigned long bg_thresh,
95643 unsigned long dirty,
95644 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
95645 index d64f5f9..9005ab5 100644
95646 --- a/mm/page_alloc.c
95647 +++ b/mm/page_alloc.c
95648 @@ -61,6 +61,7 @@
95649 #include <linux/page-debug-flags.h>
95650 #include <linux/hugetlb.h>
95651 #include <linux/sched/rt.h>
95652 +#include <linux/random.h>
95653
95654 #include <asm/sections.h>
95655 #include <asm/tlbflush.h>
95656 @@ -356,7 +357,7 @@ out:
95657 * This usage means that zero-order pages may not be compound.
95658 */
95659
95660 -static void free_compound_page(struct page *page)
95661 +void free_compound_page(struct page *page)
95662 {
95663 __free_pages_ok(page, compound_order(page));
95664 }
95665 @@ -730,6 +731,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95666 int i;
95667 int bad = 0;
95668
95669 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95670 + unsigned long index = 1UL << order;
95671 +#endif
95672 +
95673 trace_mm_page_free(page, order);
95674 kmemcheck_free_shadow(page, order);
95675
95676 @@ -746,6 +751,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95677 debug_check_no_obj_freed(page_address(page),
95678 PAGE_SIZE << order);
95679 }
95680 +
95681 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95682 + for (; index; --index)
95683 + sanitize_highpage(page + index - 1);
95684 +#endif
95685 +
95686 arch_free_page(page, order);
95687 kernel_map_pages(page, 1 << order, 0);
95688
95689 @@ -768,6 +779,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
95690 local_irq_restore(flags);
95691 }
95692
95693 +#ifdef CONFIG_PAX_LATENT_ENTROPY
95694 +bool __meminitdata extra_latent_entropy;
95695 +
95696 +static int __init setup_pax_extra_latent_entropy(char *str)
95697 +{
95698 + extra_latent_entropy = true;
95699 + return 0;
95700 +}
95701 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
95702 +
95703 +volatile u64 latent_entropy __latent_entropy;
95704 +EXPORT_SYMBOL(latent_entropy);
95705 +#endif
95706 +
95707 void __init __free_pages_bootmem(struct page *page, unsigned int order)
95708 {
95709 unsigned int nr_pages = 1 << order;
95710 @@ -783,6 +808,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
95711 __ClearPageReserved(p);
95712 set_page_count(p, 0);
95713
95714 +#ifdef CONFIG_PAX_LATENT_ENTROPY
95715 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
95716 + u64 hash = 0;
95717 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
95718 + const u64 *data = lowmem_page_address(page);
95719 +
95720 + for (index = 0; index < end; index++)
95721 + hash ^= hash + data[index];
95722 + latent_entropy ^= hash;
95723 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
95724 + }
95725 +#endif
95726 +
95727 page_zone(page)->managed_pages += nr_pages;
95728 set_page_refcounted(page);
95729 __free_pages(page, order);
95730 @@ -911,8 +949,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95731 arch_alloc_page(page, order);
95732 kernel_map_pages(page, 1 << order, 1);
95733
95734 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
95735 if (gfp_flags & __GFP_ZERO)
95736 prep_zero_page(page, order, gfp_flags);
95737 +#endif
95738
95739 if (order && (gfp_flags & __GFP_COMP))
95740 prep_compound_page(page, order);
95741 @@ -2415,7 +2455,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
95742 continue;
95743 mod_zone_page_state(zone, NR_ALLOC_BATCH,
95744 high_wmark_pages(zone) - low_wmark_pages(zone) -
95745 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
95746 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
95747 }
95748 }
95749
95750 diff --git a/mm/page_io.c b/mm/page_io.c
95751 index 7c59ef6..1358905 100644
95752 --- a/mm/page_io.c
95753 +++ b/mm/page_io.c
95754 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95755 struct file *swap_file = sis->swap_file;
95756 struct address_space *mapping = swap_file->f_mapping;
95757 struct iovec iov = {
95758 - .iov_base = kmap(page),
95759 + .iov_base = (void __force_user *)kmap(page),
95760 .iov_len = PAGE_SIZE,
95761 };
95762
95763 diff --git a/mm/percpu.c b/mm/percpu.c
95764 index 2ddf9a9..f8fc075 100644
95765 --- a/mm/percpu.c
95766 +++ b/mm/percpu.c
95767 @@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95768 static unsigned int pcpu_high_unit_cpu __read_mostly;
95769
95770 /* the address of the first chunk which starts with the kernel static area */
95771 -void *pcpu_base_addr __read_mostly;
95772 +void *pcpu_base_addr __read_only;
95773 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95774
95775 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95776 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95777 index 8505c92..946bfc9 100644
95778 --- a/mm/process_vm_access.c
95779 +++ b/mm/process_vm_access.c
95780 @@ -13,6 +13,7 @@
95781 #include <linux/uio.h>
95782 #include <linux/sched.h>
95783 #include <linux/highmem.h>
95784 +#include <linux/security.h>
95785 #include <linux/ptrace.h>
95786 #include <linux/slab.h>
95787 #include <linux/syscalls.h>
95788 @@ -161,19 +162,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95789 ssize_t iov_len;
95790 size_t total_len = iov_iter_count(iter);
95791
95792 + return -ENOSYS; // PaX: until properly audited
95793 +
95794 /*
95795 * Work out how many pages of struct pages we're going to need
95796 * when eventually calling get_user_pages
95797 */
95798 for (i = 0; i < riovcnt; i++) {
95799 iov_len = rvec[i].iov_len;
95800 - if (iov_len > 0) {
95801 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
95802 - + iov_len)
95803 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95804 - / PAGE_SIZE + 1;
95805 - nr_pages = max(nr_pages, nr_pages_iov);
95806 - }
95807 + if (iov_len <= 0)
95808 + continue;
95809 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95810 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95811 + nr_pages = max(nr_pages, nr_pages_iov);
95812 }
95813
95814 if (nr_pages == 0)
95815 @@ -201,6 +202,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95816 goto free_proc_pages;
95817 }
95818
95819 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95820 + rc = -EPERM;
95821 + goto put_task_struct;
95822 + }
95823 +
95824 mm = mm_access(task, PTRACE_MODE_ATTACH);
95825 if (!mm || IS_ERR(mm)) {
95826 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95827 diff --git a/mm/rmap.c b/mm/rmap.c
95828 index 14d1e28..3777962 100644
95829 --- a/mm/rmap.c
95830 +++ b/mm/rmap.c
95831 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95832 struct anon_vma *anon_vma = vma->anon_vma;
95833 struct anon_vma_chain *avc;
95834
95835 +#ifdef CONFIG_PAX_SEGMEXEC
95836 + struct anon_vma_chain *avc_m = NULL;
95837 +#endif
95838 +
95839 might_sleep();
95840 if (unlikely(!anon_vma)) {
95841 struct mm_struct *mm = vma->vm_mm;
95842 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95843 if (!avc)
95844 goto out_enomem;
95845
95846 +#ifdef CONFIG_PAX_SEGMEXEC
95847 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95848 + if (!avc_m)
95849 + goto out_enomem_free_avc;
95850 +#endif
95851 +
95852 anon_vma = find_mergeable_anon_vma(vma);
95853 allocated = NULL;
95854 if (!anon_vma) {
95855 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95856 /* page_table_lock to protect against threads */
95857 spin_lock(&mm->page_table_lock);
95858 if (likely(!vma->anon_vma)) {
95859 +
95860 +#ifdef CONFIG_PAX_SEGMEXEC
95861 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95862 +
95863 + if (vma_m) {
95864 + BUG_ON(vma_m->anon_vma);
95865 + vma_m->anon_vma = anon_vma;
95866 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
95867 + avc_m = NULL;
95868 + }
95869 +#endif
95870 +
95871 vma->anon_vma = anon_vma;
95872 anon_vma_chain_link(vma, avc, anon_vma);
95873 allocated = NULL;
95874 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95875
95876 if (unlikely(allocated))
95877 put_anon_vma(allocated);
95878 +
95879 +#ifdef CONFIG_PAX_SEGMEXEC
95880 + if (unlikely(avc_m))
95881 + anon_vma_chain_free(avc_m);
95882 +#endif
95883 +
95884 if (unlikely(avc))
95885 anon_vma_chain_free(avc);
95886 }
95887 return 0;
95888
95889 out_enomem_free_avc:
95890 +
95891 +#ifdef CONFIG_PAX_SEGMEXEC
95892 + if (avc_m)
95893 + anon_vma_chain_free(avc_m);
95894 +#endif
95895 +
95896 anon_vma_chain_free(avc);
95897 out_enomem:
95898 return -ENOMEM;
95899 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95900 * Attach the anon_vmas from src to dst.
95901 * Returns 0 on success, -ENOMEM on failure.
95902 */
95903 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95904 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95905 {
95906 struct anon_vma_chain *avc, *pavc;
95907 struct anon_vma *root = NULL;
95908 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95909 * the corresponding VMA in the parent process is attached to.
95910 * Returns 0 on success, non-zero on failure.
95911 */
95912 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95913 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95914 {
95915 struct anon_vma_chain *avc;
95916 struct anon_vma *anon_vma;
95917 @@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
95918 void __init anon_vma_init(void)
95919 {
95920 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95921 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95922 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95923 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95924 + anon_vma_ctor);
95925 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95926 + SLAB_PANIC|SLAB_NO_SANITIZE);
95927 }
95928
95929 /*
95930 diff --git a/mm/shmem.c b/mm/shmem.c
95931 index a2801ba..1e82984 100644
95932 --- a/mm/shmem.c
95933 +++ b/mm/shmem.c
95934 @@ -33,7 +33,7 @@
95935 #include <linux/swap.h>
95936 #include <linux/aio.h>
95937
95938 -static struct vfsmount *shm_mnt;
95939 +struct vfsmount *shm_mnt;
95940
95941 #ifdef CONFIG_SHMEM
95942 /*
95943 @@ -77,14 +77,15 @@ static struct vfsmount *shm_mnt;
95944 #define BOGO_DIRENT_SIZE 20
95945
95946 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
95947 -#define SHORT_SYMLINK_LEN 128
95948 +#define SHORT_SYMLINK_LEN 64
95949
95950 /*
95951 - * shmem_fallocate and shmem_writepage communicate via inode->i_private
95952 - * (with i_mutex making sure that it has only one user at a time):
95953 - * we would prefer not to enlarge the shmem inode just for that.
95954 + * shmem_fallocate communicates with shmem_fault or shmem_writepage via
95955 + * inode->i_private (with i_mutex making sure that it has only one user at
95956 + * a time): we would prefer not to enlarge the shmem inode just for that.
95957 */
95958 struct shmem_falloc {
95959 + wait_queue_head_t *waitq; /* faults into hole wait for punch to end */
95960 pgoff_t start; /* start of range currently being fallocated */
95961 pgoff_t next; /* the next page offset to be fallocated */
95962 pgoff_t nr_falloced; /* how many new pages have been fallocated */
95963 @@ -467,23 +468,20 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,
95964 return;
95965
95966 index = start;
95967 - for ( ; ; ) {
95968 + while (index < end) {
95969 cond_resched();
95970
95971 pvec.nr = find_get_entries(mapping, index,
95972 min(end - index, (pgoff_t)PAGEVEC_SIZE),
95973 pvec.pages, indices);
95974 if (!pvec.nr) {
95975 - if (index == start || unfalloc)
95976 + /* If all gone or hole-punch or unfalloc, we're done */
95977 + if (index == start || end != -1)
95978 break;
95979 + /* But if truncating, restart to make sure all gone */
95980 index = start;
95981 continue;
95982 }
95983 - if ((index == start || unfalloc) && indices[0] >= end) {
95984 - pagevec_remove_exceptionals(&pvec);
95985 - pagevec_release(&pvec);
95986 - break;
95987 - }
95988 mem_cgroup_uncharge_start();
95989 for (i = 0; i < pagevec_count(&pvec); i++) {
95990 struct page *page = pvec.pages[i];
95991 @@ -495,8 +493,12 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,
95992 if (radix_tree_exceptional_entry(page)) {
95993 if (unfalloc)
95994 continue;
95995 - nr_swaps_freed += !shmem_free_swap(mapping,
95996 - index, page);
95997 + if (shmem_free_swap(mapping, index, page)) {
95998 + /* Swap was replaced by page: retry */
95999 + index--;
96000 + break;
96001 + }
96002 + nr_swaps_freed++;
96003 continue;
96004 }
96005
96006 @@ -505,6 +507,11 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,
96007 if (page->mapping == mapping) {
96008 VM_BUG_ON_PAGE(PageWriteback(page), page);
96009 truncate_inode_page(mapping, page);
96010 + } else {
96011 + /* Page was replaced by swap: retry */
96012 + unlock_page(page);
96013 + index--;
96014 + break;
96015 }
96016 }
96017 unlock_page(page);
96018 @@ -759,6 +766,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
96019 spin_lock(&inode->i_lock);
96020 shmem_falloc = inode->i_private;
96021 if (shmem_falloc &&
96022 + !shmem_falloc->waitq &&
96023 index >= shmem_falloc->start &&
96024 index < shmem_falloc->next)
96025 shmem_falloc->nr_unswapped++;
96026 @@ -1233,6 +1241,64 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
96027 int error;
96028 int ret = VM_FAULT_LOCKED;
96029
96030 + /*
96031 + * Trinity finds that probing a hole which tmpfs is punching can
96032 + * prevent the hole-punch from ever completing: which in turn
96033 + * locks writers out with its hold on i_mutex. So refrain from
96034 + * faulting pages into the hole while it's being punched. Although
96035 + * shmem_undo_range() does remove the additions, it may be unable to
96036 + * keep up, as each new page needs its own unmap_mapping_range() call,
96037 + * and the i_mmap tree grows ever slower to scan if new vmas are added.
96038 + *
96039 + * It does not matter if we sometimes reach this check just before the
96040 + * hole-punch begins, so that one fault then races with the punch:
96041 + * we just need to make racing faults a rare case.
96042 + *
96043 + * The implementation below would be much simpler if we just used a
96044 + * standard mutex or completion: but we cannot take i_mutex in fault,
96045 + * and bloating every shmem inode for this unlikely case would be sad.
96046 + */
96047 + if (unlikely(inode->i_private)) {
96048 + struct shmem_falloc *shmem_falloc;
96049 +
96050 + spin_lock(&inode->i_lock);
96051 + shmem_falloc = inode->i_private;
96052 + if (shmem_falloc &&
96053 + shmem_falloc->waitq &&
96054 + vmf->pgoff >= shmem_falloc->start &&
96055 + vmf->pgoff < shmem_falloc->next) {
96056 + wait_queue_head_t *shmem_falloc_waitq;
96057 + DEFINE_WAIT(shmem_fault_wait);
96058 +
96059 + ret = VM_FAULT_NOPAGE;
96060 + if ((vmf->flags & FAULT_FLAG_ALLOW_RETRY) &&
96061 + !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
96062 + /* It's polite to up mmap_sem if we can */
96063 + up_read(&vma->vm_mm->mmap_sem);
96064 + ret = VM_FAULT_RETRY;
96065 + }
96066 +
96067 + shmem_falloc_waitq = shmem_falloc->waitq;
96068 + prepare_to_wait(shmem_falloc_waitq, &shmem_fault_wait,
96069 + TASK_UNINTERRUPTIBLE);
96070 + spin_unlock(&inode->i_lock);
96071 + schedule();
96072 +
96073 + /*
96074 + * shmem_falloc_waitq points into the shmem_fallocate()
96075 + * stack of the hole-punching task: shmem_falloc_waitq
96076 + * is usually invalid by the time we reach here, but
96077 + * finish_wait() does not dereference it in that case;
96078 + * though i_lock needed lest racing with wake_up_all().
96079 + */
96080 + spin_lock(&inode->i_lock);
96081 + finish_wait(shmem_falloc_waitq, &shmem_fault_wait);
96082 + spin_unlock(&inode->i_lock);
96083 + return ret;
96084 + }
96085 + spin_unlock(&inode->i_lock);
96086 + }
96087 +
96088 error = shmem_getpage(inode, vmf->pgoff, &vmf->page, SGP_CACHE, &ret);
96089 if (error)
96090 return ((error == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS);
96091 @@ -1737,12 +1803,25 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset,
96092 struct address_space *mapping = file->f_mapping;
96093 loff_t unmap_start = round_up(offset, PAGE_SIZE);
96094 loff_t unmap_end = round_down(offset + len, PAGE_SIZE) - 1;
96095 + DECLARE_WAIT_QUEUE_HEAD_ONSTACK(shmem_falloc_waitq);
96096 +
96097 + shmem_falloc.waitq = &shmem_falloc_waitq;
96098 + shmem_falloc.start = unmap_start >> PAGE_SHIFT;
96099 + shmem_falloc.next = (unmap_end + 1) >> PAGE_SHIFT;
96100 + spin_lock(&inode->i_lock);
96101 + inode->i_private = &shmem_falloc;
96102 + spin_unlock(&inode->i_lock);
96103
96104 if ((u64)unmap_end > (u64)unmap_start)
96105 unmap_mapping_range(mapping, unmap_start,
96106 1 + unmap_end - unmap_start, 0);
96107 shmem_truncate_range(inode, offset, offset + len - 1);
96108 /* No need to unmap again: hole-punching leaves COWed pages */
96109 +
96110 + spin_lock(&inode->i_lock);
96111 + inode->i_private = NULL;
96112 + wake_up_all(&shmem_falloc_waitq);
96113 + spin_unlock(&inode->i_lock);
96114 error = 0;
96115 goto out;
96116 }
96117 @@ -1760,6 +1839,7 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset,
96118 goto out;
96119 }
96120
96121 + shmem_falloc.waitq = NULL;
96122 shmem_falloc.start = start;
96123 shmem_falloc.next = start;
96124 shmem_falloc.nr_falloced = 0;
96125 @@ -2138,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
96126 static int shmem_xattr_validate(const char *name)
96127 {
96128 struct { const char *prefix; size_t len; } arr[] = {
96129 +
96130 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
96131 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
96132 +#endif
96133 +
96134 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
96135 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
96136 };
96137 @@ -2193,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
96138 if (err)
96139 return err;
96140
96141 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
96142 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
96143 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
96144 + return -EOPNOTSUPP;
96145 + if (size > 8)
96146 + return -EINVAL;
96147 + }
96148 +#endif
96149 +
96150 return simple_xattr_set(&info->xattrs, name, value, size, flags);
96151 }
96152
96153 @@ -2505,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
96154 int err = -ENOMEM;
96155
96156 /* Round up to L1_CACHE_BYTES to resist false sharing */
96157 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
96158 - L1_CACHE_BYTES), GFP_KERNEL);
96159 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
96160 if (!sbinfo)
96161 return -ENOMEM;
96162
96163 diff --git a/mm/slab.c b/mm/slab.c
96164 index 9432556..e0dc685 100644
96165 --- a/mm/slab.c
96166 +++ b/mm/slab.c
96167 @@ -311,10 +311,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
96168 if ((x)->max_freeable < i) \
96169 (x)->max_freeable = i; \
96170 } while (0)
96171 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
96172 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
96173 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
96174 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
96175 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
96176 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
96177 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
96178 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
96179 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
96180 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
96181 #else
96182 #define STATS_INC_ACTIVE(x) do { } while (0)
96183 #define STATS_DEC_ACTIVE(x) do { } while (0)
96184 @@ -331,6 +333,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
96185 #define STATS_INC_ALLOCMISS(x) do { } while (0)
96186 #define STATS_INC_FREEHIT(x) do { } while (0)
96187 #define STATS_INC_FREEMISS(x) do { } while (0)
96188 +#define STATS_INC_SANITIZED(x) do { } while (0)
96189 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
96190 #endif
96191
96192 #if DEBUG
96193 @@ -447,7 +451,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
96194 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
96195 */
96196 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
96197 - const struct page *page, void *obj)
96198 + const struct page *page, const void *obj)
96199 {
96200 u32 offset = (obj - page->s_mem);
96201 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
96202 @@ -1558,12 +1562,12 @@ void __init kmem_cache_init(void)
96203 */
96204
96205 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
96206 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
96207 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
96208
96209 if (INDEX_AC != INDEX_NODE)
96210 kmalloc_caches[INDEX_NODE] =
96211 create_kmalloc_cache("kmalloc-node",
96212 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
96213 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
96214
96215 slab_early_init = 0;
96216
96217 @@ -3525,6 +3529,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
96218 struct array_cache *ac = cpu_cache_get(cachep);
96219
96220 check_irq_off();
96221 +
96222 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96223 + if (pax_sanitize_slab) {
96224 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
96225 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
96226 +
96227 + if (cachep->ctor)
96228 + cachep->ctor(objp);
96229 +
96230 + STATS_INC_SANITIZED(cachep);
96231 + } else
96232 + STATS_INC_NOT_SANITIZED(cachep);
96233 + }
96234 +#endif
96235 +
96236 kmemleak_free_recursive(objp, cachep->flags);
96237 objp = cache_free_debugcheck(cachep, objp, caller);
96238
96239 @@ -3748,6 +3767,7 @@ void kfree(const void *objp)
96240
96241 if (unlikely(ZERO_OR_NULL_PTR(objp)))
96242 return;
96243 + VM_BUG_ON(!virt_addr_valid(objp));
96244 local_irq_save(flags);
96245 kfree_debugcheck(objp);
96246 c = virt_to_cache(objp);
96247 @@ -4189,14 +4209,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
96248 }
96249 /* cpu stats */
96250 {
96251 - unsigned long allochit = atomic_read(&cachep->allochit);
96252 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
96253 - unsigned long freehit = atomic_read(&cachep->freehit);
96254 - unsigned long freemiss = atomic_read(&cachep->freemiss);
96255 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
96256 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
96257 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
96258 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
96259
96260 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
96261 allochit, allocmiss, freehit, freemiss);
96262 }
96263 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96264 + {
96265 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
96266 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
96267 +
96268 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
96269 + }
96270 +#endif
96271 #endif
96272 }
96273
96274 @@ -4417,13 +4445,69 @@ static const struct file_operations proc_slabstats_operations = {
96275 static int __init slab_proc_init(void)
96276 {
96277 #ifdef CONFIG_DEBUG_SLAB_LEAK
96278 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
96279 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
96280 #endif
96281 return 0;
96282 }
96283 module_init(slab_proc_init);
96284 #endif
96285
96286 +bool is_usercopy_object(const void *ptr)
96287 +{
96288 + struct page *page;
96289 + struct kmem_cache *cachep;
96290 +
96291 + if (ZERO_OR_NULL_PTR(ptr))
96292 + return false;
96293 +
96294 + if (!slab_is_available())
96295 + return false;
96296 +
96297 + if (!virt_addr_valid(ptr))
96298 + return false;
96299 +
96300 + page = virt_to_head_page(ptr);
96301 +
96302 + if (!PageSlab(page))
96303 + return false;
96304 +
96305 + cachep = page->slab_cache;
96306 + return cachep->flags & SLAB_USERCOPY;
96307 +}
96308 +
96309 +#ifdef CONFIG_PAX_USERCOPY
96310 +const char *check_heap_object(const void *ptr, unsigned long n)
96311 +{
96312 + struct page *page;
96313 + struct kmem_cache *cachep;
96314 + unsigned int objnr;
96315 + unsigned long offset;
96316 +
96317 + if (ZERO_OR_NULL_PTR(ptr))
96318 + return "<null>";
96319 +
96320 + if (!virt_addr_valid(ptr))
96321 + return NULL;
96322 +
96323 + page = virt_to_head_page(ptr);
96324 +
96325 + if (!PageSlab(page))
96326 + return NULL;
96327 +
96328 + cachep = page->slab_cache;
96329 + if (!(cachep->flags & SLAB_USERCOPY))
96330 + return cachep->name;
96331 +
96332 + objnr = obj_to_index(cachep, page, ptr);
96333 + BUG_ON(objnr >= cachep->num);
96334 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
96335 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
96336 + return NULL;
96337 +
96338 + return cachep->name;
96339 +}
96340 +#endif
96341 +
96342 /**
96343 * ksize - get the actual amount of memory allocated for a given object
96344 * @objp: Pointer to the object
96345 diff --git a/mm/slab.h b/mm/slab.h
96346 index 6bd4c35..97565a1 100644
96347 --- a/mm/slab.h
96348 +++ b/mm/slab.h
96349 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
96350 /* The slab cache that manages slab cache information */
96351 extern struct kmem_cache *kmem_cache;
96352
96353 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96354 +#ifdef CONFIG_X86_64
96355 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
96356 +#else
96357 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
96358 +#endif
96359 +extern bool pax_sanitize_slab;
96360 +#endif
96361 +
96362 unsigned long calculate_alignment(unsigned long flags,
96363 unsigned long align, unsigned long size);
96364
96365 @@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96366
96367 /* Legal flag mask for kmem_cache_create(), for various configurations */
96368 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
96369 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
96370 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
96371 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
96372
96373 #if defined(CONFIG_DEBUG_SLAB)
96374 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
96375 @@ -245,6 +255,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
96376 return s;
96377
96378 page = virt_to_head_page(x);
96379 +
96380 + BUG_ON(!PageSlab(page));
96381 +
96382 cachep = page->slab_cache;
96383 if (slab_equal_or_root(cachep, s))
96384 return cachep;
96385 diff --git a/mm/slab_common.c b/mm/slab_common.c
96386 index 102cc6f..c7aab3d 100644
96387 --- a/mm/slab_common.c
96388 +++ b/mm/slab_common.c
96389 @@ -23,11 +23,22 @@
96390
96391 #include "slab.h"
96392
96393 -enum slab_state slab_state;
96394 +enum slab_state slab_state __read_only;
96395 LIST_HEAD(slab_caches);
96396 DEFINE_MUTEX(slab_mutex);
96397 struct kmem_cache *kmem_cache;
96398
96399 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96400 +bool pax_sanitize_slab __read_only = true;
96401 +static int __init pax_sanitize_slab_setup(char *str)
96402 +{
96403 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
96404 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
96405 + return 1;
96406 +}
96407 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
96408 +#endif
96409 +
96410 #ifdef CONFIG_DEBUG_VM
96411 static int kmem_cache_sanity_check(const char *name, size_t size)
96412 {
96413 @@ -158,7 +169,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
96414 if (err)
96415 goto out_free_cache;
96416
96417 - s->refcount = 1;
96418 + atomic_set(&s->refcount, 1);
96419 list_add(&s->list, &slab_caches);
96420 memcg_register_cache(s);
96421 out:
96422 @@ -334,8 +345,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96423 get_online_cpus();
96424 mutex_lock(&slab_mutex);
96425
96426 - s->refcount--;
96427 - if (s->refcount)
96428 + if (!atomic_dec_and_test(&s->refcount))
96429 goto out_unlock;
96430
96431 if (kmem_cache_destroy_memcg_children(s) != 0)
96432 @@ -358,7 +368,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96433 rcu_barrier();
96434
96435 memcg_free_cache_params(s);
96436 -#ifdef SLAB_SUPPORTS_SYSFS
96437 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96438 sysfs_slab_remove(s);
96439 #else
96440 slab_kmem_cache_release(s);
96441 @@ -393,7 +403,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
96442 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
96443 name, size, err);
96444
96445 - s->refcount = -1; /* Exempt from merging for now */
96446 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
96447 }
96448
96449 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96450 @@ -406,7 +416,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96451
96452 create_boot_cache(s, name, size, flags);
96453 list_add(&s->list, &slab_caches);
96454 - s->refcount = 1;
96455 + atomic_set(&s->refcount, 1);
96456 return s;
96457 }
96458
96459 @@ -418,6 +428,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
96460 EXPORT_SYMBOL(kmalloc_dma_caches);
96461 #endif
96462
96463 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96464 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
96465 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
96466 +#endif
96467 +
96468 /*
96469 * Conversion table for small slabs sizes / 8 to the index in the
96470 * kmalloc array. This is necessary for slabs < 192 since we have non power
96471 @@ -482,6 +497,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
96472 return kmalloc_dma_caches[index];
96473
96474 #endif
96475 +
96476 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96477 + if (unlikely((flags & GFP_USERCOPY)))
96478 + return kmalloc_usercopy_caches[index];
96479 +
96480 +#endif
96481 +
96482 return kmalloc_caches[index];
96483 }
96484
96485 @@ -538,7 +560,7 @@ void __init create_kmalloc_caches(unsigned long flags)
96486 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
96487 if (!kmalloc_caches[i]) {
96488 kmalloc_caches[i] = create_kmalloc_cache(NULL,
96489 - 1 << i, flags);
96490 + 1 << i, SLAB_USERCOPY | flags);
96491 }
96492
96493 /*
96494 @@ -547,10 +569,10 @@ void __init create_kmalloc_caches(unsigned long flags)
96495 * earlier power of two caches
96496 */
96497 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
96498 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
96499 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
96500
96501 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
96502 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
96503 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
96504 }
96505
96506 /* Kmalloc array is now usable */
96507 @@ -583,6 +605,23 @@ void __init create_kmalloc_caches(unsigned long flags)
96508 }
96509 }
96510 #endif
96511 +
96512 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96513 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
96514 + struct kmem_cache *s = kmalloc_caches[i];
96515 +
96516 + if (s) {
96517 + int size = kmalloc_size(i);
96518 + char *n = kasprintf(GFP_NOWAIT,
96519 + "usercopy-kmalloc-%d", size);
96520 +
96521 + BUG_ON(!n);
96522 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
96523 + size, SLAB_USERCOPY | flags);
96524 + }
96525 + }
96526 +#endif
96527 +
96528 }
96529 #endif /* !CONFIG_SLOB */
96530
96531 @@ -623,6 +662,9 @@ void print_slabinfo_header(struct seq_file *m)
96532 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
96533 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
96534 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
96535 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96536 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
96537 +#endif
96538 #endif
96539 seq_putc(m, '\n');
96540 }
96541 diff --git a/mm/slob.c b/mm/slob.c
96542 index 730cad4..8cfd442 100644
96543 --- a/mm/slob.c
96544 +++ b/mm/slob.c
96545 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
96546 /*
96547 * Return the size of a slob block.
96548 */
96549 -static slobidx_t slob_units(slob_t *s)
96550 +static slobidx_t slob_units(const slob_t *s)
96551 {
96552 if (s->units > 0)
96553 return s->units;
96554 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
96555 /*
96556 * Return the next free slob block pointer after this one.
96557 */
96558 -static slob_t *slob_next(slob_t *s)
96559 +static slob_t *slob_next(const slob_t *s)
96560 {
96561 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
96562 slobidx_t next;
96563 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
96564 /*
96565 * Returns true if s is the last free block in its page.
96566 */
96567 -static int slob_last(slob_t *s)
96568 +static int slob_last(const slob_t *s)
96569 {
96570 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
96571 }
96572
96573 -static void *slob_new_pages(gfp_t gfp, int order, int node)
96574 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
96575 {
96576 - void *page;
96577 + struct page *page;
96578
96579 #ifdef CONFIG_NUMA
96580 if (node != NUMA_NO_NODE)
96581 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96582 if (!page)
96583 return NULL;
96584
96585 - return page_address(page);
96586 + __SetPageSlab(page);
96587 + return page;
96588 }
96589
96590 -static void slob_free_pages(void *b, int order)
96591 +static void slob_free_pages(struct page *sp, int order)
96592 {
96593 if (current->reclaim_state)
96594 current->reclaim_state->reclaimed_slab += 1 << order;
96595 - free_pages((unsigned long)b, order);
96596 + __ClearPageSlab(sp);
96597 + page_mapcount_reset(sp);
96598 + sp->private = 0;
96599 + __free_pages(sp, order);
96600 }
96601
96602 /*
96603 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96604
96605 /* Not enough space: must allocate a new page */
96606 if (!b) {
96607 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96608 - if (!b)
96609 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96610 + if (!sp)
96611 return NULL;
96612 - sp = virt_to_page(b);
96613 - __SetPageSlab(sp);
96614 + b = page_address(sp);
96615
96616 spin_lock_irqsave(&slob_lock, flags);
96617 sp->units = SLOB_UNITS(PAGE_SIZE);
96618 sp->freelist = b;
96619 + sp->private = 0;
96620 INIT_LIST_HEAD(&sp->lru);
96621 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96622 set_slob_page_free(sp, slob_list);
96623 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96624 if (slob_page_free(sp))
96625 clear_slob_page_free(sp);
96626 spin_unlock_irqrestore(&slob_lock, flags);
96627 - __ClearPageSlab(sp);
96628 - page_mapcount_reset(sp);
96629 - slob_free_pages(b, 0);
96630 + slob_free_pages(sp, 0);
96631 return;
96632 }
96633
96634 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96635 + if (pax_sanitize_slab)
96636 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96637 +#endif
96638 +
96639 if (!slob_page_free(sp)) {
96640 /* This slob page is about to become partially free. Easy! */
96641 sp->units = units;
96642 @@ -424,11 +431,10 @@ out:
96643 */
96644
96645 static __always_inline void *
96646 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96647 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96648 {
96649 - unsigned int *m;
96650 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96651 - void *ret;
96652 + slob_t *m;
96653 + void *ret = NULL;
96654
96655 gfp &= gfp_allowed_mask;
96656
96657 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96658
96659 if (!m)
96660 return NULL;
96661 - *m = size;
96662 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96663 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96664 + m[0].units = size;
96665 + m[1].units = align;
96666 ret = (void *)m + align;
96667
96668 trace_kmalloc_node(caller, ret,
96669 size, size + align, gfp, node);
96670 } else {
96671 unsigned int order = get_order(size);
96672 + struct page *page;
96673
96674 if (likely(order))
96675 gfp |= __GFP_COMP;
96676 - ret = slob_new_pages(gfp, order, node);
96677 + page = slob_new_pages(gfp, order, node);
96678 + if (page) {
96679 + ret = page_address(page);
96680 + page->private = size;
96681 + }
96682
96683 trace_kmalloc_node(caller, ret,
96684 size, PAGE_SIZE << order, gfp, node);
96685 }
96686
96687 - kmemleak_alloc(ret, size, 1, gfp);
96688 + return ret;
96689 +}
96690 +
96691 +static __always_inline void *
96692 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96693 +{
96694 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96695 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96696 +
96697 + if (!ZERO_OR_NULL_PTR(ret))
96698 + kmemleak_alloc(ret, size, 1, gfp);
96699 return ret;
96700 }
96701
96702 @@ -493,34 +517,112 @@ void kfree(const void *block)
96703 return;
96704 kmemleak_free(block);
96705
96706 + VM_BUG_ON(!virt_addr_valid(block));
96707 sp = virt_to_page(block);
96708 - if (PageSlab(sp)) {
96709 + VM_BUG_ON(!PageSlab(sp));
96710 + if (!sp->private) {
96711 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96712 - unsigned int *m = (unsigned int *)(block - align);
96713 - slob_free(m, *m + align);
96714 - } else
96715 + slob_t *m = (slob_t *)(block - align);
96716 + slob_free(m, m[0].units + align);
96717 + } else {
96718 + __ClearPageSlab(sp);
96719 + page_mapcount_reset(sp);
96720 + sp->private = 0;
96721 __free_pages(sp, compound_order(sp));
96722 + }
96723 }
96724 EXPORT_SYMBOL(kfree);
96725
96726 +bool is_usercopy_object(const void *ptr)
96727 +{
96728 + if (!slab_is_available())
96729 + return false;
96730 +
96731 + // PAX: TODO
96732 +
96733 + return false;
96734 +}
96735 +
96736 +#ifdef CONFIG_PAX_USERCOPY
96737 +const char *check_heap_object(const void *ptr, unsigned long n)
96738 +{
96739 + struct page *page;
96740 + const slob_t *free;
96741 + const void *base;
96742 + unsigned long flags;
96743 +
96744 + if (ZERO_OR_NULL_PTR(ptr))
96745 + return "<null>";
96746 +
96747 + if (!virt_addr_valid(ptr))
96748 + return NULL;
96749 +
96750 + page = virt_to_head_page(ptr);
96751 + if (!PageSlab(page))
96752 + return NULL;
96753 +
96754 + if (page->private) {
96755 + base = page;
96756 + if (base <= ptr && n <= page->private - (ptr - base))
96757 + return NULL;
96758 + return "<slob>";
96759 + }
96760 +
96761 + /* some tricky double walking to find the chunk */
96762 + spin_lock_irqsave(&slob_lock, flags);
96763 + base = (void *)((unsigned long)ptr & PAGE_MASK);
96764 + free = page->freelist;
96765 +
96766 + while (!slob_last(free) && (void *)free <= ptr) {
96767 + base = free + slob_units(free);
96768 + free = slob_next(free);
96769 + }
96770 +
96771 + while (base < (void *)free) {
96772 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96773 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
96774 + int offset;
96775 +
96776 + if (ptr < base + align)
96777 + break;
96778 +
96779 + offset = ptr - base - align;
96780 + if (offset >= m) {
96781 + base += size;
96782 + continue;
96783 + }
96784 +
96785 + if (n > m - offset)
96786 + break;
96787 +
96788 + spin_unlock_irqrestore(&slob_lock, flags);
96789 + return NULL;
96790 + }
96791 +
96792 + spin_unlock_irqrestore(&slob_lock, flags);
96793 + return "<slob>";
96794 +}
96795 +#endif
96796 +
96797 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96798 size_t ksize(const void *block)
96799 {
96800 struct page *sp;
96801 int align;
96802 - unsigned int *m;
96803 + slob_t *m;
96804
96805 BUG_ON(!block);
96806 if (unlikely(block == ZERO_SIZE_PTR))
96807 return 0;
96808
96809 sp = virt_to_page(block);
96810 - if (unlikely(!PageSlab(sp)))
96811 - return PAGE_SIZE << compound_order(sp);
96812 + VM_BUG_ON(!PageSlab(sp));
96813 + if (sp->private)
96814 + return sp->private;
96815
96816 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96817 - m = (unsigned int *)(block - align);
96818 - return SLOB_UNITS(*m) * SLOB_UNIT;
96819 + m = (slob_t *)(block - align);
96820 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
96821 }
96822 EXPORT_SYMBOL(ksize);
96823
96824 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
96825
96826 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
96827 {
96828 - void *b;
96829 + void *b = NULL;
96830
96831 flags &= gfp_allowed_mask;
96832
96833 lockdep_trace_alloc(flags);
96834
96835 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96836 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
96837 +#else
96838 if (c->size < PAGE_SIZE) {
96839 b = slob_alloc(c->size, flags, c->align, node);
96840 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96841 SLOB_UNITS(c->size) * SLOB_UNIT,
96842 flags, node);
96843 } else {
96844 - b = slob_new_pages(flags, get_order(c->size), node);
96845 + struct page *sp;
96846 +
96847 + sp = slob_new_pages(flags, get_order(c->size), node);
96848 + if (sp) {
96849 + b = page_address(sp);
96850 + sp->private = c->size;
96851 + }
96852 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96853 PAGE_SIZE << get_order(c->size),
96854 flags, node);
96855 }
96856 +#endif
96857
96858 if (b && c->ctor)
96859 c->ctor(b);
96860 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
96861
96862 static void __kmem_cache_free(void *b, int size)
96863 {
96864 - if (size < PAGE_SIZE)
96865 + struct page *sp;
96866 +
96867 + sp = virt_to_page(b);
96868 + BUG_ON(!PageSlab(sp));
96869 + if (!sp->private)
96870 slob_free(b, size);
96871 else
96872 - slob_free_pages(b, get_order(size));
96873 + slob_free_pages(sp, get_order(size));
96874 }
96875
96876 static void kmem_rcu_free(struct rcu_head *head)
96877 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
96878
96879 void kmem_cache_free(struct kmem_cache *c, void *b)
96880 {
96881 + int size = c->size;
96882 +
96883 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96884 + if (size + c->align < PAGE_SIZE) {
96885 + size += c->align;
96886 + b -= c->align;
96887 + }
96888 +#endif
96889 +
96890 kmemleak_free_recursive(b, c->flags);
96891 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
96892 struct slob_rcu *slob_rcu;
96893 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
96894 - slob_rcu->size = c->size;
96895 + slob_rcu = b + (size - sizeof(struct slob_rcu));
96896 + slob_rcu->size = size;
96897 call_rcu(&slob_rcu->head, kmem_rcu_free);
96898 } else {
96899 - __kmem_cache_free(b, c->size);
96900 + __kmem_cache_free(b, size);
96901 }
96902
96903 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96904 + trace_kfree(_RET_IP_, b);
96905 +#else
96906 trace_kmem_cache_free(_RET_IP_, b);
96907 +#endif
96908 +
96909 }
96910 EXPORT_SYMBOL(kmem_cache_free);
96911
96912 diff --git a/mm/slub.c b/mm/slub.c
96913 index 2b1ce69..4a2193f 100644
96914 --- a/mm/slub.c
96915 +++ b/mm/slub.c
96916 @@ -207,7 +207,7 @@ struct track {
96917
96918 enum track_item { TRACK_ALLOC, TRACK_FREE };
96919
96920 -#ifdef CONFIG_SYSFS
96921 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96922 static int sysfs_slab_add(struct kmem_cache *);
96923 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96924 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
96925 @@ -546,7 +546,7 @@ static void print_track(const char *s, struct track *t)
96926 if (!t->addr)
96927 return;
96928
96929 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96930 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96931 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96932 #ifdef CONFIG_STACKTRACE
96933 {
96934 @@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96935
96936 slab_free_hook(s, x);
96937
96938 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96939 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96940 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96941 + if (s->ctor)
96942 + s->ctor(x);
96943 + }
96944 +#endif
96945 +
96946 redo:
96947 /*
96948 * Determine the currently cpus per cpu slab.
96949 @@ -2733,7 +2741,7 @@ static int slub_min_objects;
96950 * Merge control. If this is set then no merging of slab caches will occur.
96951 * (Could be removed. This was introduced to pacify the merge skeptics.)
96952 */
96953 -static int slub_nomerge;
96954 +static int slub_nomerge = 1;
96955
96956 /*
96957 * Calculate the order of allocation given an slab object size.
96958 @@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96959 s->inuse = size;
96960
96961 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96962 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96963 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96964 +#endif
96965 s->ctor)) {
96966 /*
96967 * Relocate free pointer after the object if it is not
96968 @@ -3343,6 +3354,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96969 EXPORT_SYMBOL(__kmalloc_node);
96970 #endif
96971
96972 +bool is_usercopy_object(const void *ptr)
96973 +{
96974 + struct page *page;
96975 + struct kmem_cache *s;
96976 +
96977 + if (ZERO_OR_NULL_PTR(ptr))
96978 + return false;
96979 +
96980 + if (!slab_is_available())
96981 + return false;
96982 +
96983 + if (!virt_addr_valid(ptr))
96984 + return false;
96985 +
96986 + page = virt_to_head_page(ptr);
96987 +
96988 + if (!PageSlab(page))
96989 + return false;
96990 +
96991 + s = page->slab_cache;
96992 + return s->flags & SLAB_USERCOPY;
96993 +}
96994 +
96995 +#ifdef CONFIG_PAX_USERCOPY
96996 +const char *check_heap_object(const void *ptr, unsigned long n)
96997 +{
96998 + struct page *page;
96999 + struct kmem_cache *s;
97000 + unsigned long offset;
97001 +
97002 + if (ZERO_OR_NULL_PTR(ptr))
97003 + return "<null>";
97004 +
97005 + if (!virt_addr_valid(ptr))
97006 + return NULL;
97007 +
97008 + page = virt_to_head_page(ptr);
97009 +
97010 + if (!PageSlab(page))
97011 + return NULL;
97012 +
97013 + s = page->slab_cache;
97014 + if (!(s->flags & SLAB_USERCOPY))
97015 + return s->name;
97016 +
97017 + offset = (ptr - page_address(page)) % s->size;
97018 + if (offset <= s->object_size && n <= s->object_size - offset)
97019 + return NULL;
97020 +
97021 + return s->name;
97022 +}
97023 +#endif
97024 +
97025 size_t ksize(const void *object)
97026 {
97027 struct page *page;
97028 @@ -3371,6 +3435,7 @@ void kfree(const void *x)
97029 if (unlikely(ZERO_OR_NULL_PTR(x)))
97030 return;
97031
97032 + VM_BUG_ON(!virt_addr_valid(x));
97033 page = virt_to_head_page(x);
97034 if (unlikely(!PageSlab(page))) {
97035 BUG_ON(!PageCompound(page));
97036 @@ -3679,7 +3744,7 @@ static int slab_unmergeable(struct kmem_cache *s)
97037 /*
97038 * We may have set a slab to be unmergeable during bootstrap.
97039 */
97040 - if (s->refcount < 0)
97041 + if (atomic_read(&s->refcount) < 0)
97042 return 1;
97043
97044 return 0;
97045 @@ -3736,7 +3801,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
97046 int i;
97047 struct kmem_cache *c;
97048
97049 - s->refcount++;
97050 + atomic_inc(&s->refcount);
97051
97052 /*
97053 * Adjust the object sizes so that we clear
97054 @@ -3755,7 +3820,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
97055 }
97056
97057 if (sysfs_slab_alias(s, name)) {
97058 - s->refcount--;
97059 + atomic_dec(&s->refcount);
97060 s = NULL;
97061 }
97062 }
97063 @@ -3872,7 +3937,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
97064 }
97065 #endif
97066
97067 -#ifdef CONFIG_SYSFS
97068 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97069 static int count_inuse(struct page *page)
97070 {
97071 return page->inuse;
97072 @@ -4156,7 +4221,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
97073 len += sprintf(buf + len, "%7ld ", l->count);
97074
97075 if (l->addr)
97076 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97077 + len += sprintf(buf + len, "%pS", NULL);
97078 +#else
97079 len += sprintf(buf + len, "%pS", (void *)l->addr);
97080 +#endif
97081 else
97082 len += sprintf(buf + len, "<not-available>");
97083
97084 @@ -4261,12 +4330,12 @@ static void resiliency_test(void)
97085 validate_slab_cache(kmalloc_caches[9]);
97086 }
97087 #else
97088 -#ifdef CONFIG_SYSFS
97089 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97090 static void resiliency_test(void) {};
97091 #endif
97092 #endif
97093
97094 -#ifdef CONFIG_SYSFS
97095 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97096 enum slab_stat_type {
97097 SL_ALL, /* All slabs */
97098 SL_PARTIAL, /* Only partially allocated slabs */
97099 @@ -4506,13 +4575,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
97100 {
97101 if (!s->ctor)
97102 return 0;
97103 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97104 + return sprintf(buf, "%pS\n", NULL);
97105 +#else
97106 return sprintf(buf, "%pS\n", s->ctor);
97107 +#endif
97108 }
97109 SLAB_ATTR_RO(ctor);
97110
97111 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
97112 {
97113 - return sprintf(buf, "%d\n", s->refcount - 1);
97114 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
97115 }
97116 SLAB_ATTR_RO(aliases);
97117
97118 @@ -4600,6 +4673,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
97119 SLAB_ATTR_RO(cache_dma);
97120 #endif
97121
97122 +#ifdef CONFIG_PAX_USERCOPY_SLABS
97123 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
97124 +{
97125 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
97126 +}
97127 +SLAB_ATTR_RO(usercopy);
97128 +#endif
97129 +
97130 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
97131 {
97132 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
97133 @@ -4934,6 +5015,9 @@ static struct attribute *slab_attrs[] = {
97134 #ifdef CONFIG_ZONE_DMA
97135 &cache_dma_attr.attr,
97136 #endif
97137 +#ifdef CONFIG_PAX_USERCOPY_SLABS
97138 + &usercopy_attr.attr,
97139 +#endif
97140 #ifdef CONFIG_NUMA
97141 &remote_node_defrag_ratio_attr.attr,
97142 #endif
97143 @@ -5184,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
97144 return name;
97145 }
97146
97147 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97148 static int sysfs_slab_add(struct kmem_cache *s)
97149 {
97150 int err;
97151 @@ -5257,6 +5342,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
97152 kobject_del(&s->kobj);
97153 kobject_put(&s->kobj);
97154 }
97155 +#endif
97156
97157 /*
97158 * Need to buffer aliases during bootup until sysfs becomes
97159 @@ -5270,6 +5356,7 @@ struct saved_alias {
97160
97161 static struct saved_alias *alias_list;
97162
97163 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97164 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
97165 {
97166 struct saved_alias *al;
97167 @@ -5292,6 +5379,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
97168 alias_list = al;
97169 return 0;
97170 }
97171 +#endif
97172
97173 static int __init slab_sysfs_init(void)
97174 {
97175 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
97176 index 4cba9c2..b4f9fcc 100644
97177 --- a/mm/sparse-vmemmap.c
97178 +++ b/mm/sparse-vmemmap.c
97179 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
97180 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
97181 if (!p)
97182 return NULL;
97183 - pud_populate(&init_mm, pud, p);
97184 + pud_populate_kernel(&init_mm, pud, p);
97185 }
97186 return pud;
97187 }
97188 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
97189 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
97190 if (!p)
97191 return NULL;
97192 - pgd_populate(&init_mm, pgd, p);
97193 + pgd_populate_kernel(&init_mm, pgd, p);
97194 }
97195 return pgd;
97196 }
97197 diff --git a/mm/sparse.c b/mm/sparse.c
97198 index d1b48b6..6e8590e 100644
97199 --- a/mm/sparse.c
97200 +++ b/mm/sparse.c
97201 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
97202
97203 for (i = 0; i < PAGES_PER_SECTION; i++) {
97204 if (PageHWPoison(&memmap[i])) {
97205 - atomic_long_sub(1, &num_poisoned_pages);
97206 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
97207 ClearPageHWPoison(&memmap[i]);
97208 }
97209 }
97210 diff --git a/mm/swap.c b/mm/swap.c
97211 index 9ce43ba..43bdc4c 100644
97212 --- a/mm/swap.c
97213 +++ b/mm/swap.c
97214 @@ -31,6 +31,7 @@
97215 #include <linux/memcontrol.h>
97216 #include <linux/gfp.h>
97217 #include <linux/uio.h>
97218 +#include <linux/hugetlb.h>
97219
97220 #include "internal.h"
97221
97222 @@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
97223
97224 __page_cache_release(page);
97225 dtor = get_compound_page_dtor(page);
97226 + if (!PageHuge(page))
97227 + BUG_ON(dtor != free_compound_page);
97228 (*dtor)(page);
97229 }
97230
97231 diff --git a/mm/swapfile.c b/mm/swapfile.c
97232 index 4a7f7e6..22cddf5 100644
97233 --- a/mm/swapfile.c
97234 +++ b/mm/swapfile.c
97235 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
97236
97237 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
97238 /* Activity counter to indicate that a swapon or swapoff has occurred */
97239 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
97240 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
97241
97242 static inline unsigned char swap_count(unsigned char ent)
97243 {
97244 @@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
97245 spin_unlock(&swap_lock);
97246
97247 err = 0;
97248 - atomic_inc(&proc_poll_event);
97249 + atomic_inc_unchecked(&proc_poll_event);
97250 wake_up_interruptible(&proc_poll_wait);
97251
97252 out_dput:
97253 @@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
97254
97255 poll_wait(file, &proc_poll_wait, wait);
97256
97257 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
97258 - seq->poll_event = atomic_read(&proc_poll_event);
97259 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
97260 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
97261 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
97262 }
97263
97264 @@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
97265 return ret;
97266
97267 seq = file->private_data;
97268 - seq->poll_event = atomic_read(&proc_poll_event);
97269 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
97270 return 0;
97271 }
97272
97273 @@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
97274 (frontswap_map) ? "FS" : "");
97275
97276 mutex_unlock(&swapon_mutex);
97277 - atomic_inc(&proc_poll_event);
97278 + atomic_inc_unchecked(&proc_poll_event);
97279 wake_up_interruptible(&proc_poll_wait);
97280
97281 if (S_ISREG(inode->i_mode))
97282 diff --git a/mm/util.c b/mm/util.c
97283 index d5ea733..e8953f9 100644
97284 --- a/mm/util.c
97285 +++ b/mm/util.c
97286 @@ -299,6 +299,12 @@ done:
97287 void arch_pick_mmap_layout(struct mm_struct *mm)
97288 {
97289 mm->mmap_base = TASK_UNMAPPED_BASE;
97290 +
97291 +#ifdef CONFIG_PAX_RANDMMAP
97292 + if (mm->pax_flags & MF_PAX_RANDMMAP)
97293 + mm->mmap_base += mm->delta_mmap;
97294 +#endif
97295 +
97296 mm->get_unmapped_area = arch_get_unmapped_area;
97297 }
97298 #endif
97299 @@ -475,6 +481,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
97300 if (!mm->arg_end)
97301 goto out_mm; /* Shh! No looking before we're done */
97302
97303 + if (gr_acl_handle_procpidmem(task))
97304 + goto out_mm;
97305 +
97306 len = mm->arg_end - mm->arg_start;
97307
97308 if (len > buflen)
97309 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
97310 index bf233b2..1dfa1bc 100644
97311 --- a/mm/vmalloc.c
97312 +++ b/mm/vmalloc.c
97313 @@ -40,6 +40,21 @@ struct vfree_deferred {
97314 };
97315 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
97316
97317 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97318 +struct stack_deferred_llist {
97319 + struct llist_head list;
97320 + void *stack;
97321 + void *lowmem_stack;
97322 +};
97323 +
97324 +struct stack_deferred {
97325 + struct stack_deferred_llist list;
97326 + struct work_struct wq;
97327 +};
97328 +
97329 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
97330 +#endif
97331 +
97332 static void __vunmap(const void *, int);
97333
97334 static void free_work(struct work_struct *w)
97335 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
97336 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
97337 struct llist_node *llnode = llist_del_all(&p->list);
97338 while (llnode) {
97339 - void *p = llnode;
97340 + void *x = llnode;
97341 llnode = llist_next(llnode);
97342 - __vunmap(p, 1);
97343 + __vunmap(x, 1);
97344 }
97345 }
97346
97347 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97348 +static void unmap_work(struct work_struct *w)
97349 +{
97350 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
97351 + struct llist_node *llnode = llist_del_all(&p->list.list);
97352 + while (llnode) {
97353 + struct stack_deferred_llist *x =
97354 + llist_entry((struct llist_head *)llnode,
97355 + struct stack_deferred_llist, list);
97356 + void *stack = ACCESS_ONCE(x->stack);
97357 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
97358 + llnode = llist_next(llnode);
97359 + __vunmap(stack, 0);
97360 + free_memcg_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
97361 + }
97362 +}
97363 +#endif
97364 +
97365 /*** Page table manipulation functions ***/
97366
97367 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
97368 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
97369
97370 pte = pte_offset_kernel(pmd, addr);
97371 do {
97372 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97373 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97374 +
97375 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97376 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
97377 + BUG_ON(!pte_exec(*pte));
97378 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
97379 + continue;
97380 + }
97381 +#endif
97382 +
97383 + {
97384 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97385 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97386 + }
97387 } while (pte++, addr += PAGE_SIZE, addr != end);
97388 }
97389
97390 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
97391 pte = pte_alloc_kernel(pmd, addr);
97392 if (!pte)
97393 return -ENOMEM;
97394 +
97395 + pax_open_kernel();
97396 do {
97397 struct page *page = pages[*nr];
97398
97399 - if (WARN_ON(!pte_none(*pte)))
97400 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97401 + if (pgprot_val(prot) & _PAGE_NX)
97402 +#endif
97403 +
97404 + if (!pte_none(*pte)) {
97405 + pax_close_kernel();
97406 + WARN_ON(1);
97407 return -EBUSY;
97408 - if (WARN_ON(!page))
97409 + }
97410 + if (!page) {
97411 + pax_close_kernel();
97412 + WARN_ON(1);
97413 return -ENOMEM;
97414 + }
97415 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
97416 (*nr)++;
97417 } while (pte++, addr += PAGE_SIZE, addr != end);
97418 + pax_close_kernel();
97419 return 0;
97420 }
97421
97422 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
97423 pmd_t *pmd;
97424 unsigned long next;
97425
97426 - pmd = pmd_alloc(&init_mm, pud, addr);
97427 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
97428 if (!pmd)
97429 return -ENOMEM;
97430 do {
97431 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
97432 pud_t *pud;
97433 unsigned long next;
97434
97435 - pud = pud_alloc(&init_mm, pgd, addr);
97436 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
97437 if (!pud)
97438 return -ENOMEM;
97439 do {
97440 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
97441 if (addr >= MODULES_VADDR && addr < MODULES_END)
97442 return 1;
97443 #endif
97444 +
97445 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97446 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
97447 + return 1;
97448 +#endif
97449 +
97450 return is_vmalloc_addr(x);
97451 }
97452
97453 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
97454
97455 if (!pgd_none(*pgd)) {
97456 pud_t *pud = pud_offset(pgd, addr);
97457 +#ifdef CONFIG_X86
97458 + if (!pud_large(*pud))
97459 +#endif
97460 if (!pud_none(*pud)) {
97461 pmd_t *pmd = pmd_offset(pud, addr);
97462 +#ifdef CONFIG_X86
97463 + if (!pmd_large(*pmd))
97464 +#endif
97465 if (!pmd_none(*pmd)) {
97466 pte_t *ptep, pte;
97467
97468 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
97469 for_each_possible_cpu(i) {
97470 struct vmap_block_queue *vbq;
97471 struct vfree_deferred *p;
97472 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97473 + struct stack_deferred *p2;
97474 +#endif
97475
97476 vbq = &per_cpu(vmap_block_queue, i);
97477 spin_lock_init(&vbq->lock);
97478 INIT_LIST_HEAD(&vbq->free);
97479 +
97480 p = &per_cpu(vfree_deferred, i);
97481 init_llist_head(&p->list);
97482 INIT_WORK(&p->wq, free_work);
97483 +
97484 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97485 + p2 = &per_cpu(stack_deferred, i);
97486 + init_llist_head(&p2->list.list);
97487 + INIT_WORK(&p2->wq, unmap_work);
97488 +#endif
97489 }
97490
97491 /* Import existing vmlist entries. */
97492 @@ -1317,6 +1396,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
97493 struct vm_struct *area;
97494
97495 BUG_ON(in_interrupt());
97496 +
97497 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97498 + if (flags & VM_KERNEXEC) {
97499 + if (start != VMALLOC_START || end != VMALLOC_END)
97500 + return NULL;
97501 + start = (unsigned long)MODULES_EXEC_VADDR;
97502 + end = (unsigned long)MODULES_EXEC_END;
97503 + }
97504 +#endif
97505 +
97506 if (flags & VM_IOREMAP)
97507 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
97508
97509 @@ -1522,6 +1611,23 @@ void vunmap(const void *addr)
97510 }
97511 EXPORT_SYMBOL(vunmap);
97512
97513 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97514 +void unmap_process_stacks(struct task_struct *task)
97515 +{
97516 + if (unlikely(in_interrupt())) {
97517 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
97518 + struct stack_deferred_llist *list = task->stack;
97519 + list->stack = task->stack;
97520 + list->lowmem_stack = task->lowmem_stack;
97521 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
97522 + schedule_work(&p->wq);
97523 + } else {
97524 + __vunmap(task->stack, 0);
97525 + free_memcg_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
97526 + }
97527 +}
97528 +#endif
97529 +
97530 /**
97531 * vmap - map an array of pages into virtually contiguous space
97532 * @pages: array of page pointers
97533 @@ -1542,6 +1648,11 @@ void *vmap(struct page **pages, unsigned int count,
97534 if (count > totalram_pages)
97535 return NULL;
97536
97537 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97538 + if (!(pgprot_val(prot) & _PAGE_NX))
97539 + flags |= VM_KERNEXEC;
97540 +#endif
97541 +
97542 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
97543 __builtin_return_address(0));
97544 if (!area)
97545 @@ -1642,6 +1753,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
97546 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
97547 goto fail;
97548
97549 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97550 + if (!(pgprot_val(prot) & _PAGE_NX))
97551 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
97552 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
97553 + else
97554 +#endif
97555 +
97556 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
97557 start, end, node, gfp_mask, caller);
97558 if (!area)
97559 @@ -1818,10 +1936,9 @@ EXPORT_SYMBOL(vzalloc_node);
97560 * For tight control over page level allocator and protection flags
97561 * use __vmalloc() instead.
97562 */
97563 -
97564 void *vmalloc_exec(unsigned long size)
97565 {
97566 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
97567 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
97568 NUMA_NO_NODE, __builtin_return_address(0));
97569 }
97570
97571 @@ -2128,6 +2245,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
97572 {
97573 struct vm_struct *area;
97574
97575 + BUG_ON(vma->vm_mirror);
97576 +
97577 size = PAGE_ALIGN(size);
97578
97579 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
97580 @@ -2610,7 +2729,11 @@ static int s_show(struct seq_file *m, void *p)
97581 v->addr, v->addr + v->size, v->size);
97582
97583 if (v->caller)
97584 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97585 + seq_printf(m, " %pK", v->caller);
97586 +#else
97587 seq_printf(m, " %pS", v->caller);
97588 +#endif
97589
97590 if (v->nr_pages)
97591 seq_printf(m, " pages=%d", v->nr_pages);
97592 diff --git a/mm/vmstat.c b/mm/vmstat.c
97593 index 302dd07..3841f1c 100644
97594 --- a/mm/vmstat.c
97595 +++ b/mm/vmstat.c
97596 @@ -20,6 +20,7 @@
97597 #include <linux/writeback.h>
97598 #include <linux/compaction.h>
97599 #include <linux/mm_inline.h>
97600 +#include <linux/grsecurity.h>
97601
97602 #include "internal.h"
97603
97604 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
97605 *
97606 * vm_stat contains the global counters
97607 */
97608 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97609 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97610 EXPORT_SYMBOL(vm_stat);
97611
97612 #ifdef CONFIG_SMP
97613 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
97614
97615 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97616 if (diff[i])
97617 - atomic_long_add(diff[i], &vm_stat[i]);
97618 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
97619 }
97620
97621 /*
97622 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
97623 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
97624 if (v) {
97625
97626 - atomic_long_add(v, &zone->vm_stat[i]);
97627 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97628 global_diff[i] += v;
97629 #ifdef CONFIG_NUMA
97630 /* 3 seconds idle till flush */
97631 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
97632
97633 v = p->vm_stat_diff[i];
97634 p->vm_stat_diff[i] = 0;
97635 - atomic_long_add(v, &zone->vm_stat[i]);
97636 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97637 global_diff[i] += v;
97638 }
97639 }
97640 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
97641 if (pset->vm_stat_diff[i]) {
97642 int v = pset->vm_stat_diff[i];
97643 pset->vm_stat_diff[i] = 0;
97644 - atomic_long_add(v, &zone->vm_stat[i]);
97645 - atomic_long_add(v, &vm_stat[i]);
97646 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97647 + atomic_long_add_unchecked(v, &vm_stat[i]);
97648 }
97649 }
97650 #endif
97651 @@ -1156,10 +1157,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
97652 stat_items_size += sizeof(struct vm_event_state);
97653 #endif
97654
97655 - v = kmalloc(stat_items_size, GFP_KERNEL);
97656 + v = kzalloc(stat_items_size, GFP_KERNEL);
97657 m->private = v;
97658 if (!v)
97659 return ERR_PTR(-ENOMEM);
97660 +
97661 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
97662 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
97663 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
97664 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
97665 + && !in_group_p(grsec_proc_gid)
97666 +#endif
97667 + )
97668 + return (unsigned long *)m->private + *pos;
97669 +#endif
97670 +#endif
97671 +
97672 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97673 v[i] = global_page_state(i);
97674 v += NR_VM_ZONE_STAT_ITEMS;
97675 @@ -1308,10 +1321,16 @@ static int __init setup_vmstat(void)
97676 cpu_notifier_register_done();
97677 #endif
97678 #ifdef CONFIG_PROC_FS
97679 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
97680 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
97681 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97682 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
97683 + {
97684 + mode_t gr_mode = S_IRUGO;
97685 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
97686 + gr_mode = S_IRUSR;
97687 +#endif
97688 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
97689 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
97690 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97691 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
97692 + }
97693 #endif
97694 return 0;
97695 }
97696 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
97697 index 44ebd5c..1f732bae 100644
97698 --- a/net/8021q/vlan.c
97699 +++ b/net/8021q/vlan.c
97700 @@ -475,7 +475,7 @@ out:
97701 return NOTIFY_DONE;
97702 }
97703
97704 -static struct notifier_block vlan_notifier_block __read_mostly = {
97705 +static struct notifier_block vlan_notifier_block = {
97706 .notifier_call = vlan_device_event,
97707 };
97708
97709 @@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
97710 err = -EPERM;
97711 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97712 break;
97713 - if ((args.u.name_type >= 0) &&
97714 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97715 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97716 struct vlan_net *vn;
97717
97718 vn = net_generic(net, vlan_net_id);
97719 diff --git a/net/9p/client.c b/net/9p/client.c
97720 index 0004cba..feba240 100644
97721 --- a/net/9p/client.c
97722 +++ b/net/9p/client.c
97723 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97724 len - inline_len);
97725 } else {
97726 err = copy_from_user(ename + inline_len,
97727 - uidata, len - inline_len);
97728 + (char __force_user *)uidata, len - inline_len);
97729 if (err) {
97730 err = -EFAULT;
97731 goto out_err;
97732 @@ -1571,7 +1571,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97733 kernel_buf = 1;
97734 indata = data;
97735 } else
97736 - indata = (__force char *)udata;
97737 + indata = (__force_kernel char *)udata;
97738 /*
97739 * response header len is 11
97740 * PDU Header(7) + IO Size (4)
97741 @@ -1646,7 +1646,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97742 kernel_buf = 1;
97743 odata = data;
97744 } else
97745 - odata = (char *)udata;
97746 + odata = (char __force_kernel *)udata;
97747 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97748 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97749 fid->fid, offset, rsize);
97750 diff --git a/net/9p/mod.c b/net/9p/mod.c
97751 index 6ab36ae..6f1841b 100644
97752 --- a/net/9p/mod.c
97753 +++ b/net/9p/mod.c
97754 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97755 void v9fs_register_trans(struct p9_trans_module *m)
97756 {
97757 spin_lock(&v9fs_trans_lock);
97758 - list_add_tail(&m->list, &v9fs_trans_list);
97759 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97760 spin_unlock(&v9fs_trans_lock);
97761 }
97762 EXPORT_SYMBOL(v9fs_register_trans);
97763 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97764 void v9fs_unregister_trans(struct p9_trans_module *m)
97765 {
97766 spin_lock(&v9fs_trans_lock);
97767 - list_del_init(&m->list);
97768 + pax_list_del_init((struct list_head *)&m->list);
97769 spin_unlock(&v9fs_trans_lock);
97770 }
97771 EXPORT_SYMBOL(v9fs_unregister_trans);
97772 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97773 index 80d08f6..de63fd1 100644
97774 --- a/net/9p/trans_fd.c
97775 +++ b/net/9p/trans_fd.c
97776 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97777 oldfs = get_fs();
97778 set_fs(get_ds());
97779 /* The cast to a user pointer is valid due to the set_fs() */
97780 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97781 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97782 set_fs(oldfs);
97783
97784 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97785 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97786 index af46bc4..f9adfcd 100644
97787 --- a/net/appletalk/atalk_proc.c
97788 +++ b/net/appletalk/atalk_proc.c
97789 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97790 struct proc_dir_entry *p;
97791 int rc = -ENOMEM;
97792
97793 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97794 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97795 if (!atalk_proc_dir)
97796 goto out;
97797
97798 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97799 index 876fbe8..8bbea9f 100644
97800 --- a/net/atm/atm_misc.c
97801 +++ b/net/atm/atm_misc.c
97802 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97803 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97804 return 1;
97805 atm_return(vcc, truesize);
97806 - atomic_inc(&vcc->stats->rx_drop);
97807 + atomic_inc_unchecked(&vcc->stats->rx_drop);
97808 return 0;
97809 }
97810 EXPORT_SYMBOL(atm_charge);
97811 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97812 }
97813 }
97814 atm_return(vcc, guess);
97815 - atomic_inc(&vcc->stats->rx_drop);
97816 + atomic_inc_unchecked(&vcc->stats->rx_drop);
97817 return NULL;
97818 }
97819 EXPORT_SYMBOL(atm_alloc_charge);
97820 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
97821
97822 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97823 {
97824 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97825 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97826 __SONET_ITEMS
97827 #undef __HANDLE_ITEM
97828 }
97829 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
97830
97831 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97832 {
97833 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97834 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
97835 __SONET_ITEMS
97836 #undef __HANDLE_ITEM
97837 }
97838 diff --git a/net/atm/lec.c b/net/atm/lec.c
97839 index 4c5b8ba..95f7005 100644
97840 --- a/net/atm/lec.c
97841 +++ b/net/atm/lec.c
97842 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
97843 }
97844
97845 static struct lane2_ops lane2_ops = {
97846 - lane2_resolve, /* resolve, spec 3.1.3 */
97847 - lane2_associate_req, /* associate_req, spec 3.1.4 */
97848 - NULL /* associate indicator, spec 3.1.5 */
97849 + .resolve = lane2_resolve,
97850 + .associate_req = lane2_associate_req,
97851 + .associate_indicator = NULL
97852 };
97853
97854 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97855 diff --git a/net/atm/lec.h b/net/atm/lec.h
97856 index 4149db1..f2ab682 100644
97857 --- a/net/atm/lec.h
97858 +++ b/net/atm/lec.h
97859 @@ -48,7 +48,7 @@ struct lane2_ops {
97860 const u8 *tlvs, u32 sizeoftlvs);
97861 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
97862 const u8 *tlvs, u32 sizeoftlvs);
97863 -};
97864 +} __no_const;
97865
97866 /*
97867 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
97868 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
97869 index d1b2d9a..d549f7f 100644
97870 --- a/net/atm/mpoa_caches.c
97871 +++ b/net/atm/mpoa_caches.c
97872 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
97873
97874
97875 static struct in_cache_ops ingress_ops = {
97876 - in_cache_add_entry, /* add_entry */
97877 - in_cache_get, /* get */
97878 - in_cache_get_with_mask, /* get_with_mask */
97879 - in_cache_get_by_vcc, /* get_by_vcc */
97880 - in_cache_put, /* put */
97881 - in_cache_remove_entry, /* remove_entry */
97882 - cache_hit, /* cache_hit */
97883 - clear_count_and_expired, /* clear_count */
97884 - check_resolving_entries, /* check_resolving */
97885 - refresh_entries, /* refresh */
97886 - in_destroy_cache /* destroy_cache */
97887 + .add_entry = in_cache_add_entry,
97888 + .get = in_cache_get,
97889 + .get_with_mask = in_cache_get_with_mask,
97890 + .get_by_vcc = in_cache_get_by_vcc,
97891 + .put = in_cache_put,
97892 + .remove_entry = in_cache_remove_entry,
97893 + .cache_hit = cache_hit,
97894 + .clear_count = clear_count_and_expired,
97895 + .check_resolving = check_resolving_entries,
97896 + .refresh = refresh_entries,
97897 + .destroy_cache = in_destroy_cache
97898 };
97899
97900 static struct eg_cache_ops egress_ops = {
97901 - eg_cache_add_entry, /* add_entry */
97902 - eg_cache_get_by_cache_id, /* get_by_cache_id */
97903 - eg_cache_get_by_tag, /* get_by_tag */
97904 - eg_cache_get_by_vcc, /* get_by_vcc */
97905 - eg_cache_get_by_src_ip, /* get_by_src_ip */
97906 - eg_cache_put, /* put */
97907 - eg_cache_remove_entry, /* remove_entry */
97908 - update_eg_cache_entry, /* update */
97909 - clear_expired, /* clear_expired */
97910 - eg_destroy_cache /* destroy_cache */
97911 + .add_entry = eg_cache_add_entry,
97912 + .get_by_cache_id = eg_cache_get_by_cache_id,
97913 + .get_by_tag = eg_cache_get_by_tag,
97914 + .get_by_vcc = eg_cache_get_by_vcc,
97915 + .get_by_src_ip = eg_cache_get_by_src_ip,
97916 + .put = eg_cache_put,
97917 + .remove_entry = eg_cache_remove_entry,
97918 + .update = update_eg_cache_entry,
97919 + .clear_expired = clear_expired,
97920 + .destroy_cache = eg_destroy_cache
97921 };
97922
97923
97924 diff --git a/net/atm/proc.c b/net/atm/proc.c
97925 index bbb6461..cf04016 100644
97926 --- a/net/atm/proc.c
97927 +++ b/net/atm/proc.c
97928 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
97929 const struct k_atm_aal_stats *stats)
97930 {
97931 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
97932 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
97933 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
97934 - atomic_read(&stats->rx_drop));
97935 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
97936 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
97937 + atomic_read_unchecked(&stats->rx_drop));
97938 }
97939
97940 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
97941 diff --git a/net/atm/resources.c b/net/atm/resources.c
97942 index 0447d5d..3cf4728 100644
97943 --- a/net/atm/resources.c
97944 +++ b/net/atm/resources.c
97945 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
97946 static void copy_aal_stats(struct k_atm_aal_stats *from,
97947 struct atm_aal_stats *to)
97948 {
97949 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97950 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97951 __AAL_STAT_ITEMS
97952 #undef __HANDLE_ITEM
97953 }
97954 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
97955 static void subtract_aal_stats(struct k_atm_aal_stats *from,
97956 struct atm_aal_stats *to)
97957 {
97958 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97959 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
97960 __AAL_STAT_ITEMS
97961 #undef __HANDLE_ITEM
97962 }
97963 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
97964 index 919a5ce..cc6b444 100644
97965 --- a/net/ax25/sysctl_net_ax25.c
97966 +++ b/net/ax25/sysctl_net_ax25.c
97967 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
97968 {
97969 char path[sizeof("net/ax25/") + IFNAMSIZ];
97970 int k;
97971 - struct ctl_table *table;
97972 + ctl_table_no_const *table;
97973
97974 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
97975 if (!table)
97976 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
97977 index f04224c..f326579 100644
97978 --- a/net/batman-adv/bat_iv_ogm.c
97979 +++ b/net/batman-adv/bat_iv_ogm.c
97980 @@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
97981
97982 /* randomize initial seqno to avoid collision */
97983 get_random_bytes(&random_seqno, sizeof(random_seqno));
97984 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97985 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97986
97987 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
97988 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
97989 @@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
97990 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
97991
97992 /* change sequence number to network order */
97993 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
97994 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
97995 batadv_ogm_packet->seqno = htonl(seqno);
97996 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
97997 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
97998
97999 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
98000
98001 @@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
98002 return;
98003
98004 /* could be changed by schedule_own_packet() */
98005 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
98006 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
98007
98008 if (ogm_packet->flags & BATADV_DIRECTLINK)
98009 has_directlink_flag = true;
98010 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
98011 index f14e54a..66f3e2e 100644
98012 --- a/net/batman-adv/fragmentation.c
98013 +++ b/net/batman-adv/fragmentation.c
98014 @@ -446,7 +446,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
98015 frag_header.packet_type = BATADV_UNICAST_FRAG;
98016 frag_header.version = BATADV_COMPAT_VERSION;
98017 frag_header.ttl = BATADV_TTL;
98018 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
98019 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
98020 frag_header.reserved = 0;
98021 frag_header.no = 0;
98022 frag_header.total_size = htons(skb->len);
98023 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
98024 index 744a59b..8fd037c 100644
98025 --- a/net/batman-adv/soft-interface.c
98026 +++ b/net/batman-adv/soft-interface.c
98027 @@ -296,7 +296,7 @@ send:
98028 primary_if->net_dev->dev_addr);
98029
98030 /* set broadcast sequence number */
98031 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
98032 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
98033 bcast_packet->seqno = htonl(seqno);
98034
98035 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
98036 @@ -729,7 +729,7 @@ static int batadv_softif_init_late(struct net_device *dev)
98037 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
98038
98039 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
98040 - atomic_set(&bat_priv->bcast_seqno, 1);
98041 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
98042 atomic_set(&bat_priv->tt.vn, 0);
98043 atomic_set(&bat_priv->tt.local_changes, 0);
98044 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
98045 @@ -743,7 +743,7 @@ static int batadv_softif_init_late(struct net_device *dev)
98046
98047 /* randomize initial seqno to avoid collision */
98048 get_random_bytes(&random_seqno, sizeof(random_seqno));
98049 - atomic_set(&bat_priv->frag_seqno, random_seqno);
98050 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
98051
98052 bat_priv->primary_if = NULL;
98053 bat_priv->num_ifaces = 0;
98054 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
98055 index 34891a5..3cfece0 100644
98056 --- a/net/batman-adv/types.h
98057 +++ b/net/batman-adv/types.h
98058 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
98059 struct batadv_hard_iface_bat_iv {
98060 unsigned char *ogm_buff;
98061 int ogm_buff_len;
98062 - atomic_t ogm_seqno;
98063 + atomic_unchecked_t ogm_seqno;
98064 };
98065
98066 /**
98067 @@ -766,7 +766,7 @@ struct batadv_priv {
98068 atomic_t bonding;
98069 atomic_t fragmentation;
98070 atomic_t packet_size_max;
98071 - atomic_t frag_seqno;
98072 + atomic_unchecked_t frag_seqno;
98073 #ifdef CONFIG_BATMAN_ADV_BLA
98074 atomic_t bridge_loop_avoidance;
98075 #endif
98076 @@ -785,7 +785,7 @@ struct batadv_priv {
98077 #endif
98078 uint32_t isolation_mark;
98079 uint32_t isolation_mark_mask;
98080 - atomic_t bcast_seqno;
98081 + atomic_unchecked_t bcast_seqno;
98082 atomic_t bcast_queue_left;
98083 atomic_t batman_queue_left;
98084 char num_ifaces;
98085 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
98086 index b9a418e..2af862a 100644
98087 --- a/net/bluetooth/hci_sock.c
98088 +++ b/net/bluetooth/hci_sock.c
98089 @@ -1053,7 +1053,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
98090 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
98091 }
98092
98093 - len = min_t(unsigned int, len, sizeof(uf));
98094 + len = min((size_t)len, sizeof(uf));
98095 if (copy_from_user(&uf, optval, len)) {
98096 err = -EFAULT;
98097 break;
98098 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
98099 index 1c97b7a..9171d69 100644
98100 --- a/net/bluetooth/l2cap_core.c
98101 +++ b/net/bluetooth/l2cap_core.c
98102 @@ -3542,8 +3542,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
98103 break;
98104
98105 case L2CAP_CONF_RFC:
98106 - if (olen == sizeof(rfc))
98107 - memcpy(&rfc, (void *)val, olen);
98108 + if (olen != sizeof(rfc))
98109 + break;
98110 +
98111 + memcpy(&rfc, (void *)val, olen);
98112
98113 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
98114 rfc.mode != chan->mode)
98115 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
98116 index e137869..33f3ebd 100644
98117 --- a/net/bluetooth/l2cap_sock.c
98118 +++ b/net/bluetooth/l2cap_sock.c
98119 @@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
98120 struct sock *sk = sock->sk;
98121 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
98122 struct l2cap_options opts;
98123 - int len, err = 0;
98124 + int err = 0;
98125 + size_t len = optlen;
98126 u32 opt;
98127
98128 BT_DBG("sk %p", sk);
98129 @@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
98130 opts.max_tx = chan->max_tx;
98131 opts.txwin_size = chan->tx_win;
98132
98133 - len = min_t(unsigned int, sizeof(opts), optlen);
98134 + len = min(sizeof(opts), len);
98135 if (copy_from_user((char *) &opts, optval, len)) {
98136 err = -EFAULT;
98137 break;
98138 @@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98139 struct bt_security sec;
98140 struct bt_power pwr;
98141 struct l2cap_conn *conn;
98142 - int len, err = 0;
98143 + int err = 0;
98144 + size_t len = optlen;
98145 u32 opt;
98146
98147 BT_DBG("sk %p", sk);
98148 @@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98149
98150 sec.level = BT_SECURITY_LOW;
98151
98152 - len = min_t(unsigned int, sizeof(sec), optlen);
98153 + len = min(sizeof(sec), len);
98154 if (copy_from_user((char *) &sec, optval, len)) {
98155 err = -EFAULT;
98156 break;
98157 @@ -861,7 +863,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98158
98159 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
98160
98161 - len = min_t(unsigned int, sizeof(pwr), optlen);
98162 + len = min(sizeof(pwr), len);
98163 if (copy_from_user((char *) &pwr, optval, len)) {
98164 err = -EFAULT;
98165 break;
98166 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
98167 index c603a5e..7f08991 100644
98168 --- a/net/bluetooth/rfcomm/sock.c
98169 +++ b/net/bluetooth/rfcomm/sock.c
98170 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
98171 struct sock *sk = sock->sk;
98172 struct bt_security sec;
98173 int err = 0;
98174 - size_t len;
98175 + size_t len = optlen;
98176 u32 opt;
98177
98178 BT_DBG("sk %p", sk);
98179 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
98180
98181 sec.level = BT_SECURITY_LOW;
98182
98183 - len = min_t(unsigned int, sizeof(sec), optlen);
98184 + len = min(sizeof(sec), len);
98185 if (copy_from_user((char *) &sec, optval, len)) {
98186 err = -EFAULT;
98187 break;
98188 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
98189 index 403ec09..a21a003 100644
98190 --- a/net/bluetooth/rfcomm/tty.c
98191 +++ b/net/bluetooth/rfcomm/tty.c
98192 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
98193 BT_DBG("tty %p id %d", tty, tty->index);
98194
98195 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
98196 - dev->channel, dev->port.count);
98197 + dev->channel, atomic_read(&dev->port.count));
98198
98199 err = tty_port_open(&dev->port, tty, filp);
98200 if (err)
98201 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
98202 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
98203
98204 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
98205 - dev->port.count);
98206 + atomic_read(&dev->port.count));
98207
98208 tty_port_close(&dev->port, tty, filp);
98209 }
98210 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
98211 index 1059ed3..d70846a 100644
98212 --- a/net/bridge/netfilter/ebtables.c
98213 +++ b/net/bridge/netfilter/ebtables.c
98214 @@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98215 tmp.valid_hooks = t->table->valid_hooks;
98216 }
98217 mutex_unlock(&ebt_mutex);
98218 - if (copy_to_user(user, &tmp, *len) != 0) {
98219 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98220 BUGPRINT("c2u Didn't work\n");
98221 ret = -EFAULT;
98222 break;
98223 @@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
98224 goto out;
98225 tmp.valid_hooks = t->valid_hooks;
98226
98227 - if (copy_to_user(user, &tmp, *len) != 0) {
98228 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98229 ret = -EFAULT;
98230 break;
98231 }
98232 @@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
98233 tmp.entries_size = t->table->entries_size;
98234 tmp.valid_hooks = t->table->valid_hooks;
98235
98236 - if (copy_to_user(user, &tmp, *len) != 0) {
98237 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98238 ret = -EFAULT;
98239 break;
98240 }
98241 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
98242 index 0f45522..dab651f 100644
98243 --- a/net/caif/cfctrl.c
98244 +++ b/net/caif/cfctrl.c
98245 @@ -10,6 +10,7 @@
98246 #include <linux/spinlock.h>
98247 #include <linux/slab.h>
98248 #include <linux/pkt_sched.h>
98249 +#include <linux/sched.h>
98250 #include <net/caif/caif_layer.h>
98251 #include <net/caif/cfpkt.h>
98252 #include <net/caif/cfctrl.h>
98253 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
98254 memset(&dev_info, 0, sizeof(dev_info));
98255 dev_info.id = 0xff;
98256 cfsrvl_init(&this->serv, 0, &dev_info, false);
98257 - atomic_set(&this->req_seq_no, 1);
98258 - atomic_set(&this->rsp_seq_no, 1);
98259 + atomic_set_unchecked(&this->req_seq_no, 1);
98260 + atomic_set_unchecked(&this->rsp_seq_no, 1);
98261 this->serv.layer.receive = cfctrl_recv;
98262 sprintf(this->serv.layer.name, "ctrl");
98263 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
98264 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
98265 struct cfctrl_request_info *req)
98266 {
98267 spin_lock_bh(&ctrl->info_list_lock);
98268 - atomic_inc(&ctrl->req_seq_no);
98269 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
98270 + atomic_inc_unchecked(&ctrl->req_seq_no);
98271 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
98272 list_add_tail(&req->list, &ctrl->list);
98273 spin_unlock_bh(&ctrl->info_list_lock);
98274 }
98275 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
98276 if (p != first)
98277 pr_warn("Requests are not received in order\n");
98278
98279 - atomic_set(&ctrl->rsp_seq_no,
98280 + atomic_set_unchecked(&ctrl->rsp_seq_no,
98281 p->sequence_no);
98282 list_del(&p->list);
98283 goto out;
98284 diff --git a/net/can/af_can.c b/net/can/af_can.c
98285 index a27f8aa..67174a3 100644
98286 --- a/net/can/af_can.c
98287 +++ b/net/can/af_can.c
98288 @@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
98289 };
98290
98291 /* notifier block for netdevice event */
98292 -static struct notifier_block can_netdev_notifier __read_mostly = {
98293 +static struct notifier_block can_netdev_notifier = {
98294 .notifier_call = can_notifier,
98295 };
98296
98297 diff --git a/net/can/bcm.c b/net/can/bcm.c
98298 index dcb75c0..24b1b43 100644
98299 --- a/net/can/bcm.c
98300 +++ b/net/can/bcm.c
98301 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
98302 }
98303
98304 /* create /proc/net/can-bcm directory */
98305 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
98306 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
98307 return 0;
98308 }
98309
98310 diff --git a/net/can/gw.c b/net/can/gw.c
98311 index 050a211..bb9fe33 100644
98312 --- a/net/can/gw.c
98313 +++ b/net/can/gw.c
98314 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
98315 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
98316
98317 static HLIST_HEAD(cgw_list);
98318 -static struct notifier_block notifier;
98319
98320 static struct kmem_cache *cgw_cache __read_mostly;
98321
98322 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
98323 return err;
98324 }
98325
98326 +static struct notifier_block notifier = {
98327 + .notifier_call = cgw_notifier
98328 +};
98329 +
98330 static __init int cgw_module_init(void)
98331 {
98332 /* sanitize given module parameter */
98333 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
98334 return -ENOMEM;
98335
98336 /* set notifier */
98337 - notifier.notifier_call = cgw_notifier;
98338 register_netdevice_notifier(&notifier);
98339
98340 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
98341 diff --git a/net/can/proc.c b/net/can/proc.c
98342 index b543470..d2ddae2 100644
98343 --- a/net/can/proc.c
98344 +++ b/net/can/proc.c
98345 @@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
98346 void can_init_proc(void)
98347 {
98348 /* create /proc/net/can directory */
98349 - can_dir = proc_mkdir("can", init_net.proc_net);
98350 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
98351
98352 if (!can_dir) {
98353 printk(KERN_INFO "can: failed to create /proc/net/can . "
98354 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
98355 index 1948d59..9e854d5 100644
98356 --- a/net/ceph/messenger.c
98357 +++ b/net/ceph/messenger.c
98358 @@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
98359 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
98360
98361 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
98362 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
98363 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
98364
98365 static struct page *zero_page; /* used in certain error cases */
98366
98367 @@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
98368 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
98369 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
98370
98371 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98372 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98373 s = addr_str[i];
98374
98375 switch (ss->ss_family) {
98376 diff --git a/net/compat.c b/net/compat.c
98377 index 9a76eaf..5b8ccfd 100644
98378 --- a/net/compat.c
98379 +++ b/net/compat.c
98380 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
98381 return -EFAULT;
98382 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
98383 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
98384 - kmsg->msg_name = compat_ptr(tmp1);
98385 - kmsg->msg_iov = compat_ptr(tmp2);
98386 - kmsg->msg_control = compat_ptr(tmp3);
98387 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
98388 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
98389 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
98390 return 0;
98391 }
98392
98393 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98394
98395 if (kern_msg->msg_namelen) {
98396 if (mode == VERIFY_READ) {
98397 - int err = move_addr_to_kernel(kern_msg->msg_name,
98398 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
98399 kern_msg->msg_namelen,
98400 kern_address);
98401 if (err < 0)
98402 @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98403 kern_msg->msg_name = NULL;
98404
98405 tot_len = iov_from_user_compat_to_kern(kern_iov,
98406 - (struct compat_iovec __user *)kern_msg->msg_iov,
98407 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
98408 kern_msg->msg_iovlen);
98409 if (tot_len >= 0)
98410 kern_msg->msg_iov = kern_iov;
98411 @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98412
98413 #define CMSG_COMPAT_FIRSTHDR(msg) \
98414 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
98415 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
98416 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
98417 (struct compat_cmsghdr __user *)NULL)
98418
98419 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
98420 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
98421 (ucmlen) <= (unsigned long) \
98422 ((mhdr)->msg_controllen - \
98423 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
98424 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
98425
98426 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
98427 struct compat_cmsghdr __user *cmsg, int cmsg_len)
98428 {
98429 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
98430 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
98431 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
98432 msg->msg_controllen)
98433 return NULL;
98434 return (struct compat_cmsghdr __user *)ptr;
98435 @@ -222,7 +222,7 @@ Efault:
98436
98437 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
98438 {
98439 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98440 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98441 struct compat_cmsghdr cmhdr;
98442 struct compat_timeval ctv;
98443 struct compat_timespec cts[3];
98444 @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
98445
98446 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
98447 {
98448 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98449 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98450 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
98451 int fdnum = scm->fp->count;
98452 struct file **fp = scm->fp->fp;
98453 @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
98454 return -EFAULT;
98455 old_fs = get_fs();
98456 set_fs(KERNEL_DS);
98457 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
98458 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
98459 set_fs(old_fs);
98460
98461 return err;
98462 @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
98463 len = sizeof(ktime);
98464 old_fs = get_fs();
98465 set_fs(KERNEL_DS);
98466 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
98467 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
98468 set_fs(old_fs);
98469
98470 if (!err) {
98471 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98472 case MCAST_JOIN_GROUP:
98473 case MCAST_LEAVE_GROUP:
98474 {
98475 - struct compat_group_req __user *gr32 = (void *)optval;
98476 + struct compat_group_req __user *gr32 = (void __user *)optval;
98477 struct group_req __user *kgr =
98478 compat_alloc_user_space(sizeof(struct group_req));
98479 u32 interface;
98480 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98481 case MCAST_BLOCK_SOURCE:
98482 case MCAST_UNBLOCK_SOURCE:
98483 {
98484 - struct compat_group_source_req __user *gsr32 = (void *)optval;
98485 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
98486 struct group_source_req __user *kgsr = compat_alloc_user_space(
98487 sizeof(struct group_source_req));
98488 u32 interface;
98489 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98490 }
98491 case MCAST_MSFILTER:
98492 {
98493 - struct compat_group_filter __user *gf32 = (void *)optval;
98494 + struct compat_group_filter __user *gf32 = (void __user *)optval;
98495 struct group_filter __user *kgf;
98496 u32 interface, fmode, numsrc;
98497
98498 @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
98499 char __user *optval, int __user *optlen,
98500 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
98501 {
98502 - struct compat_group_filter __user *gf32 = (void *)optval;
98503 + struct compat_group_filter __user *gf32 = (void __user *)optval;
98504 struct group_filter __user *kgf;
98505 int __user *koptlen;
98506 u32 interface, fmode, numsrc;
98507 @@ -803,7 +803,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
98508
98509 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
98510 return -EINVAL;
98511 - if (copy_from_user(a, args, nas[call]))
98512 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
98513 return -EFAULT;
98514 a0 = a[0];
98515 a1 = a[1];
98516 diff --git a/net/core/datagram.c b/net/core/datagram.c
98517 index a16ed7b..eb44d17 100644
98518 --- a/net/core/datagram.c
98519 +++ b/net/core/datagram.c
98520 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
98521 }
98522
98523 kfree_skb(skb);
98524 - atomic_inc(&sk->sk_drops);
98525 + atomic_inc_unchecked(&sk->sk_drops);
98526 sk_mem_reclaim_partial(sk);
98527
98528 return err;
98529 diff --git a/net/core/dev.c b/net/core/dev.c
98530 index a30bef1..51d3e33 100644
98531 --- a/net/core/dev.c
98532 +++ b/net/core/dev.c
98533 @@ -1683,14 +1683,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
98534 {
98535 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
98536 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
98537 - atomic_long_inc(&dev->rx_dropped);
98538 + atomic_long_inc_unchecked(&dev->rx_dropped);
98539 kfree_skb(skb);
98540 return NET_RX_DROP;
98541 }
98542 }
98543
98544 if (unlikely(!is_skb_forwardable(dev, skb))) {
98545 - atomic_long_inc(&dev->rx_dropped);
98546 + atomic_long_inc_unchecked(&dev->rx_dropped);
98547 kfree_skb(skb);
98548 return NET_RX_DROP;
98549 }
98550 @@ -2463,7 +2463,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
98551
98552 struct dev_gso_cb {
98553 void (*destructor)(struct sk_buff *skb);
98554 -};
98555 +} __no_const;
98556
98557 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
98558
98559 @@ -2893,7 +2893,7 @@ recursion_alert:
98560 rc = -ENETDOWN;
98561 rcu_read_unlock_bh();
98562
98563 - atomic_long_inc(&dev->tx_dropped);
98564 + atomic_long_inc_unchecked(&dev->tx_dropped);
98565 kfree_skb(skb);
98566 return rc;
98567 out:
98568 @@ -3237,7 +3237,7 @@ enqueue:
98569
98570 local_irq_restore(flags);
98571
98572 - atomic_long_inc(&skb->dev->rx_dropped);
98573 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98574 kfree_skb(skb);
98575 return NET_RX_DROP;
98576 }
98577 @@ -3314,7 +3314,7 @@ int netif_rx_ni(struct sk_buff *skb)
98578 }
98579 EXPORT_SYMBOL(netif_rx_ni);
98580
98581 -static void net_tx_action(struct softirq_action *h)
98582 +static __latent_entropy void net_tx_action(void)
98583 {
98584 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98585
98586 @@ -3647,7 +3647,7 @@ ncls:
98587 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
98588 } else {
98589 drop:
98590 - atomic_long_inc(&skb->dev->rx_dropped);
98591 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98592 kfree_skb(skb);
98593 /* Jamal, now you will not able to escape explaining
98594 * me how you were going to use this. :-)
98595 @@ -4366,7 +4366,7 @@ void netif_napi_del(struct napi_struct *napi)
98596 }
98597 EXPORT_SYMBOL(netif_napi_del);
98598
98599 -static void net_rx_action(struct softirq_action *h)
98600 +static __latent_entropy void net_rx_action(void)
98601 {
98602 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98603 unsigned long time_limit = jiffies + 2;
98604 @@ -6366,8 +6366,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
98605 } else {
98606 netdev_stats_to_stats64(storage, &dev->stats);
98607 }
98608 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
98609 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
98610 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
98611 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
98612 return storage;
98613 }
98614 EXPORT_SYMBOL(dev_get_stats);
98615 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
98616 index cf999e0..c59a975 100644
98617 --- a/net/core/dev_ioctl.c
98618 +++ b/net/core/dev_ioctl.c
98619 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
98620 if (no_module && capable(CAP_NET_ADMIN))
98621 no_module = request_module("netdev-%s", name);
98622 if (no_module && capable(CAP_SYS_MODULE)) {
98623 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
98624 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
98625 +#else
98626 if (!request_module("%s", name))
98627 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
98628 name);
98629 +#endif
98630 }
98631 }
98632 EXPORT_SYMBOL(dev_load);
98633 diff --git a/net/core/dst.c b/net/core/dst.c
98634 index 80d6286..a028409 100644
98635 --- a/net/core/dst.c
98636 +++ b/net/core/dst.c
98637 @@ -269,6 +269,15 @@ again:
98638 }
98639 EXPORT_SYMBOL(dst_destroy);
98640
98641 +static void dst_destroy_rcu(struct rcu_head *head)
98642 +{
98643 + struct dst_entry *dst = container_of(head, struct dst_entry, rcu_head);
98644 +
98645 + dst = dst_destroy(dst);
98646 + if (dst)
98647 + __dst_free(dst);
98648 +}
98649 +
98650 void dst_release(struct dst_entry *dst)
98651 {
98652 if (dst) {
98653 @@ -276,11 +285,8 @@ void dst_release(struct dst_entry *dst)
98654
98655 newrefcnt = atomic_dec_return(&dst->__refcnt);
98656 WARN_ON(newrefcnt < 0);
98657 - if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt) {
98658 - dst = dst_destroy(dst);
98659 - if (dst)
98660 - __dst_free(dst);
98661 - }
98662 + if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt)
98663 + call_rcu(&dst->rcu_head, dst_destroy_rcu);
98664 }
98665 }
98666 EXPORT_SYMBOL(dst_release);
98667 diff --git a/net/core/filter.c b/net/core/filter.c
98668 index 4aec7b9..5cf605c 100644
98669 --- a/net/core/filter.c
98670 +++ b/net/core/filter.c
98671 @@ -1121,7 +1121,11 @@ do_pass:
98672 break;
98673
98674 default:
98675 - goto err;
98676 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
98677 + fp->code, fp->jt, fp->jf, fp->k);
98678 + kfree(addrs);
98679 + BUG();
98680 + return -EINVAL;
98681 }
98682
98683 insn++;
98684 @@ -1170,7 +1174,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
98685 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
98686 int pc, ret = 0;
98687
98688 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
98689 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
98690 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
98691 if (!masks)
98692 return -ENOMEM;
98693 @@ -1605,7 +1609,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
98694 if (!fp)
98695 return -ENOMEM;
98696
98697 - memcpy(fp->insns, fprog->filter, fsize);
98698 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98699
98700 atomic_set(&fp->refcnt, 1);
98701 fp->len = fprog->len;
98702 diff --git a/net/core/flow.c b/net/core/flow.c
98703 index a0348fd..6951c76 100644
98704 --- a/net/core/flow.c
98705 +++ b/net/core/flow.c
98706 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98707 static int flow_entry_valid(struct flow_cache_entry *fle,
98708 struct netns_xfrm *xfrm)
98709 {
98710 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
98711 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
98712 return 0;
98713 if (fle->object && !fle->object->ops->check(fle->object))
98714 return 0;
98715 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98716 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98717 fcp->hash_count++;
98718 }
98719 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
98720 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
98721 flo = fle->object;
98722 if (!flo)
98723 goto ret_object;
98724 @@ -263,7 +263,7 @@ nocache:
98725 }
98726 flo = resolver(net, key, family, dir, flo, ctx);
98727 if (fle) {
98728 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
98729 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
98730 if (!IS_ERR(flo))
98731 fle->object = flo;
98732 else
98733 diff --git a/net/core/iovec.c b/net/core/iovec.c
98734 index b618694..192bbba 100644
98735 --- a/net/core/iovec.c
98736 +++ b/net/core/iovec.c
98737 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98738 if (m->msg_namelen) {
98739 if (mode == VERIFY_READ) {
98740 void __user *namep;
98741 - namep = (void __user __force *) m->msg_name;
98742 + namep = (void __force_user *) m->msg_name;
98743 err = move_addr_to_kernel(namep, m->msg_namelen,
98744 address);
98745 if (err < 0)
98746 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98747 }
98748
98749 size = m->msg_iovlen * sizeof(struct iovec);
98750 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98751 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98752 return -EFAULT;
98753
98754 m->msg_iov = iov;
98755 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98756 index 32d872e..487e769 100644
98757 --- a/net/core/neighbour.c
98758 +++ b/net/core/neighbour.c
98759 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98760 void __user *buffer, size_t *lenp, loff_t *ppos)
98761 {
98762 int size, ret;
98763 - struct ctl_table tmp = *ctl;
98764 + ctl_table_no_const tmp = *ctl;
98765
98766 tmp.extra1 = &zero;
98767 tmp.extra2 = &unres_qlen_max;
98768 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98769 void __user *buffer,
98770 size_t *lenp, loff_t *ppos)
98771 {
98772 - struct ctl_table tmp = *ctl;
98773 + ctl_table_no_const tmp = *ctl;
98774 int ret;
98775
98776 tmp.extra1 = &zero;
98777 @@ -3059,11 +3059,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98778 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98779 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98780 } else {
98781 + struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98782 dev_name_source = "default";
98783 - t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98784 - t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98785 - t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98786 - t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98787 + t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98788 + t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98789 + t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98790 + t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98791 }
98792
98793 if (handler) {
98794 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98795 index 2bf8329..2eb1423 100644
98796 --- a/net/core/net-procfs.c
98797 +++ b/net/core/net-procfs.c
98798 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98799 struct rtnl_link_stats64 temp;
98800 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98801
98802 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98803 + if (gr_proc_is_restricted())
98804 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98805 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98806 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98807 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98808 + else
98809 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98810 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98811 dev->name, stats->rx_bytes, stats->rx_packets,
98812 stats->rx_errors,
98813 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98814 return 0;
98815 }
98816
98817 -static const struct seq_operations dev_seq_ops = {
98818 +const struct seq_operations dev_seq_ops = {
98819 .start = dev_seq_start,
98820 .next = dev_seq_next,
98821 .stop = dev_seq_stop,
98822 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98823
98824 static int softnet_seq_open(struct inode *inode, struct file *file)
98825 {
98826 - return seq_open(file, &softnet_seq_ops);
98827 + return seq_open_restrict(file, &softnet_seq_ops);
98828 }
98829
98830 static const struct file_operations softnet_seq_fops = {
98831 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98832 else
98833 seq_printf(seq, "%04x", ntohs(pt->type));
98834
98835 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98836 + seq_printf(seq, " %-8s %pf\n",
98837 + pt->dev ? pt->dev->name : "", NULL);
98838 +#else
98839 seq_printf(seq, " %-8s %pf\n",
98840 pt->dev ? pt->dev->name : "", pt->func);
98841 +#endif
98842 }
98843
98844 return 0;
98845 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
98846 index 1cac29e..fb482f3 100644
98847 --- a/net/core/net-sysfs.c
98848 +++ b/net/core/net-sysfs.c
98849 @@ -259,7 +259,7 @@ static ssize_t carrier_changes_show(struct device *dev,
98850 {
98851 struct net_device *netdev = to_net_dev(dev);
98852 return sprintf(buf, fmt_dec,
98853 - atomic_read(&netdev->carrier_changes));
98854 + atomic_read_unchecked(&netdev->carrier_changes));
98855 }
98856 static DEVICE_ATTR_RO(carrier_changes);
98857
98858 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
98859 index 7c8ffd9..0cb3687 100644
98860 --- a/net/core/net_namespace.c
98861 +++ b/net/core/net_namespace.c
98862 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
98863 int error;
98864 LIST_HEAD(net_exit_list);
98865
98866 - list_add_tail(&ops->list, list);
98867 + pax_list_add_tail((struct list_head *)&ops->list, list);
98868 if (ops->init || (ops->id && ops->size)) {
98869 for_each_net(net) {
98870 error = ops_init(ops, net);
98871 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
98872
98873 out_undo:
98874 /* If I have an error cleanup all namespaces I initialized */
98875 - list_del(&ops->list);
98876 + pax_list_del((struct list_head *)&ops->list);
98877 ops_exit_list(ops, &net_exit_list);
98878 ops_free_list(ops, &net_exit_list);
98879 return error;
98880 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
98881 struct net *net;
98882 LIST_HEAD(net_exit_list);
98883
98884 - list_del(&ops->list);
98885 + pax_list_del((struct list_head *)&ops->list);
98886 for_each_net(net)
98887 list_add_tail(&net->exit_list, &net_exit_list);
98888 ops_exit_list(ops, &net_exit_list);
98889 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
98890 mutex_lock(&net_mutex);
98891 error = register_pernet_operations(&pernet_list, ops);
98892 if (!error && (first_device == &pernet_list))
98893 - first_device = &ops->list;
98894 + first_device = (struct list_head *)&ops->list;
98895 mutex_unlock(&net_mutex);
98896 return error;
98897 }
98898 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
98899 index e33937f..b2b4981 100644
98900 --- a/net/core/netpoll.c
98901 +++ b/net/core/netpoll.c
98902 @@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98903 struct udphdr *udph;
98904 struct iphdr *iph;
98905 struct ethhdr *eth;
98906 - static atomic_t ip_ident;
98907 + static atomic_unchecked_t ip_ident;
98908 struct ipv6hdr *ip6h;
98909
98910 udp_len = len + sizeof(*udph);
98911 @@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98912 put_unaligned(0x45, (unsigned char *)iph);
98913 iph->tos = 0;
98914 put_unaligned(htons(ip_len), &(iph->tot_len));
98915 - iph->id = htons(atomic_inc_return(&ip_ident));
98916 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
98917 iph->frag_off = 0;
98918 iph->ttl = 64;
98919 iph->protocol = IPPROTO_UDP;
98920 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
98921 index 0304f98..ddfead6 100644
98922 --- a/net/core/pktgen.c
98923 +++ b/net/core/pktgen.c
98924 @@ -3725,7 +3725,7 @@ static int __net_init pg_net_init(struct net *net)
98925 pn->net = net;
98926 INIT_LIST_HEAD(&pn->pktgen_threads);
98927 pn->pktgen_exiting = false;
98928 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
98929 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
98930 if (!pn->proc_dir) {
98931 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
98932 return -ENODEV;
98933 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
98934 index 1999ed8..1e6e58a 100644
98935 --- a/net/core/rtnetlink.c
98936 +++ b/net/core/rtnetlink.c
98937 @@ -58,7 +58,7 @@ struct rtnl_link {
98938 rtnl_doit_func doit;
98939 rtnl_dumpit_func dumpit;
98940 rtnl_calcit_func calcit;
98941 -};
98942 +} __no_const;
98943
98944 static DEFINE_MUTEX(rtnl_mutex);
98945
98946 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
98947 if (rtnl_link_ops_get(ops->kind))
98948 return -EEXIST;
98949
98950 - if (!ops->dellink)
98951 - ops->dellink = unregister_netdevice_queue;
98952 + if (!ops->dellink) {
98953 + pax_open_kernel();
98954 + *(void **)&ops->dellink = unregister_netdevice_queue;
98955 + pax_close_kernel();
98956 + }
98957
98958 - list_add_tail(&ops->list, &link_ops);
98959 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
98960 return 0;
98961 }
98962 EXPORT_SYMBOL_GPL(__rtnl_link_register);
98963 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
98964 for_each_net(net) {
98965 __rtnl_kill_links(net, ops);
98966 }
98967 - list_del(&ops->list);
98968 + pax_list_del((struct list_head *)&ops->list);
98969 }
98970 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
98971
98972 @@ -1008,7 +1011,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
98973 (dev->ifalias &&
98974 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
98975 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
98976 - atomic_read(&dev->carrier_changes)))
98977 + atomic_read_unchecked(&dev->carrier_changes)))
98978 goto nla_put_failure;
98979
98980 if (1) {
98981 diff --git a/net/core/scm.c b/net/core/scm.c
98982 index b442e7e..6f5b5a2 100644
98983 --- a/net/core/scm.c
98984 +++ b/net/core/scm.c
98985 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
98986 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98987 {
98988 struct cmsghdr __user *cm
98989 - = (__force struct cmsghdr __user *)msg->msg_control;
98990 + = (struct cmsghdr __force_user *)msg->msg_control;
98991 struct cmsghdr cmhdr;
98992 int cmlen = CMSG_LEN(len);
98993 int err;
98994 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98995 err = -EFAULT;
98996 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
98997 goto out;
98998 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
98999 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
99000 goto out;
99001 cmlen = CMSG_SPACE(len);
99002 if (msg->msg_controllen < cmlen)
99003 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
99004 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
99005 {
99006 struct cmsghdr __user *cm
99007 - = (__force struct cmsghdr __user*)msg->msg_control;
99008 + = (struct cmsghdr __force_user *)msg->msg_control;
99009
99010 int fdmax = 0;
99011 int fdnum = scm->fp->count;
99012 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
99013 if (fdnum < fdmax)
99014 fdmax = fdnum;
99015
99016 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
99017 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
99018 i++, cmfptr++)
99019 {
99020 struct socket *sock;
99021 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
99022 index 8383b2b..6397efb 100644
99023 --- a/net/core/skbuff.c
99024 +++ b/net/core/skbuff.c
99025 @@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
99026 __wsum skb_checksum(const struct sk_buff *skb, int offset,
99027 int len, __wsum csum)
99028 {
99029 - const struct skb_checksum_ops ops = {
99030 + static const struct skb_checksum_ops ops = {
99031 .update = csum_partial_ext,
99032 .combine = csum_block_add_ext,
99033 };
99034 @@ -3220,13 +3220,15 @@ void __init skb_init(void)
99035 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
99036 sizeof(struct sk_buff),
99037 0,
99038 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
99039 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
99040 + SLAB_NO_SANITIZE,
99041 NULL);
99042 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
99043 (2*sizeof(struct sk_buff)) +
99044 sizeof(atomic_t),
99045 0,
99046 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
99047 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
99048 + SLAB_NO_SANITIZE,
99049 NULL);
99050 }
99051
99052 diff --git a/net/core/sock.c b/net/core/sock.c
99053 index 664ee42..aaf9e6e 100644
99054 --- a/net/core/sock.c
99055 +++ b/net/core/sock.c
99056 @@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
99057 struct sk_buff_head *list = &sk->sk_receive_queue;
99058
99059 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
99060 - atomic_inc(&sk->sk_drops);
99061 + atomic_inc_unchecked(&sk->sk_drops);
99062 trace_sock_rcvqueue_full(sk, skb);
99063 return -ENOMEM;
99064 }
99065 @@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
99066 return err;
99067
99068 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
99069 - atomic_inc(&sk->sk_drops);
99070 + atomic_inc_unchecked(&sk->sk_drops);
99071 return -ENOBUFS;
99072 }
99073
99074 @@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
99075 skb_dst_force(skb);
99076
99077 spin_lock_irqsave(&list->lock, flags);
99078 - skb->dropcount = atomic_read(&sk->sk_drops);
99079 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
99080 __skb_queue_tail(list, skb);
99081 spin_unlock_irqrestore(&list->lock, flags);
99082
99083 @@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
99084 skb->dev = NULL;
99085
99086 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
99087 - atomic_inc(&sk->sk_drops);
99088 + atomic_inc_unchecked(&sk->sk_drops);
99089 goto discard_and_relse;
99090 }
99091 if (nested)
99092 @@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
99093 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
99094 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
99095 bh_unlock_sock(sk);
99096 - atomic_inc(&sk->sk_drops);
99097 + atomic_inc_unchecked(&sk->sk_drops);
99098 goto discard_and_relse;
99099 }
99100
99101 @@ -998,12 +998,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
99102 struct timeval tm;
99103 } v;
99104
99105 - int lv = sizeof(int);
99106 - int len;
99107 + unsigned int lv = sizeof(int);
99108 + unsigned int len;
99109
99110 if (get_user(len, optlen))
99111 return -EFAULT;
99112 - if (len < 0)
99113 + if (len > INT_MAX)
99114 return -EINVAL;
99115
99116 memset(&v, 0, sizeof(v));
99117 @@ -1155,11 +1155,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
99118
99119 case SO_PEERNAME:
99120 {
99121 - char address[128];
99122 + char address[_K_SS_MAXSIZE];
99123
99124 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
99125 return -ENOTCONN;
99126 - if (lv < len)
99127 + if (lv < len || sizeof address < len)
99128 return -EINVAL;
99129 if (copy_to_user(optval, address, len))
99130 return -EFAULT;
99131 @@ -1240,7 +1240,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
99132
99133 if (len > lv)
99134 len = lv;
99135 - if (copy_to_user(optval, &v, len))
99136 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
99137 return -EFAULT;
99138 lenout:
99139 if (put_user(len, optlen))
99140 @@ -2375,7 +2375,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
99141 */
99142 smp_wmb();
99143 atomic_set(&sk->sk_refcnt, 1);
99144 - atomic_set(&sk->sk_drops, 0);
99145 + atomic_set_unchecked(&sk->sk_drops, 0);
99146 }
99147 EXPORT_SYMBOL(sock_init_data);
99148
99149 @@ -2503,6 +2503,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
99150 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
99151 int level, int type)
99152 {
99153 + struct sock_extended_err ee;
99154 struct sock_exterr_skb *serr;
99155 struct sk_buff *skb, *skb2;
99156 int copied, err;
99157 @@ -2524,7 +2525,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
99158 sock_recv_timestamp(msg, sk, skb);
99159
99160 serr = SKB_EXT_ERR(skb);
99161 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
99162 + ee = serr->ee;
99163 + put_cmsg(msg, level, type, sizeof ee, &ee);
99164
99165 msg->msg_flags |= MSG_ERRQUEUE;
99166 err = copied;
99167 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
99168 index a4216a4..1c07687 100644
99169 --- a/net/core/sock_diag.c
99170 +++ b/net/core/sock_diag.c
99171 @@ -9,26 +9,33 @@
99172 #include <linux/inet_diag.h>
99173 #include <linux/sock_diag.h>
99174
99175 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
99176 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
99177 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
99178 static DEFINE_MUTEX(sock_diag_table_mutex);
99179
99180 int sock_diag_check_cookie(void *sk, __u32 *cookie)
99181 {
99182 +#ifndef CONFIG_GRKERNSEC_HIDESYM
99183 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
99184 cookie[1] != INET_DIAG_NOCOOKIE) &&
99185 ((u32)(unsigned long)sk != cookie[0] ||
99186 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
99187 return -ESTALE;
99188 else
99189 +#endif
99190 return 0;
99191 }
99192 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
99193
99194 void sock_diag_save_cookie(void *sk, __u32 *cookie)
99195 {
99196 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99197 + cookie[0] = 0;
99198 + cookie[1] = 0;
99199 +#else
99200 cookie[0] = (u32)(unsigned long)sk;
99201 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
99202 +#endif
99203 }
99204 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
99205
99206 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
99207 mutex_lock(&sock_diag_table_mutex);
99208 if (sock_diag_handlers[hndl->family])
99209 err = -EBUSY;
99210 - else
99211 + else {
99212 + pax_open_kernel();
99213 sock_diag_handlers[hndl->family] = hndl;
99214 + pax_close_kernel();
99215 + }
99216 mutex_unlock(&sock_diag_table_mutex);
99217
99218 return err;
99219 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
99220
99221 mutex_lock(&sock_diag_table_mutex);
99222 BUG_ON(sock_diag_handlers[family] != hnld);
99223 + pax_open_kernel();
99224 sock_diag_handlers[family] = NULL;
99225 + pax_close_kernel();
99226 mutex_unlock(&sock_diag_table_mutex);
99227 }
99228 EXPORT_SYMBOL_GPL(sock_diag_unregister);
99229 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
99230 index cf9cd13..8b56af3 100644
99231 --- a/net/core/sysctl_net_core.c
99232 +++ b/net/core/sysctl_net_core.c
99233 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
99234 {
99235 unsigned int orig_size, size;
99236 int ret, i;
99237 - struct ctl_table tmp = {
99238 + ctl_table_no_const tmp = {
99239 .data = &size,
99240 .maxlen = sizeof(size),
99241 .mode = table->mode
99242 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
99243 void __user *buffer, size_t *lenp, loff_t *ppos)
99244 {
99245 char id[IFNAMSIZ];
99246 - struct ctl_table tbl = {
99247 + ctl_table_no_const tbl = {
99248 .data = id,
99249 .maxlen = IFNAMSIZ,
99250 };
99251 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
99252
99253 static __net_init int sysctl_core_net_init(struct net *net)
99254 {
99255 - struct ctl_table *tbl;
99256 + ctl_table_no_const *tbl = NULL;
99257
99258 net->core.sysctl_somaxconn = SOMAXCONN;
99259
99260 - tbl = netns_core_table;
99261 if (!net_eq(net, &init_net)) {
99262 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
99263 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
99264 if (tbl == NULL)
99265 goto err_dup;
99266
99267 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
99268 if (net->user_ns != &init_user_ns) {
99269 tbl[0].procname = NULL;
99270 }
99271 - }
99272 -
99273 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
99274 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
99275 + } else
99276 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
99277 if (net->core.sysctl_hdr == NULL)
99278 goto err_reg;
99279
99280 return 0;
99281
99282 err_reg:
99283 - if (tbl != netns_core_table)
99284 - kfree(tbl);
99285 + kfree(tbl);
99286 err_dup:
99287 return -ENOMEM;
99288 }
99289 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
99290 kfree(tbl);
99291 }
99292
99293 -static __net_initdata struct pernet_operations sysctl_core_ops = {
99294 +static __net_initconst struct pernet_operations sysctl_core_ops = {
99295 .init = sysctl_core_net_init,
99296 .exit = sysctl_core_net_exit,
99297 };
99298 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
99299 index 4c04848..f575934 100644
99300 --- a/net/decnet/af_decnet.c
99301 +++ b/net/decnet/af_decnet.c
99302 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
99303 .sysctl_rmem = sysctl_decnet_rmem,
99304 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
99305 .obj_size = sizeof(struct dn_sock),
99306 + .slab_flags = SLAB_USERCOPY,
99307 };
99308
99309 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
99310 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
99311 index 3b726f3..1af6368 100644
99312 --- a/net/decnet/dn_dev.c
99313 +++ b/net/decnet/dn_dev.c
99314 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
99315 .extra1 = &min_t3,
99316 .extra2 = &max_t3
99317 },
99318 - {0}
99319 + { }
99320 },
99321 };
99322
99323 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
99324 index 5325b54..a0d4d69 100644
99325 --- a/net/decnet/sysctl_net_decnet.c
99326 +++ b/net/decnet/sysctl_net_decnet.c
99327 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
99328
99329 if (len > *lenp) len = *lenp;
99330
99331 - if (copy_to_user(buffer, addr, len))
99332 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
99333 return -EFAULT;
99334
99335 *lenp = len;
99336 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
99337
99338 if (len > *lenp) len = *lenp;
99339
99340 - if (copy_to_user(buffer, devname, len))
99341 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
99342 return -EFAULT;
99343
99344 *lenp = len;
99345 diff --git a/net/dns_resolver/dns_query.c b/net/dns_resolver/dns_query.c
99346 index e7b6d53..f005cc7 100644
99347 --- a/net/dns_resolver/dns_query.c
99348 +++ b/net/dns_resolver/dns_query.c
99349 @@ -149,7 +149,9 @@ int dns_query(const char *type, const char *name, size_t namelen,
99350 if (!*_result)
99351 goto put;
99352
99353 - memcpy(*_result, upayload->data, len + 1);
99354 + memcpy(*_result, upayload->data, len);
99355 + (*_result)[len] = '\0';
99356 +
99357 if (_expiry)
99358 *_expiry = rkey->expiry;
99359
99360 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
99361 index ef2d543..5b9b73f 100644
99362 --- a/net/ieee802154/reassembly.c
99363 +++ b/net/ieee802154/reassembly.c
99364 @@ -434,12 +434,11 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
99365
99366 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99367 {
99368 - struct ctl_table *table;
99369 + ctl_table_no_const *table = NULL;
99370 struct ctl_table_header *hdr;
99371
99372 - table = lowpan_frags_ns_ctl_table;
99373 if (!net_eq(net, &init_net)) {
99374 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
99375 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
99376 GFP_KERNEL);
99377 if (table == NULL)
99378 goto err_alloc;
99379 @@ -452,9 +451,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99380 /* Don't export sysctls to unprivileged users */
99381 if (net->user_ns != &init_user_ns)
99382 table[0].procname = NULL;
99383 - }
99384 -
99385 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
99386 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
99387 + } else
99388 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
99389 if (hdr == NULL)
99390 goto err_reg;
99391
99392 @@ -462,8 +461,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99393 return 0;
99394
99395 err_reg:
99396 - if (!net_eq(net, &init_net))
99397 - kfree(table);
99398 + kfree(table);
99399 err_alloc:
99400 return -ENOMEM;
99401 }
99402 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
99403 index 6d6dd34..e5c9bec 100644
99404 --- a/net/ipv4/af_inet.c
99405 +++ b/net/ipv4/af_inet.c
99406 @@ -1736,13 +1736,9 @@ static int __init inet_init(void)
99407
99408 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
99409
99410 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
99411 - if (!sysctl_local_reserved_ports)
99412 - goto out;
99413 -
99414 rc = proto_register(&tcp_prot, 1);
99415 if (rc)
99416 - goto out_free_reserved_ports;
99417 + goto out;
99418
99419 rc = proto_register(&udp_prot, 1);
99420 if (rc)
99421 @@ -1852,8 +1848,6 @@ out_unregister_udp_proto:
99422 proto_unregister(&udp_prot);
99423 out_unregister_tcp_proto:
99424 proto_unregister(&tcp_prot);
99425 -out_free_reserved_ports:
99426 - kfree(sysctl_local_reserved_ports);
99427 goto out;
99428 }
99429
99430 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
99431 index bdbf68b..deb4759 100644
99432 --- a/net/ipv4/devinet.c
99433 +++ b/net/ipv4/devinet.c
99434 @@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
99435 idx = 0;
99436 head = &net->dev_index_head[h];
99437 rcu_read_lock();
99438 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99439 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99440 net->dev_base_seq;
99441 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99442 if (idx < s_idx)
99443 @@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
99444 idx = 0;
99445 head = &net->dev_index_head[h];
99446 rcu_read_lock();
99447 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99448 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99449 net->dev_base_seq;
99450 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99451 if (idx < s_idx)
99452 @@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
99453 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
99454 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
99455
99456 -static struct devinet_sysctl_table {
99457 +static const struct devinet_sysctl_table {
99458 struct ctl_table_header *sysctl_header;
99459 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
99460 } devinet_sysctl = {
99461 @@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
99462 int err;
99463 struct ipv4_devconf *all, *dflt;
99464 #ifdef CONFIG_SYSCTL
99465 - struct ctl_table *tbl = ctl_forward_entry;
99466 + ctl_table_no_const *tbl = NULL;
99467 struct ctl_table_header *forw_hdr;
99468 #endif
99469
99470 @@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
99471 goto err_alloc_dflt;
99472
99473 #ifdef CONFIG_SYSCTL
99474 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
99475 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
99476 if (tbl == NULL)
99477 goto err_alloc_ctl;
99478
99479 @@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
99480 goto err_reg_dflt;
99481
99482 err = -ENOMEM;
99483 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99484 + if (!net_eq(net, &init_net))
99485 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99486 + else
99487 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
99488 if (forw_hdr == NULL)
99489 goto err_reg_ctl;
99490 net->ipv4.forw_hdr = forw_hdr;
99491 @@ -2272,8 +2275,7 @@ err_reg_ctl:
99492 err_reg_dflt:
99493 __devinet_sysctl_unregister(all);
99494 err_reg_all:
99495 - if (tbl != ctl_forward_entry)
99496 - kfree(tbl);
99497 + kfree(tbl);
99498 err_alloc_ctl:
99499 #endif
99500 if (dflt != &ipv4_devconf_dflt)
99501 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
99502 index 255aa99..45c78f8 100644
99503 --- a/net/ipv4/fib_frontend.c
99504 +++ b/net/ipv4/fib_frontend.c
99505 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
99506 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99507 fib_sync_up(dev);
99508 #endif
99509 - atomic_inc(&net->ipv4.dev_addr_genid);
99510 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99511 rt_cache_flush(dev_net(dev));
99512 break;
99513 case NETDEV_DOWN:
99514 fib_del_ifaddr(ifa, NULL);
99515 - atomic_inc(&net->ipv4.dev_addr_genid);
99516 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99517 if (ifa->ifa_dev->ifa_list == NULL) {
99518 /* Last address was deleted from this interface.
99519 * Disable IP.
99520 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
99521 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99522 fib_sync_up(dev);
99523 #endif
99524 - atomic_inc(&net->ipv4.dev_addr_genid);
99525 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99526 rt_cache_flush(net);
99527 break;
99528 case NETDEV_DOWN:
99529 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
99530 index b10cd43a..22327f9 100644
99531 --- a/net/ipv4/fib_semantics.c
99532 +++ b/net/ipv4/fib_semantics.c
99533 @@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
99534 nh->nh_saddr = inet_select_addr(nh->nh_dev,
99535 nh->nh_gw,
99536 nh->nh_parent->fib_scope);
99537 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
99538 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
99539
99540 return nh->nh_saddr;
99541 }
99542 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
99543 index a56b8e6..5be2a30 100644
99544 --- a/net/ipv4/inet_connection_sock.c
99545 +++ b/net/ipv4/inet_connection_sock.c
99546 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
99547 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
99548 #endif
99549
99550 -unsigned long *sysctl_local_reserved_ports;
99551 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
99552 EXPORT_SYMBOL(sysctl_local_reserved_ports);
99553
99554 void inet_get_local_port_range(struct net *net, int *low, int *high)
99555 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
99556 index 8b9cf27..0d8d592 100644
99557 --- a/net/ipv4/inet_hashtables.c
99558 +++ b/net/ipv4/inet_hashtables.c
99559 @@ -18,6 +18,7 @@
99560 #include <linux/sched.h>
99561 #include <linux/slab.h>
99562 #include <linux/wait.h>
99563 +#include <linux/security.h>
99564
99565 #include <net/inet_connection_sock.h>
99566 #include <net/inet_hashtables.h>
99567 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
99568 return inet_ehashfn(net, laddr, lport, faddr, fport);
99569 }
99570
99571 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
99572 +
99573 /*
99574 * Allocate and initialize a new local port bind bucket.
99575 * The bindhash mutex for snum's hash chain must be held here.
99576 @@ -554,6 +557,8 @@ ok:
99577 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
99578 spin_unlock(&head->lock);
99579
99580 + gr_update_task_in_ip_table(current, inet_sk(sk));
99581 +
99582 if (tw) {
99583 inet_twsk_deschedule(tw, death_row);
99584 while (twrefcnt) {
99585 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
99586 index 48f4244..f56d83a 100644
99587 --- a/net/ipv4/inetpeer.c
99588 +++ b/net/ipv4/inetpeer.c
99589 @@ -496,8 +496,8 @@ relookup:
99590 if (p) {
99591 p->daddr = *daddr;
99592 atomic_set(&p->refcnt, 1);
99593 - atomic_set(&p->rid, 0);
99594 - atomic_set(&p->ip_id_count,
99595 + atomic_set_unchecked(&p->rid, 0);
99596 + atomic_set_unchecked(&p->ip_id_count,
99597 (daddr->family == AF_INET) ?
99598 secure_ip_id(daddr->addr.a4) :
99599 secure_ipv6_id(daddr->addr.a6));
99600 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
99601 index ed32313..3762abe 100644
99602 --- a/net/ipv4/ip_fragment.c
99603 +++ b/net/ipv4/ip_fragment.c
99604 @@ -284,7 +284,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
99605 return 0;
99606
99607 start = qp->rid;
99608 - end = atomic_inc_return(&peer->rid);
99609 + end = atomic_inc_return_unchecked(&peer->rid);
99610 qp->rid = end;
99611
99612 rc = qp->q.fragments && (end - start) > max;
99613 @@ -761,12 +761,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
99614
99615 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99616 {
99617 - struct ctl_table *table;
99618 + ctl_table_no_const *table = NULL;
99619 struct ctl_table_header *hdr;
99620
99621 - table = ip4_frags_ns_ctl_table;
99622 if (!net_eq(net, &init_net)) {
99623 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99624 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99625 if (table == NULL)
99626 goto err_alloc;
99627
99628 @@ -777,9 +776,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99629 /* Don't export sysctls to unprivileged users */
99630 if (net->user_ns != &init_user_ns)
99631 table[0].procname = NULL;
99632 - }
99633 + hdr = register_net_sysctl(net, "net/ipv4", table);
99634 + } else
99635 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
99636
99637 - hdr = register_net_sysctl(net, "net/ipv4", table);
99638 if (hdr == NULL)
99639 goto err_reg;
99640
99641 @@ -787,8 +787,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99642 return 0;
99643
99644 err_reg:
99645 - if (!net_eq(net, &init_net))
99646 - kfree(table);
99647 + kfree(table);
99648 err_alloc:
99649 return -ENOMEM;
99650 }
99651 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
99652 index 94213c8..8bdb342 100644
99653 --- a/net/ipv4/ip_gre.c
99654 +++ b/net/ipv4/ip_gre.c
99655 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
99656 module_param(log_ecn_error, bool, 0644);
99657 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99658
99659 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
99660 +static struct rtnl_link_ops ipgre_link_ops;
99661 static int ipgre_tunnel_init(struct net_device *dev);
99662
99663 static int ipgre_net_id __read_mostly;
99664 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
99665 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
99666 };
99667
99668 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99669 +static struct rtnl_link_ops ipgre_link_ops = {
99670 .kind = "gre",
99671 .maxtype = IFLA_GRE_MAX,
99672 .policy = ipgre_policy,
99673 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99674 .fill_info = ipgre_fill_info,
99675 };
99676
99677 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
99678 +static struct rtnl_link_ops ipgre_tap_ops = {
99679 .kind = "gretap",
99680 .maxtype = IFLA_GRE_MAX,
99681 .policy = ipgre_policy,
99682 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
99683 index 64741b9..6f334a2 100644
99684 --- a/net/ipv4/ip_sockglue.c
99685 +++ b/net/ipv4/ip_sockglue.c
99686 @@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99687 len = min_t(unsigned int, len, opt->optlen);
99688 if (put_user(len, optlen))
99689 return -EFAULT;
99690 - if (copy_to_user(optval, opt->__data, len))
99691 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
99692 + copy_to_user(optval, opt->__data, len))
99693 return -EFAULT;
99694 return 0;
99695 }
99696 @@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99697 if (sk->sk_type != SOCK_STREAM)
99698 return -ENOPROTOOPT;
99699
99700 - msg.msg_control = optval;
99701 + msg.msg_control = (void __force_kernel *)optval;
99702 msg.msg_controllen = len;
99703 msg.msg_flags = flags;
99704
99705 diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
99706 index 2acc233..b93143f 100644
99707 --- a/net/ipv4/ip_tunnel.c
99708 +++ b/net/ipv4/ip_tunnel.c
99709 @@ -73,12 +73,7 @@ static void __tunnel_dst_set(struct ip_tunnel_dst *idst,
99710 {
99711 struct dst_entry *old_dst;
99712
99713 - if (dst) {
99714 - if (dst->flags & DST_NOCACHE)
99715 - dst = NULL;
99716 - else
99717 - dst_clone(dst);
99718 - }
99719 + dst_clone(dst);
99720 old_dst = xchg((__force struct dst_entry **)&idst->dst, dst);
99721 dst_release(old_dst);
99722 }
99723 @@ -108,13 +103,14 @@ static struct rtable *tunnel_rtable_get(struct ip_tunnel *t, u32 cookie)
99724
99725 rcu_read_lock();
99726 dst = rcu_dereference(this_cpu_ptr(t->dst_cache)->dst);
99727 + if (dst && !atomic_inc_not_zero(&dst->__refcnt))
99728 + dst = NULL;
99729 if (dst) {
99730 if (dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
99731 - rcu_read_unlock();
99732 tunnel_dst_reset(t);
99733 - return NULL;
99734 + dst_release(dst);
99735 + dst = NULL;
99736 }
99737 - dst_hold(dst);
99738 }
99739 rcu_read_unlock();
99740 return (struct rtable *)dst;
99741 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
99742 index 13ef00f..8ffca25 100644
99743 --- a/net/ipv4/ip_vti.c
99744 +++ b/net/ipv4/ip_vti.c
99745 @@ -45,7 +45,7 @@
99746 #include <net/net_namespace.h>
99747 #include <net/netns/generic.h>
99748
99749 -static struct rtnl_link_ops vti_link_ops __read_mostly;
99750 +static struct rtnl_link_ops vti_link_ops;
99751
99752 static int vti_net_id __read_mostly;
99753 static int vti_tunnel_init(struct net_device *dev);
99754 @@ -513,7 +513,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
99755 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
99756 };
99757
99758 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
99759 +static struct rtnl_link_ops vti_link_ops = {
99760 .kind = "vti",
99761 .maxtype = IFLA_VTI_MAX,
99762 .policy = vti_policy,
99763 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
99764 index b3e86ea..18ce98c 100644
99765 --- a/net/ipv4/ipconfig.c
99766 +++ b/net/ipv4/ipconfig.c
99767 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
99768
99769 mm_segment_t oldfs = get_fs();
99770 set_fs(get_ds());
99771 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99772 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99773 set_fs(oldfs);
99774 return res;
99775 }
99776 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
99777
99778 mm_segment_t oldfs = get_fs();
99779 set_fs(get_ds());
99780 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99781 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99782 set_fs(oldfs);
99783 return res;
99784 }
99785 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99786
99787 mm_segment_t oldfs = get_fs();
99788 set_fs(get_ds());
99789 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99790 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99791 set_fs(oldfs);
99792 return res;
99793 }
99794 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99795 index 62eaa00..29b2dc2 100644
99796 --- a/net/ipv4/ipip.c
99797 +++ b/net/ipv4/ipip.c
99798 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99799 static int ipip_net_id __read_mostly;
99800
99801 static int ipip_tunnel_init(struct net_device *dev);
99802 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
99803 +static struct rtnl_link_ops ipip_link_ops;
99804
99805 static int ipip_err(struct sk_buff *skb, u32 info)
99806 {
99807 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99808 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99809 };
99810
99811 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99812 +static struct rtnl_link_ops ipip_link_ops = {
99813 .kind = "ipip",
99814 .maxtype = IFLA_IPTUN_MAX,
99815 .policy = ipip_policy,
99816 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99817 index f95b6f9..2ee2097 100644
99818 --- a/net/ipv4/netfilter/arp_tables.c
99819 +++ b/net/ipv4/netfilter/arp_tables.c
99820 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99821 #endif
99822
99823 static int get_info(struct net *net, void __user *user,
99824 - const int *len, int compat)
99825 + int len, int compat)
99826 {
99827 char name[XT_TABLE_MAXNAMELEN];
99828 struct xt_table *t;
99829 int ret;
99830
99831 - if (*len != sizeof(struct arpt_getinfo)) {
99832 - duprintf("length %u != %Zu\n", *len,
99833 + if (len != sizeof(struct arpt_getinfo)) {
99834 + duprintf("length %u != %Zu\n", len,
99835 sizeof(struct arpt_getinfo));
99836 return -EINVAL;
99837 }
99838 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99839 info.size = private->size;
99840 strcpy(info.name, name);
99841
99842 - if (copy_to_user(user, &info, *len) != 0)
99843 + if (copy_to_user(user, &info, len) != 0)
99844 ret = -EFAULT;
99845 else
99846 ret = 0;
99847 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99848
99849 switch (cmd) {
99850 case ARPT_SO_GET_INFO:
99851 - ret = get_info(sock_net(sk), user, len, 1);
99852 + ret = get_info(sock_net(sk), user, *len, 1);
99853 break;
99854 case ARPT_SO_GET_ENTRIES:
99855 ret = compat_get_entries(sock_net(sk), user, len);
99856 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99857
99858 switch (cmd) {
99859 case ARPT_SO_GET_INFO:
99860 - ret = get_info(sock_net(sk), user, len, 0);
99861 + ret = get_info(sock_net(sk), user, *len, 0);
99862 break;
99863
99864 case ARPT_SO_GET_ENTRIES:
99865 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99866 index 99e810f..3711b81 100644
99867 --- a/net/ipv4/netfilter/ip_tables.c
99868 +++ b/net/ipv4/netfilter/ip_tables.c
99869 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99870 #endif
99871
99872 static int get_info(struct net *net, void __user *user,
99873 - const int *len, int compat)
99874 + int len, int compat)
99875 {
99876 char name[XT_TABLE_MAXNAMELEN];
99877 struct xt_table *t;
99878 int ret;
99879
99880 - if (*len != sizeof(struct ipt_getinfo)) {
99881 - duprintf("length %u != %zu\n", *len,
99882 + if (len != sizeof(struct ipt_getinfo)) {
99883 + duprintf("length %u != %zu\n", len,
99884 sizeof(struct ipt_getinfo));
99885 return -EINVAL;
99886 }
99887 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99888 info.size = private->size;
99889 strcpy(info.name, name);
99890
99891 - if (copy_to_user(user, &info, *len) != 0)
99892 + if (copy_to_user(user, &info, len) != 0)
99893 ret = -EFAULT;
99894 else
99895 ret = 0;
99896 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99897
99898 switch (cmd) {
99899 case IPT_SO_GET_INFO:
99900 - ret = get_info(sock_net(sk), user, len, 1);
99901 + ret = get_info(sock_net(sk), user, *len, 1);
99902 break;
99903 case IPT_SO_GET_ENTRIES:
99904 ret = compat_get_entries(sock_net(sk), user, len);
99905 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99906
99907 switch (cmd) {
99908 case IPT_SO_GET_INFO:
99909 - ret = get_info(sock_net(sk), user, len, 0);
99910 + ret = get_info(sock_net(sk), user, *len, 0);
99911 break;
99912
99913 case IPT_SO_GET_ENTRIES:
99914 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99915 index 2510c02..cfb34fa 100644
99916 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
99917 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99918 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
99919 spin_lock_init(&cn->lock);
99920
99921 #ifdef CONFIG_PROC_FS
99922 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
99923 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
99924 if (!cn->procdir) {
99925 pr_err("Unable to proc dir entry\n");
99926 return -ENOMEM;
99927 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
99928 index 044a0dd..e0c1971 100644
99929 --- a/net/ipv4/ping.c
99930 +++ b/net/ipv4/ping.c
99931 @@ -59,7 +59,7 @@ struct ping_table {
99932 };
99933
99934 static struct ping_table ping_table;
99935 -struct pingv6_ops pingv6_ops;
99936 +struct pingv6_ops *pingv6_ops;
99937 EXPORT_SYMBOL_GPL(pingv6_ops);
99938
99939 static u16 ping_port_rover;
99940 @@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
99941 return -ENODEV;
99942 }
99943 }
99944 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
99945 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
99946 scoped);
99947 rcu_read_unlock();
99948
99949 @@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99950 }
99951 #if IS_ENABLED(CONFIG_IPV6)
99952 } else if (skb->protocol == htons(ETH_P_IPV6)) {
99953 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
99954 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
99955 #endif
99956 }
99957
99958 @@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99959 info, (u8 *)icmph);
99960 #if IS_ENABLED(CONFIG_IPV6)
99961 } else if (family == AF_INET6) {
99962 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
99963 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
99964 info, (u8 *)icmph);
99965 #endif
99966 }
99967 @@ -844,6 +844,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99968 {
99969 struct inet_sock *isk = inet_sk(sk);
99970 int family = sk->sk_family;
99971 + struct sockaddr_in *sin;
99972 + struct sockaddr_in6 *sin6;
99973 struct sk_buff *skb;
99974 int copied, err;
99975
99976 @@ -853,12 +855,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99977 if (flags & MSG_OOB)
99978 goto out;
99979
99980 + if (addr_len) {
99981 + if (family == AF_INET)
99982 + *addr_len = sizeof(*sin);
99983 + else if (family == AF_INET6 && addr_len)
99984 + *addr_len = sizeof(*sin6);
99985 + }
99986 +
99987 if (flags & MSG_ERRQUEUE) {
99988 if (family == AF_INET) {
99989 return ip_recv_error(sk, msg, len, addr_len);
99990 #if IS_ENABLED(CONFIG_IPV6)
99991 } else if (family == AF_INET6) {
99992 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
99993 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
99994 addr_len);
99995 #endif
99996 }
99997 @@ -890,7 +899,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99998 sin->sin_port = 0 /* skb->h.uh->source */;
99999 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100000 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100001 - *addr_len = sizeof(*sin);
100002 }
100003
100004 if (isk->cmsg_flags)
100005 @@ -912,14 +920,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100006 sin6->sin6_scope_id =
100007 ipv6_iface_scope_id(&sin6->sin6_addr,
100008 IP6CB(skb)->iif);
100009 - *addr_len = sizeof(*sin6);
100010 }
100011
100012 if (inet6_sk(sk)->rxopt.all)
100013 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
100014 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
100015 if (skb->protocol == htons(ETH_P_IPV6) &&
100016 inet6_sk(sk)->rxopt.all)
100017 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
100018 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
100019 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
100020 ip_cmsg_recv(msg, skb);
100021 #endif
100022 @@ -1111,7 +1118,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
100023 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100024 0, sock_i_ino(sp),
100025 atomic_read(&sp->sk_refcnt), sp,
100026 - atomic_read(&sp->sk_drops));
100027 + atomic_read_unchecked(&sp->sk_drops));
100028 }
100029
100030 static int ping_v4_seq_show(struct seq_file *seq, void *v)
100031 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
100032 index a9dbe58..46f577f 100644
100033 --- a/net/ipv4/raw.c
100034 +++ b/net/ipv4/raw.c
100035 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
100036 int raw_rcv(struct sock *sk, struct sk_buff *skb)
100037 {
100038 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
100039 - atomic_inc(&sk->sk_drops);
100040 + atomic_inc_unchecked(&sk->sk_drops);
100041 kfree_skb(skb);
100042 return NET_RX_DROP;
100043 }
100044 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100045 if (flags & MSG_OOB)
100046 goto out;
100047
100048 + if (addr_len)
100049 + *addr_len = sizeof(*sin);
100050 +
100051 if (flags & MSG_ERRQUEUE) {
100052 err = ip_recv_error(sk, msg, len, addr_len);
100053 goto out;
100054 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100055 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100056 sin->sin_port = 0;
100057 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
100058 - *addr_len = sizeof(*sin);
100059 }
100060 if (inet->cmsg_flags)
100061 ip_cmsg_recv(msg, skb);
100062 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
100063
100064 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
100065 {
100066 + struct icmp_filter filter;
100067 +
100068 if (optlen > sizeof(struct icmp_filter))
100069 optlen = sizeof(struct icmp_filter);
100070 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
100071 + if (copy_from_user(&filter, optval, optlen))
100072 return -EFAULT;
100073 + raw_sk(sk)->filter = filter;
100074 return 0;
100075 }
100076
100077 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
100078 {
100079 int len, ret = -EFAULT;
100080 + struct icmp_filter filter;
100081
100082 if (get_user(len, optlen))
100083 goto out;
100084 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
100085 if (len > sizeof(struct icmp_filter))
100086 len = sizeof(struct icmp_filter);
100087 ret = -EFAULT;
100088 - if (put_user(len, optlen) ||
100089 - copy_to_user(optval, &raw_sk(sk)->filter, len))
100090 + filter = raw_sk(sk)->filter;
100091 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
100092 goto out;
100093 ret = 0;
100094 out: return ret;
100095 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
100096 0, 0L, 0,
100097 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
100098 0, sock_i_ino(sp),
100099 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
100100 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
100101 }
100102
100103 static int raw_seq_show(struct seq_file *seq, void *v)
100104 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
100105 index 5e676be..f6c62f1 100644
100106 --- a/net/ipv4/route.c
100107 +++ b/net/ipv4/route.c
100108 @@ -227,7 +227,7 @@ static const struct seq_operations rt_cache_seq_ops = {
100109
100110 static int rt_cache_seq_open(struct inode *inode, struct file *file)
100111 {
100112 - return seq_open(file, &rt_cache_seq_ops);
100113 + return seq_open_restrict(file, &rt_cache_seq_ops);
100114 }
100115
100116 static const struct file_operations rt_cache_seq_fops = {
100117 @@ -318,7 +318,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
100118
100119 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
100120 {
100121 - return seq_open(file, &rt_cpu_seq_ops);
100122 + return seq_open_restrict(file, &rt_cpu_seq_ops);
100123 }
100124
100125 static const struct file_operations rt_cpu_seq_fops = {
100126 @@ -356,7 +356,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
100127
100128 static int rt_acct_proc_open(struct inode *inode, struct file *file)
100129 {
100130 - return single_open(file, rt_acct_proc_show, NULL);
100131 + return single_open_restrict(file, rt_acct_proc_show, NULL);
100132 }
100133
100134 static const struct file_operations rt_acct_proc_fops = {
100135 @@ -2610,34 +2610,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
100136 .maxlen = sizeof(int),
100137 .mode = 0200,
100138 .proc_handler = ipv4_sysctl_rtcache_flush,
100139 + .extra1 = &init_net,
100140 },
100141 { },
100142 };
100143
100144 static __net_init int sysctl_route_net_init(struct net *net)
100145 {
100146 - struct ctl_table *tbl;
100147 + ctl_table_no_const *tbl = NULL;
100148
100149 - tbl = ipv4_route_flush_table;
100150 if (!net_eq(net, &init_net)) {
100151 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
100152 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
100153 if (tbl == NULL)
100154 goto err_dup;
100155
100156 /* Don't export sysctls to unprivileged users */
100157 if (net->user_ns != &init_user_ns)
100158 tbl[0].procname = NULL;
100159 - }
100160 - tbl[0].extra1 = net;
100161 + tbl[0].extra1 = net;
100162 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
100163 + } else
100164 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
100165
100166 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
100167 if (net->ipv4.route_hdr == NULL)
100168 goto err_reg;
100169 return 0;
100170
100171 err_reg:
100172 - if (tbl != ipv4_route_flush_table)
100173 - kfree(tbl);
100174 + kfree(tbl);
100175 err_dup:
100176 return -ENOMEM;
100177 }
100178 @@ -2660,8 +2660,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
100179
100180 static __net_init int rt_genid_init(struct net *net)
100181 {
100182 - atomic_set(&net->ipv4.rt_genid, 0);
100183 - atomic_set(&net->fnhe_genid, 0);
100184 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
100185 + atomic_set_unchecked(&net->fnhe_genid, 0);
100186 get_random_bytes(&net->ipv4.dev_addr_genid,
100187 sizeof(net->ipv4.dev_addr_genid));
100188 return 0;
100189 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
100190 index 5cde8f2..5f5684e 100644
100191 --- a/net/ipv4/sysctl_net_ipv4.c
100192 +++ b/net/ipv4/sysctl_net_ipv4.c
100193 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
100194 container_of(table->data, struct net, ipv4.ip_local_ports.range);
100195 int ret;
100196 int range[2];
100197 - struct ctl_table tmp = {
100198 + ctl_table_no_const tmp = {
100199 .data = &range,
100200 .maxlen = sizeof(range),
100201 .mode = table->mode,
100202 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
100203 int ret;
100204 gid_t urange[2];
100205 kgid_t low, high;
100206 - struct ctl_table tmp = {
100207 + ctl_table_no_const tmp = {
100208 .data = &urange,
100209 .maxlen = sizeof(urange),
100210 .mode = table->mode,
100211 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
100212 void __user *buffer, size_t *lenp, loff_t *ppos)
100213 {
100214 char val[TCP_CA_NAME_MAX];
100215 - struct ctl_table tbl = {
100216 + ctl_table_no_const tbl = {
100217 .data = val,
100218 .maxlen = TCP_CA_NAME_MAX,
100219 };
100220 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
100221 void __user *buffer, size_t *lenp,
100222 loff_t *ppos)
100223 {
100224 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
100225 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
100226 int ret;
100227
100228 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
100229 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
100230 void __user *buffer, size_t *lenp,
100231 loff_t *ppos)
100232 {
100233 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
100234 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
100235 int ret;
100236
100237 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
100238 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
100239 void __user *buffer, size_t *lenp,
100240 loff_t *ppos)
100241 {
100242 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
100243 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
100244 struct tcp_fastopen_context *ctxt;
100245 int ret;
100246 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
100247 @@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
100248 },
100249 {
100250 .procname = "ip_local_reserved_ports",
100251 - .data = NULL, /* initialized in sysctl_ipv4_init */
100252 + .data = sysctl_local_reserved_ports,
100253 .maxlen = 65536,
100254 .mode = 0644,
100255 .proc_handler = proc_do_large_bitmap,
100256 @@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
100257
100258 static __net_init int ipv4_sysctl_init_net(struct net *net)
100259 {
100260 - struct ctl_table *table;
100261 + ctl_table_no_const *table = NULL;
100262
100263 - table = ipv4_net_table;
100264 if (!net_eq(net, &init_net)) {
100265 int i;
100266
100267 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
100268 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
100269 if (table == NULL)
100270 goto err_alloc;
100271
100272 @@ -858,15 +857,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
100273 table[i].data += (void *)net - (void *)&init_net;
100274 }
100275
100276 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
100277 + if (!net_eq(net, &init_net))
100278 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
100279 + else
100280 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
100281 if (net->ipv4.ipv4_hdr == NULL)
100282 goto err_reg;
100283
100284 return 0;
100285
100286 err_reg:
100287 - if (!net_eq(net, &init_net))
100288 - kfree(table);
100289 + kfree(table);
100290 err_alloc:
100291 return -ENOMEM;
100292 }
100293 @@ -888,16 +889,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
100294 static __init int sysctl_ipv4_init(void)
100295 {
100296 struct ctl_table_header *hdr;
100297 - struct ctl_table *i;
100298 -
100299 - for (i = ipv4_table; i->procname; i++) {
100300 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
100301 - i->data = sysctl_local_reserved_ports;
100302 - break;
100303 - }
100304 - }
100305 - if (!i->procname)
100306 - return -EINVAL;
100307
100308 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
100309 if (hdr == NULL)
100310 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
100311 index 3a26b3b..8bbe4ae 100644
100312 --- a/net/ipv4/tcp_input.c
100313 +++ b/net/ipv4/tcp_input.c
100314 @@ -754,7 +754,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
100315 * without any lock. We want to make sure compiler wont store
100316 * intermediate values in this location.
100317 */
100318 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
100319 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
100320 sk->sk_max_pacing_rate);
100321 }
100322
100323 @@ -4478,7 +4478,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
100324 * simplifies code)
100325 */
100326 static void
100327 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
100328 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
100329 struct sk_buff *head, struct sk_buff *tail,
100330 u32 start, u32 end)
100331 {
100332 @@ -5558,6 +5558,7 @@ discard:
100333 tcp_paws_reject(&tp->rx_opt, 0))
100334 goto discard_and_undo;
100335
100336 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
100337 if (th->syn) {
100338 /* We see SYN without ACK. It is attempt of
100339 * simultaneous connect with crossed SYNs.
100340 @@ -5608,6 +5609,7 @@ discard:
100341 goto discard;
100342 #endif
100343 }
100344 +#endif
100345 /* "fifth, if neither of the SYN or RST bits is set then
100346 * drop the segment and return."
100347 */
100348 @@ -5654,7 +5656,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
100349 goto discard;
100350
100351 if (th->syn) {
100352 - if (th->fin)
100353 + if (th->fin || th->urg || th->psh)
100354 goto discard;
100355 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
100356 return 1;
100357 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
100358 index 438f3b9..bc9e1ad 100644
100359 --- a/net/ipv4/tcp_ipv4.c
100360 +++ b/net/ipv4/tcp_ipv4.c
100361 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
100362 EXPORT_SYMBOL(sysctl_tcp_low_latency);
100363
100364
100365 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100366 +extern int grsec_enable_blackhole;
100367 +#endif
100368 +
100369 #ifdef CONFIG_TCP_MD5SIG
100370 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
100371 __be32 daddr, __be32 saddr, const struct tcphdr *th);
100372 @@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
100373 return 0;
100374
100375 reset:
100376 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100377 + if (!grsec_enable_blackhole)
100378 +#endif
100379 tcp_v4_send_reset(rsk, skb);
100380 discard:
100381 kfree_skb(skb);
100382 @@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
100383 TCP_SKB_CB(skb)->sacked = 0;
100384
100385 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100386 - if (!sk)
100387 + if (!sk) {
100388 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100389 + ret = 1;
100390 +#endif
100391 goto no_tcp_socket;
100392 -
100393 + }
100394 process:
100395 - if (sk->sk_state == TCP_TIME_WAIT)
100396 + if (sk->sk_state == TCP_TIME_WAIT) {
100397 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100398 + ret = 2;
100399 +#endif
100400 goto do_time_wait;
100401 + }
100402
100403 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
100404 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100405 @@ -2033,6 +2047,10 @@ csum_error:
100406 bad_packet:
100407 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100408 } else {
100409 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100410 + if (!grsec_enable_blackhole || (ret == 1 &&
100411 + (skb->dev->flags & IFF_LOOPBACK)))
100412 +#endif
100413 tcp_v4_send_reset(NULL, skb);
100414 }
100415
100416 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
100417 index 05c1b15..3e9344b 100644
100418 --- a/net/ipv4/tcp_minisocks.c
100419 +++ b/net/ipv4/tcp_minisocks.c
100420 @@ -27,6 +27,10 @@
100421 #include <net/inet_common.h>
100422 #include <net/xfrm.h>
100423
100424 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100425 +extern int grsec_enable_blackhole;
100426 +#endif
100427 +
100428 int sysctl_tcp_syncookies __read_mostly = 1;
100429 EXPORT_SYMBOL(sysctl_tcp_syncookies);
100430
100431 @@ -709,7 +713,10 @@ embryonic_reset:
100432 * avoid becoming vulnerable to outside attack aiming at
100433 * resetting legit local connections.
100434 */
100435 - req->rsk_ops->send_reset(sk, skb);
100436 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100437 + if (!grsec_enable_blackhole)
100438 +#endif
100439 + req->rsk_ops->send_reset(sk, skb);
100440 } else if (fastopen) { /* received a valid RST pkt */
100441 reqsk_fastopen_remove(sk, req, true);
100442 tcp_reset(sk);
100443 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
100444 index 3b66610..bfbe23a 100644
100445 --- a/net/ipv4/tcp_probe.c
100446 +++ b/net/ipv4/tcp_probe.c
100447 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
100448 if (cnt + width >= len)
100449 break;
100450
100451 - if (copy_to_user(buf + cnt, tbuf, width))
100452 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
100453 return -EFAULT;
100454 cnt += width;
100455 }
100456 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
100457 index 286227a..c495a76 100644
100458 --- a/net/ipv4/tcp_timer.c
100459 +++ b/net/ipv4/tcp_timer.c
100460 @@ -22,6 +22,10 @@
100461 #include <linux/gfp.h>
100462 #include <net/tcp.h>
100463
100464 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100465 +extern int grsec_lastack_retries;
100466 +#endif
100467 +
100468 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
100469 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
100470 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
100471 @@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
100472 }
100473 }
100474
100475 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100476 + if ((sk->sk_state == TCP_LAST_ACK) &&
100477 + (grsec_lastack_retries > 0) &&
100478 + (grsec_lastack_retries < retry_until))
100479 + retry_until = grsec_lastack_retries;
100480 +#endif
100481 +
100482 if (retransmits_timed_out(sk, retry_until,
100483 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
100484 /* Has it gone just too far? */
100485 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
100486 index 54a5fe9..78fea00 100644
100487 --- a/net/ipv4/udp.c
100488 +++ b/net/ipv4/udp.c
100489 @@ -87,6 +87,7 @@
100490 #include <linux/types.h>
100491 #include <linux/fcntl.h>
100492 #include <linux/module.h>
100493 +#include <linux/security.h>
100494 #include <linux/socket.h>
100495 #include <linux/sockios.h>
100496 #include <linux/igmp.h>
100497 @@ -113,6 +114,10 @@
100498 #include <net/busy_poll.h>
100499 #include "udp_impl.h"
100500
100501 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100502 +extern int grsec_enable_blackhole;
100503 +#endif
100504 +
100505 struct udp_table udp_table __read_mostly;
100506 EXPORT_SYMBOL(udp_table);
100507
100508 @@ -615,6 +620,9 @@ found:
100509 return s;
100510 }
100511
100512 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
100513 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
100514 +
100515 /*
100516 * This routine is called by the ICMP module when it gets some
100517 * sort of error condition. If err < 0 then the socket should
100518 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100519 dport = usin->sin_port;
100520 if (dport == 0)
100521 return -EINVAL;
100522 +
100523 + err = gr_search_udp_sendmsg(sk, usin);
100524 + if (err)
100525 + return err;
100526 } else {
100527 if (sk->sk_state != TCP_ESTABLISHED)
100528 return -EDESTADDRREQ;
100529 +
100530 + err = gr_search_udp_sendmsg(sk, NULL);
100531 + if (err)
100532 + return err;
100533 +
100534 daddr = inet->inet_daddr;
100535 dport = inet->inet_dport;
100536 /* Open fast path for connected socket.
100537 @@ -1164,7 +1181,7 @@ static unsigned int first_packet_length(struct sock *sk)
100538 IS_UDPLITE(sk));
100539 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100540 IS_UDPLITE(sk));
100541 - atomic_inc(&sk->sk_drops);
100542 + atomic_inc_unchecked(&sk->sk_drops);
100543 __skb_unlink(skb, rcvq);
100544 __skb_queue_tail(&list_kill, skb);
100545 }
100546 @@ -1235,6 +1252,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100547 int is_udplite = IS_UDPLITE(sk);
100548 bool slow;
100549
100550 + /*
100551 + * Check any passed addresses
100552 + */
100553 + if (addr_len)
100554 + *addr_len = sizeof(*sin);
100555 +
100556 if (flags & MSG_ERRQUEUE)
100557 return ip_recv_error(sk, msg, len, addr_len);
100558
100559 @@ -1244,6 +1267,10 @@ try_again:
100560 if (!skb)
100561 goto out;
100562
100563 + err = gr_search_udp_recvmsg(sk, skb);
100564 + if (err)
100565 + goto out_free;
100566 +
100567 ulen = skb->len - sizeof(struct udphdr);
100568 copied = len;
100569 if (copied > ulen)
100570 @@ -1277,7 +1304,7 @@ try_again:
100571 if (unlikely(err)) {
100572 trace_kfree_skb(skb, udp_recvmsg);
100573 if (!peeked) {
100574 - atomic_inc(&sk->sk_drops);
100575 + atomic_inc_unchecked(&sk->sk_drops);
100576 UDP_INC_STATS_USER(sock_net(sk),
100577 UDP_MIB_INERRORS, is_udplite);
100578 }
100579 @@ -1296,7 +1323,6 @@ try_again:
100580 sin->sin_port = udp_hdr(skb)->source;
100581 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100582 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100583 - *addr_len = sizeof(*sin);
100584 }
100585 if (inet->cmsg_flags)
100586 ip_cmsg_recv(msg, skb);
100587 @@ -1567,7 +1593,7 @@ csum_error:
100588 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100589 drop:
100590 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100591 - atomic_inc(&sk->sk_drops);
100592 + atomic_inc_unchecked(&sk->sk_drops);
100593 kfree_skb(skb);
100594 return -1;
100595 }
100596 @@ -1586,7 +1612,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100597 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100598
100599 if (!skb1) {
100600 - atomic_inc(&sk->sk_drops);
100601 + atomic_inc_unchecked(&sk->sk_drops);
100602 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100603 IS_UDPLITE(sk));
100604 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100605 @@ -1787,6 +1813,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100606 goto csum_error;
100607
100608 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100609 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100610 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100611 +#endif
100612 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
100613
100614 /*
100615 @@ -2355,7 +2384,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
100616 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100617 0, sock_i_ino(sp),
100618 atomic_read(&sp->sk_refcnt), sp,
100619 - atomic_read(&sp->sk_drops));
100620 + atomic_read_unchecked(&sp->sk_drops));
100621 }
100622
100623 int udp4_seq_show(struct seq_file *seq, void *v)
100624 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
100625 index 6156f68..d6ab46d 100644
100626 --- a/net/ipv4/xfrm4_policy.c
100627 +++ b/net/ipv4/xfrm4_policy.c
100628 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
100629 fl4->flowi4_tos = iph->tos;
100630 }
100631
100632 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
100633 +static int xfrm4_garbage_collect(struct dst_ops *ops)
100634 {
100635 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
100636
100637 - xfrm4_policy_afinfo.garbage_collect(net);
100638 + xfrm_garbage_collect_deferred(net);
100639 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
100640 }
100641
100642 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
100643
100644 static int __net_init xfrm4_net_init(struct net *net)
100645 {
100646 - struct ctl_table *table;
100647 + ctl_table_no_const *table = NULL;
100648 struct ctl_table_header *hdr;
100649
100650 - table = xfrm4_policy_table;
100651 if (!net_eq(net, &init_net)) {
100652 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100653 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100654 if (!table)
100655 goto err_alloc;
100656
100657 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
100658 - }
100659 -
100660 - hdr = register_net_sysctl(net, "net/ipv4", table);
100661 + hdr = register_net_sysctl(net, "net/ipv4", table);
100662 + } else
100663 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
100664 if (!hdr)
100665 goto err_reg;
100666
100667 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
100668 return 0;
100669
100670 err_reg:
100671 - if (!net_eq(net, &init_net))
100672 - kfree(table);
100673 + kfree(table);
100674 err_alloc:
100675 return -ENOMEM;
100676 }
100677 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
100678 index 6c7fa08..8a31430 100644
100679 --- a/net/ipv6/addrconf.c
100680 +++ b/net/ipv6/addrconf.c
100681 @@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
100682 idx = 0;
100683 head = &net->dev_index_head[h];
100684 rcu_read_lock();
100685 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
100686 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
100687 net->dev_base_seq;
100688 hlist_for_each_entry_rcu(dev, head, index_hlist) {
100689 if (idx < s_idx)
100690 @@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
100691 p.iph.ihl = 5;
100692 p.iph.protocol = IPPROTO_IPV6;
100693 p.iph.ttl = 64;
100694 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
100695 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
100696
100697 if (ops->ndo_do_ioctl) {
100698 mm_segment_t oldfs = get_fs();
100699 @@ -3528,16 +3528,23 @@ static const struct file_operations if6_fops = {
100700 .release = seq_release_net,
100701 };
100702
100703 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
100704 +extern void unregister_ipv6_seq_ops_addr(void);
100705 +
100706 static int __net_init if6_proc_net_init(struct net *net)
100707 {
100708 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
100709 + register_ipv6_seq_ops_addr(&if6_seq_ops);
100710 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
100711 + unregister_ipv6_seq_ops_addr();
100712 return -ENOMEM;
100713 + }
100714 return 0;
100715 }
100716
100717 static void __net_exit if6_proc_net_exit(struct net *net)
100718 {
100719 remove_proc_entry("if_inet6", net->proc_net);
100720 + unregister_ipv6_seq_ops_addr();
100721 }
100722
100723 static struct pernet_operations if6_proc_net_ops = {
100724 @@ -4146,7 +4153,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
100725 s_ip_idx = ip_idx = cb->args[2];
100726
100727 rcu_read_lock();
100728 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100729 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100730 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
100731 idx = 0;
100732 head = &net->dev_index_head[h];
100733 @@ -4758,7 +4765,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
100734 dst_free(&ifp->rt->dst);
100735 break;
100736 }
100737 - atomic_inc(&net->ipv6.dev_addr_genid);
100738 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
100739 rt_genid_bump_ipv6(net);
100740 }
100741
100742 @@ -4779,7 +4786,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
100743 int *valp = ctl->data;
100744 int val = *valp;
100745 loff_t pos = *ppos;
100746 - struct ctl_table lctl;
100747 + ctl_table_no_const lctl;
100748 int ret;
100749
100750 /*
100751 @@ -4864,7 +4871,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
100752 int *valp = ctl->data;
100753 int val = *valp;
100754 loff_t pos = *ppos;
100755 - struct ctl_table lctl;
100756 + ctl_table_no_const lctl;
100757 int ret;
100758
100759 /*
100760 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
100761 index d935889..2f64330 100644
100762 --- a/net/ipv6/af_inet6.c
100763 +++ b/net/ipv6/af_inet6.c
100764 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
100765 net->ipv6.sysctl.bindv6only = 0;
100766 net->ipv6.sysctl.icmpv6_time = 1*HZ;
100767 net->ipv6.sysctl.flowlabel_consistency = 1;
100768 - atomic_set(&net->ipv6.rt_genid, 0);
100769 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
100770
100771 err = ipv6_init_mibs(net);
100772 if (err)
100773 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
100774 index c3bf2d2..1f00573 100644
100775 --- a/net/ipv6/datagram.c
100776 +++ b/net/ipv6/datagram.c
100777 @@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
100778 0,
100779 sock_i_ino(sp),
100780 atomic_read(&sp->sk_refcnt), sp,
100781 - atomic_read(&sp->sk_drops));
100782 + atomic_read_unchecked(&sp->sk_drops));
100783 }
100784 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100785 index 7b32652..0bc348b 100644
100786 --- a/net/ipv6/icmp.c
100787 +++ b/net/ipv6/icmp.c
100788 @@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100789
100790 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100791 {
100792 - struct ctl_table *table;
100793 + ctl_table_no_const *table;
100794
100795 table = kmemdup(ipv6_icmp_table_template,
100796 sizeof(ipv6_icmp_table_template),
100797 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100798 index 9d92146..d986c6a 100644
100799 --- a/net/ipv6/ip6_gre.c
100800 +++ b/net/ipv6/ip6_gre.c
100801 @@ -71,7 +71,7 @@ struct ip6gre_net {
100802 struct net_device *fb_tunnel_dev;
100803 };
100804
100805 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100806 +static struct rtnl_link_ops ip6gre_link_ops;
100807 static int ip6gre_tunnel_init(struct net_device *dev);
100808 static void ip6gre_tunnel_setup(struct net_device *dev);
100809 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100810 @@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100811 }
100812
100813
100814 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
100815 +static struct inet6_protocol ip6gre_protocol = {
100816 .handler = ip6gre_rcv,
100817 .err_handler = ip6gre_err,
100818 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100819 @@ -1636,7 +1636,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100820 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100821 };
100822
100823 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100824 +static struct rtnl_link_ops ip6gre_link_ops = {
100825 .kind = "ip6gre",
100826 .maxtype = IFLA_GRE_MAX,
100827 .policy = ip6gre_policy,
100828 @@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100829 .fill_info = ip6gre_fill_info,
100830 };
100831
100832 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100833 +static struct rtnl_link_ops ip6gre_tap_ops = {
100834 .kind = "ip6gretap",
100835 .maxtype = IFLA_GRE_MAX,
100836 .policy = ip6gre_policy,
100837 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100838 index afa0824..04ba530 100644
100839 --- a/net/ipv6/ip6_tunnel.c
100840 +++ b/net/ipv6/ip6_tunnel.c
100841 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100842
100843 static int ip6_tnl_dev_init(struct net_device *dev);
100844 static void ip6_tnl_dev_setup(struct net_device *dev);
100845 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
100846 +static struct rtnl_link_ops ip6_link_ops;
100847
100848 static int ip6_tnl_net_id __read_mostly;
100849 struct ip6_tnl_net {
100850 @@ -1708,7 +1708,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100851 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100852 };
100853
100854 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100855 +static struct rtnl_link_ops ip6_link_ops = {
100856 .kind = "ip6tnl",
100857 .maxtype = IFLA_IPTUN_MAX,
100858 .policy = ip6_tnl_policy,
100859 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100860 index 6cc9f93..6e5bb7c 100644
100861 --- a/net/ipv6/ip6_vti.c
100862 +++ b/net/ipv6/ip6_vti.c
100863 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100864
100865 static int vti6_dev_init(struct net_device *dev);
100866 static void vti6_dev_setup(struct net_device *dev);
100867 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
100868 +static struct rtnl_link_ops vti6_link_ops;
100869
100870 static int vti6_net_id __read_mostly;
100871 struct vti6_net {
100872 @@ -980,7 +980,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100873 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100874 };
100875
100876 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100877 +static struct rtnl_link_ops vti6_link_ops = {
100878 .kind = "vti6",
100879 .maxtype = IFLA_VTI_MAX,
100880 .policy = vti6_policy,
100881 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100882 index edb58af..78de133 100644
100883 --- a/net/ipv6/ipv6_sockglue.c
100884 +++ b/net/ipv6/ipv6_sockglue.c
100885 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
100886 if (sk->sk_type != SOCK_STREAM)
100887 return -ENOPROTOOPT;
100888
100889 - msg.msg_control = optval;
100890 + msg.msg_control = (void __force_kernel *)optval;
100891 msg.msg_controllen = len;
100892 msg.msg_flags = flags;
100893
100894 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
100895 index e080fbb..412b3cf 100644
100896 --- a/net/ipv6/netfilter/ip6_tables.c
100897 +++ b/net/ipv6/netfilter/ip6_tables.c
100898 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
100899 #endif
100900
100901 static int get_info(struct net *net, void __user *user,
100902 - const int *len, int compat)
100903 + int len, int compat)
100904 {
100905 char name[XT_TABLE_MAXNAMELEN];
100906 struct xt_table *t;
100907 int ret;
100908
100909 - if (*len != sizeof(struct ip6t_getinfo)) {
100910 - duprintf("length %u != %zu\n", *len,
100911 + if (len != sizeof(struct ip6t_getinfo)) {
100912 + duprintf("length %u != %zu\n", len,
100913 sizeof(struct ip6t_getinfo));
100914 return -EINVAL;
100915 }
100916 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
100917 info.size = private->size;
100918 strcpy(info.name, name);
100919
100920 - if (copy_to_user(user, &info, *len) != 0)
100921 + if (copy_to_user(user, &info, len) != 0)
100922 ret = -EFAULT;
100923 else
100924 ret = 0;
100925 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100926
100927 switch (cmd) {
100928 case IP6T_SO_GET_INFO:
100929 - ret = get_info(sock_net(sk), user, len, 1);
100930 + ret = get_info(sock_net(sk), user, *len, 1);
100931 break;
100932 case IP6T_SO_GET_ENTRIES:
100933 ret = compat_get_entries(sock_net(sk), user, len);
100934 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100935
100936 switch (cmd) {
100937 case IP6T_SO_GET_INFO:
100938 - ret = get_info(sock_net(sk), user, len, 0);
100939 + ret = get_info(sock_net(sk), user, *len, 0);
100940 break;
100941
100942 case IP6T_SO_GET_ENTRIES:
100943 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
100944 index 767ab8d..c5ec70a 100644
100945 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
100946 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
100947 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
100948
100949 static int nf_ct_frag6_sysctl_register(struct net *net)
100950 {
100951 - struct ctl_table *table;
100952 + ctl_table_no_const *table = NULL;
100953 struct ctl_table_header *hdr;
100954
100955 - table = nf_ct_frag6_sysctl_table;
100956 if (!net_eq(net, &init_net)) {
100957 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
100958 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
100959 GFP_KERNEL);
100960 if (table == NULL)
100961 goto err_alloc;
100962 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100963 table[0].data = &net->nf_frag.frags.timeout;
100964 table[1].data = &net->nf_frag.frags.low_thresh;
100965 table[2].data = &net->nf_frag.frags.high_thresh;
100966 - }
100967 -
100968 - hdr = register_net_sysctl(net, "net/netfilter", table);
100969 + hdr = register_net_sysctl(net, "net/netfilter", table);
100970 + } else
100971 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
100972 if (hdr == NULL)
100973 goto err_reg;
100974
100975 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100976 return 0;
100977
100978 err_reg:
100979 - if (!net_eq(net, &init_net))
100980 - kfree(table);
100981 + kfree(table);
100982 err_alloc:
100983 return -ENOMEM;
100984 }
100985 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
100986 index 56596ce..c734618 100644
100987 --- a/net/ipv6/output_core.c
100988 +++ b/net/ipv6/output_core.c
100989 @@ -10,7 +10,7 @@
100990
100991 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100992 {
100993 - static atomic_t ipv6_fragmentation_id;
100994 + static atomic_unchecked_t ipv6_fragmentation_id;
100995 struct in6_addr addr;
100996 int ident;
100997
100998 @@ -26,7 +26,7 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100999 return;
101000 }
101001 #endif
101002 - ident = atomic_inc_return(&ipv6_fragmentation_id);
101003 + ident = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
101004
101005 addr = rt->rt6i_dst.addr;
101006 addr.s6_addr32[0] ^= (__force __be32)ident;
101007 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
101008 index bda7429..469b26b 100644
101009 --- a/net/ipv6/ping.c
101010 +++ b/net/ipv6/ping.c
101011 @@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
101012 };
101013 #endif
101014
101015 +static struct pingv6_ops real_pingv6_ops = {
101016 + .ipv6_recv_error = ipv6_recv_error,
101017 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
101018 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
101019 + .icmpv6_err_convert = icmpv6_err_convert,
101020 + .ipv6_icmp_error = ipv6_icmp_error,
101021 + .ipv6_chk_addr = ipv6_chk_addr,
101022 +};
101023 +
101024 +static struct pingv6_ops dummy_pingv6_ops = {
101025 + .ipv6_recv_error = dummy_ipv6_recv_error,
101026 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
101027 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
101028 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
101029 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
101030 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
101031 +};
101032 +
101033 int __init pingv6_init(void)
101034 {
101035 #ifdef CONFIG_PROC_FS
101036 @@ -253,13 +271,7 @@ int __init pingv6_init(void)
101037 if (ret)
101038 return ret;
101039 #endif
101040 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
101041 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
101042 - pingv6_ops.ip6_datagram_recv_specific_ctl =
101043 - ip6_datagram_recv_specific_ctl;
101044 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
101045 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
101046 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
101047 + pingv6_ops = &real_pingv6_ops;
101048 return inet6_register_protosw(&pingv6_protosw);
101049 }
101050
101051 @@ -268,14 +280,9 @@ int __init pingv6_init(void)
101052 */
101053 void pingv6_exit(void)
101054 {
101055 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
101056 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
101057 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
101058 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
101059 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
101060 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
101061 #ifdef CONFIG_PROC_FS
101062 unregister_pernet_subsys(&ping_v6_net_ops);
101063 #endif
101064 + pingv6_ops = &dummy_pingv6_ops;
101065 inet6_unregister_protosw(&pingv6_protosw);
101066 }
101067 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
101068 index 091d066..139d410 100644
101069 --- a/net/ipv6/proc.c
101070 +++ b/net/ipv6/proc.c
101071 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
101072 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
101073 goto proc_snmp6_fail;
101074
101075 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
101076 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
101077 if (!net->mib.proc_net_devsnmp6)
101078 goto proc_dev_snmp6_fail;
101079 return 0;
101080 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
101081 index 1f29996..46fe0c7 100644
101082 --- a/net/ipv6/raw.c
101083 +++ b/net/ipv6/raw.c
101084 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
101085 {
101086 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
101087 skb_checksum_complete(skb)) {
101088 - atomic_inc(&sk->sk_drops);
101089 + atomic_inc_unchecked(&sk->sk_drops);
101090 kfree_skb(skb);
101091 return NET_RX_DROP;
101092 }
101093 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
101094 struct raw6_sock *rp = raw6_sk(sk);
101095
101096 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
101097 - atomic_inc(&sk->sk_drops);
101098 + atomic_inc_unchecked(&sk->sk_drops);
101099 kfree_skb(skb);
101100 return NET_RX_DROP;
101101 }
101102 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
101103
101104 if (inet->hdrincl) {
101105 if (skb_checksum_complete(skb)) {
101106 - atomic_inc(&sk->sk_drops);
101107 + atomic_inc_unchecked(&sk->sk_drops);
101108 kfree_skb(skb);
101109 return NET_RX_DROP;
101110 }
101111 @@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
101112 if (flags & MSG_OOB)
101113 return -EOPNOTSUPP;
101114
101115 + if (addr_len)
101116 + *addr_len=sizeof(*sin6);
101117 +
101118 if (flags & MSG_ERRQUEUE)
101119 return ipv6_recv_error(sk, msg, len, addr_len);
101120
101121 @@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
101122 sin6->sin6_flowinfo = 0;
101123 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
101124 IP6CB(skb)->iif);
101125 - *addr_len = sizeof(*sin6);
101126 }
101127
101128 sock_recv_ts_and_drops(msg, sk, skb);
101129 @@ -610,7 +612,7 @@ out:
101130 return err;
101131 }
101132
101133 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
101134 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
101135 struct flowi6 *fl6, struct dst_entry **dstp,
101136 unsigned int flags)
101137 {
101138 @@ -922,12 +924,15 @@ do_confirm:
101139 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
101140 char __user *optval, int optlen)
101141 {
101142 + struct icmp6_filter filter;
101143 +
101144 switch (optname) {
101145 case ICMPV6_FILTER:
101146 if (optlen > sizeof(struct icmp6_filter))
101147 optlen = sizeof(struct icmp6_filter);
101148 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
101149 + if (copy_from_user(&filter, optval, optlen))
101150 return -EFAULT;
101151 + raw6_sk(sk)->filter = filter;
101152 return 0;
101153 default:
101154 return -ENOPROTOOPT;
101155 @@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
101156 char __user *optval, int __user *optlen)
101157 {
101158 int len;
101159 + struct icmp6_filter filter;
101160
101161 switch (optname) {
101162 case ICMPV6_FILTER:
101163 @@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
101164 len = sizeof(struct icmp6_filter);
101165 if (put_user(len, optlen))
101166 return -EFAULT;
101167 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
101168 + filter = raw6_sk(sk)->filter;
101169 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
101170 return -EFAULT;
101171 return 0;
101172 default:
101173 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
101174 index cc85a9b..526a133 100644
101175 --- a/net/ipv6/reassembly.c
101176 +++ b/net/ipv6/reassembly.c
101177 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
101178
101179 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101180 {
101181 - struct ctl_table *table;
101182 + ctl_table_no_const *table = NULL;
101183 struct ctl_table_header *hdr;
101184
101185 - table = ip6_frags_ns_ctl_table;
101186 if (!net_eq(net, &init_net)) {
101187 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
101188 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
101189 if (table == NULL)
101190 goto err_alloc;
101191
101192 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101193 /* Don't export sysctls to unprivileged users */
101194 if (net->user_ns != &init_user_ns)
101195 table[0].procname = NULL;
101196 - }
101197 + hdr = register_net_sysctl(net, "net/ipv6", table);
101198 + } else
101199 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
101200
101201 - hdr = register_net_sysctl(net, "net/ipv6", table);
101202 if (hdr == NULL)
101203 goto err_reg;
101204
101205 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101206 return 0;
101207
101208 err_reg:
101209 - if (!net_eq(net, &init_net))
101210 - kfree(table);
101211 + kfree(table);
101212 err_alloc:
101213 return -ENOMEM;
101214 }
101215 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
101216 index 6ebdb7b6..f225ab1 100644
101217 --- a/net/ipv6/route.c
101218 +++ b/net/ipv6/route.c
101219 @@ -2971,7 +2971,7 @@ struct ctl_table ipv6_route_table_template[] = {
101220
101221 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
101222 {
101223 - struct ctl_table *table;
101224 + ctl_table_no_const *table;
101225
101226 table = kmemdup(ipv6_route_table_template,
101227 sizeof(ipv6_route_table_template),
101228 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
101229 index 4f40817..54dcbef 100644
101230 --- a/net/ipv6/sit.c
101231 +++ b/net/ipv6/sit.c
101232 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
101233 static void ipip6_dev_free(struct net_device *dev);
101234 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
101235 __be32 *v4dst);
101236 -static struct rtnl_link_ops sit_link_ops __read_mostly;
101237 +static struct rtnl_link_ops sit_link_ops;
101238
101239 static int sit_net_id __read_mostly;
101240 struct sit_net {
101241 @@ -1661,7 +1661,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
101242 unregister_netdevice_queue(dev, head);
101243 }
101244
101245 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
101246 +static struct rtnl_link_ops sit_link_ops = {
101247 .kind = "sit",
101248 .maxtype = IFLA_IPTUN_MAX,
101249 .policy = ipip6_policy,
101250 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
101251 index 7f405a1..eabef92 100644
101252 --- a/net/ipv6/sysctl_net_ipv6.c
101253 +++ b/net/ipv6/sysctl_net_ipv6.c
101254 @@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
101255
101256 static int __net_init ipv6_sysctl_net_init(struct net *net)
101257 {
101258 - struct ctl_table *ipv6_table;
101259 + ctl_table_no_const *ipv6_table;
101260 struct ctl_table *ipv6_route_table;
101261 struct ctl_table *ipv6_icmp_table;
101262 int err;
101263 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
101264 index e289830..79a5718 100644
101265 --- a/net/ipv6/tcp_ipv6.c
101266 +++ b/net/ipv6/tcp_ipv6.c
101267 @@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
101268 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
101269 }
101270
101271 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101272 +extern int grsec_enable_blackhole;
101273 +#endif
101274 +
101275 static void tcp_v6_hash(struct sock *sk)
101276 {
101277 if (sk->sk_state != TCP_CLOSE) {
101278 @@ -1416,6 +1420,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
101279 return 0;
101280
101281 reset:
101282 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101283 + if (!grsec_enable_blackhole)
101284 +#endif
101285 tcp_v6_send_reset(sk, skb);
101286 discard:
101287 if (opt_skb)
101288 @@ -1500,12 +1507,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
101289 TCP_SKB_CB(skb)->sacked = 0;
101290
101291 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
101292 - if (!sk)
101293 + if (!sk) {
101294 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101295 + ret = 1;
101296 +#endif
101297 goto no_tcp_socket;
101298 + }
101299
101300 process:
101301 - if (sk->sk_state == TCP_TIME_WAIT)
101302 + if (sk->sk_state == TCP_TIME_WAIT) {
101303 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101304 + ret = 2;
101305 +#endif
101306 goto do_time_wait;
101307 + }
101308
101309 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
101310 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
101311 @@ -1557,6 +1572,10 @@ csum_error:
101312 bad_packet:
101313 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
101314 } else {
101315 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101316 + if (!grsec_enable_blackhole || (ret == 1 &&
101317 + (skb->dev->flags & IFF_LOOPBACK)))
101318 +#endif
101319 tcp_v6_send_reset(NULL, skb);
101320 }
101321
101322 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
101323 index 20b63d2..13be908 100644
101324 --- a/net/ipv6/udp.c
101325 +++ b/net/ipv6/udp.c
101326 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
101327 udp_ipv6_hash_secret + net_hash_mix(net));
101328 }
101329
101330 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101331 +extern int grsec_enable_blackhole;
101332 +#endif
101333 +
101334 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
101335 {
101336 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
101337 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
101338 int is_udp4;
101339 bool slow;
101340
101341 + if (addr_len)
101342 + *addr_len = sizeof(struct sockaddr_in6);
101343 +
101344 if (flags & MSG_ERRQUEUE)
101345 return ipv6_recv_error(sk, msg, len, addr_len);
101346
101347 @@ -435,7 +442,7 @@ try_again:
101348 if (unlikely(err)) {
101349 trace_kfree_skb(skb, udpv6_recvmsg);
101350 if (!peeked) {
101351 - atomic_inc(&sk->sk_drops);
101352 + atomic_inc_unchecked(&sk->sk_drops);
101353 if (is_udp4)
101354 UDP_INC_STATS_USER(sock_net(sk),
101355 UDP_MIB_INERRORS,
101356 @@ -475,7 +482,7 @@ try_again:
101357 ipv6_iface_scope_id(&sin6->sin6_addr,
101358 IP6CB(skb)->iif);
101359 }
101360 - *addr_len = sizeof(*sin6);
101361 +
101362 }
101363
101364 if (np->rxopt.all)
101365 @@ -690,7 +697,7 @@ csum_error:
101366 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
101367 drop:
101368 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
101369 - atomic_inc(&sk->sk_drops);
101370 + atomic_inc_unchecked(&sk->sk_drops);
101371 kfree_skb(skb);
101372 return -1;
101373 }
101374 @@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
101375 if (likely(skb1 == NULL))
101376 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
101377 if (!skb1) {
101378 - atomic_inc(&sk->sk_drops);
101379 + atomic_inc_unchecked(&sk->sk_drops);
101380 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
101381 IS_UDPLITE(sk));
101382 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
101383 @@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
101384 goto csum_error;
101385
101386 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
101387 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101388 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
101389 +#endif
101390 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
101391
101392 kfree_skb(skb);
101393 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
101394 index 2a0bbda..d75ca57 100644
101395 --- a/net/ipv6/xfrm6_policy.c
101396 +++ b/net/ipv6/xfrm6_policy.c
101397 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
101398 }
101399 }
101400
101401 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
101402 +static int xfrm6_garbage_collect(struct dst_ops *ops)
101403 {
101404 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
101405
101406 - xfrm6_policy_afinfo.garbage_collect(net);
101407 + xfrm_garbage_collect_deferred(net);
101408 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
101409 }
101410
101411 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
101412
101413 static int __net_init xfrm6_net_init(struct net *net)
101414 {
101415 - struct ctl_table *table;
101416 + ctl_table_no_const *table = NULL;
101417 struct ctl_table_header *hdr;
101418
101419 - table = xfrm6_policy_table;
101420 if (!net_eq(net, &init_net)) {
101421 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101422 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101423 if (!table)
101424 goto err_alloc;
101425
101426 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
101427 - }
101428 + hdr = register_net_sysctl(net, "net/ipv6", table);
101429 + } else
101430 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
101431
101432 - hdr = register_net_sysctl(net, "net/ipv6", table);
101433 if (!hdr)
101434 goto err_reg;
101435
101436 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
101437 return 0;
101438
101439 err_reg:
101440 - if (!net_eq(net, &init_net))
101441 - kfree(table);
101442 + kfree(table);
101443 err_alloc:
101444 return -ENOMEM;
101445 }
101446 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
101447 index e15c16a..7cf07aa 100644
101448 --- a/net/ipx/ipx_proc.c
101449 +++ b/net/ipx/ipx_proc.c
101450 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
101451 struct proc_dir_entry *p;
101452 int rc = -ENOMEM;
101453
101454 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
101455 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
101456
101457 if (!ipx_proc_dir)
101458 goto out;
101459 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
101460 index 2ba8b97..6d33010 100644
101461 --- a/net/irda/ircomm/ircomm_tty.c
101462 +++ b/net/irda/ircomm/ircomm_tty.c
101463 @@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101464 add_wait_queue(&port->open_wait, &wait);
101465
101466 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
101467 - __FILE__, __LINE__, tty->driver->name, port->count);
101468 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101469
101470 spin_lock_irqsave(&port->lock, flags);
101471 if (!tty_hung_up_p(filp))
101472 - port->count--;
101473 + atomic_dec(&port->count);
101474 port->blocked_open++;
101475 spin_unlock_irqrestore(&port->lock, flags);
101476
101477 @@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101478 }
101479
101480 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
101481 - __FILE__, __LINE__, tty->driver->name, port->count);
101482 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101483
101484 schedule();
101485 }
101486 @@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101487
101488 spin_lock_irqsave(&port->lock, flags);
101489 if (!tty_hung_up_p(filp))
101490 - port->count++;
101491 + atomic_inc(&port->count);
101492 port->blocked_open--;
101493 spin_unlock_irqrestore(&port->lock, flags);
101494
101495 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
101496 - __FILE__, __LINE__, tty->driver->name, port->count);
101497 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101498
101499 if (!retval)
101500 port->flags |= ASYNC_NORMAL_ACTIVE;
101501 @@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
101502
101503 /* ++ is not atomic, so this should be protected - Jean II */
101504 spin_lock_irqsave(&self->port.lock, flags);
101505 - self->port.count++;
101506 + atomic_inc(&self->port.count);
101507 spin_unlock_irqrestore(&self->port.lock, flags);
101508 tty_port_tty_set(&self->port, tty);
101509
101510 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
101511 - self->line, self->port.count);
101512 + self->line, atomic_read(&self->port.count));
101513
101514 /* Not really used by us, but lets do it anyway */
101515 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
101516 @@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
101517 tty_kref_put(port->tty);
101518 }
101519 port->tty = NULL;
101520 - port->count = 0;
101521 + atomic_set(&port->count, 0);
101522 spin_unlock_irqrestore(&port->lock, flags);
101523
101524 wake_up_interruptible(&port->open_wait);
101525 @@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
101526 seq_putc(m, '\n');
101527
101528 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
101529 - seq_printf(m, "Open count: %d\n", self->port.count);
101530 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
101531 seq_printf(m, "Max data size: %d\n", self->max_data_size);
101532 seq_printf(m, "Max header size: %d\n", self->max_header_size);
101533
101534 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
101535 index b9ac598..f88cc56 100644
101536 --- a/net/irda/irproc.c
101537 +++ b/net/irda/irproc.c
101538 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
101539 {
101540 int i;
101541
101542 - proc_irda = proc_mkdir("irda", init_net.proc_net);
101543 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
101544 if (proc_irda == NULL)
101545 return;
101546
101547 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
101548 index 8c9d730..66c6305 100644
101549 --- a/net/iucv/af_iucv.c
101550 +++ b/net/iucv/af_iucv.c
101551 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
101552
101553 write_lock_bh(&iucv_sk_list.lock);
101554
101555 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
101556 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101557 while (__iucv_get_sock_by_name(name)) {
101558 sprintf(name, "%08x",
101559 - atomic_inc_return(&iucv_sk_list.autobind_name));
101560 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101561 }
101562
101563 write_unlock_bh(&iucv_sk_list.lock);
101564 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
101565 index da78793..bdd78cf 100644
101566 --- a/net/iucv/iucv.c
101567 +++ b/net/iucv/iucv.c
101568 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
101569 return NOTIFY_OK;
101570 }
101571
101572 -static struct notifier_block __refdata iucv_cpu_notifier = {
101573 +static struct notifier_block iucv_cpu_notifier = {
101574 .notifier_call = iucv_cpu_notify,
101575 };
101576
101577 diff --git a/net/key/af_key.c b/net/key/af_key.c
101578 index f3c8307..7127791 100644
101579 --- a/net/key/af_key.c
101580 +++ b/net/key/af_key.c
101581 @@ -3070,10 +3070,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
101582 static u32 get_acqseq(void)
101583 {
101584 u32 res;
101585 - static atomic_t acqseq;
101586 + static atomic_unchecked_t acqseq;
101587
101588 do {
101589 - res = atomic_inc_return(&acqseq);
101590 + res = atomic_inc_return_unchecked(&acqseq);
101591 } while (!res);
101592 return res;
101593 }
101594 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
101595 index 76125c5..e474828 100644
101596 --- a/net/l2tp/l2tp_eth.c
101597 +++ b/net/l2tp/l2tp_eth.c
101598 @@ -42,12 +42,12 @@ struct l2tp_eth {
101599 struct sock *tunnel_sock;
101600 struct l2tp_session *session;
101601 struct list_head list;
101602 - atomic_long_t tx_bytes;
101603 - atomic_long_t tx_packets;
101604 - atomic_long_t tx_dropped;
101605 - atomic_long_t rx_bytes;
101606 - atomic_long_t rx_packets;
101607 - atomic_long_t rx_errors;
101608 + atomic_long_unchecked_t tx_bytes;
101609 + atomic_long_unchecked_t tx_packets;
101610 + atomic_long_unchecked_t tx_dropped;
101611 + atomic_long_unchecked_t rx_bytes;
101612 + atomic_long_unchecked_t rx_packets;
101613 + atomic_long_unchecked_t rx_errors;
101614 };
101615
101616 /* via l2tp_session_priv() */
101617 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
101618 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
101619
101620 if (likely(ret == NET_XMIT_SUCCESS)) {
101621 - atomic_long_add(len, &priv->tx_bytes);
101622 - atomic_long_inc(&priv->tx_packets);
101623 + atomic_long_add_unchecked(len, &priv->tx_bytes);
101624 + atomic_long_inc_unchecked(&priv->tx_packets);
101625 } else {
101626 - atomic_long_inc(&priv->tx_dropped);
101627 + atomic_long_inc_unchecked(&priv->tx_dropped);
101628 }
101629 return NETDEV_TX_OK;
101630 }
101631 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
101632 {
101633 struct l2tp_eth *priv = netdev_priv(dev);
101634
101635 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
101636 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
101637 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
101638 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
101639 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
101640 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
101641 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
101642 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
101643 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
101644 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
101645 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
101646 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
101647 return stats;
101648 }
101649
101650 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
101651 nf_reset(skb);
101652
101653 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
101654 - atomic_long_inc(&priv->rx_packets);
101655 - atomic_long_add(data_len, &priv->rx_bytes);
101656 + atomic_long_inc_unchecked(&priv->rx_packets);
101657 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
101658 } else {
101659 - atomic_long_inc(&priv->rx_errors);
101660 + atomic_long_inc_unchecked(&priv->rx_errors);
101661 }
101662 return;
101663
101664 error:
101665 - atomic_long_inc(&priv->rx_errors);
101666 + atomic_long_inc_unchecked(&priv->rx_errors);
101667 kfree_skb(skb);
101668 }
101669
101670 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
101671 index 3397fe6..861fd1a 100644
101672 --- a/net/l2tp/l2tp_ip.c
101673 +++ b/net/l2tp/l2tp_ip.c
101674 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101675 if (flags & MSG_OOB)
101676 goto out;
101677
101678 + if (addr_len)
101679 + *addr_len = sizeof(*sin);
101680 +
101681 skb = skb_recv_datagram(sk, flags, noblock, &err);
101682 if (!skb)
101683 goto out;
101684 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101685 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
101686 sin->sin_port = 0;
101687 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
101688 - *addr_len = sizeof(*sin);
101689 }
101690 if (inet->cmsg_flags)
101691 ip_cmsg_recv(msg, skb);
101692 diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
101693 index 950909f..13752d9 100644
101694 --- a/net/l2tp/l2tp_ppp.c
101695 +++ b/net/l2tp/l2tp_ppp.c
101696 @@ -1365,7 +1365,7 @@ static int pppol2tp_setsockopt(struct socket *sock, int level, int optname,
101697 int err;
101698
101699 if (level != SOL_PPPOL2TP)
101700 - return udp_prot.setsockopt(sk, level, optname, optval, optlen);
101701 + return -EINVAL;
101702
101703 if (optlen < sizeof(int))
101704 return -EINVAL;
101705 @@ -1491,7 +1491,7 @@ static int pppol2tp_getsockopt(struct socket *sock, int level, int optname,
101706 struct pppol2tp_session *ps;
101707
101708 if (level != SOL_PPPOL2TP)
101709 - return udp_prot.getsockopt(sk, level, optname, optval, optlen);
101710 + return -EINVAL;
101711
101712 if (get_user(len, optlen))
101713 return -EFAULT;
101714 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
101715 index 1a3c7e0..80f8b0c 100644
101716 --- a/net/llc/llc_proc.c
101717 +++ b/net/llc/llc_proc.c
101718 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
101719 int rc = -ENOMEM;
101720 struct proc_dir_entry *p;
101721
101722 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
101723 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
101724 if (!llc_proc_dir)
101725 goto out;
101726
101727 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
101728 index aaa59d7..21a2c4a 100644
101729 --- a/net/mac80211/cfg.c
101730 +++ b/net/mac80211/cfg.c
101731 @@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
101732 ret = ieee80211_vif_use_channel(sdata, chandef,
101733 IEEE80211_CHANCTX_EXCLUSIVE);
101734 }
101735 - } else if (local->open_count == local->monitors) {
101736 + } else if (local_read(&local->open_count) == local->monitors) {
101737 local->_oper_chandef = *chandef;
101738 ieee80211_hw_config(local, 0);
101739 }
101740 @@ -3440,7 +3440,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
101741 else
101742 local->probe_req_reg--;
101743
101744 - if (!local->open_count)
101745 + if (!local_read(&local->open_count))
101746 break;
101747
101748 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
101749 @@ -3903,8 +3903,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
101750 if (chanctx_conf) {
101751 *chandef = chanctx_conf->def;
101752 ret = 0;
101753 - } else if (local->open_count > 0 &&
101754 - local->open_count == local->monitors &&
101755 + } else if (local_read(&local->open_count) > 0 &&
101756 + local_read(&local->open_count) == local->monitors &&
101757 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
101758 if (local->use_chanctx)
101759 *chandef = local->monitor_chandef;
101760 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
101761 index f169b6e..a5dc4eb 100644
101762 --- a/net/mac80211/ieee80211_i.h
101763 +++ b/net/mac80211/ieee80211_i.h
101764 @@ -28,6 +28,7 @@
101765 #include <net/ieee80211_radiotap.h>
101766 #include <net/cfg80211.h>
101767 #include <net/mac80211.h>
101768 +#include <asm/local.h>
101769 #include "key.h"
101770 #include "sta_info.h"
101771 #include "debug.h"
101772 @@ -999,7 +1000,7 @@ struct ieee80211_local {
101773 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
101774 spinlock_t queue_stop_reason_lock;
101775
101776 - int open_count;
101777 + local_t open_count;
101778 int monitors, cooked_mntrs;
101779 /* number of interfaces with corresponding FIF_ flags */
101780 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
101781 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
101782 index 34799e0..b411290 100644
101783 --- a/net/mac80211/iface.c
101784 +++ b/net/mac80211/iface.c
101785 @@ -524,7 +524,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101786 break;
101787 }
101788
101789 - if (local->open_count == 0) {
101790 + if (local_read(&local->open_count) == 0) {
101791 res = drv_start(local);
101792 if (res)
101793 goto err_del_bss;
101794 @@ -571,7 +571,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101795 res = drv_add_interface(local, sdata);
101796 if (res)
101797 goto err_stop;
101798 - } else if (local->monitors == 0 && local->open_count == 0) {
101799 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
101800 res = ieee80211_add_virtual_monitor(local);
101801 if (res)
101802 goto err_stop;
101803 @@ -680,7 +680,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101804 atomic_inc(&local->iff_promiscs);
101805
101806 if (coming_up)
101807 - local->open_count++;
101808 + local_inc(&local->open_count);
101809
101810 if (hw_reconf_flags)
101811 ieee80211_hw_config(local, hw_reconf_flags);
101812 @@ -718,7 +718,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101813 err_del_interface:
101814 drv_remove_interface(local, sdata);
101815 err_stop:
101816 - if (!local->open_count)
101817 + if (!local_read(&local->open_count))
101818 drv_stop(local);
101819 err_del_bss:
101820 sdata->bss = NULL;
101821 @@ -871,7 +871,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101822 }
101823
101824 if (going_down)
101825 - local->open_count--;
101826 + local_dec(&local->open_count);
101827
101828 switch (sdata->vif.type) {
101829 case NL80211_IFTYPE_AP_VLAN:
101830 @@ -930,7 +930,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101831 }
101832 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
101833
101834 - if (local->open_count == 0)
101835 + if (local_read(&local->open_count) == 0)
101836 ieee80211_clear_tx_pending(local);
101837
101838 /*
101839 @@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101840
101841 ieee80211_recalc_ps(local, -1);
101842
101843 - if (local->open_count == 0) {
101844 + if (local_read(&local->open_count) == 0) {
101845 ieee80211_stop_device(local);
101846
101847 /* no reconfiguring after stop! */
101848 @@ -981,7 +981,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101849 ieee80211_configure_filter(local);
101850 ieee80211_hw_config(local, hw_reconf_flags);
101851
101852 - if (local->monitors == local->open_count)
101853 + if (local->monitors == local_read(&local->open_count))
101854 ieee80211_add_virtual_monitor(local);
101855 }
101856
101857 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
101858 index 4c1bf61..00b449b 100644
101859 --- a/net/mac80211/main.c
101860 +++ b/net/mac80211/main.c
101861 @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
101862 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
101863 IEEE80211_CONF_CHANGE_POWER);
101864
101865 - if (changed && local->open_count) {
101866 + if (changed && local_read(&local->open_count)) {
101867 ret = drv_config(local, changed);
101868 /*
101869 * Goal:
101870 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101871 index d478b88..8c8d157 100644
101872 --- a/net/mac80211/pm.c
101873 +++ b/net/mac80211/pm.c
101874 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101875 struct ieee80211_sub_if_data *sdata;
101876 struct sta_info *sta;
101877
101878 - if (!local->open_count)
101879 + if (!local_read(&local->open_count))
101880 goto suspend;
101881
101882 ieee80211_scan_cancel(local);
101883 @@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101884 cancel_work_sync(&local->dynamic_ps_enable_work);
101885 del_timer_sync(&local->dynamic_ps_timer);
101886
101887 - local->wowlan = wowlan && local->open_count;
101888 + local->wowlan = wowlan && local_read(&local->open_count);
101889 if (local->wowlan) {
101890 int err = drv_suspend(local, wowlan);
101891 if (err < 0) {
101892 @@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101893 WARN_ON(!list_empty(&local->chanctx_list));
101894
101895 /* stop hardware - this must stop RX */
101896 - if (local->open_count)
101897 + if (local_read(&local->open_count))
101898 ieee80211_stop_device(local);
101899
101900 suspend:
101901 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101902 index 8fdadfd..a4f72b8 100644
101903 --- a/net/mac80211/rate.c
101904 +++ b/net/mac80211/rate.c
101905 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101906
101907 ASSERT_RTNL();
101908
101909 - if (local->open_count)
101910 + if (local_read(&local->open_count))
101911 return -EBUSY;
101912
101913 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101914 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101915 index 6ff1346..936ca9a 100644
101916 --- a/net/mac80211/rc80211_pid_debugfs.c
101917 +++ b/net/mac80211/rc80211_pid_debugfs.c
101918 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
101919
101920 spin_unlock_irqrestore(&events->lock, status);
101921
101922 - if (copy_to_user(buf, pb, p))
101923 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
101924 return -EFAULT;
101925
101926 return p;
101927 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
101928 index 3c36583..12887fe 100644
101929 --- a/net/mac80211/util.c
101930 +++ b/net/mac80211/util.c
101931 @@ -1509,7 +1509,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101932 }
101933 #endif
101934 /* everything else happens only if HW was up & running */
101935 - if (!local->open_count)
101936 + if (!local_read(&local->open_count))
101937 goto wake_up;
101938
101939 /*
101940 @@ -1734,7 +1734,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101941 local->in_reconfig = false;
101942 barrier();
101943
101944 - if (local->monitors == local->open_count && local->monitors > 0)
101945 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
101946 ieee80211_add_virtual_monitor(local);
101947
101948 /*
101949 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
101950 index e9410d1..77b6378 100644
101951 --- a/net/netfilter/Kconfig
101952 +++ b/net/netfilter/Kconfig
101953 @@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
101954
101955 To compile it as a module, choose M here. If unsure, say N.
101956
101957 +config NETFILTER_XT_MATCH_GRADM
101958 + tristate '"gradm" match support'
101959 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
101960 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
101961 + ---help---
101962 + The gradm match allows to match on grsecurity RBAC being enabled.
101963 + It is useful when iptables rules are applied early on bootup to
101964 + prevent connections to the machine (except from a trusted host)
101965 + while the RBAC system is disabled.
101966 +
101967 config NETFILTER_XT_MATCH_HASHLIMIT
101968 tristate '"hashlimit" match support'
101969 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
101970 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
101971 index bffdad7..f9317d1 100644
101972 --- a/net/netfilter/Makefile
101973 +++ b/net/netfilter/Makefile
101974 @@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
101975 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
101976 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
101977 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
101978 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
101979 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
101980 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
101981 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
101982 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
101983 index 1172083..986f1c1 100644
101984 --- a/net/netfilter/ipset/ip_set_core.c
101985 +++ b/net/netfilter/ipset/ip_set_core.c
101986 @@ -1924,7 +1924,7 @@ done:
101987 return ret;
101988 }
101989
101990 -static struct nf_sockopt_ops so_set __read_mostly = {
101991 +static struct nf_sockopt_ops so_set = {
101992 .pf = PF_INET,
101993 .get_optmin = SO_IP_SET,
101994 .get_optmax = SO_IP_SET + 1,
101995 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
101996 index a8eb0a8..86f2de4 100644
101997 --- a/net/netfilter/ipvs/ip_vs_conn.c
101998 +++ b/net/netfilter/ipvs/ip_vs_conn.c
101999 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
102000 /* Increase the refcnt counter of the dest */
102001 ip_vs_dest_hold(dest);
102002
102003 - conn_flags = atomic_read(&dest->conn_flags);
102004 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
102005 if (cp->protocol != IPPROTO_UDP)
102006 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
102007 flags = cp->flags;
102008 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
102009
102010 cp->control = NULL;
102011 atomic_set(&cp->n_control, 0);
102012 - atomic_set(&cp->in_pkts, 0);
102013 + atomic_set_unchecked(&cp->in_pkts, 0);
102014
102015 cp->packet_xmit = NULL;
102016 cp->app = NULL;
102017 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
102018
102019 /* Don't drop the entry if its number of incoming packets is not
102020 located in [0, 8] */
102021 - i = atomic_read(&cp->in_pkts);
102022 + i = atomic_read_unchecked(&cp->in_pkts);
102023 if (i > 8 || i < 0) return 0;
102024
102025 if (!todrop_rate[i]) return 0;
102026 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
102027 index 3d2d2c8..c87e4d3 100644
102028 --- a/net/netfilter/ipvs/ip_vs_core.c
102029 +++ b/net/netfilter/ipvs/ip_vs_core.c
102030 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
102031 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
102032 /* do not touch skb anymore */
102033
102034 - atomic_inc(&cp->in_pkts);
102035 + atomic_inc_unchecked(&cp->in_pkts);
102036 ip_vs_conn_put(cp);
102037 return ret;
102038 }
102039 @@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
102040 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
102041 pkts = sysctl_sync_threshold(ipvs);
102042 else
102043 - pkts = atomic_add_return(1, &cp->in_pkts);
102044 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
102045
102046 if (ipvs->sync_state & IP_VS_STATE_MASTER)
102047 ip_vs_sync_conn(net, cp, pkts);
102048 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
102049 index c42e83d..a6a3f8b 100644
102050 --- a/net/netfilter/ipvs/ip_vs_ctl.c
102051 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
102052 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
102053 */
102054 ip_vs_rs_hash(ipvs, dest);
102055 }
102056 - atomic_set(&dest->conn_flags, conn_flags);
102057 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
102058
102059 /* bind the service */
102060 old_svc = rcu_dereference_protected(dest->svc, 1);
102061 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
102062 * align with netns init in ip_vs_control_net_init()
102063 */
102064
102065 -static struct ctl_table vs_vars[] = {
102066 +static ctl_table_no_const vs_vars[] __read_only = {
102067 {
102068 .procname = "amemthresh",
102069 .maxlen = sizeof(int),
102070 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
102071 " %-7s %-6d %-10d %-10d\n",
102072 &dest->addr.in6,
102073 ntohs(dest->port),
102074 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
102075 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
102076 atomic_read(&dest->weight),
102077 atomic_read(&dest->activeconns),
102078 atomic_read(&dest->inactconns));
102079 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
102080 "%-7s %-6d %-10d %-10d\n",
102081 ntohl(dest->addr.ip),
102082 ntohs(dest->port),
102083 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
102084 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
102085 atomic_read(&dest->weight),
102086 atomic_read(&dest->activeconns),
102087 atomic_read(&dest->inactconns));
102088 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
102089
102090 entry.addr = dest->addr.ip;
102091 entry.port = dest->port;
102092 - entry.conn_flags = atomic_read(&dest->conn_flags);
102093 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
102094 entry.weight = atomic_read(&dest->weight);
102095 entry.u_threshold = dest->u_threshold;
102096 entry.l_threshold = dest->l_threshold;
102097 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
102098 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
102099 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
102100 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
102101 - (atomic_read(&dest->conn_flags) &
102102 + (atomic_read_unchecked(&dest->conn_flags) &
102103 IP_VS_CONN_F_FWD_MASK)) ||
102104 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
102105 atomic_read(&dest->weight)) ||
102106 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
102107 {
102108 int idx;
102109 struct netns_ipvs *ipvs = net_ipvs(net);
102110 - struct ctl_table *tbl;
102111 + ctl_table_no_const *tbl;
102112
102113 atomic_set(&ipvs->dropentry, 0);
102114 spin_lock_init(&ipvs->dropentry_lock);
102115 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
102116 index 547ff33..c8c8117 100644
102117 --- a/net/netfilter/ipvs/ip_vs_lblc.c
102118 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
102119 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
102120 * IPVS LBLC sysctl table
102121 */
102122 #ifdef CONFIG_SYSCTL
102123 -static struct ctl_table vs_vars_table[] = {
102124 +static ctl_table_no_const vs_vars_table[] __read_only = {
102125 {
102126 .procname = "lblc_expiration",
102127 .data = NULL,
102128 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
102129 index 3f21a2f..a112e85 100644
102130 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
102131 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
102132 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
102133 * IPVS LBLCR sysctl table
102134 */
102135
102136 -static struct ctl_table vs_vars_table[] = {
102137 +static ctl_table_no_const vs_vars_table[] __read_only = {
102138 {
102139 .procname = "lblcr_expiration",
102140 .data = NULL,
102141 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
102142 index db80126..ef7110e 100644
102143 --- a/net/netfilter/ipvs/ip_vs_sync.c
102144 +++ b/net/netfilter/ipvs/ip_vs_sync.c
102145 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
102146 cp = cp->control;
102147 if (cp) {
102148 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
102149 - pkts = atomic_add_return(1, &cp->in_pkts);
102150 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
102151 else
102152 pkts = sysctl_sync_threshold(ipvs);
102153 ip_vs_sync_conn(net, cp->control, pkts);
102154 @@ -771,7 +771,7 @@ control:
102155 if (!cp)
102156 return;
102157 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
102158 - pkts = atomic_add_return(1, &cp->in_pkts);
102159 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
102160 else
102161 pkts = sysctl_sync_threshold(ipvs);
102162 goto sloop;
102163 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
102164
102165 if (opt)
102166 memcpy(&cp->in_seq, opt, sizeof(*opt));
102167 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
102168 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
102169 cp->state = state;
102170 cp->old_state = cp->state;
102171 /*
102172 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
102173 index c47444e..b0961c6 100644
102174 --- a/net/netfilter/ipvs/ip_vs_xmit.c
102175 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
102176 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
102177 else
102178 rc = NF_ACCEPT;
102179 /* do not touch skb anymore */
102180 - atomic_inc(&cp->in_pkts);
102181 + atomic_inc_unchecked(&cp->in_pkts);
102182 goto out;
102183 }
102184
102185 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
102186 else
102187 rc = NF_ACCEPT;
102188 /* do not touch skb anymore */
102189 - atomic_inc(&cp->in_pkts);
102190 + atomic_inc_unchecked(&cp->in_pkts);
102191 goto out;
102192 }
102193
102194 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
102195 index a4b5e2a..13b1de3 100644
102196 --- a/net/netfilter/nf_conntrack_acct.c
102197 +++ b/net/netfilter/nf_conntrack_acct.c
102198 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
102199 #ifdef CONFIG_SYSCTL
102200 static int nf_conntrack_acct_init_sysctl(struct net *net)
102201 {
102202 - struct ctl_table *table;
102203 + ctl_table_no_const *table;
102204
102205 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
102206 GFP_KERNEL);
102207 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
102208 index 75421f2..0e69621 100644
102209 --- a/net/netfilter/nf_conntrack_core.c
102210 +++ b/net/netfilter/nf_conntrack_core.c
102211 @@ -1789,6 +1789,10 @@ void nf_conntrack_init_end(void)
102212 #define DYING_NULLS_VAL ((1<<30)+1)
102213 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
102214
102215 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102216 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
102217 +#endif
102218 +
102219 int nf_conntrack_init_net(struct net *net)
102220 {
102221 int ret = -ENOMEM;
102222 @@ -1814,7 +1818,11 @@ int nf_conntrack_init_net(struct net *net)
102223 if (!net->ct.stat)
102224 goto err_pcpu_lists;
102225
102226 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102227 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
102228 +#else
102229 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
102230 +#endif
102231 if (!net->ct.slabname)
102232 goto err_slabname;
102233
102234 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
102235 index 1df1761..ce8b88a 100644
102236 --- a/net/netfilter/nf_conntrack_ecache.c
102237 +++ b/net/netfilter/nf_conntrack_ecache.c
102238 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
102239 #ifdef CONFIG_SYSCTL
102240 static int nf_conntrack_event_init_sysctl(struct net *net)
102241 {
102242 - struct ctl_table *table;
102243 + ctl_table_no_const *table;
102244
102245 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
102246 GFP_KERNEL);
102247 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
102248 index 5b3eae7..dd4b8fe 100644
102249 --- a/net/netfilter/nf_conntrack_helper.c
102250 +++ b/net/netfilter/nf_conntrack_helper.c
102251 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
102252
102253 static int nf_conntrack_helper_init_sysctl(struct net *net)
102254 {
102255 - struct ctl_table *table;
102256 + ctl_table_no_const *table;
102257
102258 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
102259 GFP_KERNEL);
102260 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
102261 index b65d586..beec902 100644
102262 --- a/net/netfilter/nf_conntrack_proto.c
102263 +++ b/net/netfilter/nf_conntrack_proto.c
102264 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
102265
102266 static void
102267 nf_ct_unregister_sysctl(struct ctl_table_header **header,
102268 - struct ctl_table **table,
102269 + ctl_table_no_const **table,
102270 unsigned int users)
102271 {
102272 if (users > 0)
102273 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
102274 index f641751..d3c5b51 100644
102275 --- a/net/netfilter/nf_conntrack_standalone.c
102276 +++ b/net/netfilter/nf_conntrack_standalone.c
102277 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
102278
102279 static int nf_conntrack_standalone_init_sysctl(struct net *net)
102280 {
102281 - struct ctl_table *table;
102282 + ctl_table_no_const *table;
102283
102284 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
102285 GFP_KERNEL);
102286 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
102287 index 7a394df..bd91a8a 100644
102288 --- a/net/netfilter/nf_conntrack_timestamp.c
102289 +++ b/net/netfilter/nf_conntrack_timestamp.c
102290 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
102291 #ifdef CONFIG_SYSCTL
102292 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
102293 {
102294 - struct ctl_table *table;
102295 + ctl_table_no_const *table;
102296
102297 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
102298 GFP_KERNEL);
102299 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
102300 index 85296d4..8becdec 100644
102301 --- a/net/netfilter/nf_log.c
102302 +++ b/net/netfilter/nf_log.c
102303 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
102304
102305 #ifdef CONFIG_SYSCTL
102306 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
102307 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
102308 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
102309
102310 static int nf_log_proc_dostring(struct ctl_table *table, int write,
102311 void __user *buffer, size_t *lenp, loff_t *ppos)
102312 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
102313 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
102314 mutex_unlock(&nf_log_mutex);
102315 } else {
102316 + ctl_table_no_const nf_log_table = *table;
102317 +
102318 mutex_lock(&nf_log_mutex);
102319 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
102320 lockdep_is_held(&nf_log_mutex));
102321 if (!logger)
102322 - table->data = "NONE";
102323 + nf_log_table.data = "NONE";
102324 else
102325 - table->data = logger->name;
102326 - r = proc_dostring(table, write, buffer, lenp, ppos);
102327 + nf_log_table.data = logger->name;
102328 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
102329 mutex_unlock(&nf_log_mutex);
102330 }
102331
102332 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
102333 index f042ae5..30ea486 100644
102334 --- a/net/netfilter/nf_sockopt.c
102335 +++ b/net/netfilter/nf_sockopt.c
102336 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
102337 }
102338 }
102339
102340 - list_add(&reg->list, &nf_sockopts);
102341 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
102342 out:
102343 mutex_unlock(&nf_sockopt_mutex);
102344 return ret;
102345 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
102346 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
102347 {
102348 mutex_lock(&nf_sockopt_mutex);
102349 - list_del(&reg->list);
102350 + pax_list_del((struct list_head *)&reg->list);
102351 mutex_unlock(&nf_sockopt_mutex);
102352 }
102353 EXPORT_SYMBOL(nf_unregister_sockopt);
102354 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
102355 index d292c8d..9f1e166 100644
102356 --- a/net/netfilter/nfnetlink_log.c
102357 +++ b/net/netfilter/nfnetlink_log.c
102358 @@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
102359 struct nfnl_log_net {
102360 spinlock_t instances_lock;
102361 struct hlist_head instance_table[INSTANCE_BUCKETS];
102362 - atomic_t global_seq;
102363 + atomic_unchecked_t global_seq;
102364 };
102365
102366 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
102367 @@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
102368 /* global sequence number */
102369 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
102370 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
102371 - htonl(atomic_inc_return(&log->global_seq))))
102372 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
102373 goto nla_put_failure;
102374
102375 if (data_len) {
102376 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
102377 index 8a779be..1551d4c 100644
102378 --- a/net/netfilter/nft_compat.c
102379 +++ b/net/netfilter/nft_compat.c
102380 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
102381 /* We want to reuse existing compat_to_user */
102382 old_fs = get_fs();
102383 set_fs(KERNEL_DS);
102384 - t->compat_to_user(out, in);
102385 + t->compat_to_user((void __force_user *)out, in);
102386 set_fs(old_fs);
102387 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
102388 kfree(out);
102389 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
102390 /* We want to reuse existing compat_to_user */
102391 old_fs = get_fs();
102392 set_fs(KERNEL_DS);
102393 - m->compat_to_user(out, in);
102394 + m->compat_to_user((void __force_user *)out, in);
102395 set_fs(old_fs);
102396 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
102397 kfree(out);
102398 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
102399 new file mode 100644
102400 index 0000000..c566332
102401 --- /dev/null
102402 +++ b/net/netfilter/xt_gradm.c
102403 @@ -0,0 +1,51 @@
102404 +/*
102405 + * gradm match for netfilter
102406 + * Copyright © Zbigniew Krzystolik, 2010
102407 + *
102408 + * This program is free software; you can redistribute it and/or modify
102409 + * it under the terms of the GNU General Public License; either version
102410 + * 2 or 3 as published by the Free Software Foundation.
102411 + */
102412 +#include <linux/module.h>
102413 +#include <linux/moduleparam.h>
102414 +#include <linux/skbuff.h>
102415 +#include <linux/netfilter/x_tables.h>
102416 +#include <linux/grsecurity.h>
102417 +#include <linux/netfilter/xt_gradm.h>
102418 +
102419 +static bool
102420 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
102421 +{
102422 + const struct xt_gradm_mtinfo *info = par->matchinfo;
102423 + bool retval = false;
102424 + if (gr_acl_is_enabled())
102425 + retval = true;
102426 + return retval ^ info->invflags;
102427 +}
102428 +
102429 +static struct xt_match gradm_mt_reg __read_mostly = {
102430 + .name = "gradm",
102431 + .revision = 0,
102432 + .family = NFPROTO_UNSPEC,
102433 + .match = gradm_mt,
102434 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
102435 + .me = THIS_MODULE,
102436 +};
102437 +
102438 +static int __init gradm_mt_init(void)
102439 +{
102440 + return xt_register_match(&gradm_mt_reg);
102441 +}
102442 +
102443 +static void __exit gradm_mt_exit(void)
102444 +{
102445 + xt_unregister_match(&gradm_mt_reg);
102446 +}
102447 +
102448 +module_init(gradm_mt_init);
102449 +module_exit(gradm_mt_exit);
102450 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
102451 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
102452 +MODULE_LICENSE("GPL");
102453 +MODULE_ALIAS("ipt_gradm");
102454 +MODULE_ALIAS("ip6t_gradm");
102455 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
102456 index a3910fc..2d2ba14 100644
102457 --- a/net/netfilter/xt_hashlimit.c
102458 +++ b/net/netfilter/xt_hashlimit.c
102459 @@ -870,11 +870,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
102460 {
102461 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
102462
102463 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
102464 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
102465 if (!hashlimit_net->ipt_hashlimit)
102466 return -ENOMEM;
102467 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
102468 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
102469 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
102470 if (!hashlimit_net->ip6t_hashlimit) {
102471 remove_proc_entry("ipt_hashlimit", net->proc_net);
102472 return -ENOMEM;
102473 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
102474 index 1e657cf..1eb1c34 100644
102475 --- a/net/netfilter/xt_recent.c
102476 +++ b/net/netfilter/xt_recent.c
102477 @@ -618,7 +618,7 @@ static int __net_init recent_proc_net_init(struct net *net)
102478 {
102479 struct recent_net *recent_net = recent_pernet(net);
102480
102481 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
102482 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
102483 if (!recent_net->xt_recent)
102484 return -ENOMEM;
102485 return 0;
102486 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
102487 index 11de55e..f25e448 100644
102488 --- a/net/netfilter/xt_statistic.c
102489 +++ b/net/netfilter/xt_statistic.c
102490 @@ -19,7 +19,7 @@
102491 #include <linux/module.h>
102492
102493 struct xt_statistic_priv {
102494 - atomic_t count;
102495 + atomic_unchecked_t count;
102496 } ____cacheline_aligned_in_smp;
102497
102498 MODULE_LICENSE("GPL");
102499 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
102500 break;
102501 case XT_STATISTIC_MODE_NTH:
102502 do {
102503 - oval = atomic_read(&info->master->count);
102504 + oval = atomic_read_unchecked(&info->master->count);
102505 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
102506 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
102507 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
102508 if (nval == 0)
102509 ret = !ret;
102510 break;
102511 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
102512 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
102513 if (info->master == NULL)
102514 return -ENOMEM;
102515 - atomic_set(&info->master->count, info->u.nth.count);
102516 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
102517
102518 return 0;
102519 }
102520 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
102521 index f22757a..daf62a2 100644
102522 --- a/net/netlink/af_netlink.c
102523 +++ b/net/netlink/af_netlink.c
102524 @@ -257,7 +257,7 @@ static void netlink_overrun(struct sock *sk)
102525 sk->sk_error_report(sk);
102526 }
102527 }
102528 - atomic_inc(&sk->sk_drops);
102529 + atomic_inc_unchecked(&sk->sk_drops);
102530 }
102531
102532 static void netlink_rcv_wake(struct sock *sk)
102533 @@ -3028,7 +3028,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
102534 sk_wmem_alloc_get(s),
102535 nlk->cb_running,
102536 atomic_read(&s->sk_refcnt),
102537 - atomic_read(&s->sk_drops),
102538 + atomic_read_unchecked(&s->sk_drops),
102539 sock_i_ino(s)
102540 );
102541
102542 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
102543 index ede50d1..d2468e6 100644
102544 --- a/net/netrom/af_netrom.c
102545 +++ b/net/netrom/af_netrom.c
102546 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
102547 *uaddr_len = sizeof(struct full_sockaddr_ax25);
102548 } else {
102549 sax->fsa_ax25.sax25_family = AF_NETROM;
102550 - sax->fsa_ax25.sax25_ndigis = 0;
102551 sax->fsa_ax25.sax25_call = nr->source_addr;
102552 *uaddr_len = sizeof(struct sockaddr_ax25);
102553 }
102554 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
102555 index b85c67c..27c3368 100644
102556 --- a/net/packet/af_packet.c
102557 +++ b/net/packet/af_packet.c
102558 @@ -275,7 +275,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
102559
102560 return ret;
102561 drop:
102562 - atomic_long_inc(&dev->tx_dropped);
102563 + atomic_long_inc_unchecked(&dev->tx_dropped);
102564 kfree_skb(skb);
102565 return NET_XMIT_DROP;
102566 }
102567 @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
102568
102569 spin_lock(&sk->sk_receive_queue.lock);
102570 po->stats.stats1.tp_packets++;
102571 - skb->dropcount = atomic_read(&sk->sk_drops);
102572 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
102573 __skb_queue_tail(&sk->sk_receive_queue, skb);
102574 spin_unlock(&sk->sk_receive_queue.lock);
102575 sk->sk_data_ready(sk);
102576 @@ -1854,7 +1854,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
102577 drop_n_acct:
102578 spin_lock(&sk->sk_receive_queue.lock);
102579 po->stats.stats1.tp_drops++;
102580 - atomic_inc(&sk->sk_drops);
102581 + atomic_inc_unchecked(&sk->sk_drops);
102582 spin_unlock(&sk->sk_receive_queue.lock);
102583
102584 drop_n_restore:
102585 @@ -3459,7 +3459,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
102586 case PACKET_HDRLEN:
102587 if (len > sizeof(int))
102588 len = sizeof(int);
102589 - if (copy_from_user(&val, optval, len))
102590 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
102591 return -EFAULT;
102592 switch (val) {
102593 case TPACKET_V1:
102594 @@ -3505,7 +3505,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
102595 len = lv;
102596 if (put_user(len, optlen))
102597 return -EFAULT;
102598 - if (copy_to_user(optval, data, len))
102599 + if (len > sizeof(st) || copy_to_user(optval, data, len))
102600 return -EFAULT;
102601 return 0;
102602 }
102603 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
102604 index 70a547e..23477fe 100644
102605 --- a/net/phonet/pep.c
102606 +++ b/net/phonet/pep.c
102607 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
102608
102609 case PNS_PEP_CTRL_REQ:
102610 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
102611 - atomic_inc(&sk->sk_drops);
102612 + atomic_inc_unchecked(&sk->sk_drops);
102613 break;
102614 }
102615 __skb_pull(skb, 4);
102616 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
102617 }
102618
102619 if (pn->rx_credits == 0) {
102620 - atomic_inc(&sk->sk_drops);
102621 + atomic_inc_unchecked(&sk->sk_drops);
102622 err = -ENOBUFS;
102623 break;
102624 }
102625 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
102626 }
102627
102628 if (pn->rx_credits == 0) {
102629 - atomic_inc(&sk->sk_drops);
102630 + atomic_inc_unchecked(&sk->sk_drops);
102631 err = NET_RX_DROP;
102632 break;
102633 }
102634 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
102635 index 008214a..bb68240 100644
102636 --- a/net/phonet/socket.c
102637 +++ b/net/phonet/socket.c
102638 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
102639 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
102640 sock_i_ino(sk),
102641 atomic_read(&sk->sk_refcnt), sk,
102642 - atomic_read(&sk->sk_drops));
102643 + atomic_read_unchecked(&sk->sk_drops));
102644 }
102645 seq_pad(seq, '\n');
102646 return 0;
102647 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
102648 index c02a8c4..3c5b600 100644
102649 --- a/net/phonet/sysctl.c
102650 +++ b/net/phonet/sysctl.c
102651 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
102652 {
102653 int ret;
102654 int range[2] = {local_port_range[0], local_port_range[1]};
102655 - struct ctl_table tmp = {
102656 + ctl_table_no_const tmp = {
102657 .data = &range,
102658 .maxlen = sizeof(range),
102659 .mode = table->mode,
102660 diff --git a/net/rds/cong.c b/net/rds/cong.c
102661 index e5b65ac..f3b6fb7 100644
102662 --- a/net/rds/cong.c
102663 +++ b/net/rds/cong.c
102664 @@ -78,7 +78,7 @@
102665 * finds that the saved generation number is smaller than the global generation
102666 * number, it wakes up the process.
102667 */
102668 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
102669 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
102670
102671 /*
102672 * Congestion monitoring
102673 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
102674 rdsdebug("waking map %p for %pI4\n",
102675 map, &map->m_addr);
102676 rds_stats_inc(s_cong_update_received);
102677 - atomic_inc(&rds_cong_generation);
102678 + atomic_inc_unchecked(&rds_cong_generation);
102679 if (waitqueue_active(&map->m_waitq))
102680 wake_up(&map->m_waitq);
102681 if (waitqueue_active(&rds_poll_waitq))
102682 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
102683
102684 int rds_cong_updated_since(unsigned long *recent)
102685 {
102686 - unsigned long gen = atomic_read(&rds_cong_generation);
102687 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
102688
102689 if (likely(*recent == gen))
102690 return 0;
102691 diff --git a/net/rds/ib.h b/net/rds/ib.h
102692 index 7280ab8..e04f4ea 100644
102693 --- a/net/rds/ib.h
102694 +++ b/net/rds/ib.h
102695 @@ -128,7 +128,7 @@ struct rds_ib_connection {
102696 /* sending acks */
102697 unsigned long i_ack_flags;
102698 #ifdef KERNEL_HAS_ATOMIC64
102699 - atomic64_t i_ack_next; /* next ACK to send */
102700 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
102701 #else
102702 spinlock_t i_ack_lock; /* protect i_ack_next */
102703 u64 i_ack_next; /* next ACK to send */
102704 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
102705 index 31b74f5..dc1fbfa 100644
102706 --- a/net/rds/ib_cm.c
102707 +++ b/net/rds/ib_cm.c
102708 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
102709 /* Clear the ACK state */
102710 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
102711 #ifdef KERNEL_HAS_ATOMIC64
102712 - atomic64_set(&ic->i_ack_next, 0);
102713 + atomic64_set_unchecked(&ic->i_ack_next, 0);
102714 #else
102715 ic->i_ack_next = 0;
102716 #endif
102717 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
102718 index b7ebe23..b6352f6 100644
102719 --- a/net/rds/ib_recv.c
102720 +++ b/net/rds/ib_recv.c
102721 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
102722 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
102723 int ack_required)
102724 {
102725 - atomic64_set(&ic->i_ack_next, seq);
102726 + atomic64_set_unchecked(&ic->i_ack_next, seq);
102727 if (ack_required) {
102728 smp_mb__before_clear_bit();
102729 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102730 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
102731 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102732 smp_mb__after_clear_bit();
102733
102734 - return atomic64_read(&ic->i_ack_next);
102735 + return atomic64_read_unchecked(&ic->i_ack_next);
102736 }
102737 #endif
102738
102739 diff --git a/net/rds/iw.h b/net/rds/iw.h
102740 index 04ce3b1..48119a6 100644
102741 --- a/net/rds/iw.h
102742 +++ b/net/rds/iw.h
102743 @@ -134,7 +134,7 @@ struct rds_iw_connection {
102744 /* sending acks */
102745 unsigned long i_ack_flags;
102746 #ifdef KERNEL_HAS_ATOMIC64
102747 - atomic64_t i_ack_next; /* next ACK to send */
102748 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
102749 #else
102750 spinlock_t i_ack_lock; /* protect i_ack_next */
102751 u64 i_ack_next; /* next ACK to send */
102752 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
102753 index a91e1db..cf3053f 100644
102754 --- a/net/rds/iw_cm.c
102755 +++ b/net/rds/iw_cm.c
102756 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
102757 /* Clear the ACK state */
102758 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
102759 #ifdef KERNEL_HAS_ATOMIC64
102760 - atomic64_set(&ic->i_ack_next, 0);
102761 + atomic64_set_unchecked(&ic->i_ack_next, 0);
102762 #else
102763 ic->i_ack_next = 0;
102764 #endif
102765 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
102766 index 4503335..db566b4 100644
102767 --- a/net/rds/iw_recv.c
102768 +++ b/net/rds/iw_recv.c
102769 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
102770 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
102771 int ack_required)
102772 {
102773 - atomic64_set(&ic->i_ack_next, seq);
102774 + atomic64_set_unchecked(&ic->i_ack_next, seq);
102775 if (ack_required) {
102776 smp_mb__before_clear_bit();
102777 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102778 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
102779 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102780 smp_mb__after_clear_bit();
102781
102782 - return atomic64_read(&ic->i_ack_next);
102783 + return atomic64_read_unchecked(&ic->i_ack_next);
102784 }
102785 #endif
102786
102787 diff --git a/net/rds/rds.h b/net/rds/rds.h
102788 index 48f8ffc..0ef3eec 100644
102789 --- a/net/rds/rds.h
102790 +++ b/net/rds/rds.h
102791 @@ -449,7 +449,7 @@ struct rds_transport {
102792 void (*sync_mr)(void *trans_private, int direction);
102793 void (*free_mr)(void *trans_private, int invalidate);
102794 void (*flush_mrs)(void);
102795 -};
102796 +} __do_const;
102797
102798 struct rds_sock {
102799 struct sock rs_sk;
102800 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
102801 index edac9ef..16bcb98 100644
102802 --- a/net/rds/tcp.c
102803 +++ b/net/rds/tcp.c
102804 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
102805 int val = 1;
102806
102807 set_fs(KERNEL_DS);
102808 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
102809 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
102810 sizeof(val));
102811 set_fs(oldfs);
102812 }
102813 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
102814 index 81cf5a4..b5826ff 100644
102815 --- a/net/rds/tcp_send.c
102816 +++ b/net/rds/tcp_send.c
102817 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
102818
102819 oldfs = get_fs();
102820 set_fs(KERNEL_DS);
102821 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
102822 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
102823 sizeof(val));
102824 set_fs(oldfs);
102825 }
102826 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
102827 index 7b16704..9628ec6 100644
102828 --- a/net/rxrpc/af_rxrpc.c
102829 +++ b/net/rxrpc/af_rxrpc.c
102830 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
102831 __be32 rxrpc_epoch;
102832
102833 /* current debugging ID */
102834 -atomic_t rxrpc_debug_id;
102835 +atomic_unchecked_t rxrpc_debug_id;
102836
102837 /* count of skbs currently in use */
102838 atomic_t rxrpc_n_skbs;
102839 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
102840 index c6be17a..2a6200a 100644
102841 --- a/net/rxrpc/ar-ack.c
102842 +++ b/net/rxrpc/ar-ack.c
102843 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
102844
102845 _enter("{%d,%d,%d,%d},",
102846 call->acks_hard, call->acks_unacked,
102847 - atomic_read(&call->sequence),
102848 + atomic_read_unchecked(&call->sequence),
102849 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
102850
102851 stop = 0;
102852 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
102853
102854 /* each Tx packet has a new serial number */
102855 sp->hdr.serial =
102856 - htonl(atomic_inc_return(&call->conn->serial));
102857 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
102858
102859 hdr = (struct rxrpc_header *) txb->head;
102860 hdr->serial = sp->hdr.serial;
102861 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
102862 */
102863 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
102864 {
102865 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
102866 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
102867 }
102868
102869 /*
102870 @@ -677,7 +677,7 @@ process_further:
102871
102872 latest = ntohl(sp->hdr.serial);
102873 hard = ntohl(ack.firstPacket);
102874 - tx = atomic_read(&call->sequence);
102875 + tx = atomic_read_unchecked(&call->sequence);
102876
102877 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
102878 latest,
102879 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
102880 goto maybe_reschedule;
102881
102882 send_ACK_with_skew:
102883 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
102884 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
102885 ntohl(ack.serial));
102886 send_ACK:
102887 mtu = call->conn->trans->peer->if_mtu;
102888 @@ -1221,7 +1221,7 @@ send_ACK:
102889 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
102890 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
102891
102892 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
102893 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
102894 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
102895 ntohl(hdr.serial),
102896 ntohs(ack.maxSkew),
102897 @@ -1239,7 +1239,7 @@ send_ACK:
102898 send_message:
102899 _debug("send message");
102900
102901 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
102902 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
102903 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
102904 send_message_2:
102905
102906 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
102907 index a9e05db..194e793 100644
102908 --- a/net/rxrpc/ar-call.c
102909 +++ b/net/rxrpc/ar-call.c
102910 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
102911 spin_lock_init(&call->lock);
102912 rwlock_init(&call->state_lock);
102913 atomic_set(&call->usage, 1);
102914 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
102915 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102916 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
102917
102918 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
102919 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
102920 index 6631f4f..bfdf056 100644
102921 --- a/net/rxrpc/ar-connection.c
102922 +++ b/net/rxrpc/ar-connection.c
102923 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
102924 rwlock_init(&conn->lock);
102925 spin_lock_init(&conn->state_lock);
102926 atomic_set(&conn->usage, 1);
102927 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
102928 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102929 conn->avail_calls = RXRPC_MAXCALLS;
102930 conn->size_align = 4;
102931 conn->header_size = sizeof(struct rxrpc_header);
102932 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
102933 index e7ed43a..6afa140 100644
102934 --- a/net/rxrpc/ar-connevent.c
102935 +++ b/net/rxrpc/ar-connevent.c
102936 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
102937
102938 len = iov[0].iov_len + iov[1].iov_len;
102939
102940 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
102941 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
102942 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
102943
102944 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
102945 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
102946 index 63b21e5..330232e 100644
102947 --- a/net/rxrpc/ar-input.c
102948 +++ b/net/rxrpc/ar-input.c
102949 @@ -338,9 +338,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
102950 /* track the latest serial number on this connection for ACK packet
102951 * information */
102952 serial = ntohl(sp->hdr.serial);
102953 - hi_serial = atomic_read(&call->conn->hi_serial);
102954 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
102955 while (serial > hi_serial)
102956 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
102957 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
102958 serial);
102959
102960 /* request ACK generation for any ACK or DATA packet that requests
102961 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
102962 index ba9fd36..9bbfe01 100644
102963 --- a/net/rxrpc/ar-internal.h
102964 +++ b/net/rxrpc/ar-internal.h
102965 @@ -272,8 +272,8 @@ struct rxrpc_connection {
102966 int error; /* error code for local abort */
102967 int debug_id; /* debug ID for printks */
102968 unsigned int call_counter; /* call ID counter */
102969 - atomic_t serial; /* packet serial number counter */
102970 - atomic_t hi_serial; /* highest serial number received */
102971 + atomic_unchecked_t serial; /* packet serial number counter */
102972 + atomic_unchecked_t hi_serial; /* highest serial number received */
102973 u8 avail_calls; /* number of calls available */
102974 u8 size_align; /* data size alignment (for security) */
102975 u8 header_size; /* rxrpc + security header size */
102976 @@ -346,7 +346,7 @@ struct rxrpc_call {
102977 spinlock_t lock;
102978 rwlock_t state_lock; /* lock for state transition */
102979 atomic_t usage;
102980 - atomic_t sequence; /* Tx data packet sequence counter */
102981 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
102982 u32 abort_code; /* local/remote abort code */
102983 enum { /* current state of call */
102984 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
102985 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
102986 */
102987 extern atomic_t rxrpc_n_skbs;
102988 extern __be32 rxrpc_epoch;
102989 -extern atomic_t rxrpc_debug_id;
102990 +extern atomic_unchecked_t rxrpc_debug_id;
102991 extern struct workqueue_struct *rxrpc_workqueue;
102992
102993 /*
102994 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
102995 index 87f7135..74d3703 100644
102996 --- a/net/rxrpc/ar-local.c
102997 +++ b/net/rxrpc/ar-local.c
102998 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
102999 spin_lock_init(&local->lock);
103000 rwlock_init(&local->services_lock);
103001 atomic_set(&local->usage, 1);
103002 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
103003 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
103004 memcpy(&local->srx, srx, sizeof(*srx));
103005 }
103006
103007 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
103008 index 0b4b9a7..966ffbb 100644
103009 --- a/net/rxrpc/ar-output.c
103010 +++ b/net/rxrpc/ar-output.c
103011 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
103012 memset(skb_put(skb, pad), 0, pad);
103013 }
103014
103015 - seq = atomic_inc_return(&call->sequence);
103016 + seq = atomic_inc_return_unchecked(&call->sequence);
103017
103018 sp->hdr.epoch = conn->epoch;
103019 sp->hdr.cid = call->cid;
103020 sp->hdr.callNumber = call->call_id;
103021 sp->hdr.seq = htonl(seq);
103022 sp->hdr.serial =
103023 - htonl(atomic_inc_return(&conn->serial));
103024 + htonl(atomic_inc_return_unchecked(&conn->serial));
103025 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
103026 sp->hdr.userStatus = 0;
103027 sp->hdr.securityIndex = conn->security_ix;
103028 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
103029 index bebaa43..2644591 100644
103030 --- a/net/rxrpc/ar-peer.c
103031 +++ b/net/rxrpc/ar-peer.c
103032 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
103033 INIT_LIST_HEAD(&peer->error_targets);
103034 spin_lock_init(&peer->lock);
103035 atomic_set(&peer->usage, 1);
103036 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
103037 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
103038 memcpy(&peer->srx, srx, sizeof(*srx));
103039
103040 rxrpc_assess_MTU_size(peer);
103041 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
103042 index 38047f7..9f48511 100644
103043 --- a/net/rxrpc/ar-proc.c
103044 +++ b/net/rxrpc/ar-proc.c
103045 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
103046 atomic_read(&conn->usage),
103047 rxrpc_conn_states[conn->state],
103048 key_serial(conn->key),
103049 - atomic_read(&conn->serial),
103050 - atomic_read(&conn->hi_serial));
103051 + atomic_read_unchecked(&conn->serial),
103052 + atomic_read_unchecked(&conn->hi_serial));
103053
103054 return 0;
103055 }
103056 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
103057 index 1976dec..aa70be5 100644
103058 --- a/net/rxrpc/ar-transport.c
103059 +++ b/net/rxrpc/ar-transport.c
103060 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
103061 spin_lock_init(&trans->client_lock);
103062 rwlock_init(&trans->conn_lock);
103063 atomic_set(&trans->usage, 1);
103064 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
103065 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
103066
103067 if (peer->srx.transport.family == AF_INET) {
103068 switch (peer->srx.transport_type) {
103069 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
103070 index f226709..0e735a8 100644
103071 --- a/net/rxrpc/rxkad.c
103072 +++ b/net/rxrpc/rxkad.c
103073 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
103074
103075 len = iov[0].iov_len + iov[1].iov_len;
103076
103077 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
103078 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
103079 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
103080
103081 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
103082 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
103083
103084 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
103085
103086 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
103087 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
103088 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
103089
103090 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
103091 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
103092 index e1543b0..7ce8bd0 100644
103093 --- a/net/sched/sch_generic.c
103094 +++ b/net/sched/sch_generic.c
103095 @@ -310,7 +310,7 @@ void netif_carrier_on(struct net_device *dev)
103096 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
103097 if (dev->reg_state == NETREG_UNINITIALIZED)
103098 return;
103099 - atomic_inc(&dev->carrier_changes);
103100 + atomic_inc_unchecked(&dev->carrier_changes);
103101 linkwatch_fire_event(dev);
103102 if (netif_running(dev))
103103 __netdev_watchdog_up(dev);
103104 @@ -329,7 +329,7 @@ void netif_carrier_off(struct net_device *dev)
103105 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
103106 if (dev->reg_state == NETREG_UNINITIALIZED)
103107 return;
103108 - atomic_inc(&dev->carrier_changes);
103109 + atomic_inc_unchecked(&dev->carrier_changes);
103110 linkwatch_fire_event(dev);
103111 }
103112 }
103113 diff --git a/net/sctp/associola.c b/net/sctp/associola.c
103114 index 0b99998..a6953b0 100644
103115 --- a/net/sctp/associola.c
103116 +++ b/net/sctp/associola.c
103117 @@ -1151,6 +1151,7 @@ void sctp_assoc_update(struct sctp_association *asoc,
103118 asoc->c = new->c;
103119 asoc->peer.rwnd = new->peer.rwnd;
103120 asoc->peer.sack_needed = new->peer.sack_needed;
103121 + asoc->peer.auth_capable = new->peer.auth_capable;
103122 asoc->peer.i = new->peer.i;
103123 sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL,
103124 asoc->peer.i.initial_tsn, GFP_ATOMIC);
103125 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
103126 index 2b1738e..a9d0fc9 100644
103127 --- a/net/sctp/ipv6.c
103128 +++ b/net/sctp/ipv6.c
103129 @@ -966,7 +966,7 @@ static const struct inet6_protocol sctpv6_protocol = {
103130 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
103131 };
103132
103133 -static struct sctp_af sctp_af_inet6 = {
103134 +static struct sctp_af sctp_af_inet6 __read_only = {
103135 .sa_family = AF_INET6,
103136 .sctp_xmit = sctp_v6_xmit,
103137 .setsockopt = ipv6_setsockopt,
103138 @@ -998,7 +998,7 @@ static struct sctp_af sctp_af_inet6 = {
103139 #endif
103140 };
103141
103142 -static struct sctp_pf sctp_pf_inet6 = {
103143 +static struct sctp_pf sctp_pf_inet6 __read_only = {
103144 .event_msgname = sctp_inet6_event_msgname,
103145 .skb_msgname = sctp_inet6_skb_msgname,
103146 .af_supported = sctp_inet6_af_supported,
103147 @@ -1023,7 +1023,7 @@ void sctp_v6_pf_init(void)
103148
103149 void sctp_v6_pf_exit(void)
103150 {
103151 - list_del(&sctp_af_inet6.list);
103152 + pax_list_del(&sctp_af_inet6.list);
103153 }
103154
103155 /* Initialize IPv6 support and register with socket layer. */
103156 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
103157 index 44cbb54..4c5dce6 100644
103158 --- a/net/sctp/protocol.c
103159 +++ b/net/sctp/protocol.c
103160 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
103161 return 0;
103162 }
103163
103164 + pax_open_kernel();
103165 INIT_LIST_HEAD(&af->list);
103166 - list_add_tail(&af->list, &sctp_address_families);
103167 + pax_close_kernel();
103168 + pax_list_add_tail(&af->list, &sctp_address_families);
103169 return 1;
103170 }
103171
103172 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
103173
103174 static struct sctp_af sctp_af_inet;
103175
103176 -static struct sctp_pf sctp_pf_inet = {
103177 +static struct sctp_pf sctp_pf_inet __read_only = {
103178 .event_msgname = sctp_inet_event_msgname,
103179 .skb_msgname = sctp_inet_skb_msgname,
103180 .af_supported = sctp_inet_af_supported,
103181 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
103182 };
103183
103184 /* IPv4 address related functions. */
103185 -static struct sctp_af sctp_af_inet = {
103186 +static struct sctp_af sctp_af_inet __read_only = {
103187 .sa_family = AF_INET,
103188 .sctp_xmit = sctp_v4_xmit,
103189 .setsockopt = ip_setsockopt,
103190 @@ -1124,7 +1126,7 @@ static void sctp_v4_pf_init(void)
103191
103192 static void sctp_v4_pf_exit(void)
103193 {
103194 - list_del(&sctp_af_inet.list);
103195 + pax_list_del(&sctp_af_inet.list);
103196 }
103197
103198 static int sctp_v4_protosw_init(void)
103199 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
103200 index fef2acd..c705c4f 100644
103201 --- a/net/sctp/sm_sideeffect.c
103202 +++ b/net/sctp/sm_sideeffect.c
103203 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
103204 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
103205 }
103206
103207 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
103208 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
103209 NULL,
103210 sctp_generate_t1_cookie_event,
103211 sctp_generate_t1_init_event,
103212 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
103213 index fee06b9..eabc613 100644
103214 --- a/net/sctp/socket.c
103215 +++ b/net/sctp/socket.c
103216 @@ -2175,11 +2175,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
103217 {
103218 struct sctp_association *asoc;
103219 struct sctp_ulpevent *event;
103220 + struct sctp_event_subscribe subscribe;
103221
103222 if (optlen > sizeof(struct sctp_event_subscribe))
103223 return -EINVAL;
103224 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
103225 + if (copy_from_user(&subscribe, optval, optlen))
103226 return -EFAULT;
103227 + sctp_sk(sk)->subscribe = subscribe;
103228
103229 /*
103230 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
103231 @@ -4259,13 +4261,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
103232 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
103233 int __user *optlen)
103234 {
103235 + struct sctp_event_subscribe subscribe;
103236 +
103237 if (len <= 0)
103238 return -EINVAL;
103239 if (len > sizeof(struct sctp_event_subscribe))
103240 len = sizeof(struct sctp_event_subscribe);
103241 if (put_user(len, optlen))
103242 return -EFAULT;
103243 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
103244 + subscribe = sctp_sk(sk)->subscribe;
103245 + if (copy_to_user(optval, &subscribe, len))
103246 return -EFAULT;
103247 return 0;
103248 }
103249 @@ -4283,6 +4288,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
103250 */
103251 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
103252 {
103253 + __u32 autoclose;
103254 +
103255 /* Applicable to UDP-style socket only */
103256 if (sctp_style(sk, TCP))
103257 return -EOPNOTSUPP;
103258 @@ -4291,7 +4298,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
103259 len = sizeof(int);
103260 if (put_user(len, optlen))
103261 return -EFAULT;
103262 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
103263 + autoclose = sctp_sk(sk)->autoclose;
103264 + if (copy_to_user(optval, &autoclose, sizeof(int)))
103265 return -EFAULT;
103266 return 0;
103267 }
103268 @@ -4666,12 +4674,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
103269 */
103270 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
103271 {
103272 + struct sctp_initmsg initmsg;
103273 +
103274 if (len < sizeof(struct sctp_initmsg))
103275 return -EINVAL;
103276 len = sizeof(struct sctp_initmsg);
103277 if (put_user(len, optlen))
103278 return -EFAULT;
103279 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
103280 + initmsg = sctp_sk(sk)->initmsg;
103281 + if (copy_to_user(optval, &initmsg, len))
103282 return -EFAULT;
103283 return 0;
103284 }
103285 @@ -4712,6 +4723,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
103286 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
103287 if (space_left < addrlen)
103288 return -ENOMEM;
103289 + if (addrlen > sizeof(temp) || addrlen < 0)
103290 + return -EFAULT;
103291 if (copy_to_user(to, &temp, addrlen))
103292 return -EFAULT;
103293 to += addrlen;
103294 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
103295 index c82fdc1..4ca1f95 100644
103296 --- a/net/sctp/sysctl.c
103297 +++ b/net/sctp/sysctl.c
103298 @@ -308,7 +308,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
103299 {
103300 struct net *net = current->nsproxy->net_ns;
103301 char tmp[8];
103302 - struct ctl_table tbl;
103303 + ctl_table_no_const tbl;
103304 int ret;
103305 int changed = 0;
103306 char *none = "none";
103307 @@ -355,7 +355,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
103308 {
103309 struct net *net = current->nsproxy->net_ns;
103310 int new_value;
103311 - struct ctl_table tbl;
103312 + ctl_table_no_const tbl;
103313 unsigned int min = *(unsigned int *) ctl->extra1;
103314 unsigned int max = *(unsigned int *) ctl->extra2;
103315 int ret;
103316 @@ -382,7 +382,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
103317 {
103318 struct net *net = current->nsproxy->net_ns;
103319 int new_value;
103320 - struct ctl_table tbl;
103321 + ctl_table_no_const tbl;
103322 unsigned int min = *(unsigned int *) ctl->extra1;
103323 unsigned int max = *(unsigned int *) ctl->extra2;
103324 int ret;
103325 @@ -408,7 +408,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
103326 loff_t *ppos)
103327 {
103328 struct net *net = current->nsproxy->net_ns;
103329 - struct ctl_table tbl;
103330 + ctl_table_no_const tbl;
103331 int new_value, ret;
103332
103333 memset(&tbl, 0, sizeof(struct ctl_table));
103334 @@ -436,7 +436,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
103335
103336 int sctp_sysctl_net_register(struct net *net)
103337 {
103338 - struct ctl_table *table = sctp_net_table;
103339 + ctl_table_no_const *table = NULL;
103340
103341 if (!net_eq(net, &init_net)) {
103342 int i;
103343 @@ -449,7 +449,10 @@ int sctp_sysctl_net_register(struct net *net)
103344 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
103345 }
103346
103347 - net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
103348 + if (!net_eq(net, &init_net))
103349 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
103350 + else
103351 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", sctp_net_table);
103352 return 0;
103353 }
103354
103355 diff --git a/net/sctp/ulpevent.c b/net/sctp/ulpevent.c
103356 index 85c6465..879f3cd 100644
103357 --- a/net/sctp/ulpevent.c
103358 +++ b/net/sctp/ulpevent.c
103359 @@ -411,6 +411,7 @@ struct sctp_ulpevent *sctp_ulpevent_make_remote_error(
103360 * sre_type:
103361 * It should be SCTP_REMOTE_ERROR.
103362 */
103363 + memset(sre, 0, sizeof(*sre));
103364 sre->sre_type = SCTP_REMOTE_ERROR;
103365
103366 /*
103367 @@ -916,6 +917,7 @@ void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event,
103368 * For recvmsg() the SCTP stack places the message's stream number in
103369 * this value.
103370 */
103371 + memset(&sinfo, 0, sizeof(sinfo));
103372 sinfo.sinfo_stream = event->stream;
103373 /* sinfo_ssn: 16 bits (unsigned integer)
103374 *
103375 diff --git a/net/socket.c b/net/socket.c
103376 index abf56b2..b8998bc 100644
103377 --- a/net/socket.c
103378 +++ b/net/socket.c
103379 @@ -89,6 +89,7 @@
103380 #include <linux/magic.h>
103381 #include <linux/slab.h>
103382 #include <linux/xattr.h>
103383 +#include <linux/in.h>
103384
103385 #include <asm/uaccess.h>
103386 #include <asm/unistd.h>
103387 @@ -112,6 +113,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
103388 unsigned int sysctl_net_busy_poll __read_mostly;
103389 #endif
103390
103391 +#include <linux/grsock.h>
103392 +
103393 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
103394 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
103395 unsigned long nr_segs, loff_t pos);
103396 @@ -163,7 +166,7 @@ static const struct file_operations socket_file_ops = {
103397 */
103398
103399 static DEFINE_SPINLOCK(net_family_lock);
103400 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
103401 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
103402
103403 /*
103404 * Statistics counters of the socket lists
103405 @@ -329,7 +332,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
103406 &sockfs_dentry_operations, SOCKFS_MAGIC);
103407 }
103408
103409 -static struct vfsmount *sock_mnt __read_mostly;
103410 +struct vfsmount *sock_mnt __read_mostly;
103411
103412 static struct file_system_type sock_fs_type = {
103413 .name = "sockfs",
103414 @@ -1257,6 +1260,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
103415 return -EAFNOSUPPORT;
103416 if (type < 0 || type >= SOCK_MAX)
103417 return -EINVAL;
103418 + if (protocol < 0)
103419 + return -EINVAL;
103420
103421 /* Compatibility.
103422
103423 @@ -1277,6 +1282,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
103424 if (err)
103425 return err;
103426
103427 + if(!kern && !gr_search_socket(family, type, protocol)) {
103428 + if (rcu_access_pointer(net_families[family]) == NULL)
103429 + return -EAFNOSUPPORT;
103430 + else
103431 + return -EACCES;
103432 + }
103433 +
103434 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
103435 + if (rcu_access_pointer(net_families[family]) == NULL)
103436 + return -EAFNOSUPPORT;
103437 + else
103438 + return -EACCES;
103439 + }
103440 +
103441 /*
103442 * Allocate the socket and allow the family to set things up. if
103443 * the protocol is 0, the family is instructed to select an appropriate
103444 @@ -1528,6 +1547,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
103445 if (sock) {
103446 err = move_addr_to_kernel(umyaddr, addrlen, &address);
103447 if (err >= 0) {
103448 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
103449 + err = -EACCES;
103450 + goto error;
103451 + }
103452 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
103453 + if (err)
103454 + goto error;
103455 +
103456 err = security_socket_bind(sock,
103457 (struct sockaddr *)&address,
103458 addrlen);
103459 @@ -1536,6 +1563,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
103460 (struct sockaddr *)
103461 &address, addrlen);
103462 }
103463 +error:
103464 fput_light(sock->file, fput_needed);
103465 }
103466 return err;
103467 @@ -1559,10 +1587,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
103468 if ((unsigned int)backlog > somaxconn)
103469 backlog = somaxconn;
103470
103471 + if (gr_handle_sock_server_other(sock->sk)) {
103472 + err = -EPERM;
103473 + goto error;
103474 + }
103475 +
103476 + err = gr_search_listen(sock);
103477 + if (err)
103478 + goto error;
103479 +
103480 err = security_socket_listen(sock, backlog);
103481 if (!err)
103482 err = sock->ops->listen(sock, backlog);
103483
103484 +error:
103485 fput_light(sock->file, fput_needed);
103486 }
103487 return err;
103488 @@ -1606,6 +1644,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
103489 newsock->type = sock->type;
103490 newsock->ops = sock->ops;
103491
103492 + if (gr_handle_sock_server_other(sock->sk)) {
103493 + err = -EPERM;
103494 + sock_release(newsock);
103495 + goto out_put;
103496 + }
103497 +
103498 + err = gr_search_accept(sock);
103499 + if (err) {
103500 + sock_release(newsock);
103501 + goto out_put;
103502 + }
103503 +
103504 /*
103505 * We don't need try_module_get here, as the listening socket (sock)
103506 * has the protocol module (sock->ops->owner) held.
103507 @@ -1651,6 +1701,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
103508 fd_install(newfd, newfile);
103509 err = newfd;
103510
103511 + gr_attach_curr_ip(newsock->sk);
103512 +
103513 out_put:
103514 fput_light(sock->file, fput_needed);
103515 out:
103516 @@ -1683,6 +1735,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
103517 int, addrlen)
103518 {
103519 struct socket *sock;
103520 + struct sockaddr *sck;
103521 struct sockaddr_storage address;
103522 int err, fput_needed;
103523
103524 @@ -1693,6 +1746,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
103525 if (err < 0)
103526 goto out_put;
103527
103528 + sck = (struct sockaddr *)&address;
103529 +
103530 + if (gr_handle_sock_client(sck)) {
103531 + err = -EACCES;
103532 + goto out_put;
103533 + }
103534 +
103535 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
103536 + if (err)
103537 + goto out_put;
103538 +
103539 err =
103540 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
103541 if (err)
103542 @@ -1774,6 +1838,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
103543 * the protocol.
103544 */
103545
103546 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
103547 +
103548 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
103549 unsigned int, flags, struct sockaddr __user *, addr,
103550 int, addr_len)
103551 @@ -1840,7 +1906,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
103552 struct socket *sock;
103553 struct iovec iov;
103554 struct msghdr msg;
103555 - struct sockaddr_storage address;
103556 + struct sockaddr_storage address = { };
103557 int err, err2;
103558 int fput_needed;
103559
103560 @@ -2066,7 +2132,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
103561 * checking falls down on this.
103562 */
103563 if (copy_from_user(ctl_buf,
103564 - (void __user __force *)msg_sys->msg_control,
103565 + (void __force_user *)msg_sys->msg_control,
103566 ctl_len))
103567 goto out_freectl;
103568 msg_sys->msg_control = ctl_buf;
103569 @@ -2217,7 +2283,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
103570 int err, total_len, len;
103571
103572 /* kernel mode address */
103573 - struct sockaddr_storage addr;
103574 + struct sockaddr_storage addr = { };
103575
103576 /* user mode address pointers */
103577 struct sockaddr __user *uaddr;
103578 @@ -2246,7 +2312,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
103579 /* Save the user-mode address (verify_iovec will change the
103580 * kernel msghdr to use the kernel address space)
103581 */
103582 - uaddr = (__force void __user *)msg_sys->msg_name;
103583 + uaddr = (void __force_user *)msg_sys->msg_name;
103584 uaddr_len = COMPAT_NAMELEN(msg);
103585 if (MSG_CMSG_COMPAT & flags)
103586 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
103587 @@ -2887,7 +2953,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
103588 ifr = compat_alloc_user_space(buf_size);
103589 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
103590
103591 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
103592 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
103593 return -EFAULT;
103594
103595 if (put_user(convert_in ? rxnfc : compat_ptr(data),
103596 @@ -2998,7 +3064,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
103597 old_fs = get_fs();
103598 set_fs(KERNEL_DS);
103599 err = dev_ioctl(net, cmd,
103600 - (struct ifreq __user __force *) &kifr);
103601 + (struct ifreq __force_user *) &kifr);
103602 set_fs(old_fs);
103603
103604 return err;
103605 @@ -3091,7 +3157,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
103606
103607 old_fs = get_fs();
103608 set_fs(KERNEL_DS);
103609 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
103610 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
103611 set_fs(old_fs);
103612
103613 if (cmd == SIOCGIFMAP && !err) {
103614 @@ -3175,7 +3241,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
103615 ret |= get_user(rtdev, &(ur4->rt_dev));
103616 if (rtdev) {
103617 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
103618 - r4.rt_dev = (char __user __force *)devname;
103619 + r4.rt_dev = (char __force_user *)devname;
103620 devname[15] = 0;
103621 } else
103622 r4.rt_dev = NULL;
103623 @@ -3402,8 +3468,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
103624 int __user *uoptlen;
103625 int err;
103626
103627 - uoptval = (char __user __force *) optval;
103628 - uoptlen = (int __user __force *) optlen;
103629 + uoptval = (char __force_user *) optval;
103630 + uoptlen = (int __force_user *) optlen;
103631
103632 set_fs(KERNEL_DS);
103633 if (level == SOL_SOCKET)
103634 @@ -3423,7 +3489,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
103635 char __user *uoptval;
103636 int err;
103637
103638 - uoptval = (char __user __force *) optval;
103639 + uoptval = (char __force_user *) optval;
103640
103641 set_fs(KERNEL_DS);
103642 if (level == SOL_SOCKET)
103643 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
103644 index 0f73f45..a96aa52 100644
103645 --- a/net/sunrpc/auth_gss/svcauth_gss.c
103646 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
103647 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
103648 uint64_t *handle)
103649 {
103650 struct rsc rsci, *rscp = NULL;
103651 - static atomic64_t ctxhctr;
103652 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
103653 long long ctxh;
103654 struct gss_api_mech *gm = NULL;
103655 time_t expiry;
103656 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
103657 status = -ENOMEM;
103658 /* the handle needs to be just a unique id,
103659 * use a static counter */
103660 - ctxh = atomic64_inc_return(&ctxhctr);
103661 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
103662
103663 /* make a copy for the caller */
103664 *handle = ctxh;
103665 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
103666 index ae333c1..18521f0 100644
103667 --- a/net/sunrpc/cache.c
103668 +++ b/net/sunrpc/cache.c
103669 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
103670 struct sunrpc_net *sn;
103671
103672 sn = net_generic(net, sunrpc_net_id);
103673 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
103674 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
103675 if (cd->u.procfs.proc_ent == NULL)
103676 goto out_nomem;
103677 cd->u.procfs.channel_ent = NULL;
103678 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
103679 index 2e6ab10..3170800 100644
103680 --- a/net/sunrpc/clnt.c
103681 +++ b/net/sunrpc/clnt.c
103682 @@ -1425,7 +1425,9 @@ call_start(struct rpc_task *task)
103683 (RPC_IS_ASYNC(task) ? "async" : "sync"));
103684
103685 /* Increment call count */
103686 - task->tk_msg.rpc_proc->p_count++;
103687 + pax_open_kernel();
103688 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
103689 + pax_close_kernel();
103690 clnt->cl_stats->rpccnt++;
103691 task->tk_action = call_reserve;
103692 }
103693 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
103694 index 25578af..a29298d 100644
103695 --- a/net/sunrpc/sched.c
103696 +++ b/net/sunrpc/sched.c
103697 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
103698 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
103699 static void rpc_task_set_debuginfo(struct rpc_task *task)
103700 {
103701 - static atomic_t rpc_pid;
103702 + static atomic_unchecked_t rpc_pid;
103703
103704 - task->tk_pid = atomic_inc_return(&rpc_pid);
103705 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
103706 }
103707 #else
103708 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
103709 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
103710 index 5453049..465669a 100644
103711 --- a/net/sunrpc/stats.c
103712 +++ b/net/sunrpc/stats.c
103713 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
103714
103715 dprintk("RPC: registering /proc/net/rpc\n");
103716 sn = net_generic(net, sunrpc_net_id);
103717 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
103718 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
103719 if (sn->proc_net_rpc == NULL)
103720 return -ENOMEM;
103721
103722 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
103723 index 5de6801..b4e330d 100644
103724 --- a/net/sunrpc/svc.c
103725 +++ b/net/sunrpc/svc.c
103726 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
103727 svc_putnl(resv, RPC_SUCCESS);
103728
103729 /* Bump per-procedure stats counter */
103730 - procp->pc_count++;
103731 + pax_open_kernel();
103732 + (*(unsigned int *)&procp->pc_count)++;
103733 + pax_close_kernel();
103734
103735 /* Initialize storage for argp and resp */
103736 memset(rqstp->rq_argp, 0, procp->pc_argsize);
103737 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
103738 index 621ca7b..59421dd 100644
103739 --- a/net/sunrpc/svcauth_unix.c
103740 +++ b/net/sunrpc/svcauth_unix.c
103741 @@ -414,7 +414,7 @@ struct unix_gid {
103742 struct group_info *gi;
103743 };
103744
103745 -static int unix_gid_hash(kuid_t uid)
103746 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
103747 {
103748 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
103749 }
103750 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
103751 (*bpp)[-1] = '\n';
103752 }
103753
103754 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
103755 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
103756
103757 static int unix_gid_parse(struct cache_detail *cd,
103758 char *mesg, int mlen)
103759 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
103760 index c1b6270..05089c1 100644
103761 --- a/net/sunrpc/xprtrdma/svc_rdma.c
103762 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
103763 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
103764 static unsigned int min_max_inline = 4096;
103765 static unsigned int max_max_inline = 65536;
103766
103767 -atomic_t rdma_stat_recv;
103768 -atomic_t rdma_stat_read;
103769 -atomic_t rdma_stat_write;
103770 -atomic_t rdma_stat_sq_starve;
103771 -atomic_t rdma_stat_rq_starve;
103772 -atomic_t rdma_stat_rq_poll;
103773 -atomic_t rdma_stat_rq_prod;
103774 -atomic_t rdma_stat_sq_poll;
103775 -atomic_t rdma_stat_sq_prod;
103776 +atomic_unchecked_t rdma_stat_recv;
103777 +atomic_unchecked_t rdma_stat_read;
103778 +atomic_unchecked_t rdma_stat_write;
103779 +atomic_unchecked_t rdma_stat_sq_starve;
103780 +atomic_unchecked_t rdma_stat_rq_starve;
103781 +atomic_unchecked_t rdma_stat_rq_poll;
103782 +atomic_unchecked_t rdma_stat_rq_prod;
103783 +atomic_unchecked_t rdma_stat_sq_poll;
103784 +atomic_unchecked_t rdma_stat_sq_prod;
103785
103786 /* Temporary NFS request map and context caches */
103787 struct kmem_cache *svc_rdma_map_cachep;
103788 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
103789 len -= *ppos;
103790 if (len > *lenp)
103791 len = *lenp;
103792 - if (len && copy_to_user(buffer, str_buf, len))
103793 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
103794 return -EFAULT;
103795 *lenp = len;
103796 *ppos += len;
103797 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
103798 {
103799 .procname = "rdma_stat_read",
103800 .data = &rdma_stat_read,
103801 - .maxlen = sizeof(atomic_t),
103802 + .maxlen = sizeof(atomic_unchecked_t),
103803 .mode = 0644,
103804 .proc_handler = read_reset_stat,
103805 },
103806 {
103807 .procname = "rdma_stat_recv",
103808 .data = &rdma_stat_recv,
103809 - .maxlen = sizeof(atomic_t),
103810 + .maxlen = sizeof(atomic_unchecked_t),
103811 .mode = 0644,
103812 .proc_handler = read_reset_stat,
103813 },
103814 {
103815 .procname = "rdma_stat_write",
103816 .data = &rdma_stat_write,
103817 - .maxlen = sizeof(atomic_t),
103818 + .maxlen = sizeof(atomic_unchecked_t),
103819 .mode = 0644,
103820 .proc_handler = read_reset_stat,
103821 },
103822 {
103823 .procname = "rdma_stat_sq_starve",
103824 .data = &rdma_stat_sq_starve,
103825 - .maxlen = sizeof(atomic_t),
103826 + .maxlen = sizeof(atomic_unchecked_t),
103827 .mode = 0644,
103828 .proc_handler = read_reset_stat,
103829 },
103830 {
103831 .procname = "rdma_stat_rq_starve",
103832 .data = &rdma_stat_rq_starve,
103833 - .maxlen = sizeof(atomic_t),
103834 + .maxlen = sizeof(atomic_unchecked_t),
103835 .mode = 0644,
103836 .proc_handler = read_reset_stat,
103837 },
103838 {
103839 .procname = "rdma_stat_rq_poll",
103840 .data = &rdma_stat_rq_poll,
103841 - .maxlen = sizeof(atomic_t),
103842 + .maxlen = sizeof(atomic_unchecked_t),
103843 .mode = 0644,
103844 .proc_handler = read_reset_stat,
103845 },
103846 {
103847 .procname = "rdma_stat_rq_prod",
103848 .data = &rdma_stat_rq_prod,
103849 - .maxlen = sizeof(atomic_t),
103850 + .maxlen = sizeof(atomic_unchecked_t),
103851 .mode = 0644,
103852 .proc_handler = read_reset_stat,
103853 },
103854 {
103855 .procname = "rdma_stat_sq_poll",
103856 .data = &rdma_stat_sq_poll,
103857 - .maxlen = sizeof(atomic_t),
103858 + .maxlen = sizeof(atomic_unchecked_t),
103859 .mode = 0644,
103860 .proc_handler = read_reset_stat,
103861 },
103862 {
103863 .procname = "rdma_stat_sq_prod",
103864 .data = &rdma_stat_sq_prod,
103865 - .maxlen = sizeof(atomic_t),
103866 + .maxlen = sizeof(atomic_unchecked_t),
103867 .mode = 0644,
103868 .proc_handler = read_reset_stat,
103869 },
103870 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103871 index 8d904e4..b2fc727 100644
103872 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103873 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103874 @@ -504,7 +504,7 @@ next_sge:
103875 svc_rdma_put_context(ctxt, 0);
103876 goto out;
103877 }
103878 - atomic_inc(&rdma_stat_read);
103879 + atomic_inc_unchecked(&rdma_stat_read);
103880
103881 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
103882 chl_map->ch[ch_no].count -= read_wr.num_sge;
103883 @@ -607,7 +607,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
103884 dto_q);
103885 list_del_init(&ctxt->dto_q);
103886 } else {
103887 - atomic_inc(&rdma_stat_rq_starve);
103888 + atomic_inc_unchecked(&rdma_stat_rq_starve);
103889 clear_bit(XPT_DATA, &xprt->xpt_flags);
103890 ctxt = NULL;
103891 }
103892 @@ -627,7 +627,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
103893 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
103894 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
103895 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
103896 - atomic_inc(&rdma_stat_recv);
103897 + atomic_inc_unchecked(&rdma_stat_recv);
103898
103899 /* Build up the XDR from the receive buffers. */
103900 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
103901 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103902 index 7e024a5..17f13d3 100644
103903 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103904 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103905 @@ -363,7 +363,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
103906 write_wr.wr.rdma.remote_addr = to;
103907
103908 /* Post It */
103909 - atomic_inc(&rdma_stat_write);
103910 + atomic_inc_unchecked(&rdma_stat_write);
103911 if (svc_rdma_send(xprt, &write_wr))
103912 goto err;
103913 return 0;
103914 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
103915 index 25688fa..dc72003 100644
103916 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
103917 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
103918 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
103919 return;
103920
103921 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
103922 - atomic_inc(&rdma_stat_rq_poll);
103923 + atomic_inc_unchecked(&rdma_stat_rq_poll);
103924
103925 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
103926 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
103927 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
103928 }
103929
103930 if (ctxt)
103931 - atomic_inc(&rdma_stat_rq_prod);
103932 + atomic_inc_unchecked(&rdma_stat_rq_prod);
103933
103934 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
103935 /*
103936 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
103937 return;
103938
103939 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
103940 - atomic_inc(&rdma_stat_sq_poll);
103941 + atomic_inc_unchecked(&rdma_stat_sq_poll);
103942 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
103943 if (wc.status != IB_WC_SUCCESS)
103944 /* Close the transport */
103945 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
103946 }
103947
103948 if (ctxt)
103949 - atomic_inc(&rdma_stat_sq_prod);
103950 + atomic_inc_unchecked(&rdma_stat_sq_prod);
103951 }
103952
103953 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
103954 @@ -1261,7 +1261,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
103955 spin_lock_bh(&xprt->sc_lock);
103956 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
103957 spin_unlock_bh(&xprt->sc_lock);
103958 - atomic_inc(&rdma_stat_sq_starve);
103959 + atomic_inc_unchecked(&rdma_stat_sq_starve);
103960
103961 /* See if we can opportunistically reap SQ WR to make room */
103962 sq_cq_reap(xprt);
103963 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
103964 index e7000be..e3b0ba7 100644
103965 --- a/net/sysctl_net.c
103966 +++ b/net/sysctl_net.c
103967 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
103968 kgid_t root_gid = make_kgid(net->user_ns, 0);
103969
103970 /* Allow network administrator to have same access as root. */
103971 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
103972 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
103973 uid_eq(root_uid, current_euid())) {
103974 int mode = (table->mode >> 6) & 7;
103975 return (mode << 6) | (mode << 3) | mode;
103976 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
103977 index 6424372..afd36e9 100644
103978 --- a/net/tipc/subscr.c
103979 +++ b/net/tipc/subscr.c
103980 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
103981 struct tipc_subscriber *subscriber = sub->subscriber;
103982 struct kvec msg_sect;
103983
103984 - msg_sect.iov_base = (void *)&sub->evt;
103985 + msg_sect.iov_base = &sub->evt;
103986 msg_sect.iov_len = sizeof(struct tipc_event);
103987 sub->evt.event = htohl(event, sub->swap);
103988 sub->evt.found_lower = htohl(found_lower, sub->swap);
103989 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
103990 index bb7e8ba..9f444c6 100644
103991 --- a/net/unix/af_unix.c
103992 +++ b/net/unix/af_unix.c
103993 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
103994 err = -ECONNREFUSED;
103995 if (!S_ISSOCK(inode->i_mode))
103996 goto put_fail;
103997 +
103998 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
103999 + err = -EACCES;
104000 + goto put_fail;
104001 + }
104002 +
104003 u = unix_find_socket_byinode(inode);
104004 if (!u)
104005 goto put_fail;
104006 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
104007 if (u) {
104008 struct dentry *dentry;
104009 dentry = unix_sk(u)->path.dentry;
104010 +
104011 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
104012 + err = -EPERM;
104013 + sock_put(u);
104014 + goto fail;
104015 + }
104016 +
104017 if (dentry)
104018 touch_atime(&unix_sk(u)->path);
104019 } else
104020 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
104021 */
104022 err = security_path_mknod(&path, dentry, mode, 0);
104023 if (!err) {
104024 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
104025 + err = -EACCES;
104026 + goto out;
104027 + }
104028 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
104029 if (!err) {
104030 res->mnt = mntget(path.mnt);
104031 res->dentry = dget(dentry);
104032 + gr_handle_create(dentry, path.mnt);
104033 }
104034 }
104035 +out:
104036 done_path_create(&path, dentry);
104037 return err;
104038 }
104039 @@ -2344,9 +2363,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
104040 seq_puts(seq, "Num RefCount Protocol Flags Type St "
104041 "Inode Path\n");
104042 else {
104043 - struct sock *s = v;
104044 + struct sock *s = v, *peer;
104045 struct unix_sock *u = unix_sk(s);
104046 unix_state_lock(s);
104047 + peer = unix_peer(s);
104048 + unix_state_unlock(s);
104049 +
104050 + unix_state_double_lock(s, peer);
104051
104052 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
104053 s,
104054 @@ -2373,8 +2396,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
104055 }
104056 for ( ; i < len; i++)
104057 seq_putc(seq, u->addr->name->sun_path[i]);
104058 - }
104059 - unix_state_unlock(s);
104060 + } else if (peer)
104061 + seq_printf(seq, " P%lu", sock_i_ino(peer));
104062 +
104063 + unix_state_double_unlock(s, peer);
104064 seq_putc(seq, '\n');
104065 }
104066
104067 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
104068 index b3d5150..ff3a837 100644
104069 --- a/net/unix/sysctl_net_unix.c
104070 +++ b/net/unix/sysctl_net_unix.c
104071 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
104072
104073 int __net_init unix_sysctl_register(struct net *net)
104074 {
104075 - struct ctl_table *table;
104076 + ctl_table_no_const *table;
104077
104078 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
104079 if (table == NULL)
104080 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
104081 index 9b7f207..2596621 100644
104082 --- a/net/vmw_vsock/vmci_transport_notify.c
104083 +++ b/net/vmw_vsock/vmci_transport_notify.c
104084 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
104085
104086 /* Socket control packet based operations. */
104087 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
104088 - vmci_transport_notify_pkt_socket_init,
104089 - vmci_transport_notify_pkt_socket_destruct,
104090 - vmci_transport_notify_pkt_poll_in,
104091 - vmci_transport_notify_pkt_poll_out,
104092 - vmci_transport_notify_pkt_handle_pkt,
104093 - vmci_transport_notify_pkt_recv_init,
104094 - vmci_transport_notify_pkt_recv_pre_block,
104095 - vmci_transport_notify_pkt_recv_pre_dequeue,
104096 - vmci_transport_notify_pkt_recv_post_dequeue,
104097 - vmci_transport_notify_pkt_send_init,
104098 - vmci_transport_notify_pkt_send_pre_block,
104099 - vmci_transport_notify_pkt_send_pre_enqueue,
104100 - vmci_transport_notify_pkt_send_post_enqueue,
104101 - vmci_transport_notify_pkt_process_request,
104102 - vmci_transport_notify_pkt_process_negotiate,
104103 + .socket_init = vmci_transport_notify_pkt_socket_init,
104104 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
104105 + .poll_in = vmci_transport_notify_pkt_poll_in,
104106 + .poll_out = vmci_transport_notify_pkt_poll_out,
104107 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
104108 + .recv_init = vmci_transport_notify_pkt_recv_init,
104109 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
104110 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
104111 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
104112 + .send_init = vmci_transport_notify_pkt_send_init,
104113 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
104114 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
104115 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
104116 + .process_request = vmci_transport_notify_pkt_process_request,
104117 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
104118 };
104119 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
104120 index dc9c792..3089de0 100644
104121 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
104122 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
104123 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
104124
104125 /* Socket always on control packet based operations. */
104126 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
104127 - vmci_transport_notify_pkt_socket_init,
104128 - vmci_transport_notify_pkt_socket_destruct,
104129 - vmci_transport_notify_pkt_poll_in,
104130 - vmci_transport_notify_pkt_poll_out,
104131 - vmci_transport_notify_pkt_handle_pkt,
104132 - vmci_transport_notify_pkt_recv_init,
104133 - vmci_transport_notify_pkt_recv_pre_block,
104134 - vmci_transport_notify_pkt_recv_pre_dequeue,
104135 - vmci_transport_notify_pkt_recv_post_dequeue,
104136 - vmci_transport_notify_pkt_send_init,
104137 - vmci_transport_notify_pkt_send_pre_block,
104138 - vmci_transport_notify_pkt_send_pre_enqueue,
104139 - vmci_transport_notify_pkt_send_post_enqueue,
104140 - vmci_transport_notify_pkt_process_request,
104141 - vmci_transport_notify_pkt_process_negotiate,
104142 + .socket_init = vmci_transport_notify_pkt_socket_init,
104143 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
104144 + .poll_in = vmci_transport_notify_pkt_poll_in,
104145 + .poll_out = vmci_transport_notify_pkt_poll_out,
104146 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
104147 + .recv_init = vmci_transport_notify_pkt_recv_init,
104148 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
104149 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
104150 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
104151 + .send_init = vmci_transport_notify_pkt_send_init,
104152 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
104153 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
104154 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
104155 + .process_request = vmci_transport_notify_pkt_process_request,
104156 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
104157 };
104158 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
104159 index c8717c1..08539f5 100644
104160 --- a/net/wireless/wext-core.c
104161 +++ b/net/wireless/wext-core.c
104162 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
104163 */
104164
104165 /* Support for very large requests */
104166 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
104167 - (user_length > descr->max_tokens)) {
104168 + if (user_length > descr->max_tokens) {
104169 /* Allow userspace to GET more than max so
104170 * we can support any size GET requests.
104171 * There is still a limit : -ENOMEM.
104172 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
104173 }
104174 }
104175
104176 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
104177 - /*
104178 - * If this is a GET, but not NOMAX, it means that the extra
104179 - * data is not bounded by userspace, but by max_tokens. Thus
104180 - * set the length to max_tokens. This matches the extra data
104181 - * allocation.
104182 - * The driver should fill it with the number of tokens it
104183 - * provided, and it may check iwp->length rather than having
104184 - * knowledge of max_tokens. If the driver doesn't change the
104185 - * iwp->length, this ioctl just copies back max_token tokens
104186 - * filled with zeroes. Hopefully the driver isn't claiming
104187 - * them to be valid data.
104188 - */
104189 - iwp->length = descr->max_tokens;
104190 - }
104191 -
104192 err = handler(dev, info, (union iwreq_data *) iwp, extra);
104193
104194 iwp->length += essid_compat;
104195 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
104196 index 4323952..a06dfe1 100644
104197 --- a/net/x25/sysctl_net_x25.c
104198 +++ b/net/x25/sysctl_net_x25.c
104199 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
104200 .mode = 0644,
104201 .proc_handler = proc_dointvec,
104202 },
104203 - { 0, },
104204 + { },
104205 };
104206
104207 void __init x25_register_sysctl(void)
104208 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
104209 index 0917f04..f4e3d8c 100644
104210 --- a/net/x25/x25_proc.c
104211 +++ b/net/x25/x25_proc.c
104212 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
104213
104214 int __init x25_proc_init(void)
104215 {
104216 - if (!proc_mkdir("x25", init_net.proc_net))
104217 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
104218 return -ENOMEM;
104219
104220 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
104221 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
104222 index c08fbd1..3d99e85 100644
104223 --- a/net/xfrm/xfrm_policy.c
104224 +++ b/net/xfrm/xfrm_policy.c
104225 @@ -325,7 +325,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
104226 {
104227 policy->walk.dead = 1;
104228
104229 - atomic_inc(&policy->genid);
104230 + atomic_inc_unchecked(&policy->genid);
104231
104232 if (del_timer(&policy->polq.hold_timer))
104233 xfrm_pol_put(policy);
104234 @@ -659,7 +659,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
104235 hlist_add_head(&policy->bydst, chain);
104236 xfrm_pol_hold(policy);
104237 net->xfrm.policy_count[dir]++;
104238 - atomic_inc(&net->xfrm.flow_cache_genid);
104239 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
104240
104241 /* After previous checking, family can either be AF_INET or AF_INET6 */
104242 if (policy->family == AF_INET)
104243 @@ -1759,7 +1759,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
104244
104245 xdst->num_pols = num_pols;
104246 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
104247 - xdst->policy_genid = atomic_read(&pols[0]->genid);
104248 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
104249
104250 return xdst;
104251 }
104252 @@ -2546,10 +2546,11 @@ void xfrm_garbage_collect(struct net *net)
104253 }
104254 EXPORT_SYMBOL(xfrm_garbage_collect);
104255
104256 -static void xfrm_garbage_collect_deferred(struct net *net)
104257 +void xfrm_garbage_collect_deferred(struct net *net)
104258 {
104259 flow_cache_flush_deferred(net);
104260 }
104261 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
104262
104263 static void xfrm_init_pmtu(struct dst_entry *dst)
104264 {
104265 @@ -2599,7 +2600,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
104266 if (xdst->xfrm_genid != dst->xfrm->genid)
104267 return 0;
104268 if (xdst->num_pols > 0 &&
104269 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
104270 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
104271 return 0;
104272
104273 mtu = dst_mtu(dst->child);
104274 @@ -2687,8 +2688,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
104275 dst_ops->link_failure = xfrm_link_failure;
104276 if (likely(dst_ops->neigh_lookup == NULL))
104277 dst_ops->neigh_lookup = xfrm_neigh_lookup;
104278 - if (likely(afinfo->garbage_collect == NULL))
104279 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
104280 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
104281 }
104282 spin_unlock(&xfrm_policy_afinfo_lock);
104283 @@ -2742,7 +2741,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
104284 dst_ops->check = NULL;
104285 dst_ops->negative_advice = NULL;
104286 dst_ops->link_failure = NULL;
104287 - afinfo->garbage_collect = NULL;
104288 }
104289 return err;
104290 }
104291 @@ -3137,7 +3135,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
104292 sizeof(pol->xfrm_vec[i].saddr));
104293 pol->xfrm_vec[i].encap_family = mp->new_family;
104294 /* flush bundles */
104295 - atomic_inc(&pol->genid);
104296 + atomic_inc_unchecked(&pol->genid);
104297 }
104298 }
104299
104300 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
104301 index 8e9c781..3972135 100644
104302 --- a/net/xfrm/xfrm_state.c
104303 +++ b/net/xfrm/xfrm_state.c
104304 @@ -173,12 +173,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
104305
104306 if (unlikely(afinfo == NULL))
104307 return -EAFNOSUPPORT;
104308 - typemap = afinfo->type_map;
104309 + typemap = (const struct xfrm_type **)afinfo->type_map;
104310 spin_lock_bh(&xfrm_type_lock);
104311
104312 - if (likely(typemap[type->proto] == NULL))
104313 + if (likely(typemap[type->proto] == NULL)) {
104314 + pax_open_kernel();
104315 typemap[type->proto] = type;
104316 - else
104317 + pax_close_kernel();
104318 + } else
104319 err = -EEXIST;
104320 spin_unlock_bh(&xfrm_type_lock);
104321 xfrm_state_put_afinfo(afinfo);
104322 @@ -194,13 +196,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
104323
104324 if (unlikely(afinfo == NULL))
104325 return -EAFNOSUPPORT;
104326 - typemap = afinfo->type_map;
104327 + typemap = (const struct xfrm_type **)afinfo->type_map;
104328 spin_lock_bh(&xfrm_type_lock);
104329
104330 if (unlikely(typemap[type->proto] != type))
104331 err = -ENOENT;
104332 - else
104333 + else {
104334 + pax_open_kernel();
104335 typemap[type->proto] = NULL;
104336 + pax_close_kernel();
104337 + }
104338 spin_unlock_bh(&xfrm_type_lock);
104339 xfrm_state_put_afinfo(afinfo);
104340 return err;
104341 @@ -210,7 +215,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
104342 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
104343 {
104344 struct xfrm_state_afinfo *afinfo;
104345 - const struct xfrm_type **typemap;
104346 const struct xfrm_type *type;
104347 int modload_attempted = 0;
104348
104349 @@ -218,9 +222,8 @@ retry:
104350 afinfo = xfrm_state_get_afinfo(family);
104351 if (unlikely(afinfo == NULL))
104352 return NULL;
104353 - typemap = afinfo->type_map;
104354
104355 - type = typemap[proto];
104356 + type = afinfo->type_map[proto];
104357 if (unlikely(type && !try_module_get(type->owner)))
104358 type = NULL;
104359 if (!type && !modload_attempted) {
104360 @@ -254,7 +257,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
104361 return -EAFNOSUPPORT;
104362
104363 err = -EEXIST;
104364 - modemap = afinfo->mode_map;
104365 + modemap = (struct xfrm_mode **)afinfo->mode_map;
104366 spin_lock_bh(&xfrm_mode_lock);
104367 if (modemap[mode->encap])
104368 goto out;
104369 @@ -263,8 +266,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
104370 if (!try_module_get(afinfo->owner))
104371 goto out;
104372
104373 - mode->afinfo = afinfo;
104374 + pax_open_kernel();
104375 + *(const void **)&mode->afinfo = afinfo;
104376 modemap[mode->encap] = mode;
104377 + pax_close_kernel();
104378 err = 0;
104379
104380 out:
104381 @@ -288,10 +293,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
104382 return -EAFNOSUPPORT;
104383
104384 err = -ENOENT;
104385 - modemap = afinfo->mode_map;
104386 + modemap = (struct xfrm_mode **)afinfo->mode_map;
104387 spin_lock_bh(&xfrm_mode_lock);
104388 if (likely(modemap[mode->encap] == mode)) {
104389 + pax_open_kernel();
104390 modemap[mode->encap] = NULL;
104391 + pax_close_kernel();
104392 module_put(mode->afinfo->owner);
104393 err = 0;
104394 }
104395 @@ -1519,10 +1526,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
104396 u32 xfrm_get_acqseq(void)
104397 {
104398 u32 res;
104399 - static atomic_t acqseq;
104400 + static atomic_unchecked_t acqseq;
104401
104402 do {
104403 - res = atomic_inc_return(&acqseq);
104404 + res = atomic_inc_return_unchecked(&acqseq);
104405 } while (!res);
104406
104407 return res;
104408 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
104409 index 05a6e3d..6716ec9 100644
104410 --- a/net/xfrm/xfrm_sysctl.c
104411 +++ b/net/xfrm/xfrm_sysctl.c
104412 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
104413
104414 int __net_init xfrm_sysctl_init(struct net *net)
104415 {
104416 - struct ctl_table *table;
104417 + ctl_table_no_const *table;
104418
104419 __xfrm_sysctl_init(net);
104420
104421 diff --git a/scripts/Makefile b/scripts/Makefile
104422 index 1d07860..f16fc22 100644
104423 --- a/scripts/Makefile
104424 +++ b/scripts/Makefile
104425 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
104426
104427 # Let clean descend into subdirs
104428 subdir- += basic kconfig package selinux
104429 +
104430 +clean-files := randstruct.seed
104431 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
104432 index 003bc26..d5f02b0 100644
104433 --- a/scripts/Makefile.build
104434 +++ b/scripts/Makefile.build
104435 @@ -121,7 +121,7 @@ endif
104436 endif
104437
104438 # Do not include host rules unless needed
104439 -ifneq ($(hostprogs-y)$(hostprogs-m),)
104440 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
104441 include scripts/Makefile.host
104442 endif
104443
104444 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
104445 index 686cb0d..9d653bf 100644
104446 --- a/scripts/Makefile.clean
104447 +++ b/scripts/Makefile.clean
104448 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
104449 __clean-files := $(extra-y) $(always) \
104450 $(targets) $(clean-files) \
104451 $(host-progs) \
104452 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
104453 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
104454 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
104455
104456 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
104457
104458 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
104459 index 1ac414f..38575f7 100644
104460 --- a/scripts/Makefile.host
104461 +++ b/scripts/Makefile.host
104462 @@ -31,6 +31,8 @@
104463 # Note: Shared libraries consisting of C++ files are not supported
104464
104465 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
104466 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
104467 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
104468
104469 # C code
104470 # Executables compiled from a single .c file
104471 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
104472 # Shared libaries (only .c supported)
104473 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
104474 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
104475 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
104476 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
104477 # Remove .so files from "xxx-objs"
104478 host-cobjs := $(filter-out %.so,$(host-cobjs))
104479 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
104480
104481 -#Object (.o) files used by the shared libaries
104482 +# Object (.o) files used by the shared libaries
104483 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
104484 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
104485
104486 # output directory for programs/.o files
104487 # hostprogs-y := tools/build may have been specified. Retrieve directory
104488 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
104489 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
104490 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
104491 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
104492 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
104493 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
104494 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
104495 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
104496
104497 obj-dirs += $(host-objdirs)
104498 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
104499 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
104500 $(call if_changed_dep,host-cshobjs)
104501
104502 +# Compile .c file, create position independent .o file
104503 +# host-cxxshobjs -> .o
104504 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
104505 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
104506 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
104507 + $(call if_changed_dep,host-cxxshobjs)
104508 +
104509 # Link a shared library, based on position independent .o files
104510 # *.o -> .so shared library (host-cshlib)
104511 quiet_cmd_host-cshlib = HOSTLLD -shared $@
104512 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
104513 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
104514 $(call if_changed,host-cshlib)
104515
104516 +# Link a shared library, based on position independent .o files
104517 +# *.o -> .so shared library (host-cxxshlib)
104518 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
104519 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
104520 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
104521 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
104522 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
104523 + $(call if_changed,host-cxxshlib)
104524 +
104525 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
104526 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
104527 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
104528
104529 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
104530 index 078fe1d..fbdb363 100644
104531 --- a/scripts/basic/fixdep.c
104532 +++ b/scripts/basic/fixdep.c
104533 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
104534 /*
104535 * Lookup a value in the configuration string.
104536 */
104537 -static int is_defined_config(const char *name, int len, unsigned int hash)
104538 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
104539 {
104540 struct item *aux;
104541
104542 @@ -211,10 +211,10 @@ static void clear_config(void)
104543 /*
104544 * Record the use of a CONFIG_* word.
104545 */
104546 -static void use_config(const char *m, int slen)
104547 +static void use_config(const char *m, unsigned int slen)
104548 {
104549 unsigned int hash = strhash(m, slen);
104550 - int c, i;
104551 + unsigned int c, i;
104552
104553 if (is_defined_config(m, slen, hash))
104554 return;
104555 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
104556
104557 static void parse_config_file(const char *map, size_t len)
104558 {
104559 - const int *end = (const int *) (map + len);
104560 + const unsigned int *end = (const unsigned int *) (map + len);
104561 /* start at +1, so that p can never be < map */
104562 - const int *m = (const int *) map + 1;
104563 + const unsigned int *m = (const unsigned int *) map + 1;
104564 const char *p, *q;
104565
104566 for (; m < end; m++) {
104567 @@ -435,7 +435,7 @@ static void print_deps(void)
104568 static void traps(void)
104569 {
104570 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
104571 - int *p = (int *)test;
104572 + unsigned int *p = (unsigned int *)test;
104573
104574 if (*p != INT_CONF) {
104575 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
104576 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
104577 new file mode 100644
104578 index 0000000..3fd3699
104579 --- /dev/null
104580 +++ b/scripts/gcc-plugin.sh
104581 @@ -0,0 +1,43 @@
104582 +#!/bin/bash
104583 +srctree=$(dirname "$0")
104584 +gccplugins_dir=$($3 -print-file-name=plugin)
104585 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
104586 +#include "gcc-common.h"
104587 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
104588 +#warning $2 CXX
104589 +#else
104590 +#warning $1 CC
104591 +#endif
104592 +EOF
104593 +)
104594 +
104595 +if [ $? -ne 0 ]
104596 +then
104597 + exit 1
104598 +fi
104599 +
104600 +if [[ "$plugincc" =~ "$1 CC" ]]
104601 +then
104602 + echo "$1"
104603 + exit 0
104604 +fi
104605 +
104606 +if [[ "$plugincc" =~ "$2 CXX" ]]
104607 +then
104608 +plugincc=$($1 -c -x c++ -std=gnu++98 - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
104609 +#include "gcc-common.h"
104610 +class test {
104611 +public:
104612 + int test;
104613 +} test = {
104614 + .test = 1
104615 +};
104616 +EOF
104617 +)
104618 +if [ $? -eq 0 ]
104619 +then
104620 + echo "$2"
104621 + exit 0
104622 +fi
104623 +fi
104624 +exit 1
104625 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
104626 index 5de5660..d3deb89 100644
104627 --- a/scripts/headers_install.sh
104628 +++ b/scripts/headers_install.sh
104629 @@ -32,6 +32,7 @@ do
104630 FILE="$(basename "$i")"
104631 sed -r \
104632 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
104633 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
104634 -e 's/__attribute_const__([ \t]|$)/\1/g' \
104635 -e 's@^#include <linux/compiler.h>@@' \
104636 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
104637 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
104638 index 86a4fe7..99e91f9 100644
104639 --- a/scripts/link-vmlinux.sh
104640 +++ b/scripts/link-vmlinux.sh
104641 @@ -166,7 +166,7 @@ else
104642 fi;
104643
104644 # final build of init/
104645 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
104646 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
104647
104648 kallsymso=""
104649 kallsyms_vmlinux=""
104650 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
104651 index 1924990..3de7363 100644
104652 --- a/scripts/mod/file2alias.c
104653 +++ b/scripts/mod/file2alias.c
104654 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
104655 unsigned long size, unsigned long id_size,
104656 void *symval)
104657 {
104658 - int i;
104659 + unsigned int i;
104660
104661 if (size % id_size || size < id_size) {
104662 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
104663 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
104664 /* USB is special because the bcdDevice can be matched against a numeric range */
104665 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
104666 static void do_usb_entry(void *symval,
104667 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
104668 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
104669 unsigned char range_lo, unsigned char range_hi,
104670 unsigned char max, struct module *mod)
104671 {
104672 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
104673 {
104674 unsigned int devlo, devhi;
104675 unsigned char chi, clo, max;
104676 - int ndigits;
104677 + unsigned int ndigits;
104678
104679 DEF_FIELD(symval, usb_device_id, match_flags);
104680 DEF_FIELD(symval, usb_device_id, idVendor);
104681 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
104682 for (i = 0; i < count; i++) {
104683 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
104684 char acpi_id[sizeof(*id)];
104685 - int j;
104686 + unsigned int j;
104687
104688 buf_printf(&mod->dev_table_buf,
104689 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
104690 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
104691
104692 for (j = 0; j < PNP_MAX_DEVICES; j++) {
104693 const char *id = (char *)(*devs)[j].id;
104694 - int i2, j2;
104695 + unsigned int i2, j2;
104696 int dup = 0;
104697
104698 if (!id[0])
104699 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
104700 /* add an individual alias for every device entry */
104701 if (!dup) {
104702 char acpi_id[PNP_ID_LEN];
104703 - int k;
104704 + unsigned int k;
104705
104706 buf_printf(&mod->dev_table_buf,
104707 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
104708 @@ -941,7 +941,7 @@ static void dmi_ascii_filter(char *d, const char *s)
104709 static int do_dmi_entry(const char *filename, void *symval,
104710 char *alias)
104711 {
104712 - int i, j;
104713 + unsigned int i, j;
104714 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
104715 sprintf(alias, "dmi*");
104716
104717 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
104718 index 0663556..d9494f0 100644
104719 --- a/scripts/mod/modpost.c
104720 +++ b/scripts/mod/modpost.c
104721 @@ -949,6 +949,7 @@ enum mismatch {
104722 ANY_INIT_TO_ANY_EXIT,
104723 ANY_EXIT_TO_ANY_INIT,
104724 EXPORT_TO_INIT_EXIT,
104725 + DATA_TO_TEXT
104726 };
104727
104728 struct sectioncheck {
104729 @@ -1035,6 +1036,12 @@ const struct sectioncheck sectioncheck[] = {
104730 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
104731 .mismatch = EXPORT_TO_INIT_EXIT,
104732 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
104733 +},
104734 +/* Do not reference code from writable data */
104735 +{
104736 + .fromsec = { DATA_SECTIONS, NULL },
104737 + .tosec = { TEXT_SECTIONS, NULL },
104738 + .mismatch = DATA_TO_TEXT
104739 }
104740 };
104741
104742 @@ -1155,10 +1162,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
104743 continue;
104744 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
104745 continue;
104746 - if (sym->st_value == addr)
104747 - return sym;
104748 /* Find a symbol nearby - addr are maybe negative */
104749 d = sym->st_value - addr;
104750 + if (d == 0)
104751 + return sym;
104752 if (d < 0)
104753 d = addr - sym->st_value;
104754 if (d < distance) {
104755 @@ -1436,6 +1443,14 @@ static void report_sec_mismatch(const char *modname,
104756 tosym, prl_to, prl_to, tosym);
104757 free(prl_to);
104758 break;
104759 + case DATA_TO_TEXT:
104760 +#if 0
104761 + fprintf(stderr,
104762 + "The %s %s:%s references\n"
104763 + "the %s %s:%s%s\n",
104764 + from, fromsec, fromsym, to, tosec, tosym, to_p);
104765 +#endif
104766 + break;
104767 }
104768 fprintf(stderr, "\n");
104769 }
104770 @@ -1687,7 +1702,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
104771 static void check_sec_ref(struct module *mod, const char *modname,
104772 struct elf_info *elf)
104773 {
104774 - int i;
104775 + unsigned int i;
104776 Elf_Shdr *sechdrs = elf->sechdrs;
104777
104778 /* Walk through all sections */
104779 @@ -1819,7 +1834,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
104780 va_end(ap);
104781 }
104782
104783 -void buf_write(struct buffer *buf, const char *s, int len)
104784 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
104785 {
104786 if (buf->size - buf->pos < len) {
104787 buf->size += len + SZ;
104788 @@ -2038,7 +2053,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
104789 if (fstat(fileno(file), &st) < 0)
104790 goto close_write;
104791
104792 - if (st.st_size != b->pos)
104793 + if (st.st_size != (off_t)b->pos)
104794 goto close_write;
104795
104796 tmp = NOFAIL(malloc(b->pos));
104797 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
104798 index 168b43d..77914bf 100644
104799 --- a/scripts/mod/modpost.h
104800 +++ b/scripts/mod/modpost.h
104801 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
104802
104803 struct buffer {
104804 char *p;
104805 - int pos;
104806 - int size;
104807 + unsigned int pos;
104808 + unsigned int size;
104809 };
104810
104811 void __attribute__((format(printf, 2, 3)))
104812 buf_printf(struct buffer *buf, const char *fmt, ...);
104813
104814 void
104815 -buf_write(struct buffer *buf, const char *s, int len);
104816 +buf_write(struct buffer *buf, const char *s, unsigned int len);
104817
104818 struct module {
104819 struct module *next;
104820 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
104821 index deb2994..af4f63e 100644
104822 --- a/scripts/mod/sumversion.c
104823 +++ b/scripts/mod/sumversion.c
104824 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
104825 goto out;
104826 }
104827
104828 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
104829 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
104830 warn("writing sum in %s failed: %s\n",
104831 filename, strerror(errno));
104832 goto out;
104833 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
104834 index 0865b3e..7235dd4 100644
104835 --- a/scripts/module-common.lds
104836 +++ b/scripts/module-common.lds
104837 @@ -6,6 +6,10 @@
104838 SECTIONS {
104839 /DISCARD/ : { *(.discard) }
104840
104841 + .rodata : {
104842 + *(.rodata) *(.rodata.*)
104843 + *(.data..read_only)
104844 + }
104845 __ksymtab : { *(SORT(___ksymtab+*)) }
104846 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
104847 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
104848 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
104849 index 152d4d2..791684c 100644
104850 --- a/scripts/package/builddeb
104851 +++ b/scripts/package/builddeb
104852 @@ -291,6 +291,7 @@ fi
104853 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
104854 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
104855 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
104856 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
104857 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
104858 mkdir -p "$destdir"
104859 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
104860 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
104861 index 68bb4ef..2f419e1 100644
104862 --- a/scripts/pnmtologo.c
104863 +++ b/scripts/pnmtologo.c
104864 @@ -244,14 +244,14 @@ static void write_header(void)
104865 fprintf(out, " * Linux logo %s\n", logoname);
104866 fputs(" */\n\n", out);
104867 fputs("#include <linux/linux_logo.h>\n\n", out);
104868 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
104869 + fprintf(out, "static unsigned char %s_data[] = {\n",
104870 logoname);
104871 }
104872
104873 static void write_footer(void)
104874 {
104875 fputs("\n};\n\n", out);
104876 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
104877 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
104878 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
104879 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
104880 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
104881 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
104882 fputs("\n};\n\n", out);
104883
104884 /* write logo clut */
104885 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
104886 + fprintf(out, "static unsigned char %s_clut[] = {\n",
104887 logoname);
104888 write_hex_cnt = 0;
104889 for (i = 0; i < logo_clutsize; i++) {
104890 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
104891 index 8fac3fd..32ff38d 100644
104892 --- a/scripts/sortextable.h
104893 +++ b/scripts/sortextable.h
104894 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
104895 const char *secstrtab;
104896 const char *strtab;
104897 char *extab_image;
104898 - int extab_index = 0;
104899 - int i;
104900 - int idx;
104901 + unsigned int extab_index = 0;
104902 + unsigned int i;
104903 + unsigned int idx;
104904 unsigned int num_sections;
104905 unsigned int secindex_strings;
104906
104907 diff --git a/security/Kconfig b/security/Kconfig
104908 index beb86b5..40b1edb 100644
104909 --- a/security/Kconfig
104910 +++ b/security/Kconfig
104911 @@ -4,6 +4,957 @@
104912
104913 menu "Security options"
104914
104915 +menu "Grsecurity"
104916 +
104917 + config ARCH_TRACK_EXEC_LIMIT
104918 + bool
104919 +
104920 + config PAX_KERNEXEC_PLUGIN
104921 + bool
104922 +
104923 + config PAX_PER_CPU_PGD
104924 + bool
104925 +
104926 + config TASK_SIZE_MAX_SHIFT
104927 + int
104928 + depends on X86_64
104929 + default 47 if !PAX_PER_CPU_PGD
104930 + default 42 if PAX_PER_CPU_PGD
104931 +
104932 + config PAX_ENABLE_PAE
104933 + bool
104934 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
104935 +
104936 + config PAX_USERCOPY_SLABS
104937 + bool
104938 +
104939 +config GRKERNSEC
104940 + bool "Grsecurity"
104941 + select CRYPTO
104942 + select CRYPTO_SHA256
104943 + select PROC_FS
104944 + select STOP_MACHINE
104945 + select TTY
104946 + select DEBUG_KERNEL
104947 + select DEBUG_LIST
104948 + help
104949 + If you say Y here, you will be able to configure many features
104950 + that will enhance the security of your system. It is highly
104951 + recommended that you say Y here and read through the help
104952 + for each option so that you fully understand the features and
104953 + can evaluate their usefulness for your machine.
104954 +
104955 +choice
104956 + prompt "Configuration Method"
104957 + depends on GRKERNSEC
104958 + default GRKERNSEC_CONFIG_CUSTOM
104959 + help
104960 +
104961 +config GRKERNSEC_CONFIG_AUTO
104962 + bool "Automatic"
104963 + help
104964 + If you choose this configuration method, you'll be able to answer a small
104965 + number of simple questions about how you plan to use this kernel.
104966 + The settings of grsecurity and PaX will be automatically configured for
104967 + the highest commonly-used settings within the provided constraints.
104968 +
104969 + If you require additional configuration, custom changes can still be made
104970 + from the "custom configuration" menu.
104971 +
104972 +config GRKERNSEC_CONFIG_CUSTOM
104973 + bool "Custom"
104974 + help
104975 + If you choose this configuration method, you'll be able to configure all
104976 + grsecurity and PaX settings manually. Via this method, no options are
104977 + automatically enabled.
104978 +
104979 +endchoice
104980 +
104981 +choice
104982 + prompt "Usage Type"
104983 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
104984 + default GRKERNSEC_CONFIG_SERVER
104985 + help
104986 +
104987 +config GRKERNSEC_CONFIG_SERVER
104988 + bool "Server"
104989 + help
104990 + Choose this option if you plan to use this kernel on a server.
104991 +
104992 +config GRKERNSEC_CONFIG_DESKTOP
104993 + bool "Desktop"
104994 + help
104995 + Choose this option if you plan to use this kernel on a desktop.
104996 +
104997 +endchoice
104998 +
104999 +choice
105000 + prompt "Virtualization Type"
105001 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
105002 + default GRKERNSEC_CONFIG_VIRT_NONE
105003 + help
105004 +
105005 +config GRKERNSEC_CONFIG_VIRT_NONE
105006 + bool "None"
105007 + help
105008 + Choose this option if this kernel will be run on bare metal.
105009 +
105010 +config GRKERNSEC_CONFIG_VIRT_GUEST
105011 + bool "Guest"
105012 + help
105013 + Choose this option if this kernel will be run as a VM guest.
105014 +
105015 +config GRKERNSEC_CONFIG_VIRT_HOST
105016 + bool "Host"
105017 + help
105018 + Choose this option if this kernel will be run as a VM host.
105019 +
105020 +endchoice
105021 +
105022 +choice
105023 + prompt "Virtualization Hardware"
105024 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
105025 + help
105026 +
105027 +config GRKERNSEC_CONFIG_VIRT_EPT
105028 + bool "EPT/RVI Processor Support"
105029 + depends on X86
105030 + help
105031 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
105032 + hardware virtualization. This allows for additional kernel hardening protections
105033 + to operate without additional performance impact.
105034 +
105035 + To see if your Intel processor supports EPT, see:
105036 + http://ark.intel.com/Products/VirtualizationTechnology
105037 + (Most Core i3/5/7 support EPT)
105038 +
105039 + To see if your AMD processor supports RVI, see:
105040 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
105041 +
105042 +config GRKERNSEC_CONFIG_VIRT_SOFT
105043 + bool "First-gen/No Hardware Virtualization"
105044 + help
105045 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
105046 + support hardware virtualization or doesn't support the EPT/RVI extensions.
105047 +
105048 +endchoice
105049 +
105050 +choice
105051 + prompt "Virtualization Software"
105052 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
105053 + help
105054 +
105055 +config GRKERNSEC_CONFIG_VIRT_XEN
105056 + bool "Xen"
105057 + help
105058 + Choose this option if this kernel is running as a Xen guest or host.
105059 +
105060 +config GRKERNSEC_CONFIG_VIRT_VMWARE
105061 + bool "VMWare"
105062 + help
105063 + Choose this option if this kernel is running as a VMWare guest or host.
105064 +
105065 +config GRKERNSEC_CONFIG_VIRT_KVM
105066 + bool "KVM"
105067 + help
105068 + Choose this option if this kernel is running as a KVM guest or host.
105069 +
105070 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
105071 + bool "VirtualBox"
105072 + help
105073 + Choose this option if this kernel is running as a VirtualBox guest or host.
105074 +
105075 +endchoice
105076 +
105077 +choice
105078 + prompt "Required Priorities"
105079 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
105080 + default GRKERNSEC_CONFIG_PRIORITY_PERF
105081 + help
105082 +
105083 +config GRKERNSEC_CONFIG_PRIORITY_PERF
105084 + bool "Performance"
105085 + help
105086 + Choose this option if performance is of highest priority for this deployment
105087 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
105088 + clearing of structures intended for userland, and freed memory sanitizing will
105089 + be disabled.
105090 +
105091 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
105092 + bool "Security"
105093 + help
105094 + Choose this option if security is of highest priority for this deployment of
105095 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
105096 + for userland, and freed memory sanitizing will be enabled for this kernel.
105097 + In a worst-case scenario, these features can introduce a 20% performance hit
105098 + (UDEREF on x64 contributing half of this hit).
105099 +
105100 +endchoice
105101 +
105102 +menu "Default Special Groups"
105103 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
105104 +
105105 +config GRKERNSEC_PROC_GID
105106 + int "GID exempted from /proc restrictions"
105107 + default 1001
105108 + help
105109 + Setting this GID determines which group will be exempted from
105110 + grsecurity's /proc restrictions, allowing users of the specified
105111 + group to view network statistics and the existence of other users'
105112 + processes on the system. This GID may also be chosen at boot time
105113 + via "grsec_proc_gid=" on the kernel commandline.
105114 +
105115 +config GRKERNSEC_TPE_UNTRUSTED_GID
105116 + int "GID for TPE-untrusted users"
105117 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
105118 + default 1005
105119 + help
105120 + Setting this GID determines which group untrusted users should
105121 + be added to. These users will be placed under grsecurity's Trusted Path
105122 + Execution mechanism, preventing them from executing their own binaries.
105123 + The users will only be able to execute binaries in directories owned and
105124 + writable only by the root user. If the sysctl option is enabled, a sysctl
105125 + option with name "tpe_gid" is created.
105126 +
105127 +config GRKERNSEC_TPE_TRUSTED_GID
105128 + int "GID for TPE-trusted users"
105129 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
105130 + default 1005
105131 + help
105132 + Setting this GID determines what group TPE restrictions will be
105133 + *disabled* for. If the sysctl option is enabled, a sysctl option
105134 + with name "tpe_gid" is created.
105135 +
105136 +config GRKERNSEC_SYMLINKOWN_GID
105137 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
105138 + depends on GRKERNSEC_CONFIG_SERVER
105139 + default 1006
105140 + help
105141 + Setting this GID determines what group kernel-enforced
105142 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
105143 + is enabled, a sysctl option with name "symlinkown_gid" is created.
105144 +
105145 +
105146 +endmenu
105147 +
105148 +menu "Customize Configuration"
105149 +depends on GRKERNSEC
105150 +
105151 +menu "PaX"
105152 +
105153 +config PAX
105154 + bool "Enable various PaX features"
105155 + default y if GRKERNSEC_CONFIG_AUTO
105156 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
105157 + help
105158 + This allows you to enable various PaX features. PaX adds
105159 + intrusion prevention mechanisms to the kernel that reduce
105160 + the risks posed by exploitable memory corruption bugs.
105161 +
105162 +menu "PaX Control"
105163 + depends on PAX
105164 +
105165 +config PAX_SOFTMODE
105166 + bool 'Support soft mode'
105167 + help
105168 + Enabling this option will allow you to run PaX in soft mode, that
105169 + is, PaX features will not be enforced by default, only on executables
105170 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
105171 + support as they are the only way to mark executables for soft mode use.
105172 +
105173 + Soft mode can be activated by using the "pax_softmode=1" kernel command
105174 + line option on boot. Furthermore you can control various PaX features
105175 + at runtime via the entries in /proc/sys/kernel/pax.
105176 +
105177 +config PAX_EI_PAX
105178 + bool 'Use legacy ELF header marking'
105179 + default y if GRKERNSEC_CONFIG_AUTO
105180 + help
105181 + Enabling this option will allow you to control PaX features on
105182 + a per executable basis via the 'chpax' utility available at
105183 + http://pax.grsecurity.net/. The control flags will be read from
105184 + an otherwise reserved part of the ELF header. This marking has
105185 + numerous drawbacks (no support for soft-mode, toolchain does not
105186 + know about the non-standard use of the ELF header) therefore it
105187 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
105188 + support.
105189 +
105190 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
105191 + support as well, they will override the legacy EI_PAX marks.
105192 +
105193 + If you enable none of the marking options then all applications
105194 + will run with PaX enabled on them by default.
105195 +
105196 +config PAX_PT_PAX_FLAGS
105197 + bool 'Use ELF program header marking'
105198 + default y if GRKERNSEC_CONFIG_AUTO
105199 + help
105200 + Enabling this option will allow you to control PaX features on
105201 + a per executable basis via the 'paxctl' utility available at
105202 + http://pax.grsecurity.net/. The control flags will be read from
105203 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
105204 + has the benefits of supporting both soft mode and being fully
105205 + integrated into the toolchain (the binutils patch is available
105206 + from http://pax.grsecurity.net).
105207 +
105208 + Note that if you enable the legacy EI_PAX marking support as well,
105209 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
105210 +
105211 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
105212 + must make sure that the marks are the same if a binary has both marks.
105213 +
105214 + If you enable none of the marking options then all applications
105215 + will run with PaX enabled on them by default.
105216 +
105217 +config PAX_XATTR_PAX_FLAGS
105218 + bool 'Use filesystem extended attributes marking'
105219 + default y if GRKERNSEC_CONFIG_AUTO
105220 + select CIFS_XATTR if CIFS
105221 + select F2FS_FS_XATTR if F2FS_FS
105222 + select EXT2_FS_XATTR if EXT2_FS
105223 + select EXT3_FS_XATTR if EXT3_FS
105224 + select JFFS2_FS_XATTR if JFFS2_FS
105225 + select REISERFS_FS_XATTR if REISERFS_FS
105226 + select SQUASHFS_XATTR if SQUASHFS
105227 + select TMPFS_XATTR if TMPFS
105228 + help
105229 + Enabling this option will allow you to control PaX features on
105230 + a per executable basis via the 'setfattr' utility. The control
105231 + flags will be read from the user.pax.flags extended attribute of
105232 + the file. This marking has the benefit of supporting binary-only
105233 + applications that self-check themselves (e.g., skype) and would
105234 + not tolerate chpax/paxctl changes. The main drawback is that
105235 + extended attributes are not supported by some filesystems (e.g.,
105236 + isofs, udf, vfat) so copying files through such filesystems will
105237 + lose the extended attributes and these PaX markings.
105238 +
105239 + Note that if you enable the legacy EI_PAX marking support as well,
105240 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
105241 +
105242 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
105243 + must make sure that the marks are the same if a binary has both marks.
105244 +
105245 + If you enable none of the marking options then all applications
105246 + will run with PaX enabled on them by default.
105247 +
105248 +choice
105249 + prompt 'MAC system integration'
105250 + default PAX_HAVE_ACL_FLAGS
105251 + help
105252 + Mandatory Access Control systems have the option of controlling
105253 + PaX flags on a per executable basis, choose the method supported
105254 + by your particular system.
105255 +
105256 + - "none": if your MAC system does not interact with PaX,
105257 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
105258 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
105259 +
105260 + NOTE: this option is for developers/integrators only.
105261 +
105262 + config PAX_NO_ACL_FLAGS
105263 + bool 'none'
105264 +
105265 + config PAX_HAVE_ACL_FLAGS
105266 + bool 'direct'
105267 +
105268 + config PAX_HOOK_ACL_FLAGS
105269 + bool 'hook'
105270 +endchoice
105271 +
105272 +endmenu
105273 +
105274 +menu "Non-executable pages"
105275 + depends on PAX
105276 +
105277 +config PAX_NOEXEC
105278 + bool "Enforce non-executable pages"
105279 + default y if GRKERNSEC_CONFIG_AUTO
105280 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
105281 + help
105282 + By design some architectures do not allow for protecting memory
105283 + pages against execution or even if they do, Linux does not make
105284 + use of this feature. In practice this means that if a page is
105285 + readable (such as the stack or heap) it is also executable.
105286 +
105287 + There is a well known exploit technique that makes use of this
105288 + fact and a common programming mistake where an attacker can
105289 + introduce code of his choice somewhere in the attacked program's
105290 + memory (typically the stack or the heap) and then execute it.
105291 +
105292 + If the attacked program was running with different (typically
105293 + higher) privileges than that of the attacker, then he can elevate
105294 + his own privilege level (e.g. get a root shell, write to files for
105295 + which he does not have write access to, etc).
105296 +
105297 + Enabling this option will let you choose from various features
105298 + that prevent the injection and execution of 'foreign' code in
105299 + a program.
105300 +
105301 + This will also break programs that rely on the old behaviour and
105302 + expect that dynamically allocated memory via the malloc() family
105303 + of functions is executable (which it is not). Notable examples
105304 + are the XFree86 4.x server, the java runtime and wine.
105305 +
105306 +config PAX_PAGEEXEC
105307 + bool "Paging based non-executable pages"
105308 + default y if GRKERNSEC_CONFIG_AUTO
105309 + 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)
105310 + select ARCH_TRACK_EXEC_LIMIT if X86_32
105311 + help
105312 + This implementation is based on the paging feature of the CPU.
105313 + On i386 without hardware non-executable bit support there is a
105314 + variable but usually low performance impact, however on Intel's
105315 + P4 core based CPUs it is very high so you should not enable this
105316 + for kernels meant to be used on such CPUs.
105317 +
105318 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
105319 + with hardware non-executable bit support there is no performance
105320 + impact, on ppc the impact is negligible.
105321 +
105322 + Note that several architectures require various emulations due to
105323 + badly designed userland ABIs, this will cause a performance impact
105324 + but will disappear as soon as userland is fixed. For example, ppc
105325 + userland MUST have been built with secure-plt by a recent toolchain.
105326 +
105327 +config PAX_SEGMEXEC
105328 + bool "Segmentation based non-executable pages"
105329 + default y if GRKERNSEC_CONFIG_AUTO
105330 + depends on PAX_NOEXEC && X86_32
105331 + help
105332 + This implementation is based on the segmentation feature of the
105333 + CPU and has a very small performance impact, however applications
105334 + will be limited to a 1.5 GB address space instead of the normal
105335 + 3 GB.
105336 +
105337 +config PAX_EMUTRAMP
105338 + bool "Emulate trampolines"
105339 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
105340 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
105341 + help
105342 + There are some programs and libraries that for one reason or
105343 + another attempt to execute special small code snippets from
105344 + non-executable memory pages. Most notable examples are the
105345 + signal handler return code generated by the kernel itself and
105346 + the GCC trampolines.
105347 +
105348 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
105349 + such programs will no longer work under your kernel.
105350 +
105351 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
105352 + utilities to enable trampoline emulation for the affected programs
105353 + yet still have the protection provided by the non-executable pages.
105354 +
105355 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
105356 + your system will not even boot.
105357 +
105358 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
105359 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
105360 + for the affected files.
105361 +
105362 + NOTE: enabling this feature *may* open up a loophole in the
105363 + protection provided by non-executable pages that an attacker
105364 + could abuse. Therefore the best solution is to not have any
105365 + files on your system that would require this option. This can
105366 + be achieved by not using libc5 (which relies on the kernel
105367 + signal handler return code) and not using or rewriting programs
105368 + that make use of the nested function implementation of GCC.
105369 + Skilled users can just fix GCC itself so that it implements
105370 + nested function calls in a way that does not interfere with PaX.
105371 +
105372 +config PAX_EMUSIGRT
105373 + bool "Automatically emulate sigreturn trampolines"
105374 + depends on PAX_EMUTRAMP && PARISC
105375 + default y
105376 + help
105377 + Enabling this option will have the kernel automatically detect
105378 + and emulate signal return trampolines executing on the stack
105379 + that would otherwise lead to task termination.
105380 +
105381 + This solution is intended as a temporary one for users with
105382 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
105383 + Modula-3 runtime, etc) or executables linked to such, basically
105384 + everything that does not specify its own SA_RESTORER function in
105385 + normal executable memory like glibc 2.1+ does.
105386 +
105387 + On parisc you MUST enable this option, otherwise your system will
105388 + not even boot.
105389 +
105390 + NOTE: this feature cannot be disabled on a per executable basis
105391 + and since it *does* open up a loophole in the protection provided
105392 + by non-executable pages, the best solution is to not have any
105393 + files on your system that would require this option.
105394 +
105395 +config PAX_MPROTECT
105396 + bool "Restrict mprotect()"
105397 + default y if GRKERNSEC_CONFIG_AUTO
105398 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
105399 + help
105400 + Enabling this option will prevent programs from
105401 + - changing the executable status of memory pages that were
105402 + not originally created as executable,
105403 + - making read-only executable pages writable again,
105404 + - creating executable pages from anonymous memory,
105405 + - making read-only-after-relocations (RELRO) data pages writable again.
105406 +
105407 + You should say Y here to complete the protection provided by
105408 + the enforcement of non-executable pages.
105409 +
105410 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
105411 + this feature on a per file basis.
105412 +
105413 +config PAX_MPROTECT_COMPAT
105414 + bool "Use legacy/compat protection demoting (read help)"
105415 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
105416 + depends on PAX_MPROTECT
105417 + help
105418 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
105419 + by sending the proper error code to the application. For some broken
105420 + userland, this can cause problems with Python or other applications. The
105421 + current implementation however allows for applications like clamav to
105422 + detect if JIT compilation/execution is allowed and to fall back gracefully
105423 + to an interpreter-based mode if it does not. While we encourage everyone
105424 + to use the current implementation as-is and push upstream to fix broken
105425 + userland (note that the RWX logging option can assist with this), in some
105426 + environments this may not be possible. Having to disable MPROTECT
105427 + completely on certain binaries reduces the security benefit of PaX,
105428 + so this option is provided for those environments to revert to the old
105429 + behavior.
105430 +
105431 +config PAX_ELFRELOCS
105432 + bool "Allow ELF text relocations (read help)"
105433 + depends on PAX_MPROTECT
105434 + default n
105435 + help
105436 + Non-executable pages and mprotect() restrictions are effective
105437 + in preventing the introduction of new executable code into an
105438 + attacked task's address space. There remain only two venues
105439 + for this kind of attack: if the attacker can execute already
105440 + existing code in the attacked task then he can either have it
105441 + create and mmap() a file containing his code or have it mmap()
105442 + an already existing ELF library that does not have position
105443 + independent code in it and use mprotect() on it to make it
105444 + writable and copy his code there. While protecting against
105445 + the former approach is beyond PaX, the latter can be prevented
105446 + by having only PIC ELF libraries on one's system (which do not
105447 + need to relocate their code). If you are sure this is your case,
105448 + as is the case with all modern Linux distributions, then leave
105449 + this option disabled. You should say 'n' here.
105450 +
105451 +config PAX_ETEXECRELOCS
105452 + bool "Allow ELF ET_EXEC text relocations"
105453 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
105454 + select PAX_ELFRELOCS
105455 + default y
105456 + help
105457 + On some architectures there are incorrectly created applications
105458 + that require text relocations and would not work without enabling
105459 + this option. If you are an alpha, ia64 or parisc user, you should
105460 + enable this option and disable it once you have made sure that
105461 + none of your applications need it.
105462 +
105463 +config PAX_EMUPLT
105464 + bool "Automatically emulate ELF PLT"
105465 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
105466 + default y
105467 + help
105468 + Enabling this option will have the kernel automatically detect
105469 + and emulate the Procedure Linkage Table entries in ELF files.
105470 + On some architectures such entries are in writable memory, and
105471 + become non-executable leading to task termination. Therefore
105472 + it is mandatory that you enable this option on alpha, parisc,
105473 + sparc and sparc64, otherwise your system would not even boot.
105474 +
105475 + NOTE: this feature *does* open up a loophole in the protection
105476 + provided by the non-executable pages, therefore the proper
105477 + solution is to modify the toolchain to produce a PLT that does
105478 + not need to be writable.
105479 +
105480 +config PAX_DLRESOLVE
105481 + bool 'Emulate old glibc resolver stub'
105482 + depends on PAX_EMUPLT && SPARC
105483 + default n
105484 + help
105485 + This option is needed if userland has an old glibc (before 2.4)
105486 + that puts a 'save' instruction into the runtime generated resolver
105487 + stub that needs special emulation.
105488 +
105489 +config PAX_KERNEXEC
105490 + bool "Enforce non-executable kernel pages"
105491 + 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))
105492 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
105493 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
105494 + select PAX_KERNEXEC_PLUGIN if X86_64
105495 + help
105496 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
105497 + that is, enabling this option will make it harder to inject
105498 + and execute 'foreign' code in kernel memory itself.
105499 +
105500 +choice
105501 + prompt "Return Address Instrumentation Method"
105502 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
105503 + depends on PAX_KERNEXEC_PLUGIN
105504 + help
105505 + Select the method used to instrument function pointer dereferences.
105506 + Note that binary modules cannot be instrumented by this approach.
105507 +
105508 + Note that the implementation requires a gcc with plugin support,
105509 + i.e., gcc 4.5 or newer. You may need to install the supporting
105510 + headers explicitly in addition to the normal gcc package.
105511 +
105512 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
105513 + bool "bts"
105514 + help
105515 + This method is compatible with binary only modules but has
105516 + a higher runtime overhead.
105517 +
105518 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
105519 + bool "or"
105520 + depends on !PARAVIRT
105521 + help
105522 + This method is incompatible with binary only modules but has
105523 + a lower runtime overhead.
105524 +endchoice
105525 +
105526 +config PAX_KERNEXEC_PLUGIN_METHOD
105527 + string
105528 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
105529 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
105530 + default ""
105531 +
105532 +config PAX_KERNEXEC_MODULE_TEXT
105533 + int "Minimum amount of memory reserved for module code"
105534 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
105535 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
105536 + depends on PAX_KERNEXEC && X86_32
105537 + help
105538 + Due to implementation details the kernel must reserve a fixed
105539 + amount of memory for runtime allocated code (such as modules)
105540 + at compile time that cannot be changed at runtime. Here you
105541 + can specify the minimum amount in MB that will be reserved.
105542 + Due to the same implementation details this size will always
105543 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
105544 + the actually available memory for runtime allocated code will
105545 + usually be more than this minimum.
105546 +
105547 + The default 4 MB should be enough for most users but if you have
105548 + an excessive number of modules (e.g., most distribution configs
105549 + compile many drivers as modules) or use huge modules such as
105550 + nvidia's kernel driver, you will need to adjust this amount.
105551 + A good rule of thumb is to look at your currently loaded kernel
105552 + modules and add up their sizes.
105553 +
105554 +endmenu
105555 +
105556 +menu "Address Space Layout Randomization"
105557 + depends on PAX
105558 +
105559 +config PAX_ASLR
105560 + bool "Address Space Layout Randomization"
105561 + default y if GRKERNSEC_CONFIG_AUTO
105562 + help
105563 + Many if not most exploit techniques rely on the knowledge of
105564 + certain addresses in the attacked program. The following options
105565 + will allow the kernel to apply a certain amount of randomization
105566 + to specific parts of the program thereby forcing an attacker to
105567 + guess them in most cases. Any failed guess will most likely crash
105568 + the attacked program which allows the kernel to detect such attempts
105569 + and react on them. PaX itself provides no reaction mechanisms,
105570 + instead it is strongly encouraged that you make use of grsecurity's
105571 + (http://www.grsecurity.net/) built-in crash detection features or
105572 + develop one yourself.
105573 +
105574 + By saying Y here you can choose to randomize the following areas:
105575 + - top of the task's kernel stack
105576 + - top of the task's userland stack
105577 + - base address for mmap() requests that do not specify one
105578 + (this includes all libraries)
105579 + - base address of the main executable
105580 +
105581 + It is strongly recommended to say Y here as address space layout
105582 + randomization has negligible impact on performance yet it provides
105583 + a very effective protection.
105584 +
105585 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
105586 + this feature on a per file basis.
105587 +
105588 +config PAX_RANDKSTACK
105589 + bool "Randomize kernel stack base"
105590 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
105591 + depends on X86_TSC && X86
105592 + help
105593 + By saying Y here the kernel will randomize every task's kernel
105594 + stack on every system call. This will not only force an attacker
105595 + to guess it but also prevent him from making use of possible
105596 + leaked information about it.
105597 +
105598 + Since the kernel stack is a rather scarce resource, randomization
105599 + may cause unexpected stack overflows, therefore you should very
105600 + carefully test your system. Note that once enabled in the kernel
105601 + configuration, this feature cannot be disabled on a per file basis.
105602 +
105603 +config PAX_RANDUSTACK
105604 + bool
105605 +
105606 +config PAX_RANDMMAP
105607 + bool "Randomize user stack and mmap() bases"
105608 + default y if GRKERNSEC_CONFIG_AUTO
105609 + depends on PAX_ASLR
105610 + select PAX_RANDUSTACK
105611 + help
105612 + By saying Y here the kernel will randomize every task's userland
105613 + stack and use a randomized base address for mmap() requests that
105614 + do not specify one themselves.
105615 +
105616 + The stack randomization is done in two steps where the second
105617 + one may apply a big amount of shift to the top of the stack and
105618 + cause problems for programs that want to use lots of memory (more
105619 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
105620 +
105621 + As a result of mmap randomization all dynamically loaded libraries
105622 + will appear at random addresses and therefore be harder to exploit
105623 + by a technique where an attacker attempts to execute library code
105624 + for his purposes (e.g. spawn a shell from an exploited program that
105625 + is running at an elevated privilege level).
105626 +
105627 + Furthermore, if a program is relinked as a dynamic ELF file, its
105628 + base address will be randomized as well, completing the full
105629 + randomization of the address space layout. Attacking such programs
105630 + becomes a guess game. You can find an example of doing this at
105631 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
105632 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
105633 +
105634 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
105635 + feature on a per file basis.
105636 +
105637 +endmenu
105638 +
105639 +menu "Miscellaneous hardening features"
105640 +
105641 +config PAX_MEMORY_SANITIZE
105642 + bool "Sanitize all freed memory"
105643 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105644 + help
105645 + By saying Y here the kernel will erase memory pages and slab objects
105646 + as soon as they are freed. This in turn reduces the lifetime of data
105647 + stored in them, making it less likely that sensitive information such
105648 + as passwords, cryptographic secrets, etc stay in memory for too long.
105649 +
105650 + This is especially useful for programs whose runtime is short, long
105651 + lived processes and the kernel itself benefit from this as long as
105652 + they ensure timely freeing of memory that may hold sensitive
105653 + information.
105654 +
105655 + A nice side effect of the sanitization of slab objects is the
105656 + reduction of possible info leaks caused by padding bytes within the
105657 + leaky structures. Use-after-free bugs for structures containing
105658 + pointers can also be detected as dereferencing the sanitized pointer
105659 + will generate an access violation.
105660 +
105661 + The tradeoff is performance impact, on a single CPU system kernel
105662 + compilation sees a 3% slowdown, other systems and workloads may vary
105663 + and you are advised to test this feature on your expected workload
105664 + before deploying it.
105665 +
105666 + To reduce the performance penalty by sanitizing pages only, albeit
105667 + limiting the effectiveness of this feature at the same time, slab
105668 + sanitization can be disabled with the kernel commandline parameter
105669 + "pax_sanitize_slab=0".
105670 +
105671 + Note that this feature does not protect data stored in live pages,
105672 + e.g., process memory swapped to disk may stay there for a long time.
105673 +
105674 +config PAX_MEMORY_STACKLEAK
105675 + bool "Sanitize kernel stack"
105676 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105677 + depends on X86
105678 + help
105679 + By saying Y here the kernel will erase the kernel stack before it
105680 + returns from a system call. This in turn reduces the information
105681 + that a kernel stack leak bug can reveal.
105682 +
105683 + Note that such a bug can still leak information that was put on
105684 + the stack by the current system call (the one eventually triggering
105685 + the bug) but traces of earlier system calls on the kernel stack
105686 + cannot leak anymore.
105687 +
105688 + The tradeoff is performance impact: on a single CPU system kernel
105689 + compilation sees a 1% slowdown, other systems and workloads may vary
105690 + and you are advised to test this feature on your expected workload
105691 + before deploying it.
105692 +
105693 + Note that the full feature requires a gcc with plugin support,
105694 + i.e., gcc 4.5 or newer. You may need to install the supporting
105695 + headers explicitly in addition to the normal gcc package. Using
105696 + older gcc versions means that functions with large enough stack
105697 + frames may leave uninitialized memory behind that may be exposed
105698 + to a later syscall leaking the stack.
105699 +
105700 +config PAX_MEMORY_STRUCTLEAK
105701 + bool "Forcibly initialize local variables copied to userland"
105702 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105703 + help
105704 + By saying Y here the kernel will zero initialize some local
105705 + variables that are going to be copied to userland. This in
105706 + turn prevents unintended information leakage from the kernel
105707 + stack should later code forget to explicitly set all parts of
105708 + the copied variable.
105709 +
105710 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
105711 + at a much smaller coverage.
105712 +
105713 + Note that the implementation requires a gcc with plugin support,
105714 + i.e., gcc 4.5 or newer. You may need to install the supporting
105715 + headers explicitly in addition to the normal gcc package.
105716 +
105717 +config PAX_MEMORY_UDEREF
105718 + bool "Prevent invalid userland pointer dereference"
105719 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
105720 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
105721 + select PAX_PER_CPU_PGD if X86_64
105722 + help
105723 + By saying Y here the kernel will be prevented from dereferencing
105724 + userland pointers in contexts where the kernel expects only kernel
105725 + pointers. This is both a useful runtime debugging feature and a
105726 + security measure that prevents exploiting a class of kernel bugs.
105727 +
105728 + The tradeoff is that some virtualization solutions may experience
105729 + a huge slowdown and therefore you should not enable this feature
105730 + for kernels meant to run in such environments. Whether a given VM
105731 + solution is affected or not is best determined by simply trying it
105732 + out, the performance impact will be obvious right on boot as this
105733 + mechanism engages from very early on. A good rule of thumb is that
105734 + VMs running on CPUs without hardware virtualization support (i.e.,
105735 + the majority of IA-32 CPUs) will likely experience the slowdown.
105736 +
105737 + On X86_64 the kernel will make use of PCID support when available
105738 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
105739 + or performance impact. Pass pax_weakuderef on the kernel command
105740 + line to choose the latter.
105741 +
105742 +config PAX_REFCOUNT
105743 + bool "Prevent various kernel object reference counter overflows"
105744 + default y if GRKERNSEC_CONFIG_AUTO
105745 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
105746 + help
105747 + By saying Y here the kernel will detect and prevent overflowing
105748 + various (but not all) kinds of object reference counters. Such
105749 + overflows can normally occur due to bugs only and are often, if
105750 + not always, exploitable.
105751 +
105752 + The tradeoff is that data structures protected by an overflowed
105753 + refcount will never be freed and therefore will leak memory. Note
105754 + that this leak also happens even without this protection but in
105755 + that case the overflow can eventually trigger the freeing of the
105756 + data structure while it is still being used elsewhere, resulting
105757 + in the exploitable situation that this feature prevents.
105758 +
105759 + Since this has a negligible performance impact, you should enable
105760 + this feature.
105761 +
105762 +config PAX_CONSTIFY_PLUGIN
105763 + bool "Automatically constify eligible structures"
105764 + default y
105765 + depends on !UML && PAX_KERNEXEC
105766 + help
105767 + By saying Y here the compiler will automatically constify a class
105768 + of types that contain only function pointers. This reduces the
105769 + kernel's attack surface and also produces a better memory layout.
105770 +
105771 + Note that the implementation requires a gcc with plugin support,
105772 + i.e., gcc 4.5 or newer. You may need to install the supporting
105773 + headers explicitly in addition to the normal gcc package.
105774 +
105775 + Note that if some code really has to modify constified variables
105776 + then the source code will have to be patched to allow it. Examples
105777 + can be found in PaX itself (the no_const attribute) and for some
105778 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
105779 +
105780 +config PAX_USERCOPY
105781 + bool "Harden heap object copies between kernel and userland"
105782 + default y if GRKERNSEC_CONFIG_AUTO
105783 + depends on ARM || IA64 || PPC || SPARC || X86
105784 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
105785 + select PAX_USERCOPY_SLABS
105786 + help
105787 + By saying Y here the kernel will enforce the size of heap objects
105788 + when they are copied in either direction between the kernel and
105789 + userland, even if only a part of the heap object is copied.
105790 +
105791 + Specifically, this checking prevents information leaking from the
105792 + kernel heap during kernel to userland copies (if the kernel heap
105793 + object is otherwise fully initialized) and prevents kernel heap
105794 + overflows during userland to kernel copies.
105795 +
105796 + Note that the current implementation provides the strictest bounds
105797 + checks for the SLUB allocator.
105798 +
105799 + Enabling this option also enables per-slab cache protection against
105800 + data in a given cache being copied into/out of via userland
105801 + accessors. Though the whitelist of regions will be reduced over
105802 + time, it notably protects important data structures like task structs.
105803 +
105804 + If frame pointers are enabled on x86, this option will also restrict
105805 + copies into and out of the kernel stack to local variables within a
105806 + single frame.
105807 +
105808 + Since this has a negligible performance impact, you should enable
105809 + this feature.
105810 +
105811 +config PAX_USERCOPY_DEBUG
105812 + bool
105813 + depends on X86 && PAX_USERCOPY
105814 + default n
105815 +
105816 +config PAX_SIZE_OVERFLOW
105817 + bool "Prevent various integer overflows in function size parameters"
105818 + default y if GRKERNSEC_CONFIG_AUTO
105819 + depends on X86
105820 + help
105821 + By saying Y here the kernel recomputes expressions of function
105822 + arguments marked by a size_overflow attribute with double integer
105823 + precision (DImode/TImode for 32/64 bit integer types).
105824 +
105825 + The recomputed argument is checked against TYPE_MAX and an event
105826 + is logged on overflow and the triggering process is killed.
105827 +
105828 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
105829 +
105830 + Note that the implementation requires a gcc with plugin support,
105831 + i.e., gcc 4.5 or newer. You may need to install the supporting
105832 + headers explicitly in addition to the normal gcc package.
105833 +
105834 +config PAX_LATENT_ENTROPY
105835 + bool "Generate some entropy during boot and runtime"
105836 + default y if GRKERNSEC_CONFIG_AUTO
105837 + help
105838 + By saying Y here the kernel will instrument some kernel code to
105839 + extract some entropy from both original and artificially created
105840 + program state. This will help especially embedded systems where
105841 + there is little 'natural' source of entropy normally. The cost
105842 + is some slowdown of the boot process and fork and irq processing.
105843 +
105844 + When pax_extra_latent_entropy is passed on the kernel command line,
105845 + entropy will be extracted from up to the first 4GB of RAM while the
105846 + runtime memory allocator is being initialized. This costs even more
105847 + slowdown of the boot process.
105848 +
105849 + Note that the implementation requires a gcc with plugin support,
105850 + i.e., gcc 4.5 or newer. You may need to install the supporting
105851 + headers explicitly in addition to the normal gcc package.
105852 +
105853 + Note that entropy extracted this way is not cryptographically
105854 + secure!
105855 +
105856 +endmenu
105857 +
105858 +endmenu
105859 +
105860 +source grsecurity/Kconfig
105861 +
105862 +endmenu
105863 +
105864 +endmenu
105865 +
105866 source security/keys/Kconfig
105867
105868 config SECURITY_DMESG_RESTRICT
105869 @@ -103,7 +1054,7 @@ config INTEL_TXT
105870 config LSM_MMAP_MIN_ADDR
105871 int "Low address space for LSM to protect from user allocation"
105872 depends on SECURITY && SECURITY_SELINUX
105873 - default 32768 if ARM || (ARM64 && COMPAT)
105874 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
105875 default 65536
105876 help
105877 This is the portion of low virtual memory which should be protected
105878 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
105879 index fdaa50c..2761dcb 100644
105880 --- a/security/apparmor/file.c
105881 +++ b/security/apparmor/file.c
105882 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
105883 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
105884 struct path *new_dir, struct dentry *new_dentry)
105885 {
105886 - struct path link = { new_dir->mnt, new_dentry };
105887 - struct path target = { new_dir->mnt, old_dentry };
105888 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
105889 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
105890 struct path_cond cond = {
105891 old_dentry->d_inode->i_uid,
105892 old_dentry->d_inode->i_mode
105893 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
105894 index 9981000..eb21356 100644
105895 --- a/security/apparmor/lsm.c
105896 +++ b/security/apparmor/lsm.c
105897 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
105898 struct dentry *dentry, u32 mask,
105899 struct path_cond *cond)
105900 {
105901 - struct path path = { dir->mnt, dentry };
105902 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
105903
105904 return common_perm(op, &path, mask, cond);
105905 }
105906 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
105907 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
105908 struct dentry *dentry, u32 mask)
105909 {
105910 - struct path path = { mnt, dentry };
105911 + struct path path = { .mnt = mnt, .dentry = dentry };
105912 struct path_cond cond = { dentry->d_inode->i_uid,
105913 dentry->d_inode->i_mode
105914 };
105915 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
105916
105917 profile = aa_current_profile();
105918 if (!unconfined(profile)) {
105919 - struct path old_path = { old_dir->mnt, old_dentry };
105920 - struct path new_path = { new_dir->mnt, new_dentry };
105921 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
105922 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
105923 struct path_cond cond = { old_dentry->d_inode->i_uid,
105924 old_dentry->d_inode->i_mode
105925 };
105926 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
105927 return error;
105928 }
105929
105930 -static struct security_operations apparmor_ops = {
105931 +static struct security_operations apparmor_ops __read_only = {
105932 .name = "apparmor",
105933
105934 .ptrace_access_check = apparmor_ptrace_access_check,
105935 diff --git a/security/commoncap.c b/security/commoncap.c
105936 index b9d613e..f68305c 100644
105937 --- a/security/commoncap.c
105938 +++ b/security/commoncap.c
105939 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
105940 return 0;
105941 }
105942
105943 +/* returns:
105944 + 1 for suid privilege
105945 + 2 for sgid privilege
105946 + 3 for fscap privilege
105947 +*/
105948 +int is_privileged_binary(const struct dentry *dentry)
105949 +{
105950 + struct cpu_vfs_cap_data capdata;
105951 + struct inode *inode = dentry->d_inode;
105952 +
105953 + if (!inode || S_ISDIR(inode->i_mode))
105954 + return 0;
105955 +
105956 + if (inode->i_mode & S_ISUID)
105957 + return 1;
105958 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
105959 + return 2;
105960 +
105961 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
105962 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
105963 + return 3;
105964 + }
105965 +
105966 + return 0;
105967 +}
105968 +
105969 /*
105970 * Attempt to get the on-exec apply capability sets for an executable file from
105971 * its xattrs and, if present, apply them to the proposed credentials being
105972 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
105973 const struct cred *cred = current_cred();
105974 kuid_t root_uid = make_kuid(cred->user_ns, 0);
105975
105976 + if (gr_acl_enable_at_secure())
105977 + return 1;
105978 +
105979 if (!uid_eq(cred->uid, root_uid)) {
105980 if (bprm->cap_effective)
105981 return 1;
105982 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
105983 index f79fa8b..6161868 100644
105984 --- a/security/integrity/ima/ima.h
105985 +++ b/security/integrity/ima/ima.h
105986 @@ -118,8 +118,8 @@ int ima_init_template(void);
105987 extern spinlock_t ima_queue_lock;
105988
105989 struct ima_h_table {
105990 - atomic_long_t len; /* number of stored measurements in the list */
105991 - atomic_long_t violations;
105992 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
105993 + atomic_long_unchecked_t violations;
105994 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
105995 };
105996 extern struct ima_h_table ima_htable;
105997 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
105998 index d9cd5ce..c5c29ac 100644
105999 --- a/security/integrity/ima/ima_api.c
106000 +++ b/security/integrity/ima/ima_api.c
106001 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
106002 int result;
106003
106004 /* can overflow, only indicator */
106005 - atomic_long_inc(&ima_htable.violations);
106006 + atomic_long_inc_unchecked(&ima_htable.violations);
106007
106008 result = ima_alloc_init_template(NULL, file, filename,
106009 NULL, 0, &entry);
106010 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
106011 index da92fcc..8a5d390 100644
106012 --- a/security/integrity/ima/ima_fs.c
106013 +++ b/security/integrity/ima/ima_fs.c
106014 @@ -28,12 +28,12 @@
106015 static int valid_policy = 1;
106016 #define TMPBUFLEN 12
106017 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
106018 - loff_t *ppos, atomic_long_t *val)
106019 + loff_t *ppos, atomic_long_unchecked_t *val)
106020 {
106021 char tmpbuf[TMPBUFLEN];
106022 ssize_t len;
106023
106024 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
106025 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
106026 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
106027 }
106028
106029 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
106030 index 552705d..9920f4fb 100644
106031 --- a/security/integrity/ima/ima_queue.c
106032 +++ b/security/integrity/ima/ima_queue.c
106033 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
106034 INIT_LIST_HEAD(&qe->later);
106035 list_add_tail_rcu(&qe->later, &ima_measurements);
106036
106037 - atomic_long_inc(&ima_htable.len);
106038 + atomic_long_inc_unchecked(&ima_htable.len);
106039 key = ima_hash_key(entry->digest);
106040 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
106041 return 0;
106042 diff --git a/security/keys/compat.c b/security/keys/compat.c
106043 index 3478965..ec7bb9e 100644
106044 --- a/security/keys/compat.c
106045 +++ b/security/keys/compat.c
106046 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
106047 if (ret == 0)
106048 goto no_payload_free;
106049
106050 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
106051 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
106052 err:
106053 if (iov != iovstack)
106054 kfree(iov);
106055 diff --git a/security/keys/internal.h b/security/keys/internal.h
106056 index 80b2aac..bb7ee65 100644
106057 --- a/security/keys/internal.h
106058 +++ b/security/keys/internal.h
106059 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
106060 extern long keyctl_invalidate_key(key_serial_t);
106061
106062 extern long keyctl_instantiate_key_common(key_serial_t,
106063 - const struct iovec *,
106064 + const struct iovec __user *,
106065 unsigned, size_t, key_serial_t);
106066 #ifdef CONFIG_PERSISTENT_KEYRINGS
106067 extern long keyctl_get_persistent(uid_t, key_serial_t);
106068 diff --git a/security/keys/key.c b/security/keys/key.c
106069 index 6e21c11..9ed67ca 100644
106070 --- a/security/keys/key.c
106071 +++ b/security/keys/key.c
106072 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
106073
106074 atomic_set(&key->usage, 1);
106075 init_rwsem(&key->sem);
106076 - lockdep_set_class(&key->sem, &type->lock_class);
106077 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
106078 key->index_key.type = type;
106079 key->user = user;
106080 key->quotalen = quotalen;
106081 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
106082 struct key_type *p;
106083 int ret;
106084
106085 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
106086 + pax_open_kernel();
106087 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
106088 + pax_close_kernel();
106089
106090 ret = -EEXIST;
106091 down_write(&key_types_sem);
106092 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
106093 }
106094
106095 /* store the type */
106096 - list_add(&ktype->link, &key_types_list);
106097 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
106098
106099 pr_notice("Key type %s registered\n", ktype->name);
106100 ret = 0;
106101 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
106102 void unregister_key_type(struct key_type *ktype)
106103 {
106104 down_write(&key_types_sem);
106105 - list_del_init(&ktype->link);
106106 + pax_list_del_init((struct list_head *)&ktype->link);
106107 downgrade_write(&key_types_sem);
106108 key_gc_keytype(ktype);
106109 pr_notice("Key type %s unregistered\n", ktype->name);
106110 @@ -1088,10 +1090,10 @@ void __init key_init(void)
106111 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
106112
106113 /* add the special key types */
106114 - list_add_tail(&key_type_keyring.link, &key_types_list);
106115 - list_add_tail(&key_type_dead.link, &key_types_list);
106116 - list_add_tail(&key_type_user.link, &key_types_list);
106117 - list_add_tail(&key_type_logon.link, &key_types_list);
106118 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
106119 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
106120 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
106121 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
106122
106123 /* record the root user tracking */
106124 rb_link_node(&root_key_user.node,
106125 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
106126 index cee72ce..e46074a 100644
106127 --- a/security/keys/keyctl.c
106128 +++ b/security/keys/keyctl.c
106129 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
106130 /*
106131 * Copy the iovec data from userspace
106132 */
106133 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
106134 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
106135 unsigned ioc)
106136 {
106137 for (; ioc > 0; ioc--) {
106138 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
106139 * If successful, 0 will be returned.
106140 */
106141 long keyctl_instantiate_key_common(key_serial_t id,
106142 - const struct iovec *payload_iov,
106143 + const struct iovec __user *payload_iov,
106144 unsigned ioc,
106145 size_t plen,
106146 key_serial_t ringid)
106147 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
106148 [0].iov_len = plen
106149 };
106150
106151 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
106152 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
106153 }
106154
106155 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
106156 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
106157 if (ret == 0)
106158 goto no_payload_free;
106159
106160 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
106161 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
106162 err:
106163 if (iov != iovstack)
106164 kfree(iov);
106165 diff --git a/security/min_addr.c b/security/min_addr.c
106166 index f728728..6457a0c 100644
106167 --- a/security/min_addr.c
106168 +++ b/security/min_addr.c
106169 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
106170 */
106171 static void update_mmap_min_addr(void)
106172 {
106173 +#ifndef SPARC
106174 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
106175 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
106176 mmap_min_addr = dac_mmap_min_addr;
106177 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
106178 #else
106179 mmap_min_addr = dac_mmap_min_addr;
106180 #endif
106181 +#endif
106182 }
106183
106184 /*
106185 diff --git a/security/security.c b/security/security.c
106186 index 8b774f3..a396233 100644
106187 --- a/security/security.c
106188 +++ b/security/security.c
106189 @@ -33,8 +33,8 @@
106190 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
106191 CONFIG_DEFAULT_SECURITY;
106192
106193 -static struct security_operations *security_ops;
106194 -static struct security_operations default_security_ops = {
106195 +struct security_operations *security_ops __read_only;
106196 +struct security_operations default_security_ops __read_only = {
106197 .name = "default",
106198 };
106199
106200 @@ -73,11 +73,6 @@ int __init security_init(void)
106201 return 0;
106202 }
106203
106204 -void reset_security_ops(void)
106205 -{
106206 - security_ops = &default_security_ops;
106207 -}
106208 -
106209 /* Save user chosen LSM */
106210 static int __init choose_lsm(char *str)
106211 {
106212 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
106213 index fc3e662..7844c60 100644
106214 --- a/security/selinux/avc.c
106215 +++ b/security/selinux/avc.c
106216 @@ -59,7 +59,7 @@ struct avc_node {
106217 struct avc_cache {
106218 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
106219 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
106220 - atomic_t lru_hint; /* LRU hint for reclaim scan */
106221 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
106222 atomic_t active_nodes;
106223 u32 latest_notif; /* latest revocation notification */
106224 };
106225 @@ -167,7 +167,7 @@ void __init avc_init(void)
106226 spin_lock_init(&avc_cache.slots_lock[i]);
106227 }
106228 atomic_set(&avc_cache.active_nodes, 0);
106229 - atomic_set(&avc_cache.lru_hint, 0);
106230 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
106231
106232 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
106233 0, SLAB_PANIC, NULL);
106234 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
106235 spinlock_t *lock;
106236
106237 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
106238 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
106239 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
106240 head = &avc_cache.slots[hvalue];
106241 lock = &avc_cache.slots_lock[hvalue];
106242
106243 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
106244 index 2c7341d..1da068e 100644
106245 --- a/security/selinux/hooks.c
106246 +++ b/security/selinux/hooks.c
106247 @@ -95,8 +95,6 @@
106248 #include "audit.h"
106249 #include "avc_ss.h"
106250
106251 -extern struct security_operations *security_ops;
106252 -
106253 /* SECMARK reference count */
106254 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
106255
106256 @@ -5758,7 +5756,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
106257
106258 #endif
106259
106260 -static struct security_operations selinux_ops = {
106261 +static struct security_operations selinux_ops __read_only = {
106262 .name = "selinux",
106263
106264 .ptrace_access_check = selinux_ptrace_access_check,
106265 @@ -6111,6 +6109,9 @@ static void selinux_nf_ip_exit(void)
106266 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
106267 static int selinux_disabled;
106268
106269 +extern struct security_operations *security_ops;
106270 +extern struct security_operations default_security_ops;
106271 +
106272 int selinux_disable(void)
106273 {
106274 if (ss_initialized) {
106275 @@ -6128,7 +6129,9 @@ int selinux_disable(void)
106276 selinux_disabled = 1;
106277 selinux_enabled = 0;
106278
106279 - reset_security_ops();
106280 + pax_open_kernel();
106281 + security_ops = &default_security_ops;
106282 + pax_close_kernel();
106283
106284 /* Try to destroy the avc node cache */
106285 avc_disable();
106286 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
106287 index 1450f85..a91e0bc 100644
106288 --- a/security/selinux/include/xfrm.h
106289 +++ b/security/selinux/include/xfrm.h
106290 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
106291
106292 rtnl_lock();
106293 for_each_net(net) {
106294 - atomic_inc(&net->xfrm.flow_cache_genid);
106295 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
106296 rt_genid_bump_all(net);
106297 }
106298 rtnl_unlock();
106299 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
106300 index 14f52be..7352368 100644
106301 --- a/security/smack/smack_lsm.c
106302 +++ b/security/smack/smack_lsm.c
106303 @@ -3726,7 +3726,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
106304 return 0;
106305 }
106306
106307 -struct security_operations smack_ops = {
106308 +struct security_operations smack_ops __read_only = {
106309 .name = "smack",
106310
106311 .ptrace_access_check = smack_ptrace_access_check,
106312 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
106313 index 4003907..13a2b55 100644
106314 --- a/security/tomoyo/file.c
106315 +++ b/security/tomoyo/file.c
106316 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
106317 {
106318 struct tomoyo_request_info r;
106319 struct tomoyo_obj_info obj = {
106320 - .path1 = *path,
106321 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
106322 };
106323 int error = -ENOMEM;
106324 struct tomoyo_path_info buf;
106325 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
106326 struct tomoyo_path_info buf;
106327 struct tomoyo_request_info r;
106328 struct tomoyo_obj_info obj = {
106329 - .path1 = *path,
106330 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
106331 };
106332 int idx;
106333
106334 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
106335 {
106336 struct tomoyo_request_info r;
106337 struct tomoyo_obj_info obj = {
106338 - .path1 = *path,
106339 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
106340 };
106341 int error;
106342 struct tomoyo_path_info buf;
106343 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
106344 {
106345 struct tomoyo_request_info r;
106346 struct tomoyo_obj_info obj = {
106347 - .path1 = *path,
106348 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
106349 };
106350 int error = -ENOMEM;
106351 struct tomoyo_path_info buf;
106352 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
106353 struct tomoyo_path_info buf2;
106354 struct tomoyo_request_info r;
106355 struct tomoyo_obj_info obj = {
106356 - .path1 = *path1,
106357 - .path2 = *path2,
106358 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
106359 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
106360 };
106361 int idx;
106362
106363 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
106364 index 390c646..f2f8db3 100644
106365 --- a/security/tomoyo/mount.c
106366 +++ b/security/tomoyo/mount.c
106367 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
106368 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
106369 need_dev = -1; /* dev_name is a directory */
106370 } else {
106371 + if (!capable(CAP_SYS_ADMIN)) {
106372 + error = -EPERM;
106373 + goto out;
106374 + }
106375 fstype = get_fs_type(type);
106376 if (!fstype) {
106377 error = -ENODEV;
106378 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
106379 index f0b756e..8aa497b 100644
106380 --- a/security/tomoyo/tomoyo.c
106381 +++ b/security/tomoyo/tomoyo.c
106382 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
106383 */
106384 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
106385 {
106386 - struct path path = { mnt, dentry };
106387 + struct path path = { .mnt = mnt, .dentry = dentry };
106388 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
106389 }
106390
106391 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
106392 */
106393 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
106394 {
106395 - struct path path = { parent->mnt, dentry };
106396 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106397 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
106398 }
106399
106400 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
106401 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
106402 umode_t mode)
106403 {
106404 - struct path path = { parent->mnt, dentry };
106405 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106406 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
106407 mode & S_IALLUGO);
106408 }
106409 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
106410 */
106411 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
106412 {
106413 - struct path path = { parent->mnt, dentry };
106414 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106415 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
106416 }
106417
106418 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
106419 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
106420 const char *old_name)
106421 {
106422 - struct path path = { parent->mnt, dentry };
106423 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106424 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
106425 }
106426
106427 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
106428 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
106429 umode_t mode, unsigned int dev)
106430 {
106431 - struct path path = { parent->mnt, dentry };
106432 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106433 int type = TOMOYO_TYPE_CREATE;
106434 const unsigned int perm = mode & S_IALLUGO;
106435
106436 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
106437 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
106438 struct dentry *new_dentry)
106439 {
106440 - struct path path1 = { new_dir->mnt, old_dentry };
106441 - struct path path2 = { new_dir->mnt, new_dentry };
106442 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
106443 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
106444 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
106445 }
106446
106447 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
106448 struct path *new_parent,
106449 struct dentry *new_dentry)
106450 {
106451 - struct path path1 = { old_parent->mnt, old_dentry };
106452 - struct path path2 = { new_parent->mnt, new_dentry };
106453 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
106454 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
106455 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
106456 }
106457
106458 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
106459 */
106460 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
106461 {
106462 - struct path path = { mnt, mnt->mnt_root };
106463 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
106464 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
106465 }
106466
106467 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
106468 * tomoyo_security_ops is a "struct security_operations" which is used for
106469 * registering TOMOYO.
106470 */
106471 -static struct security_operations tomoyo_security_ops = {
106472 +static struct security_operations tomoyo_security_ops __read_only = {
106473 .name = "tomoyo",
106474 .cred_alloc_blank = tomoyo_cred_alloc_blank,
106475 .cred_prepare = tomoyo_cred_prepare,
106476 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
106477 index 20ef514..4182bed 100644
106478 --- a/security/yama/Kconfig
106479 +++ b/security/yama/Kconfig
106480 @@ -1,6 +1,6 @@
106481 config SECURITY_YAMA
106482 bool "Yama support"
106483 - depends on SECURITY
106484 + depends on SECURITY && !GRKERNSEC
106485 select SECURITYFS
106486 select SECURITY_PATH
106487 default n
106488 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
106489 index 13c88fbc..f8c115e 100644
106490 --- a/security/yama/yama_lsm.c
106491 +++ b/security/yama/yama_lsm.c
106492 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
106493 }
106494
106495 #ifndef CONFIG_SECURITY_YAMA_STACKED
106496 -static struct security_operations yama_ops = {
106497 +static struct security_operations yama_ops __read_only = {
106498 .name = "yama",
106499
106500 .ptrace_access_check = yama_ptrace_access_check,
106501 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
106502 #endif
106503
106504 #ifdef CONFIG_SYSCTL
106505 +static int zero __read_only;
106506 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
106507 +
106508 static int yama_dointvec_minmax(struct ctl_table *table, int write,
106509 void __user *buffer, size_t *lenp, loff_t *ppos)
106510 {
106511 - int rc;
106512 + ctl_table_no_const yama_table;
106513
106514 if (write && !capable(CAP_SYS_PTRACE))
106515 return -EPERM;
106516
106517 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
106518 - if (rc)
106519 - return rc;
106520 -
106521 + yama_table = *table;
106522 /* Lock the max value if it ever gets set. */
106523 - if (write && *(int *)table->data == *(int *)table->extra2)
106524 - table->extra1 = table->extra2;
106525 -
106526 - return rc;
106527 + if (ptrace_scope == max_scope)
106528 + yama_table.extra1 = &max_scope;
106529 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
106530 }
106531
106532 -static int zero;
106533 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
106534 -
106535 struct ctl_path yama_sysctl_path[] = {
106536 { .procname = "kernel", },
106537 { .procname = "yama", },
106538 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
106539 index f01bffb..bdda392 100644
106540 --- a/sound/aoa/codecs/onyx.c
106541 +++ b/sound/aoa/codecs/onyx.c
106542 @@ -54,7 +54,7 @@ struct onyx {
106543 spdif_locked:1,
106544 analog_locked:1,
106545 original_mute:2;
106546 - int open_count;
106547 + local_t open_count;
106548 struct codec_info *codec_info;
106549
106550 /* mutex serializes concurrent access to the device
106551 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
106552 struct onyx *onyx = cii->codec_data;
106553
106554 mutex_lock(&onyx->mutex);
106555 - onyx->open_count++;
106556 + local_inc(&onyx->open_count);
106557 mutex_unlock(&onyx->mutex);
106558
106559 return 0;
106560 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
106561 struct onyx *onyx = cii->codec_data;
106562
106563 mutex_lock(&onyx->mutex);
106564 - onyx->open_count--;
106565 - if (!onyx->open_count)
106566 + if (local_dec_and_test(&onyx->open_count))
106567 onyx->spdif_locked = onyx->analog_locked = 0;
106568 mutex_unlock(&onyx->mutex);
106569
106570 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
106571 index ffd2025..df062c9 100644
106572 --- a/sound/aoa/codecs/onyx.h
106573 +++ b/sound/aoa/codecs/onyx.h
106574 @@ -11,6 +11,7 @@
106575 #include <linux/i2c.h>
106576 #include <asm/pmac_low_i2c.h>
106577 #include <asm/prom.h>
106578 +#include <asm/local.h>
106579
106580 /* PCM3052 register definitions */
106581
106582 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
106583 index ada69d7..5f65386 100644
106584 --- a/sound/core/oss/pcm_oss.c
106585 +++ b/sound/core/oss/pcm_oss.c
106586 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
106587 if (in_kernel) {
106588 mm_segment_t fs;
106589 fs = snd_enter_user();
106590 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
106591 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
106592 snd_leave_user(fs);
106593 } else {
106594 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
106595 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
106596 }
106597 if (ret != -EPIPE && ret != -ESTRPIPE)
106598 break;
106599 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
106600 if (in_kernel) {
106601 mm_segment_t fs;
106602 fs = snd_enter_user();
106603 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
106604 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
106605 snd_leave_user(fs);
106606 } else {
106607 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
106608 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
106609 }
106610 if (ret == -EPIPE) {
106611 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
106612 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
106613 struct snd_pcm_plugin_channel *channels;
106614 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
106615 if (!in_kernel) {
106616 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
106617 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
106618 return -EFAULT;
106619 buf = runtime->oss.buffer;
106620 }
106621 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
106622 }
106623 } else {
106624 tmp = snd_pcm_oss_write2(substream,
106625 - (const char __force *)buf,
106626 + (const char __force_kernel *)buf,
106627 runtime->oss.period_bytes, 0);
106628 if (tmp <= 0)
106629 goto err;
106630 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
106631 struct snd_pcm_runtime *runtime = substream->runtime;
106632 snd_pcm_sframes_t frames, frames1;
106633 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
106634 - char __user *final_dst = (char __force __user *)buf;
106635 + char __user *final_dst = (char __force_user *)buf;
106636 if (runtime->oss.plugin_first) {
106637 struct snd_pcm_plugin_channel *channels;
106638 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
106639 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
106640 xfer += tmp;
106641 runtime->oss.buffer_used -= tmp;
106642 } else {
106643 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
106644 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
106645 runtime->oss.period_bytes, 0);
106646 if (tmp <= 0)
106647 goto err;
106648 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
106649 size1);
106650 size1 /= runtime->channels; /* frames */
106651 fs = snd_enter_user();
106652 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
106653 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
106654 snd_leave_user(fs);
106655 }
106656 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
106657 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
106658 index af49721..e85058e 100644
106659 --- a/sound/core/pcm_compat.c
106660 +++ b/sound/core/pcm_compat.c
106661 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
106662 int err;
106663
106664 fs = snd_enter_user();
106665 - err = snd_pcm_delay(substream, &delay);
106666 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
106667 snd_leave_user(fs);
106668 if (err < 0)
106669 return err;
106670 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
106671 index b653ab0..a4738e3 100644
106672 --- a/sound/core/pcm_native.c
106673 +++ b/sound/core/pcm_native.c
106674 @@ -2812,11 +2812,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
106675 switch (substream->stream) {
106676 case SNDRV_PCM_STREAM_PLAYBACK:
106677 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
106678 - (void __user *)arg);
106679 + (void __force_user *)arg);
106680 break;
106681 case SNDRV_PCM_STREAM_CAPTURE:
106682 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
106683 - (void __user *)arg);
106684 + (void __force_user *)arg);
106685 break;
106686 default:
106687 result = -EINVAL;
106688 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
106689 index 16d4267..fe8b49b 100644
106690 --- a/sound/core/seq/oss/seq_oss.c
106691 +++ b/sound/core/seq/oss/seq_oss.c
106692 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
106693 {
106694 int rc;
106695 static struct snd_seq_dev_ops ops = {
106696 - snd_seq_oss_synth_register,
106697 - snd_seq_oss_synth_unregister,
106698 + .init_device = snd_seq_oss_synth_register,
106699 + .free_device = snd_seq_oss_synth_unregister,
106700 };
106701
106702 snd_seq_autoload_lock();
106703 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
106704 index 91a786a..4c07ed4 100644
106705 --- a/sound/core/seq/seq_device.c
106706 +++ b/sound/core/seq/seq_device.c
106707 @@ -64,7 +64,7 @@ struct ops_list {
106708 int argsize; /* argument size */
106709
106710 /* operators */
106711 - struct snd_seq_dev_ops ops;
106712 + struct snd_seq_dev_ops *ops;
106713
106714 /* registered devices */
106715 struct list_head dev_list; /* list of devices */
106716 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
106717
106718 mutex_lock(&ops->reg_mutex);
106719 /* copy driver operators */
106720 - ops->ops = *entry;
106721 + ops->ops = entry;
106722 ops->driver |= DRIVER_LOADED;
106723 ops->argsize = argsize;
106724
106725 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
106726 dev->name, ops->id, ops->argsize, dev->argsize);
106727 return -EINVAL;
106728 }
106729 - if (ops->ops.init_device(dev) >= 0) {
106730 + if (ops->ops->init_device(dev) >= 0) {
106731 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
106732 ops->num_init_devices++;
106733 } else {
106734 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
106735 dev->name, ops->id, ops->argsize, dev->argsize);
106736 return -EINVAL;
106737 }
106738 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
106739 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
106740 dev->status = SNDRV_SEQ_DEVICE_FREE;
106741 dev->driver_data = NULL;
106742 ops->num_init_devices--;
106743 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
106744 index 3e05c55..0f02efc 100644
106745 --- a/sound/core/seq/seq_midi.c
106746 +++ b/sound/core/seq/seq_midi.c
106747 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
106748 static int __init alsa_seq_midi_init(void)
106749 {
106750 static struct snd_seq_dev_ops ops = {
106751 - snd_seq_midisynth_register_port,
106752 - snd_seq_midisynth_unregister_port,
106753 + .init_device = snd_seq_midisynth_register_port,
106754 + .free_device = snd_seq_midisynth_unregister_port,
106755 };
106756 memset(&synths, 0, sizeof(synths));
106757 snd_seq_autoload_lock();
106758 diff --git a/sound/core/sound.c b/sound/core/sound.c
106759 index 38ad1a0..5010a40 100644
106760 --- a/sound/core/sound.c
106761 +++ b/sound/core/sound.c
106762 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
106763 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
106764 default: return;
106765 }
106766 - request_module(str);
106767 + request_module("%s", str);
106768 }
106769
106770 #endif /* modular kernel */
106771 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
106772 index f5fd448..6ae276da 100644
106773 --- a/sound/drivers/mts64.c
106774 +++ b/sound/drivers/mts64.c
106775 @@ -29,6 +29,7 @@
106776 #include <sound/initval.h>
106777 #include <sound/rawmidi.h>
106778 #include <sound/control.h>
106779 +#include <asm/local.h>
106780
106781 #define CARD_NAME "Miditerminal 4140"
106782 #define DRIVER_NAME "MTS64"
106783 @@ -67,7 +68,7 @@ struct mts64 {
106784 struct pardevice *pardev;
106785 int pardev_claimed;
106786
106787 - int open_count;
106788 + local_t open_count;
106789 int current_midi_output_port;
106790 int current_midi_input_port;
106791 u8 mode[MTS64_NUM_INPUT_PORTS];
106792 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
106793 {
106794 struct mts64 *mts = substream->rmidi->private_data;
106795
106796 - if (mts->open_count == 0) {
106797 + if (local_read(&mts->open_count) == 0) {
106798 /* We don't need a spinlock here, because this is just called
106799 if the device has not been opened before.
106800 So there aren't any IRQs from the device */
106801 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
106802
106803 msleep(50);
106804 }
106805 - ++(mts->open_count);
106806 + local_inc(&mts->open_count);
106807
106808 return 0;
106809 }
106810 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
106811 struct mts64 *mts = substream->rmidi->private_data;
106812 unsigned long flags;
106813
106814 - --(mts->open_count);
106815 - if (mts->open_count == 0) {
106816 + if (local_dec_return(&mts->open_count) == 0) {
106817 /* We need the spinlock_irqsave here because we can still
106818 have IRQs at this point */
106819 spin_lock_irqsave(&mts->lock, flags);
106820 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
106821
106822 msleep(500);
106823
106824 - } else if (mts->open_count < 0)
106825 - mts->open_count = 0;
106826 + } else if (local_read(&mts->open_count) < 0)
106827 + local_set(&mts->open_count, 0);
106828
106829 return 0;
106830 }
106831 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
106832 index 6839953..7a0f4b9 100644
106833 --- a/sound/drivers/opl3/opl3_seq.c
106834 +++ b/sound/drivers/opl3/opl3_seq.c
106835 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
106836 {
106837 static struct snd_seq_dev_ops ops =
106838 {
106839 - snd_opl3_seq_new_device,
106840 - snd_opl3_seq_delete_device
106841 + .init_device = snd_opl3_seq_new_device,
106842 + .free_device = snd_opl3_seq_delete_device
106843 };
106844
106845 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
106846 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
106847 index b953fb4..1999c01 100644
106848 --- a/sound/drivers/opl4/opl4_lib.c
106849 +++ b/sound/drivers/opl4/opl4_lib.c
106850 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
106851 MODULE_DESCRIPTION("OPL4 driver");
106852 MODULE_LICENSE("GPL");
106853
106854 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
106855 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
106856 {
106857 int timeout = 10;
106858 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
106859 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
106860 index 9919769..d7de36c 100644
106861 --- a/sound/drivers/opl4/opl4_seq.c
106862 +++ b/sound/drivers/opl4/opl4_seq.c
106863 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
106864 static int __init alsa_opl4_synth_init(void)
106865 {
106866 static struct snd_seq_dev_ops ops = {
106867 - snd_opl4_seq_new_device,
106868 - snd_opl4_seq_delete_device
106869 + .init_device = snd_opl4_seq_new_device,
106870 + .free_device = snd_opl4_seq_delete_device
106871 };
106872
106873 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
106874 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
106875 index 78ccfa4..7a0857b 100644
106876 --- a/sound/drivers/portman2x4.c
106877 +++ b/sound/drivers/portman2x4.c
106878 @@ -48,6 +48,7 @@
106879 #include <sound/initval.h>
106880 #include <sound/rawmidi.h>
106881 #include <sound/control.h>
106882 +#include <asm/local.h>
106883
106884 #define CARD_NAME "Portman 2x4"
106885 #define DRIVER_NAME "portman"
106886 @@ -85,7 +86,7 @@ struct portman {
106887 struct pardevice *pardev;
106888 int pardev_claimed;
106889
106890 - int open_count;
106891 + local_t open_count;
106892 int mode[PORTMAN_NUM_INPUT_PORTS];
106893 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
106894 };
106895 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
106896 index 9048777..2d8b1fc 100644
106897 --- a/sound/firewire/amdtp.c
106898 +++ b/sound/firewire/amdtp.c
106899 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
106900 ptr = s->pcm_buffer_pointer + data_blocks;
106901 if (ptr >= pcm->runtime->buffer_size)
106902 ptr -= pcm->runtime->buffer_size;
106903 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
106904 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
106905
106906 s->pcm_period_pointer += data_blocks;
106907 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
106908 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
106909 */
106910 void amdtp_out_stream_update(struct amdtp_out_stream *s)
106911 {
106912 - ACCESS_ONCE(s->source_node_id_field) =
106913 + ACCESS_ONCE_RW(s->source_node_id_field) =
106914 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
106915 }
106916 EXPORT_SYMBOL(amdtp_out_stream_update);
106917 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
106918 index 2746ecd..c35dedd 100644
106919 --- a/sound/firewire/amdtp.h
106920 +++ b/sound/firewire/amdtp.h
106921 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
106922 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
106923 struct snd_pcm_substream *pcm)
106924 {
106925 - ACCESS_ONCE(s->pcm) = pcm;
106926 + ACCESS_ONCE_RW(s->pcm) = pcm;
106927 }
106928
106929 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
106930 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
106931 index 7ac9443..0ec6274 100644
106932 --- a/sound/firewire/isight.c
106933 +++ b/sound/firewire/isight.c
106934 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
106935 ptr += count;
106936 if (ptr >= runtime->buffer_size)
106937 ptr -= runtime->buffer_size;
106938 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
106939 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
106940
106941 isight->period_counter += count;
106942 if (isight->period_counter >= runtime->period_size) {
106943 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
106944 if (err < 0)
106945 return err;
106946
106947 - ACCESS_ONCE(isight->pcm_active) = true;
106948 + ACCESS_ONCE_RW(isight->pcm_active) = true;
106949
106950 return 0;
106951 }
106952 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
106953 {
106954 struct isight *isight = substream->private_data;
106955
106956 - ACCESS_ONCE(isight->pcm_active) = false;
106957 + ACCESS_ONCE_RW(isight->pcm_active) = false;
106958
106959 mutex_lock(&isight->mutex);
106960 isight_stop_streaming(isight);
106961 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
106962
106963 switch (cmd) {
106964 case SNDRV_PCM_TRIGGER_START:
106965 - ACCESS_ONCE(isight->pcm_running) = true;
106966 + ACCESS_ONCE_RW(isight->pcm_running) = true;
106967 break;
106968 case SNDRV_PCM_TRIGGER_STOP:
106969 - ACCESS_ONCE(isight->pcm_running) = false;
106970 + ACCESS_ONCE_RW(isight->pcm_running) = false;
106971 break;
106972 default:
106973 return -EINVAL;
106974 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
106975 index 2dba848..c682aef 100644
106976 --- a/sound/firewire/scs1x.c
106977 +++ b/sound/firewire/scs1x.c
106978 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
106979 {
106980 struct scs *scs = stream->rmidi->private_data;
106981
106982 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
106983 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
106984 if (up) {
106985 scs->output_idle = false;
106986 tasklet_schedule(&scs->tasklet);
106987 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
106988 {
106989 struct scs *scs = stream->rmidi->private_data;
106990
106991 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
106992 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
106993 }
106994
106995 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
106996 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
106997
106998 snd_card_disconnect(scs->card);
106999
107000 - ACCESS_ONCE(scs->output) = NULL;
107001 - ACCESS_ONCE(scs->input) = NULL;
107002 + ACCESS_ONCE_RW(scs->output) = NULL;
107003 + ACCESS_ONCE_RW(scs->input) = NULL;
107004
107005 wait_event(scs->idle_wait, scs->output_idle);
107006
107007 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
107008 index 4e3fcfb..ab45a9d 100644
107009 --- a/sound/isa/sb/emu8000_synth.c
107010 +++ b/sound/isa/sb/emu8000_synth.c
107011 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
107012 {
107013
107014 static struct snd_seq_dev_ops ops = {
107015 - snd_emu8000_new_device,
107016 - snd_emu8000_delete_device,
107017 + .init_device = snd_emu8000_new_device,
107018 + .free_device = snd_emu8000_delete_device,
107019 };
107020 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
107021 sizeof(struct snd_emu8000*));
107022 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
107023 index 048439a..3be9f6f 100644
107024 --- a/sound/oss/sb_audio.c
107025 +++ b/sound/oss/sb_audio.c
107026 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
107027 buf16 = (signed short *)(localbuf + localoffs);
107028 while (c)
107029 {
107030 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
107031 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
107032 if (copy_from_user(lbuf8,
107033 userbuf+useroffs + p,
107034 locallen))
107035 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
107036 index f851fd0..92576fb 100644
107037 --- a/sound/oss/swarm_cs4297a.c
107038 +++ b/sound/oss/swarm_cs4297a.c
107039 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
107040 {
107041 struct cs4297a_state *s;
107042 u32 pwr, id;
107043 - mm_segment_t fs;
107044 int rval;
107045 #ifndef CONFIG_BCM_CS4297A_CSWARM
107046 u64 cfg;
107047 @@ -2713,22 +2712,23 @@ static int __init cs4297a_init(void)
107048 if (!rval) {
107049 char *sb1250_duart_present;
107050
107051 +#if 0
107052 + mm_segment_t fs;
107053 fs = get_fs();
107054 set_fs(KERNEL_DS);
107055 -#if 0
107056 val = SOUND_MASK_LINE;
107057 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
107058 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
107059 val = initvol[i].vol;
107060 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
107061 }
107062 + set_fs(fs);
107063 // cs4297a_write_ac97(s, 0x18, 0x0808);
107064 #else
107065 // cs4297a_write_ac97(s, 0x5e, 0x180);
107066 cs4297a_write_ac97(s, 0x02, 0x0808);
107067 cs4297a_write_ac97(s, 0x18, 0x0808);
107068 #endif
107069 - set_fs(fs);
107070
107071 list_add(&s->list, &cs4297a_devs);
107072
107073 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
107074 index 4c41c90..37f3631 100644
107075 --- a/sound/pci/emu10k1/emu10k1_synth.c
107076 +++ b/sound/pci/emu10k1/emu10k1_synth.c
107077 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
107078 {
107079
107080 static struct snd_seq_dev_ops ops = {
107081 - snd_emu10k1_synth_new_device,
107082 - snd_emu10k1_synth_delete_device,
107083 + .init_device = snd_emu10k1_synth_new_device,
107084 + .free_device = snd_emu10k1_synth_delete_device,
107085 };
107086 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
107087 sizeof(struct snd_emu10k1_synth_arg));
107088 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
107089 index 4c20277..91abdce 100644
107090 --- a/sound/pci/hda/hda_codec.c
107091 +++ b/sound/pci/hda/hda_codec.c
107092 @@ -966,14 +966,10 @@ find_codec_preset(struct hda_codec *codec)
107093 mutex_unlock(&preset_mutex);
107094
107095 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
107096 - char name[32];
107097 if (!mod_requested)
107098 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
107099 - codec->vendor_id);
107100 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
107101 else
107102 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
107103 - (codec->vendor_id >> 16) & 0xffff);
107104 - request_module(name);
107105 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
107106 mod_requested++;
107107 goto again;
107108 }
107109 @@ -2777,7 +2773,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
107110 /* FIXME: set_fs() hack for obtaining user-space TLV data */
107111 mm_segment_t fs = get_fs();
107112 set_fs(get_ds());
107113 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
107114 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
107115 tlv = _tlv;
107116 set_fs(fs);
107117 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
107118 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
107119 index 4631a23..001ae57 100644
107120 --- a/sound/pci/ymfpci/ymfpci.h
107121 +++ b/sound/pci/ymfpci/ymfpci.h
107122 @@ -358,7 +358,7 @@ struct snd_ymfpci {
107123 spinlock_t reg_lock;
107124 spinlock_t voice_lock;
107125 wait_queue_head_t interrupt_sleep;
107126 - atomic_t interrupt_sleep_count;
107127 + atomic_unchecked_t interrupt_sleep_count;
107128 struct snd_info_entry *proc_entry;
107129 const struct firmware *dsp_microcode;
107130 const struct firmware *controller_microcode;
107131 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
107132 index 81c916a..516f0bf 100644
107133 --- a/sound/pci/ymfpci/ymfpci_main.c
107134 +++ b/sound/pci/ymfpci/ymfpci_main.c
107135 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
107136 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
107137 break;
107138 }
107139 - if (atomic_read(&chip->interrupt_sleep_count)) {
107140 - atomic_set(&chip->interrupt_sleep_count, 0);
107141 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
107142 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
107143 wake_up(&chip->interrupt_sleep);
107144 }
107145 __end:
107146 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
107147 continue;
107148 init_waitqueue_entry(&wait, current);
107149 add_wait_queue(&chip->interrupt_sleep, &wait);
107150 - atomic_inc(&chip->interrupt_sleep_count);
107151 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
107152 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
107153 remove_wait_queue(&chip->interrupt_sleep, &wait);
107154 }
107155 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
107156 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
107157 spin_unlock(&chip->reg_lock);
107158
107159 - if (atomic_read(&chip->interrupt_sleep_count)) {
107160 - atomic_set(&chip->interrupt_sleep_count, 0);
107161 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
107162 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
107163 wake_up(&chip->interrupt_sleep);
107164 }
107165 }
107166 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
107167 spin_lock_init(&chip->reg_lock);
107168 spin_lock_init(&chip->voice_lock);
107169 init_waitqueue_head(&chip->interrupt_sleep);
107170 - atomic_set(&chip->interrupt_sleep_count, 0);
107171 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
107172 chip->card = card;
107173 chip->pci = pci;
107174 chip->irq = -1;
107175 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
107176 index 5428a1f..474f651 100644
107177 --- a/sound/soc/fsl/fsl_ssi.c
107178 +++ b/sound/soc/fsl/fsl_ssi.c
107179 @@ -1255,7 +1255,6 @@ static int fsl_ssi_probe(struct platform_device *pdev)
107180 {
107181 struct fsl_ssi_private *ssi_private;
107182 int ret = 0;
107183 - struct device_attribute *dev_attr = NULL;
107184 struct device_node *np = pdev->dev.of_node;
107185 const struct of_device_id *of_id;
107186 enum fsl_ssi_type hw_type;
107187 @@ -1481,7 +1480,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
107188 &ssi_private->cpu_dai_drv, 1);
107189 if (ret) {
107190 dev_err(&pdev->dev, "failed to register DAI: %d\n", ret);
107191 - goto error_dev;
107192 + goto error_clk;
107193 }
107194
107195 ret = fsl_ssi_debugfs_create(ssi_private, &pdev->dev);
107196 @@ -1562,9 +1561,6 @@ error_pcm:
107197 error_dbgfs:
107198 snd_soc_unregister_component(&pdev->dev);
107199
107200 -error_dev:
107201 - device_remove_file(&pdev->dev, dev_attr);
107202 -
107203 error_clk:
107204 if (ssi_private->ssi_on_imx) {
107205 if (!IS_ERR(ssi_private->baudclk))
107206 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
107207 index 051c006..70598e8 100644
107208 --- a/sound/soc/soc-core.c
107209 +++ b/sound/soc/soc-core.c
107210 @@ -2255,8 +2255,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
107211 if (ret)
107212 return ret;
107213
107214 - ops->warm_reset = snd_soc_ac97_warm_reset;
107215 - ops->reset = snd_soc_ac97_reset;
107216 + pax_open_kernel();
107217 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
107218 + *(void **)&ops->reset = snd_soc_ac97_reset;
107219 + pax_close_kernel();
107220
107221 snd_ac97_rst_cfg = cfg;
107222 return 0;
107223 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
107224 index 7778b8e..3d619fc 100644
107225 --- a/sound/synth/emux/emux_seq.c
107226 +++ b/sound/synth/emux/emux_seq.c
107227 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
107228 * MIDI emulation operators
107229 */
107230 static struct snd_midi_op emux_ops = {
107231 - snd_emux_note_on,
107232 - snd_emux_note_off,
107233 - snd_emux_key_press,
107234 - snd_emux_terminate_note,
107235 - snd_emux_control,
107236 - snd_emux_nrpn,
107237 - snd_emux_sysex,
107238 + .note_on = snd_emux_note_on,
107239 + .note_off = snd_emux_note_off,
107240 + .key_press = snd_emux_key_press,
107241 + .note_terminate = snd_emux_terminate_note,
107242 + .control = snd_emux_control,
107243 + .nrpn = snd_emux_nrpn,
107244 + .sysex = snd_emux_sysex,
107245 };
107246
107247
107248 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
107249 new file mode 100644
107250 index 0000000..de92ed9
107251 --- /dev/null
107252 +++ b/tools/gcc/.gitignore
107253 @@ -0,0 +1 @@
107254 +randomize_layout_seed.h
107255 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
107256 new file mode 100644
107257 index 0000000..7b8921f
107258 --- /dev/null
107259 +++ b/tools/gcc/Makefile
107260 @@ -0,0 +1,52 @@
107261 +#CC := gcc
107262 +#PLUGIN_SOURCE_FILES := pax_plugin.c
107263 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
107264 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
107265 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
107266 +
107267 +ifeq ($(PLUGINCC),$(HOSTCC))
107268 +HOSTLIBS := hostlibs
107269 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
107270 +export HOST_EXTRACFLAGS
107271 +else
107272 +HOSTLIBS := hostcxxlibs
107273 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
107274 +export HOST_EXTRACXXFLAGS
107275 +endif
107276 +
107277 +export GCCPLUGINS_DIR HOSTLIBS
107278 +
107279 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
107280 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
107281 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
107282 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
107283 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
107284 +$(HOSTLIBS)-y += colorize_plugin.so
107285 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
107286 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
107287 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
107288 +
107289 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
107290 +subdir- += size_overflow_plugin
107291 +
107292 +always := $($(HOSTLIBS)-y)
107293 +
107294 +constify_plugin-objs := constify_plugin.o
107295 +stackleak_plugin-objs := stackleak_plugin.o
107296 +kallocstat_plugin-objs := kallocstat_plugin.o
107297 +kernexec_plugin-objs := kernexec_plugin.o
107298 +checker_plugin-objs := checker_plugin.o
107299 +colorize_plugin-objs := colorize_plugin.o
107300 +latent_entropy_plugin-objs := latent_entropy_plugin.o
107301 +structleak_plugin-objs := structleak_plugin.o
107302 +randomize_layout_plugin-objs := randomize_layout_plugin.o
107303 +
107304 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
107305 +
107306 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
107307 + cmd_create_randomize_layout_seed = \
107308 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
107309 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
107310 + $(call if_changed,create_randomize_layout_seed)
107311 +
107312 +targets += randomize_layout_seed.h randomize_layout_hash.h
107313 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
107314 new file mode 100644
107315 index 0000000..5452feea
107316 --- /dev/null
107317 +++ b/tools/gcc/checker_plugin.c
107318 @@ -0,0 +1,150 @@
107319 +/*
107320 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
107321 + * Licensed under the GPL v2
107322 + *
107323 + * Note: the choice of the license means that the compilation process is
107324 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107325 + * but for the kernel it doesn't matter since it doesn't link against
107326 + * any of the gcc libraries
107327 + *
107328 + * gcc plugin to implement various sparse (source code checker) features
107329 + *
107330 + * TODO:
107331 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
107332 + *
107333 + * BUGS:
107334 + * - none known
107335 + */
107336 +
107337 +#include "gcc-common.h"
107338 +
107339 +extern void c_register_addr_space (const char *str, addr_space_t as);
107340 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
107341 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
107342 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
107343 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
107344 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
107345 +
107346 +int plugin_is_GPL_compatible;
107347 +
107348 +static struct plugin_info checker_plugin_info = {
107349 + .version = "201304082245",
107350 + .help = NULL,
107351 +};
107352 +
107353 +#define ADDR_SPACE_KERNEL 0
107354 +#define ADDR_SPACE_FORCE_KERNEL 1
107355 +#define ADDR_SPACE_USER 2
107356 +#define ADDR_SPACE_FORCE_USER 3
107357 +#define ADDR_SPACE_IOMEM 0
107358 +#define ADDR_SPACE_FORCE_IOMEM 0
107359 +#define ADDR_SPACE_PERCPU 0
107360 +#define ADDR_SPACE_FORCE_PERCPU 0
107361 +#define ADDR_SPACE_RCU 0
107362 +#define ADDR_SPACE_FORCE_RCU 0
107363 +
107364 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
107365 +{
107366 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
107367 +}
107368 +
107369 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
107370 +{
107371 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
107372 +}
107373 +
107374 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
107375 +{
107376 + return default_addr_space_valid_pointer_mode(mode, as);
107377 +}
107378 +
107379 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
107380 +{
107381 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
107382 +}
107383 +
107384 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
107385 +{
107386 + return default_addr_space_legitimize_address(x, oldx, mode, as);
107387 +}
107388 +
107389 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
107390 +{
107391 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
107392 + return true;
107393 +
107394 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
107395 + return true;
107396 +
107397 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
107398 + return true;
107399 +
107400 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
107401 + return true;
107402 +
107403 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
107404 + return true;
107405 +
107406 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
107407 + return true;
107408 +
107409 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
107410 + return true;
107411 +
107412 + return subset == superset;
107413 +}
107414 +
107415 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
107416 +{
107417 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
107418 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
107419 +
107420 + return op;
107421 +}
107422 +
107423 +static void register_checker_address_spaces(void *event_data, void *data)
107424 +{
107425 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
107426 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
107427 + c_register_addr_space("__user", ADDR_SPACE_USER);
107428 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
107429 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
107430 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
107431 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
107432 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
107433 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
107434 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
107435 +
107436 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
107437 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
107438 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
107439 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
107440 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
107441 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
107442 + targetm.addr_space.convert = checker_addr_space_convert;
107443 +}
107444 +
107445 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107446 +{
107447 + const char * const plugin_name = plugin_info->base_name;
107448 + const int argc = plugin_info->argc;
107449 + const struct plugin_argument * const argv = plugin_info->argv;
107450 + int i;
107451 +
107452 + if (!plugin_default_version_check(version, &gcc_version)) {
107453 + error(G_("incompatible gcc/plugin versions"));
107454 + return 1;
107455 + }
107456 +
107457 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
107458 +
107459 + for (i = 0; i < argc; ++i)
107460 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107461 +
107462 + if (TARGET_64BIT == 0)
107463 + return 0;
107464 +
107465 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
107466 +
107467 + return 0;
107468 +}
107469 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
107470 new file mode 100644
107471 index 0000000..54461af
107472 --- /dev/null
107473 +++ b/tools/gcc/colorize_plugin.c
107474 @@ -0,0 +1,210 @@
107475 +/*
107476 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
107477 + * Licensed under the GPL v2
107478 + *
107479 + * Note: the choice of the license means that the compilation process is
107480 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107481 + * but for the kernel it doesn't matter since it doesn't link against
107482 + * any of the gcc libraries
107483 + *
107484 + * gcc plugin to colorize diagnostic output
107485 + *
107486 + */
107487 +
107488 +#include "gcc-common.h"
107489 +
107490 +int plugin_is_GPL_compatible;
107491 +
107492 +static struct plugin_info colorize_plugin_info = {
107493 + .version = "201404202350",
107494 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
107495 +};
107496 +
107497 +#define GREEN "\033[32m\033[K"
107498 +#define LIGHTGREEN "\033[1;32m\033[K"
107499 +#define YELLOW "\033[33m\033[K"
107500 +#define LIGHTYELLOW "\033[1;33m\033[K"
107501 +#define RED "\033[31m\033[K"
107502 +#define LIGHTRED "\033[1;31m\033[K"
107503 +#define BLUE "\033[34m\033[K"
107504 +#define LIGHTBLUE "\033[1;34m\033[K"
107505 +#define BRIGHT "\033[1;m\033[K"
107506 +#define NORMAL "\033[m\033[K"
107507 +
107508 +static diagnostic_starter_fn old_starter;
107509 +static diagnostic_finalizer_fn old_finalizer;
107510 +
107511 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
107512 +{
107513 + const char *color;
107514 + char *newprefix;
107515 +
107516 + switch (diagnostic->kind) {
107517 + case DK_NOTE:
107518 + color = LIGHTBLUE;
107519 + break;
107520 +
107521 + case DK_PEDWARN:
107522 + case DK_WARNING:
107523 + color = LIGHTYELLOW;
107524 + break;
107525 +
107526 + case DK_ERROR:
107527 + case DK_FATAL:
107528 + case DK_ICE:
107529 + case DK_PERMERROR:
107530 + case DK_SORRY:
107531 + color = LIGHTRED;
107532 + break;
107533 +
107534 + default:
107535 + color = NORMAL;
107536 + }
107537 +
107538 + old_starter(context, diagnostic);
107539 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
107540 + return;
107541 + pp_destroy_prefix(context->printer);
107542 + pp_set_prefix(context->printer, newprefix);
107543 +}
107544 +
107545 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
107546 +{
107547 + old_finalizer(context, diagnostic);
107548 +}
107549 +
107550 +static void colorize_arm(void)
107551 +{
107552 + old_starter = diagnostic_starter(global_dc);
107553 + old_finalizer = diagnostic_finalizer(global_dc);
107554 +
107555 + diagnostic_starter(global_dc) = start_colorize;
107556 + diagnostic_finalizer(global_dc) = finalize_colorize;
107557 +}
107558 +
107559 +static unsigned int execute_colorize_rearm(void)
107560 +{
107561 + if (diagnostic_starter(global_dc) == start_colorize)
107562 + return 0;
107563 +
107564 + colorize_arm();
107565 + return 0;
107566 +}
107567 +
107568 +#if BUILDING_GCC_VERSION >= 4009
107569 +static const struct pass_data colorize_rearm_pass_data = {
107570 +#else
107571 +struct simple_ipa_opt_pass colorize_rearm_pass = {
107572 + .pass = {
107573 +#endif
107574 + .type = SIMPLE_IPA_PASS,
107575 + .name = "colorize_rearm",
107576 +#if BUILDING_GCC_VERSION >= 4008
107577 + .optinfo_flags = OPTGROUP_NONE,
107578 +#endif
107579 +#if BUILDING_GCC_VERSION >= 4009
107580 + .has_gate = false,
107581 + .has_execute = true,
107582 +#else
107583 + .gate = NULL,
107584 + .execute = execute_colorize_rearm,
107585 + .sub = NULL,
107586 + .next = NULL,
107587 + .static_pass_number = 0,
107588 +#endif
107589 + .tv_id = TV_NONE,
107590 + .properties_required = 0,
107591 + .properties_provided = 0,
107592 + .properties_destroyed = 0,
107593 + .todo_flags_start = 0,
107594 + .todo_flags_finish = 0
107595 +#if BUILDING_GCC_VERSION < 4009
107596 + }
107597 +#endif
107598 +};
107599 +
107600 +#if BUILDING_GCC_VERSION >= 4009
107601 +namespace {
107602 +class colorize_rearm_pass : public simple_ipa_opt_pass {
107603 +public:
107604 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
107605 + unsigned int execute() { return execute_colorize_rearm(); }
107606 +};
107607 +}
107608 +
107609 +static opt_pass *make_colorize_rearm_pass(void)
107610 +{
107611 + return new colorize_rearm_pass();
107612 +}
107613 +#else
107614 +static struct opt_pass *make_colorize_rearm_pass(void)
107615 +{
107616 + return &colorize_rearm_pass.pass;
107617 +}
107618 +#endif
107619 +
107620 +static void colorize_start_unit(void *gcc_data, void *user_data)
107621 +{
107622 + colorize_arm();
107623 +}
107624 +
107625 +static bool should_colorize(void)
107626 +{
107627 +#if BUILDING_GCC_VERSION >= 4009
107628 + return false;
107629 +#else
107630 + char const *t = getenv("TERM");
107631 +
107632 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
107633 +#endif
107634 +}
107635 +
107636 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107637 +{
107638 + const char * const plugin_name = plugin_info->base_name;
107639 + const int argc = plugin_info->argc;
107640 + const struct plugin_argument * const argv = plugin_info->argv;
107641 + int i;
107642 + struct register_pass_info colorize_rearm_pass_info;
107643 + bool colorize;
107644 +
107645 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
107646 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
107647 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
107648 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107649 +
107650 + if (!plugin_default_version_check(version, &gcc_version)) {
107651 + error(G_("incompatible gcc/plugin versions"));
107652 + return 1;
107653 + }
107654 +
107655 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
107656 +
107657 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
107658 +
107659 + for (i = 0; i < argc; ++i) {
107660 + if (!strcmp(argv[i].key, "color")) {
107661 + if (!argv[i].value) {
107662 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107663 + continue;
107664 + }
107665 + if (!strcmp(argv[i].value, "always"))
107666 + colorize = true;
107667 + else if (!strcmp(argv[i].value, "never"))
107668 + colorize = false;
107669 + else if (!strcmp(argv[i].value, "auto"))
107670 + colorize = should_colorize();
107671 + else
107672 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
107673 + continue;
107674 + }
107675 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107676 + }
107677 +
107678 + if (colorize) {
107679 + // TODO: parse GCC_COLORS as used by gcc 4.9+
107680 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
107681 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
107682 + }
107683 + return 0;
107684 +}
107685 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
107686 new file mode 100644
107687 index 0000000..82bc5a8
107688 --- /dev/null
107689 +++ b/tools/gcc/constify_plugin.c
107690 @@ -0,0 +1,557 @@
107691 +/*
107692 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
107693 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
107694 + * Licensed under the GPL v2, or (at your option) v3
107695 + *
107696 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
107697 + *
107698 + * Homepage:
107699 + * http://www.grsecurity.net/~ephox/const_plugin/
107700 + *
107701 + * Usage:
107702 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
107703 + * $ gcc -fplugin=constify_plugin.so test.c -O2
107704 + */
107705 +
107706 +#include "gcc-common.h"
107707 +
107708 +// unused C type flag in all versions 4.5-4.9
107709 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
107710 +
107711 +int plugin_is_GPL_compatible;
107712 +
107713 +static struct plugin_info const_plugin_info = {
107714 + .version = "201401270210",
107715 + .help = "no-constify\tturn off constification\n",
107716 +};
107717 +
107718 +typedef struct {
107719 + bool has_fptr_field;
107720 + bool has_writable_field;
107721 + bool has_do_const_field;
107722 + bool has_no_const_field;
107723 +} constify_info;
107724 +
107725 +static const_tree get_field_type(const_tree field)
107726 +{
107727 + return strip_array_types(TREE_TYPE(field));
107728 +}
107729 +
107730 +static bool is_fptr(const_tree field)
107731 +{
107732 + const_tree ptr = get_field_type(field);
107733 +
107734 + if (TREE_CODE(ptr) != POINTER_TYPE)
107735 + return false;
107736 +
107737 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
107738 +}
107739 +
107740 +/*
107741 + * determine whether the given structure type meets the requirements for automatic constification,
107742 + * including the constification attributes on nested structure types
107743 + */
107744 +static void constifiable(const_tree node, constify_info *cinfo)
107745 +{
107746 + const_tree field;
107747 +
107748 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
107749 +
107750 + // e.g., pointer to structure fields while still constructing the structure type
107751 + if (TYPE_FIELDS(node) == NULL_TREE)
107752 + return;
107753 +
107754 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
107755 + const_tree type = get_field_type(field);
107756 + enum tree_code code = TREE_CODE(type);
107757 +
107758 + if (node == type)
107759 + continue;
107760 +
107761 + if (is_fptr(field))
107762 + cinfo->has_fptr_field = true;
107763 + else if (!TREE_READONLY(field))
107764 + cinfo->has_writable_field = true;
107765 +
107766 + if (code == RECORD_TYPE || code == UNION_TYPE) {
107767 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
107768 + cinfo->has_do_const_field = true;
107769 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
107770 + cinfo->has_no_const_field = true;
107771 + else
107772 + constifiable(type, cinfo);
107773 + }
107774 + }
107775 +}
107776 +
107777 +static bool constified(const_tree node)
107778 +{
107779 + constify_info cinfo = {
107780 + .has_fptr_field = false,
107781 + .has_writable_field = false,
107782 + .has_do_const_field = false,
107783 + .has_no_const_field = false
107784 + };
107785 +
107786 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
107787 +
107788 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
107789 +// gcc_assert(!TYPE_READONLY(node));
107790 + return false;
107791 + }
107792 +
107793 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
107794 + gcc_assert(TYPE_READONLY(node));
107795 + return true;
107796 + }
107797 +
107798 + constifiable(node, &cinfo);
107799 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
107800 + return false;
107801 +
107802 + return TYPE_READONLY(node);
107803 +}
107804 +
107805 +static void deconstify_tree(tree node);
107806 +
107807 +static void deconstify_type(tree type)
107808 +{
107809 + tree field;
107810 +
107811 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
107812 +
107813 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
107814 + const_tree fieldtype = get_field_type(field);
107815 +
107816 + // special case handling of simple ptr-to-same-array-type members
107817 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
107818 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
107819 +
107820 + if (TREE_TYPE(TREE_TYPE(field)) == type)
107821 + continue;
107822 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
107823 + continue;
107824 + if (!constified(ptrtype))
107825 + continue;
107826 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
107827 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
107828 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
107829 + }
107830 + continue;
107831 + }
107832 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
107833 + continue;
107834 + if (!constified(fieldtype))
107835 + continue;
107836 +
107837 + deconstify_tree(field);
107838 + TREE_READONLY(field) = 0;
107839 + }
107840 + TYPE_READONLY(type) = 0;
107841 + C_TYPE_FIELDS_READONLY(type) = 0;
107842 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107843 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
107844 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
107845 + }
107846 +}
107847 +
107848 +static void deconstify_tree(tree node)
107849 +{
107850 + tree old_type, new_type, field;
107851 +
107852 + old_type = TREE_TYPE(node);
107853 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
107854 + node = TREE_TYPE(node) = copy_node(old_type);
107855 + old_type = TREE_TYPE(old_type);
107856 + }
107857 +
107858 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
107859 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
107860 +
107861 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
107862 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
107863 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
107864 + DECL_FIELD_CONTEXT(field) = new_type;
107865 +
107866 + deconstify_type(new_type);
107867 +
107868 + TREE_TYPE(node) = new_type;
107869 +}
107870 +
107871 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107872 +{
107873 + tree type;
107874 + constify_info cinfo = {
107875 + .has_fptr_field = false,
107876 + .has_writable_field = false,
107877 + .has_do_const_field = false,
107878 + .has_no_const_field = false
107879 + };
107880 +
107881 + *no_add_attrs = true;
107882 + if (TREE_CODE(*node) == FUNCTION_DECL) {
107883 + error("%qE attribute does not apply to functions (%qF)", name, *node);
107884 + return NULL_TREE;
107885 + }
107886 +
107887 + if (TREE_CODE(*node) == PARM_DECL) {
107888 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
107889 + return NULL_TREE;
107890 + }
107891 +
107892 + if (TREE_CODE(*node) == VAR_DECL) {
107893 + error("%qE attribute does not apply to variables (%qD)", name, *node);
107894 + return NULL_TREE;
107895 + }
107896 +
107897 + if (TYPE_P(*node)) {
107898 + type = *node;
107899 + } else {
107900 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
107901 + type = TREE_TYPE(*node);
107902 + }
107903 +
107904 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
107905 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
107906 + return NULL_TREE;
107907 + }
107908 +
107909 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
107910 + error("%qE attribute is already applied to the type %qT", name, type);
107911 + return NULL_TREE;
107912 + }
107913 +
107914 + if (TYPE_P(*node)) {
107915 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
107916 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
107917 + else
107918 + *no_add_attrs = false;
107919 + return NULL_TREE;
107920 + }
107921 +
107922 + constifiable(type, &cinfo);
107923 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107924 + deconstify_tree(*node);
107925 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
107926 + return NULL_TREE;
107927 + }
107928 +
107929 + error("%qE attribute used on type %qT that is not constified", name, type);
107930 + return NULL_TREE;
107931 +}
107932 +
107933 +static void constify_type(tree type)
107934 +{
107935 + TYPE_READONLY(type) = 1;
107936 + C_TYPE_FIELDS_READONLY(type) = 1;
107937 + TYPE_CONSTIFY_VISITED(type) = 1;
107938 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
107939 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
107940 +}
107941 +
107942 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107943 +{
107944 + *no_add_attrs = true;
107945 + if (!TYPE_P(*node)) {
107946 + error("%qE attribute applies to types only (%qD)", name, *node);
107947 + return NULL_TREE;
107948 + }
107949 +
107950 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
107951 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
107952 + return NULL_TREE;
107953 + }
107954 +
107955 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
107956 + error("%qE attribute used on %qT is already applied to the type", name, *node);
107957 + return NULL_TREE;
107958 + }
107959 +
107960 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
107961 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
107962 + return NULL_TREE;
107963 + }
107964 +
107965 + *no_add_attrs = false;
107966 + return NULL_TREE;
107967 +}
107968 +
107969 +static struct attribute_spec no_const_attr = {
107970 + .name = "no_const",
107971 + .min_length = 0,
107972 + .max_length = 0,
107973 + .decl_required = false,
107974 + .type_required = false,
107975 + .function_type_required = false,
107976 + .handler = handle_no_const_attribute,
107977 +#if BUILDING_GCC_VERSION >= 4007
107978 + .affects_type_identity = true
107979 +#endif
107980 +};
107981 +
107982 +static struct attribute_spec do_const_attr = {
107983 + .name = "do_const",
107984 + .min_length = 0,
107985 + .max_length = 0,
107986 + .decl_required = false,
107987 + .type_required = false,
107988 + .function_type_required = false,
107989 + .handler = handle_do_const_attribute,
107990 +#if BUILDING_GCC_VERSION >= 4007
107991 + .affects_type_identity = true
107992 +#endif
107993 +};
107994 +
107995 +static void register_attributes(void *event_data, void *data)
107996 +{
107997 + register_attribute(&no_const_attr);
107998 + register_attribute(&do_const_attr);
107999 +}
108000 +
108001 +static void finish_type(void *event_data, void *data)
108002 +{
108003 + tree type = (tree)event_data;
108004 + constify_info cinfo = {
108005 + .has_fptr_field = false,
108006 + .has_writable_field = false,
108007 + .has_do_const_field = false,
108008 + .has_no_const_field = false
108009 + };
108010 +
108011 + if (type == NULL_TREE || type == error_mark_node)
108012 + return;
108013 +
108014 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
108015 + return;
108016 +
108017 + constifiable(type, &cinfo);
108018 +
108019 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
108020 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
108021 + deconstify_type(type);
108022 + TYPE_CONSTIFY_VISITED(type) = 1;
108023 + } else
108024 + error("'no_const' attribute used on type %qT that is not constified", type);
108025 + return;
108026 + }
108027 +
108028 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
108029 + if (!cinfo.has_writable_field) {
108030 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
108031 + return;
108032 + }
108033 + constify_type(type);
108034 + return;
108035 + }
108036 +
108037 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
108038 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
108039 + error("'do_const' attribute used on type %qT that is constified", type);
108040 + return;
108041 + }
108042 + constify_type(type);
108043 + return;
108044 + }
108045 +
108046 + deconstify_type(type);
108047 + TYPE_CONSTIFY_VISITED(type) = 1;
108048 +}
108049 +
108050 +static void check_global_variables(void *event_data, void *data)
108051 +{
108052 +#if BUILDING_GCC_VERSION >= 4009
108053 + varpool_node *node;
108054 +#else
108055 + struct varpool_node *node;
108056 +#endif
108057 +
108058 + FOR_EACH_VARIABLE(node) {
108059 + tree var = NODE_DECL(node);
108060 + tree type = TREE_TYPE(var);
108061 +
108062 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
108063 + continue;
108064 +
108065 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
108066 + continue;
108067 +
108068 + if (!TYPE_CONSTIFY_VISITED(type))
108069 + continue;
108070 +
108071 + if (DECL_EXTERNAL(var))
108072 + continue;
108073 +
108074 + if (DECL_INITIAL(var))
108075 + continue;
108076 +
108077 + // this works around a gcc bug/feature where uninitialized globals
108078 + // are moved into the .bss section regardless of any constification
108079 + DECL_INITIAL(var) = build_constructor(type, NULL);
108080 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
108081 + }
108082 +}
108083 +
108084 +static unsigned int check_local_variables(void)
108085 +{
108086 + unsigned int ret = 0;
108087 + tree var;
108088 +
108089 + unsigned int i;
108090 +
108091 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
108092 + tree type = TREE_TYPE(var);
108093 +
108094 + gcc_assert(DECL_P(var));
108095 + if (is_global_var(var))
108096 + continue;
108097 +
108098 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
108099 + continue;
108100 +
108101 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
108102 + continue;
108103 +
108104 + if (!TYPE_CONSTIFY_VISITED(type))
108105 + continue;
108106 +
108107 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
108108 + ret = 1;
108109 + }
108110 + return ret;
108111 +}
108112 +
108113 +#if BUILDING_GCC_VERSION >= 4009
108114 +static const struct pass_data check_local_variables_pass_data = {
108115 +#else
108116 +static struct gimple_opt_pass check_local_variables_pass = {
108117 + .pass = {
108118 +#endif
108119 + .type = GIMPLE_PASS,
108120 + .name = "check_local_variables",
108121 +#if BUILDING_GCC_VERSION >= 4008
108122 + .optinfo_flags = OPTGROUP_NONE,
108123 +#endif
108124 +#if BUILDING_GCC_VERSION >= 4009
108125 + .has_gate = false,
108126 + .has_execute = true,
108127 +#else
108128 + .gate = NULL,
108129 + .execute = check_local_variables,
108130 + .sub = NULL,
108131 + .next = NULL,
108132 + .static_pass_number = 0,
108133 +#endif
108134 + .tv_id = TV_NONE,
108135 + .properties_required = 0,
108136 + .properties_provided = 0,
108137 + .properties_destroyed = 0,
108138 + .todo_flags_start = 0,
108139 + .todo_flags_finish = 0
108140 +#if BUILDING_GCC_VERSION < 4009
108141 + }
108142 +#endif
108143 +};
108144 +
108145 +#if BUILDING_GCC_VERSION >= 4009
108146 +namespace {
108147 +class check_local_variables_pass : public gimple_opt_pass {
108148 +public:
108149 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
108150 + unsigned int execute() { return check_local_variables(); }
108151 +};
108152 +}
108153 +
108154 +static opt_pass *make_check_local_variables_pass(void)
108155 +{
108156 + return new check_local_variables_pass();
108157 +}
108158 +#else
108159 +static struct opt_pass *make_check_local_variables_pass(void)
108160 +{
108161 + return &check_local_variables_pass.pass;
108162 +}
108163 +#endif
108164 +
108165 +static struct {
108166 + const char *name;
108167 + const char *asm_op;
108168 +} sections[] = {
108169 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
108170 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
108171 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
108172 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
108173 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
108174 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
108175 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
108176 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
108177 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
108178 +};
108179 +
108180 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
108181 +
108182 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
108183 +{
108184 + size_t i;
108185 +
108186 + for (i = 0; i < ARRAY_SIZE(sections); i++)
108187 + if (!strcmp(sections[i].name, name))
108188 + return 0;
108189 + return old_section_type_flags(decl, name, reloc);
108190 +}
108191 +
108192 +static void constify_start_unit(void *gcc_data, void *user_data)
108193 +{
108194 +// size_t i;
108195 +
108196 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
108197 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
108198 +// sections[i].section = get_section(sections[i].name, 0, NULL);
108199 +
108200 + old_section_type_flags = targetm.section_type_flags;
108201 + targetm.section_type_flags = constify_section_type_flags;
108202 +}
108203 +
108204 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108205 +{
108206 + const char * const plugin_name = plugin_info->base_name;
108207 + const int argc = plugin_info->argc;
108208 + const struct plugin_argument * const argv = plugin_info->argv;
108209 + int i;
108210 + bool constify = true;
108211 +
108212 + struct register_pass_info check_local_variables_pass_info;
108213 +
108214 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
108215 + check_local_variables_pass_info.reference_pass_name = "ssa";
108216 + check_local_variables_pass_info.ref_pass_instance_number = 1;
108217 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
108218 +
108219 + if (!plugin_default_version_check(version, &gcc_version)) {
108220 + error(G_("incompatible gcc/plugin versions"));
108221 + return 1;
108222 + }
108223 +
108224 + for (i = 0; i < argc; ++i) {
108225 + if (!(strcmp(argv[i].key, "no-constify"))) {
108226 + constify = false;
108227 + continue;
108228 + }
108229 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
108230 + }
108231 +
108232 + if (strcmp(lang_hooks.name, "GNU C")) {
108233 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
108234 + constify = false;
108235 + }
108236 +
108237 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
108238 + if (constify) {
108239 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
108240 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
108241 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
108242 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
108243 + }
108244 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
108245 +
108246 + return 0;
108247 +}
108248 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
108249 new file mode 100644
108250 index 0000000..e90c205
108251 --- /dev/null
108252 +++ b/tools/gcc/gcc-common.h
108253 @@ -0,0 +1,295 @@
108254 +#ifndef GCC_COMMON_H_INCLUDED
108255 +#define GCC_COMMON_H_INCLUDED
108256 +
108257 +#include "plugin.h"
108258 +#include "bversion.h"
108259 +#include "plugin-version.h"
108260 +#include "config.h"
108261 +#include "system.h"
108262 +#include "coretypes.h"
108263 +#include "tm.h"
108264 +#include "line-map.h"
108265 +#include "input.h"
108266 +#include "tree.h"
108267 +
108268 +#include "tree-inline.h"
108269 +#include "version.h"
108270 +#include "rtl.h"
108271 +#include "tm_p.h"
108272 +#include "flags.h"
108273 +//#include "insn-attr.h"
108274 +//#include "insn-config.h"
108275 +//#include "insn-flags.h"
108276 +#include "hard-reg-set.h"
108277 +//#include "recog.h"
108278 +#include "output.h"
108279 +#include "except.h"
108280 +#include "function.h"
108281 +#include "toplev.h"
108282 +//#include "expr.h"
108283 +#include "basic-block.h"
108284 +#include "intl.h"
108285 +#include "ggc.h"
108286 +//#include "regs.h"
108287 +#include "timevar.h"
108288 +
108289 +#include "params.h"
108290 +#include "pointer-set.h"
108291 +#include "emit-rtl.h"
108292 +//#include "reload.h"
108293 +//#include "ira.h"
108294 +//#include "dwarf2asm.h"
108295 +#include "debug.h"
108296 +#include "target.h"
108297 +#include "langhooks.h"
108298 +#include "cfgloop.h"
108299 +//#include "hosthooks.h"
108300 +#include "cgraph.h"
108301 +#include "opts.h"
108302 +//#include "coverage.h"
108303 +//#include "value-prof.h"
108304 +
108305 +#if BUILDING_GCC_VERSION >= 4007
108306 +#include "tree-pretty-print.h"
108307 +#include "gimple-pretty-print.h"
108308 +#include "c-tree.h"
108309 +//#include "alloc-pool.h"
108310 +#endif
108311 +
108312 +#if BUILDING_GCC_VERSION <= 4008
108313 +#include "tree-flow.h"
108314 +#else
108315 +#include "tree-cfgcleanup.h"
108316 +#endif
108317 +
108318 +#include "diagnostic.h"
108319 +//#include "tree-diagnostic.h"
108320 +#include "tree-dump.h"
108321 +#include "tree-pass.h"
108322 +//#include "df.h"
108323 +#include "predict.h"
108324 +#include "ipa-utils.h"
108325 +
108326 +#if BUILDING_GCC_VERSION >= 4009
108327 +#include "varasm.h"
108328 +#include "stor-layout.h"
108329 +#include "internal-fn.h"
108330 +#include "gimple-expr.h"
108331 +//#include "diagnostic-color.h"
108332 +#include "context.h"
108333 +#include "tree-ssa-alias.h"
108334 +#include "stringpool.h"
108335 +#include "tree-ssanames.h"
108336 +#include "print-tree.h"
108337 +#include "tree-eh.h"
108338 +#include "stmt.h"
108339 +#endif
108340 +
108341 +#include "gimple.h"
108342 +
108343 +#if BUILDING_GCC_VERSION >= 4009
108344 +#include "tree-ssa-operands.h"
108345 +#include "tree-phinodes.h"
108346 +#include "tree-cfg.h"
108347 +#include "gimple-iterator.h"
108348 +#include "gimple-ssa.h"
108349 +#include "ssa-iterators.h"
108350 +#endif
108351 +
108352 +//#include "lto/lto.h"
108353 +//#include "data-streamer.h"
108354 +//#include "lto-compress.h"
108355 +
108356 +//#include "expr.h" where are you...
108357 +extern rtx emit_move_insn(rtx x, rtx y);
108358 +
108359 +// missing from basic_block.h...
108360 +extern void debug_dominance_info(enum cdi_direction dir);
108361 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
108362 +
108363 +#define __unused __attribute__((__unused__))
108364 +
108365 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
108366 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
108367 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
108368 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
108369 +
108370 +#if BUILDING_GCC_VERSION == 4005
108371 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
108372 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
108373 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
108374 +#define TODO_rebuild_cgraph_edges 0
108375 +
108376 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
108377 +{
108378 + tree fndecl;
108379 +
108380 + if (!is_gimple_call(stmt))
108381 + return false;
108382 + fndecl = gimple_call_fndecl(stmt);
108383 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
108384 + return false;
108385 +// print_node(stderr, "pax", fndecl, 4);
108386 + return DECL_FUNCTION_CODE(fndecl) == code;
108387 +}
108388 +
108389 +static inline bool is_simple_builtin(tree decl)
108390 +{
108391 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
108392 + return false;
108393 +
108394 + switch (DECL_FUNCTION_CODE(decl)) {
108395 + /* Builtins that expand to constants. */
108396 + case BUILT_IN_CONSTANT_P:
108397 + case BUILT_IN_EXPECT:
108398 + case BUILT_IN_OBJECT_SIZE:
108399 + case BUILT_IN_UNREACHABLE:
108400 + /* Simple register moves or loads from stack. */
108401 + case BUILT_IN_RETURN_ADDRESS:
108402 + case BUILT_IN_EXTRACT_RETURN_ADDR:
108403 + case BUILT_IN_FROB_RETURN_ADDR:
108404 + case BUILT_IN_RETURN:
108405 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
108406 + case BUILT_IN_FRAME_ADDRESS:
108407 + case BUILT_IN_VA_END:
108408 + case BUILT_IN_STACK_SAVE:
108409 + case BUILT_IN_STACK_RESTORE:
108410 + /* Exception state returns or moves registers around. */
108411 + case BUILT_IN_EH_FILTER:
108412 + case BUILT_IN_EH_POINTER:
108413 + case BUILT_IN_EH_COPY_VALUES:
108414 + return true;
108415 +
108416 + default:
108417 + return false;
108418 + }
108419 +}
108420 +#endif
108421 +
108422 +#if BUILDING_GCC_VERSION <= 4006
108423 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
108424 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
108425 +
108426 +// should come from c-tree.h if only it were installed for gcc 4.5...
108427 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
108428 +
108429 +#define get_random_seed(noinit) ({ \
108430 + unsigned HOST_WIDE_INT seed; \
108431 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
108432 + seed * seed; })
108433 +
108434 +static inline bool gimple_clobber_p(gimple s)
108435 +{
108436 + return false;
108437 +}
108438 +
108439 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
108440 +{
108441 + return implicit_built_in_decls[fncode];
108442 +}
108443 +
108444 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
108445 +{
108446 + struct cgraph_node *node = cgraph_get_node(decl);
108447 +
108448 + return node ? node : cgraph_node(decl);
108449 +}
108450 +
108451 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
108452 +{
108453 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
108454 +}
108455 +
108456 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
108457 +{
108458 + struct cgraph_node *node;
108459 +
108460 + for (node = cgraph_nodes; node; node = node->next)
108461 + if (cgraph_function_with_gimple_body_p(node))
108462 + return node;
108463 + return NULL;
108464 +}
108465 +
108466 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
108467 +{
108468 + for (node = node->next; node; node = node->next)
108469 + if (cgraph_function_with_gimple_body_p(node))
108470 + return node;
108471 + return NULL;
108472 +}
108473 +
108474 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
108475 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
108476 + (node) = cgraph_next_function_with_gimple_body(node))
108477 +#endif
108478 +
108479 +#if BUILDING_GCC_VERSION == 4006
108480 +extern void debug_gimple_stmt(gimple);
108481 +extern void debug_gimple_seq(gimple_seq);
108482 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
108483 +extern void print_gimple_stmt(FILE *, gimple, int, int);
108484 +extern void print_gimple_expr(FILE *, gimple, int, int);
108485 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
108486 +#endif
108487 +
108488 +#if BUILDING_GCC_VERSION <= 4007
108489 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
108490 +#define PROP_loops 0
108491 +
108492 +static inline int bb_loop_depth(const_basic_block bb)
108493 +{
108494 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
108495 +}
108496 +
108497 +static inline bool gimple_store_p(gimple gs)
108498 +{
108499 + tree lhs = gimple_get_lhs(gs);
108500 + return lhs && !is_gimple_reg(lhs);
108501 +}
108502 +#endif
108503 +
108504 +#if BUILDING_GCC_VERSION >= 4007
108505 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
108506 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
108507 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
108508 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
108509 +#endif
108510 +
108511 +#if BUILDING_GCC_VERSION <= 4008
108512 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
108513 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
108514 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
108515 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
108516 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
108517 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
108518 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
108519 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
108520 +
108521 +static inline const char *get_tree_code_name(enum tree_code code)
108522 +{
108523 + gcc_assert(code < MAX_TREE_CODES);
108524 + return tree_code_name[code];
108525 +}
108526 +
108527 +#define ipa_remove_stmt_references(cnode, stmt)
108528 +#endif
108529 +
108530 +#if BUILDING_GCC_VERSION == 4008
108531 +#define NODE_DECL(node) node->symbol.decl
108532 +#else
108533 +#define NODE_DECL(node) node->decl
108534 +#endif
108535 +
108536 +#if BUILDING_GCC_VERSION >= 4008
108537 +#define add_referenced_var(var)
108538 +#define mark_sym_for_renaming(var)
108539 +#define varpool_mark_needed_node(node)
108540 +#define TODO_dump_func 0
108541 +#define TODO_dump_cgraph 0
108542 +#endif
108543 +
108544 +#if BUILDING_GCC_VERSION >= 4009
108545 +#define TODO_ggc_collect 0
108546 +#endif
108547 +
108548 +#endif
108549 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
108550 new file mode 100644
108551 index 0000000..7514850
108552 --- /dev/null
108553 +++ b/tools/gcc/gen-random-seed.sh
108554 @@ -0,0 +1,8 @@
108555 +#!/bin/sh
108556 +
108557 +if [ ! -f "$1" ]; then
108558 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
108559 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
108560 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
108561 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
108562 +fi
108563 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
108564 new file mode 100644
108565 index 0000000..d81c094
108566 --- /dev/null
108567 +++ b/tools/gcc/kallocstat_plugin.c
108568 @@ -0,0 +1,183 @@
108569 +/*
108570 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
108571 + * Licensed under the GPL v2
108572 + *
108573 + * Note: the choice of the license means that the compilation process is
108574 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
108575 + * but for the kernel it doesn't matter since it doesn't link against
108576 + * any of the gcc libraries
108577 + *
108578 + * gcc plugin to find the distribution of k*alloc sizes
108579 + *
108580 + * TODO:
108581 + *
108582 + * BUGS:
108583 + * - none known
108584 + */
108585 +
108586 +#include "gcc-common.h"
108587 +
108588 +int plugin_is_GPL_compatible;
108589 +
108590 +static struct plugin_info kallocstat_plugin_info = {
108591 + .version = "201401260140",
108592 + .help = NULL
108593 +};
108594 +
108595 +static const char * const kalloc_functions[] = {
108596 + "__kmalloc",
108597 + "kmalloc",
108598 + "kmalloc_large",
108599 + "kmalloc_node",
108600 + "kmalloc_order",
108601 + "kmalloc_order_trace",
108602 + "kmalloc_slab",
108603 + "kzalloc",
108604 + "kzalloc_node",
108605 +};
108606 +
108607 +static bool is_kalloc(const char *fnname)
108608 +{
108609 + size_t i;
108610 +
108611 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
108612 + if (!strcmp(fnname, kalloc_functions[i]))
108613 + return true;
108614 + return false;
108615 +}
108616 +
108617 +static unsigned int execute_kallocstat(void)
108618 +{
108619 + basic_block bb;
108620 +
108621 + // 1. loop through BBs and GIMPLE statements
108622 + FOR_EACH_BB_FN(bb, cfun) {
108623 + gimple_stmt_iterator gsi;
108624 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108625 + // gimple match:
108626 + tree fndecl, size;
108627 + gimple stmt;
108628 + const char *fnname;
108629 +
108630 + // is it a call
108631 + stmt = gsi_stmt(gsi);
108632 + if (!is_gimple_call(stmt))
108633 + continue;
108634 + fndecl = gimple_call_fndecl(stmt);
108635 + if (fndecl == NULL_TREE)
108636 + continue;
108637 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
108638 + continue;
108639 +
108640 + // is it a call to k*alloc
108641 + fnname = DECL_NAME_POINTER(fndecl);
108642 + if (!is_kalloc(fnname))
108643 + continue;
108644 +
108645 + // is the size arg const or the result of a simple const assignment
108646 + size = gimple_call_arg(stmt, 0);
108647 + while (true) {
108648 + expanded_location xloc;
108649 + size_t size_val;
108650 +
108651 + if (TREE_CONSTANT(size)) {
108652 + xloc = expand_location(gimple_location(stmt));
108653 + if (!xloc.file)
108654 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
108655 + size_val = TREE_INT_CST_LOW(size);
108656 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
108657 + break;
108658 + }
108659 +
108660 + if (TREE_CODE(size) != SSA_NAME)
108661 + break;
108662 + stmt = SSA_NAME_DEF_STMT(size);
108663 +//debug_gimple_stmt(stmt);
108664 +//debug_tree(size);
108665 + if (!stmt || !is_gimple_assign(stmt))
108666 + break;
108667 + if (gimple_num_ops(stmt) != 2)
108668 + break;
108669 + size = gimple_assign_rhs1(stmt);
108670 + }
108671 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
108672 +//debug_tree(gimple_call_fn(call_stmt));
108673 +//print_node(stderr, "pax", fndecl, 4);
108674 + }
108675 + }
108676 +
108677 + return 0;
108678 +}
108679 +
108680 +#if BUILDING_GCC_VERSION >= 4009
108681 +static const struct pass_data kallocstat_pass_data = {
108682 +#else
108683 +static struct gimple_opt_pass kallocstat_pass = {
108684 + .pass = {
108685 +#endif
108686 + .type = GIMPLE_PASS,
108687 + .name = "kallocstat",
108688 +#if BUILDING_GCC_VERSION >= 4008
108689 + .optinfo_flags = OPTGROUP_NONE,
108690 +#endif
108691 +#if BUILDING_GCC_VERSION >= 4009
108692 + .has_gate = false,
108693 + .has_execute = true,
108694 +#else
108695 + .gate = NULL,
108696 + .execute = execute_kallocstat,
108697 + .sub = NULL,
108698 + .next = NULL,
108699 + .static_pass_number = 0,
108700 +#endif
108701 + .tv_id = TV_NONE,
108702 + .properties_required = 0,
108703 + .properties_provided = 0,
108704 + .properties_destroyed = 0,
108705 + .todo_flags_start = 0,
108706 + .todo_flags_finish = 0
108707 +#if BUILDING_GCC_VERSION < 4009
108708 + }
108709 +#endif
108710 +};
108711 +
108712 +#if BUILDING_GCC_VERSION >= 4009
108713 +namespace {
108714 +class kallocstat_pass : public gimple_opt_pass {
108715 +public:
108716 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
108717 + unsigned int execute() { return execute_kallocstat(); }
108718 +};
108719 +}
108720 +
108721 +static opt_pass *make_kallocstat_pass(void)
108722 +{
108723 + return new kallocstat_pass();
108724 +}
108725 +#else
108726 +static struct opt_pass *make_kallocstat_pass(void)
108727 +{
108728 + return &kallocstat_pass.pass;
108729 +}
108730 +#endif
108731 +
108732 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108733 +{
108734 + const char * const plugin_name = plugin_info->base_name;
108735 + struct register_pass_info kallocstat_pass_info;
108736 +
108737 + kallocstat_pass_info.pass = make_kallocstat_pass();
108738 + kallocstat_pass_info.reference_pass_name = "ssa";
108739 + kallocstat_pass_info.ref_pass_instance_number = 1;
108740 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108741 +
108742 + if (!plugin_default_version_check(version, &gcc_version)) {
108743 + error(G_("incompatible gcc/plugin versions"));
108744 + return 1;
108745 + }
108746 +
108747 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
108748 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
108749 +
108750 + return 0;
108751 +}
108752 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
108753 new file mode 100644
108754 index 0000000..89f256d
108755 --- /dev/null
108756 +++ b/tools/gcc/kernexec_plugin.c
108757 @@ -0,0 +1,522 @@
108758 +/*
108759 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
108760 + * Licensed under the GPL v2
108761 + *
108762 + * Note: the choice of the license means that the compilation process is
108763 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
108764 + * but for the kernel it doesn't matter since it doesn't link against
108765 + * any of the gcc libraries
108766 + *
108767 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
108768 + *
108769 + * TODO:
108770 + *
108771 + * BUGS:
108772 + * - none known
108773 + */
108774 +
108775 +#include "gcc-common.h"
108776 +
108777 +int plugin_is_GPL_compatible;
108778 +
108779 +static struct plugin_info kernexec_plugin_info = {
108780 + .version = "201401260140",
108781 + .help = "method=[bts|or]\tinstrumentation method\n"
108782 +};
108783 +
108784 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
108785 +static void (*kernexec_instrument_retaddr)(rtx);
108786 +
108787 +/*
108788 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
108789 + */
108790 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
108791 +{
108792 + gimple asm_movabs_stmt;
108793 +
108794 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
108795 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
108796 + gimple_asm_set_volatile(asm_movabs_stmt, true);
108797 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
108798 + update_stmt(asm_movabs_stmt);
108799 +}
108800 +
108801 +/*
108802 + * find all asm() stmts that clobber r12 and add a reload of r12
108803 + */
108804 +static unsigned int execute_kernexec_reload(void)
108805 +{
108806 + basic_block bb;
108807 +
108808 + // 1. loop through BBs and GIMPLE statements
108809 + FOR_EACH_BB_FN(bb, cfun) {
108810 + gimple_stmt_iterator gsi;
108811 +
108812 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108813 + // gimple match: __asm__ ("" : : : "r12");
108814 + gimple asm_stmt;
108815 + size_t nclobbers;
108816 +
108817 + // is it an asm ...
108818 + asm_stmt = gsi_stmt(gsi);
108819 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
108820 + continue;
108821 +
108822 + // ... clobbering r12
108823 + nclobbers = gimple_asm_nclobbers(asm_stmt);
108824 + while (nclobbers--) {
108825 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
108826 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
108827 + continue;
108828 + kernexec_reload_fptr_mask(&gsi);
108829 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
108830 + break;
108831 + }
108832 + }
108833 + }
108834 +
108835 + return 0;
108836 +}
108837 +
108838 +/*
108839 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
108840 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
108841 + */
108842 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
108843 +{
108844 + gimple assign_intptr, assign_new_fptr, call_stmt;
108845 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
108846 +
108847 + call_stmt = gsi_stmt(*gsi);
108848 + old_fptr = gimple_call_fn(call_stmt);
108849 +
108850 + // create temporary unsigned long variable used for bitops and cast fptr to it
108851 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
108852 + add_referenced_var(intptr);
108853 + intptr = make_ssa_name(intptr, NULL);
108854 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
108855 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
108856 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
108857 + update_stmt(assign_intptr);
108858 +
108859 + // apply logical or to temporary unsigned long and bitmask
108860 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
108861 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
108862 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
108863 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
108864 + assign_intptr = gimple_build_assign(intptr, orptr);
108865 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
108866 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
108867 + update_stmt(assign_intptr);
108868 +
108869 + // cast temporary unsigned long back to a temporary fptr variable
108870 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
108871 + add_referenced_var(new_fptr);
108872 + new_fptr = make_ssa_name(new_fptr, NULL);
108873 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
108874 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
108875 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
108876 + update_stmt(assign_new_fptr);
108877 +
108878 + // replace call stmt fn with the new fptr
108879 + gimple_call_set_fn(call_stmt, new_fptr);
108880 + update_stmt(call_stmt);
108881 +}
108882 +
108883 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
108884 +{
108885 + gimple asm_or_stmt, call_stmt;
108886 + tree old_fptr, new_fptr, input, output;
108887 +#if BUILDING_GCC_VERSION <= 4007
108888 + VEC(tree, gc) *inputs = NULL;
108889 + VEC(tree, gc) *outputs = NULL;
108890 +#else
108891 + vec<tree, va_gc> *inputs = NULL;
108892 + vec<tree, va_gc> *outputs = NULL;
108893 +#endif
108894 +
108895 + call_stmt = gsi_stmt(*gsi);
108896 + old_fptr = gimple_call_fn(call_stmt);
108897 +
108898 + // create temporary fptr variable
108899 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
108900 + add_referenced_var(new_fptr);
108901 + new_fptr = make_ssa_name(new_fptr, NULL);
108902 +
108903 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
108904 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
108905 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
108906 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
108907 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
108908 +#if BUILDING_GCC_VERSION <= 4007
108909 + VEC_safe_push(tree, gc, inputs, input);
108910 + VEC_safe_push(tree, gc, outputs, output);
108911 +#else
108912 + vec_safe_push(inputs, input);
108913 + vec_safe_push(outputs, output);
108914 +#endif
108915 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
108916 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
108917 + gimple_asm_set_volatile(asm_or_stmt, true);
108918 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
108919 + update_stmt(asm_or_stmt);
108920 +
108921 + // replace call stmt fn with the new fptr
108922 + gimple_call_set_fn(call_stmt, new_fptr);
108923 + update_stmt(call_stmt);
108924 +}
108925 +
108926 +/*
108927 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
108928 + */
108929 +static unsigned int execute_kernexec_fptr(void)
108930 +{
108931 + basic_block bb;
108932 +
108933 + // 1. loop through BBs and GIMPLE statements
108934 + FOR_EACH_BB_FN(bb, cfun) {
108935 + gimple_stmt_iterator gsi;
108936 +
108937 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108938 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
108939 + tree fn;
108940 + gimple call_stmt;
108941 +
108942 + // is it a call ...
108943 + call_stmt = gsi_stmt(gsi);
108944 + if (!is_gimple_call(call_stmt))
108945 + continue;
108946 + fn = gimple_call_fn(call_stmt);
108947 + if (TREE_CODE(fn) == ADDR_EXPR)
108948 + continue;
108949 + if (TREE_CODE(fn) != SSA_NAME)
108950 + gcc_unreachable();
108951 +
108952 + // ... through a function pointer
108953 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
108954 + fn = SSA_NAME_VAR(fn);
108955 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
108956 + debug_tree(fn);
108957 + gcc_unreachable();
108958 + }
108959 + }
108960 + fn = TREE_TYPE(fn);
108961 + if (TREE_CODE(fn) != POINTER_TYPE)
108962 + continue;
108963 + fn = TREE_TYPE(fn);
108964 + if (TREE_CODE(fn) != FUNCTION_TYPE)
108965 + continue;
108966 +
108967 + kernexec_instrument_fptr(&gsi);
108968 +
108969 +//debug_tree(gimple_call_fn(call_stmt));
108970 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
108971 + }
108972 + }
108973 +
108974 + return 0;
108975 +}
108976 +
108977 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
108978 +static void kernexec_instrument_retaddr_bts(rtx insn)
108979 +{
108980 + rtx btsq;
108981 + rtvec argvec, constraintvec, labelvec;
108982 + int line;
108983 +
108984 + // create asm volatile("btsq $63,(%%rsp)":::)
108985 + argvec = rtvec_alloc(0);
108986 + constraintvec = rtvec_alloc(0);
108987 + labelvec = rtvec_alloc(0);
108988 + line = expand_location(RTL_LOCATION(insn)).line;
108989 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
108990 + MEM_VOLATILE_P(btsq) = 1;
108991 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
108992 + emit_insn_before(btsq, insn);
108993 +}
108994 +
108995 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
108996 +static void kernexec_instrument_retaddr_or(rtx insn)
108997 +{
108998 + rtx orq;
108999 + rtvec argvec, constraintvec, labelvec;
109000 + int line;
109001 +
109002 + // create asm volatile("orq %%r12,(%%rsp)":::)
109003 + argvec = rtvec_alloc(0);
109004 + constraintvec = rtvec_alloc(0);
109005 + labelvec = rtvec_alloc(0);
109006 + line = expand_location(RTL_LOCATION(insn)).line;
109007 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
109008 + MEM_VOLATILE_P(orq) = 1;
109009 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
109010 + emit_insn_before(orq, insn);
109011 +}
109012 +
109013 +/*
109014 + * find all asm level function returns and forcibly set the highest bit of the return address
109015 + */
109016 +static unsigned int execute_kernexec_retaddr(void)
109017 +{
109018 + rtx insn;
109019 +
109020 +// if (stack_realign_drap)
109021 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
109022 +
109023 + // 1. find function returns
109024 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
109025 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
109026 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
109027 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
109028 + rtx body;
109029 +
109030 + // is it a retn
109031 + if (!JUMP_P(insn))
109032 + continue;
109033 + body = PATTERN(insn);
109034 + if (GET_CODE(body) == PARALLEL)
109035 + body = XVECEXP(body, 0, 0);
109036 + if (!ANY_RETURN_P(body))
109037 + continue;
109038 + kernexec_instrument_retaddr(insn);
109039 + }
109040 +
109041 +// print_simple_rtl(stderr, get_insns());
109042 +// print_rtl(stderr, get_insns());
109043 +
109044 + return 0;
109045 +}
109046 +
109047 +static bool kernexec_cmodel_check(void)
109048 +{
109049 + tree section;
109050 +
109051 + if (ix86_cmodel != CM_KERNEL)
109052 + return false;
109053 +
109054 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
109055 + if (!section || !TREE_VALUE(section))
109056 + return true;
109057 +
109058 + section = TREE_VALUE(TREE_VALUE(section));
109059 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
109060 + return true;
109061 +
109062 + return false;
109063 +}
109064 +
109065 +#if BUILDING_GCC_VERSION >= 4009
109066 +static const struct pass_data kernexec_reload_pass_data = {
109067 +#else
109068 +static struct gimple_opt_pass kernexec_reload_pass = {
109069 + .pass = {
109070 +#endif
109071 + .type = GIMPLE_PASS,
109072 + .name = "kernexec_reload",
109073 +#if BUILDING_GCC_VERSION >= 4008
109074 + .optinfo_flags = OPTGROUP_NONE,
109075 +#endif
109076 +#if BUILDING_GCC_VERSION >= 4009
109077 + .has_gate = true,
109078 + .has_execute = true,
109079 +#else
109080 + .gate = kernexec_cmodel_check,
109081 + .execute = execute_kernexec_reload,
109082 + .sub = NULL,
109083 + .next = NULL,
109084 + .static_pass_number = 0,
109085 +#endif
109086 + .tv_id = TV_NONE,
109087 + .properties_required = 0,
109088 + .properties_provided = 0,
109089 + .properties_destroyed = 0,
109090 + .todo_flags_start = 0,
109091 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
109092 +#if BUILDING_GCC_VERSION < 4009
109093 + }
109094 +#endif
109095 +};
109096 +
109097 +#if BUILDING_GCC_VERSION >= 4009
109098 +static const struct pass_data kernexec_fptr_pass_data = {
109099 +#else
109100 +static struct gimple_opt_pass kernexec_fptr_pass = {
109101 + .pass = {
109102 +#endif
109103 + .type = GIMPLE_PASS,
109104 + .name = "kernexec_fptr",
109105 +#if BUILDING_GCC_VERSION >= 4008
109106 + .optinfo_flags = OPTGROUP_NONE,
109107 +#endif
109108 +#if BUILDING_GCC_VERSION >= 4009
109109 + .has_gate = true,
109110 + .has_execute = true,
109111 +#else
109112 + .gate = kernexec_cmodel_check,
109113 + .execute = execute_kernexec_fptr,
109114 + .sub = NULL,
109115 + .next = NULL,
109116 + .static_pass_number = 0,
109117 +#endif
109118 + .tv_id = TV_NONE,
109119 + .properties_required = 0,
109120 + .properties_provided = 0,
109121 + .properties_destroyed = 0,
109122 + .todo_flags_start = 0,
109123 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
109124 +#if BUILDING_GCC_VERSION < 4009
109125 + }
109126 +#endif
109127 +};
109128 +
109129 +#if BUILDING_GCC_VERSION >= 4009
109130 +static const struct pass_data kernexec_retaddr_pass_data = {
109131 +#else
109132 +static struct rtl_opt_pass kernexec_retaddr_pass = {
109133 + .pass = {
109134 +#endif
109135 + .type = RTL_PASS,
109136 + .name = "kernexec_retaddr",
109137 +#if BUILDING_GCC_VERSION >= 4008
109138 + .optinfo_flags = OPTGROUP_NONE,
109139 +#endif
109140 +#if BUILDING_GCC_VERSION >= 4009
109141 + .has_gate = true,
109142 + .has_execute = true,
109143 +#else
109144 + .gate = kernexec_cmodel_check,
109145 + .execute = execute_kernexec_retaddr,
109146 + .sub = NULL,
109147 + .next = NULL,
109148 + .static_pass_number = 0,
109149 +#endif
109150 + .tv_id = TV_NONE,
109151 + .properties_required = 0,
109152 + .properties_provided = 0,
109153 + .properties_destroyed = 0,
109154 + .todo_flags_start = 0,
109155 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
109156 +#if BUILDING_GCC_VERSION < 4009
109157 + }
109158 +#endif
109159 +};
109160 +
109161 +#if BUILDING_GCC_VERSION >= 4009
109162 +namespace {
109163 +class kernexec_reload_pass : public gimple_opt_pass {
109164 +public:
109165 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
109166 + bool gate() { return kernexec_cmodel_check(); }
109167 + unsigned int execute() { return execute_kernexec_reload(); }
109168 +};
109169 +
109170 +class kernexec_fptr_pass : public gimple_opt_pass {
109171 +public:
109172 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
109173 + bool gate() { return kernexec_cmodel_check(); }
109174 + unsigned int execute() { return execute_kernexec_fptr(); }
109175 +};
109176 +
109177 +class kernexec_retaddr_pass : public rtl_opt_pass {
109178 +public:
109179 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
109180 + bool gate() { return kernexec_cmodel_check(); }
109181 + unsigned int execute() { return execute_kernexec_retaddr(); }
109182 +};
109183 +}
109184 +
109185 +static opt_pass *make_kernexec_reload_pass(void)
109186 +{
109187 + return new kernexec_reload_pass();
109188 +}
109189 +
109190 +static opt_pass *make_kernexec_fptr_pass(void)
109191 +{
109192 + return new kernexec_fptr_pass();
109193 +}
109194 +
109195 +static opt_pass *make_kernexec_retaddr_pass(void)
109196 +{
109197 + return new kernexec_retaddr_pass();
109198 +}
109199 +#else
109200 +static struct opt_pass *make_kernexec_reload_pass(void)
109201 +{
109202 + return &kernexec_reload_pass.pass;
109203 +}
109204 +
109205 +static struct opt_pass *make_kernexec_fptr_pass(void)
109206 +{
109207 + return &kernexec_fptr_pass.pass;
109208 +}
109209 +
109210 +static struct opt_pass *make_kernexec_retaddr_pass(void)
109211 +{
109212 + return &kernexec_retaddr_pass.pass;
109213 +}
109214 +#endif
109215 +
109216 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
109217 +{
109218 + const char * const plugin_name = plugin_info->base_name;
109219 + const int argc = plugin_info->argc;
109220 + const struct plugin_argument * const argv = plugin_info->argv;
109221 + int i;
109222 + struct register_pass_info kernexec_reload_pass_info;
109223 + struct register_pass_info kernexec_fptr_pass_info;
109224 + struct register_pass_info kernexec_retaddr_pass_info;
109225 +
109226 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
109227 + kernexec_reload_pass_info.reference_pass_name = "ssa";
109228 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
109229 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
109230 +
109231 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
109232 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
109233 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
109234 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
109235 +
109236 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
109237 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
109238 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
109239 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
109240 +
109241 + if (!plugin_default_version_check(version, &gcc_version)) {
109242 + error(G_("incompatible gcc/plugin versions"));
109243 + return 1;
109244 + }
109245 +
109246 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
109247 +
109248 + if (TARGET_64BIT == 0)
109249 + return 0;
109250 +
109251 + for (i = 0; i < argc; ++i) {
109252 + if (!strcmp(argv[i].key, "method")) {
109253 + if (!argv[i].value) {
109254 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
109255 + continue;
109256 + }
109257 + if (!strcmp(argv[i].value, "bts")) {
109258 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
109259 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
109260 + } else if (!strcmp(argv[i].value, "or")) {
109261 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
109262 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
109263 + fix_register("r12", 1, 1);
109264 + } else
109265 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
109266 + continue;
109267 + }
109268 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
109269 + }
109270 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
109271 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
109272 +
109273 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
109274 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
109275 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
109276 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
109277 +
109278 + return 0;
109279 +}
109280 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
109281 new file mode 100644
109282 index 0000000..39d7cc7
109283 --- /dev/null
109284 +++ b/tools/gcc/latent_entropy_plugin.c
109285 @@ -0,0 +1,462 @@
109286 +/*
109287 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
109288 + * Licensed under the GPL v2
109289 + *
109290 + * Note: the choice of the license means that the compilation process is
109291 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
109292 + * but for the kernel it doesn't matter since it doesn't link against
109293 + * any of the gcc libraries
109294 + *
109295 + * gcc plugin to help generate a little bit of entropy from program state,
109296 + * used throughout the uptime of the kernel
109297 + *
109298 + * TODO:
109299 + * - add ipa pass to identify not explicitly marked candidate functions
109300 + * - mix in more program state (function arguments/return values, loop variables, etc)
109301 + * - more instrumentation control via attribute parameters
109302 + *
109303 + * BUGS:
109304 + * - LTO needs -flto-partition=none for now
109305 + */
109306 +
109307 +#include "gcc-common.h"
109308 +
109309 +int plugin_is_GPL_compatible;
109310 +
109311 +static tree latent_entropy_decl;
109312 +
109313 +static struct plugin_info latent_entropy_plugin_info = {
109314 + .version = "201403280150",
109315 + .help = NULL
109316 +};
109317 +
109318 +static unsigned HOST_WIDE_INT seed;
109319 +static unsigned HOST_WIDE_INT get_random_const(void)
109320 +{
109321 + unsigned int i;
109322 + unsigned HOST_WIDE_INT ret = 0;
109323 +
109324 + for (i = 0; i < 8 * sizeof ret; i++) {
109325 + ret = (ret << 1) | (seed & 1);
109326 + seed >>= 1;
109327 + if (ret & 1)
109328 + seed ^= 0xD800000000000000ULL;
109329 + }
109330 +
109331 + return ret;
109332 +}
109333 +
109334 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109335 +{
109336 + tree type;
109337 + unsigned long long mask;
109338 +#if BUILDING_GCC_VERSION <= 4007
109339 + VEC(constructor_elt, gc) *vals;
109340 +#else
109341 + vec<constructor_elt, va_gc> *vals;
109342 +#endif
109343 +
109344 + switch (TREE_CODE(*node)) {
109345 + default:
109346 + *no_add_attrs = true;
109347 + error("%qE attribute only applies to functions and variables", name);
109348 + break;
109349 +
109350 + case VAR_DECL:
109351 + if (DECL_INITIAL(*node)) {
109352 + *no_add_attrs = true;
109353 + error("variable %qD with %qE attribute must not be initialized", *node, name);
109354 + break;
109355 + }
109356 +
109357 + if (!TREE_STATIC(*node)) {
109358 + *no_add_attrs = true;
109359 + error("variable %qD with %qE attribute must not be local", *node, name);
109360 + break;
109361 + }
109362 +
109363 + type = TREE_TYPE(*node);
109364 + switch (TREE_CODE(type)) {
109365 + default:
109366 + *no_add_attrs = true;
109367 + 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);
109368 + break;
109369 +
109370 + case RECORD_TYPE: {
109371 + tree field;
109372 + unsigned int nelt = 0;
109373 +
109374 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
109375 + tree fieldtype;
109376 +
109377 + fieldtype = TREE_TYPE(field);
109378 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
109379 + *no_add_attrs = true;
109380 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
109381 + break;
109382 + }
109383 + }
109384 +
109385 + if (field)
109386 + break;
109387 +
109388 +#if BUILDING_GCC_VERSION <= 4007
109389 + vals = VEC_alloc(constructor_elt, gc, nelt);
109390 +#else
109391 + vec_alloc(vals, nelt);
109392 +#endif
109393 +
109394 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
109395 + tree fieldtype;
109396 +
109397 + fieldtype = TREE_TYPE(field);
109398 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
109399 + mask = 2 * (mask - 1) + 1;
109400 +
109401 + if (TYPE_UNSIGNED(fieldtype))
109402 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
109403 + else
109404 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
109405 + }
109406 +
109407 + DECL_INITIAL(*node) = build_constructor(type, vals);
109408 +//debug_tree(DECL_INITIAL(*node));
109409 + break;
109410 + }
109411 +
109412 + case INTEGER_TYPE:
109413 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
109414 + mask = 2 * (mask - 1) + 1;
109415 +
109416 + if (TYPE_UNSIGNED(type))
109417 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
109418 + else
109419 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
109420 + break;
109421 +
109422 + case ARRAY_TYPE: {
109423 + tree elt_type, array_size, elt_size;
109424 + unsigned int i, nelt;
109425 +
109426 + elt_type = TREE_TYPE(type);
109427 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
109428 + array_size = TYPE_SIZE_UNIT(type);
109429 +
109430 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
109431 + *no_add_attrs = true;
109432 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
109433 + break;
109434 + }
109435 +
109436 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
109437 +#if BUILDING_GCC_VERSION <= 4007
109438 + vals = VEC_alloc(constructor_elt, gc, nelt);
109439 +#else
109440 + vec_alloc(vals, nelt);
109441 +#endif
109442 +
109443 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
109444 + mask = 2 * (mask - 1) + 1;
109445 +
109446 + for (i = 0; i < nelt; i++)
109447 + if (TYPE_UNSIGNED(elt_type))
109448 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
109449 + else
109450 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
109451 +
109452 + DECL_INITIAL(*node) = build_constructor(type, vals);
109453 +//debug_tree(DECL_INITIAL(*node));
109454 + break;
109455 + }
109456 + }
109457 + break;
109458 +
109459 + case FUNCTION_DECL:
109460 + break;
109461 + }
109462 +
109463 + return NULL_TREE;
109464 +}
109465 +
109466 +static struct attribute_spec latent_entropy_attr = {
109467 + .name = "latent_entropy",
109468 + .min_length = 0,
109469 + .max_length = 0,
109470 + .decl_required = true,
109471 + .type_required = false,
109472 + .function_type_required = false,
109473 + .handler = handle_latent_entropy_attribute,
109474 +#if BUILDING_GCC_VERSION >= 4007
109475 + .affects_type_identity = false
109476 +#endif
109477 +};
109478 +
109479 +static void register_attributes(void *event_data, void *data)
109480 +{
109481 + register_attribute(&latent_entropy_attr);
109482 +}
109483 +
109484 +static bool gate_latent_entropy(void)
109485 +{
109486 + // don't bother with noreturn functions for now
109487 + if (TREE_THIS_VOLATILE(current_function_decl))
109488 + return false;
109489 +
109490 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
109491 +}
109492 +
109493 +static enum tree_code get_op(tree *rhs)
109494 +{
109495 + static enum tree_code op;
109496 + unsigned HOST_WIDE_INT random_const;
109497 +
109498 + random_const = get_random_const();
109499 +
109500 + switch (op) {
109501 + case BIT_XOR_EXPR:
109502 + op = PLUS_EXPR;
109503 + break;
109504 +
109505 + case PLUS_EXPR:
109506 + if (rhs) {
109507 + op = LROTATE_EXPR;
109508 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
109509 + break;
109510 + }
109511 +
109512 + case LROTATE_EXPR:
109513 + default:
109514 + op = BIT_XOR_EXPR;
109515 + break;
109516 + }
109517 + if (rhs)
109518 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
109519 + return op;
109520 +}
109521 +
109522 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
109523 +{
109524 + gimple_stmt_iterator gsi;
109525 + gimple assign;
109526 + tree addxorrol, rhs;
109527 + enum tree_code op;
109528 +
109529 + op = get_op(&rhs);
109530 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
109531 + assign = gimple_build_assign(local_entropy, addxorrol);
109532 + gsi = gsi_after_labels(bb);
109533 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
109534 + update_stmt(assign);
109535 +//debug_bb(bb);
109536 +}
109537 +
109538 +static void perturb_latent_entropy(basic_block bb, tree rhs)
109539 +{
109540 + gimple_stmt_iterator gsi;
109541 + gimple assign;
109542 + tree addxorrol, temp;
109543 +
109544 + // 1. create temporary copy of latent_entropy
109545 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
109546 + add_referenced_var(temp);
109547 +
109548 + // 2. read...
109549 + temp = make_ssa_name(temp, NULL);
109550 + assign = gimple_build_assign(temp, latent_entropy_decl);
109551 + SSA_NAME_DEF_STMT(temp) = assign;
109552 + add_referenced_var(latent_entropy_decl);
109553 + gsi = gsi_after_labels(bb);
109554 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109555 + update_stmt(assign);
109556 +
109557 + // 3. ...modify...
109558 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
109559 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
109560 + assign = gimple_build_assign(temp, addxorrol);
109561 + SSA_NAME_DEF_STMT(temp) = assign;
109562 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109563 + update_stmt(assign);
109564 +
109565 + // 4. ...write latent_entropy
109566 + assign = gimple_build_assign(latent_entropy_decl, temp);
109567 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109568 + update_stmt(assign);
109569 +}
109570 +
109571 +static unsigned int execute_latent_entropy(void)
109572 +{
109573 + basic_block bb;
109574 + gimple assign;
109575 + gimple_stmt_iterator gsi;
109576 + tree local_entropy;
109577 +
109578 + if (!latent_entropy_decl) {
109579 +#if BUILDING_GCC_VERSION >= 4009
109580 + varpool_node *node;
109581 +#else
109582 + struct varpool_node *node;
109583 +#endif
109584 +
109585 + FOR_EACH_VARIABLE(node) {
109586 + tree var = NODE_DECL(node);
109587 +
109588 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
109589 + continue;
109590 + latent_entropy_decl = var;
109591 +// debug_tree(var);
109592 + break;
109593 + }
109594 + if (!latent_entropy_decl) {
109595 +// debug_tree(current_function_decl);
109596 + return 0;
109597 + }
109598 + }
109599 +
109600 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
109601 +
109602 + // 1. create local entropy variable
109603 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
109604 + add_referenced_var(local_entropy);
109605 + mark_sym_for_renaming(local_entropy);
109606 +
109607 + // 2. initialize local entropy variable
109608 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
109609 + if (dom_info_available_p(CDI_DOMINATORS))
109610 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
109611 + gsi = gsi_start_bb(bb);
109612 +
109613 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
109614 +// gimple_set_location(assign, loc);
109615 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109616 + update_stmt(assign);
109617 +//debug_bb(bb);
109618 + gcc_assert(single_succ_p(bb));
109619 + bb = single_succ(bb);
109620 +
109621 + // 3. instrument each BB with an operation on the local entropy variable
109622 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
109623 + perturb_local_entropy(bb, local_entropy);
109624 +//debug_bb(bb);
109625 + bb = bb->next_bb;
109626 + };
109627 +
109628 + // 4. mix local entropy into the global entropy variable
109629 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
109630 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
109631 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
109632 + return 0;
109633 +}
109634 +
109635 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
109636 +{
109637 + tree latent_entropy_type;
109638 +
109639 + seed = get_random_seed(false);
109640 +
109641 + if (in_lto_p)
109642 + return;
109643 +
109644 + // extern volatile u64 latent_entropy
109645 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
109646 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
109647 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
109648 +
109649 + TREE_STATIC(latent_entropy_decl) = 1;
109650 + TREE_PUBLIC(latent_entropy_decl) = 1;
109651 + TREE_USED(latent_entropy_decl) = 1;
109652 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
109653 + DECL_EXTERNAL(latent_entropy_decl) = 1;
109654 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
109655 + lang_hooks.decls.pushdecl(latent_entropy_decl);
109656 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
109657 +// varpool_finalize_decl(latent_entropy_decl);
109658 +// varpool_mark_needed_node(latent_entropy_decl);
109659 +}
109660 +
109661 +#if BUILDING_GCC_VERSION >= 4009
109662 +static const struct pass_data latent_entropy_pass_data = {
109663 +#else
109664 +static struct gimple_opt_pass latent_entropy_pass = {
109665 + .pass = {
109666 +#endif
109667 + .type = GIMPLE_PASS,
109668 + .name = "latent_entropy",
109669 +#if BUILDING_GCC_VERSION >= 4008
109670 + .optinfo_flags = OPTGROUP_NONE,
109671 +#endif
109672 +#if BUILDING_GCC_VERSION >= 4009
109673 + .has_gate = true,
109674 + .has_execute = true,
109675 +#else
109676 + .gate = gate_latent_entropy,
109677 + .execute = execute_latent_entropy,
109678 + .sub = NULL,
109679 + .next = NULL,
109680 + .static_pass_number = 0,
109681 +#endif
109682 + .tv_id = TV_NONE,
109683 + .properties_required = PROP_gimple_leh | PROP_cfg,
109684 + .properties_provided = 0,
109685 + .properties_destroyed = 0,
109686 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
109687 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
109688 +#if BUILDING_GCC_VERSION < 4009
109689 + }
109690 +#endif
109691 +};
109692 +
109693 +#if BUILDING_GCC_VERSION >= 4009
109694 +namespace {
109695 +class latent_entropy_pass : public gimple_opt_pass {
109696 +public:
109697 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
109698 + bool gate() { return gate_latent_entropy(); }
109699 + unsigned int execute() { return execute_latent_entropy(); }
109700 +};
109701 +}
109702 +
109703 +static opt_pass *make_latent_entropy_pass(void)
109704 +{
109705 + return new latent_entropy_pass();
109706 +}
109707 +#else
109708 +static struct opt_pass *make_latent_entropy_pass(void)
109709 +{
109710 + return &latent_entropy_pass.pass;
109711 +}
109712 +#endif
109713 +
109714 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
109715 +{
109716 + const char * const plugin_name = plugin_info->base_name;
109717 + struct register_pass_info latent_entropy_pass_info;
109718 +
109719 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
109720 + latent_entropy_pass_info.reference_pass_name = "optimized";
109721 + latent_entropy_pass_info.ref_pass_instance_number = 1;
109722 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
109723 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
109724 + {
109725 + .base = &latent_entropy_decl,
109726 + .nelt = 1,
109727 + .stride = sizeof(latent_entropy_decl),
109728 + .cb = &gt_ggc_mx_tree_node,
109729 + .pchw = &gt_pch_nx_tree_node
109730 + },
109731 + LAST_GGC_ROOT_TAB
109732 + };
109733 +
109734 + if (!plugin_default_version_check(version, &gcc_version)) {
109735 + error(G_("incompatible gcc/plugin versions"));
109736 + return 1;
109737 + }
109738 +
109739 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
109740 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
109741 + if (!in_lto_p)
109742 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
109743 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
109744 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
109745 +
109746 + return 0;
109747 +}
109748 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
109749 new file mode 100644
109750 index 0000000..8dafb22
109751 --- /dev/null
109752 +++ b/tools/gcc/randomize_layout_plugin.c
109753 @@ -0,0 +1,910 @@
109754 +/*
109755 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
109756 + * and PaX Team <pageexec@freemail.hu>
109757 + * Licensed under the GPL v2
109758 + *
109759 + * Usage:
109760 + * $ # for 4.5/4.6/C based 4.7
109761 + * $ 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
109762 + * $ # for C++ based 4.7/4.8+
109763 + * $ 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
109764 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
109765 + */
109766 +
109767 +#include "gcc-common.h"
109768 +#include "randomize_layout_seed.h"
109769 +
109770 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
109771 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
109772 +#endif
109773 +
109774 +#define ORIG_TYPE_NAME(node) \
109775 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
109776 +
109777 +int plugin_is_GPL_compatible;
109778 +
109779 +static int performance_mode;
109780 +
109781 +static struct plugin_info randomize_layout_plugin_info = {
109782 + .version = "201402201816",
109783 + .help = "disable\t\t\tdo not activate plugin\n"
109784 + "performance-mode\tenable cacheline-aware layout randomization\n"
109785 +};
109786 +
109787 +/* from old Linux dcache.h */
109788 +static inline unsigned long
109789 +partial_name_hash(unsigned long c, unsigned long prevhash)
109790 +{
109791 + return (prevhash + (c << 4) + (c >> 4)) * 11;
109792 +}
109793 +static inline unsigned int
109794 +name_hash(const unsigned char *name)
109795 +{
109796 + unsigned long hash = 0;
109797 + unsigned int len = strlen((const char *)name);
109798 + while (len--)
109799 + hash = partial_name_hash(*name++, hash);
109800 + return (unsigned int)hash;
109801 +}
109802 +
109803 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109804 +{
109805 + tree type;
109806 +
109807 + *no_add_attrs = true;
109808 + if (TREE_CODE(*node) == FUNCTION_DECL) {
109809 + error("%qE attribute does not apply to functions (%qF)", name, *node);
109810 + return NULL_TREE;
109811 + }
109812 +
109813 + if (TREE_CODE(*node) == PARM_DECL) {
109814 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
109815 + return NULL_TREE;
109816 + }
109817 +
109818 + if (TREE_CODE(*node) == VAR_DECL) {
109819 + error("%qE attribute does not apply to variables (%qD)", name, *node);
109820 + return NULL_TREE;
109821 + }
109822 +
109823 + if (TYPE_P(*node)) {
109824 + type = *node;
109825 + } else {
109826 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
109827 + type = TREE_TYPE(*node);
109828 + }
109829 +
109830 + if (TREE_CODE(type) != RECORD_TYPE) {
109831 + error("%qE attribute used on %qT applies to struct types only", name, type);
109832 + return NULL_TREE;
109833 + }
109834 +
109835 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
109836 + error("%qE attribute is already applied to the type %qT", name, type);
109837 + return NULL_TREE;
109838 + }
109839 +
109840 + *no_add_attrs = false;
109841 +
109842 + return NULL_TREE;
109843 +}
109844 +
109845 +/* set on complete types that we don't need to inspect further at all */
109846 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109847 +{
109848 + *no_add_attrs = false;
109849 + return NULL_TREE;
109850 +}
109851 +
109852 +/*
109853 + * set on types that we've performed a shuffle on, to prevent re-shuffling
109854 + * this does not preclude us from inspecting its fields for potential shuffles
109855 + */
109856 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109857 +{
109858 + *no_add_attrs = false;
109859 + return NULL_TREE;
109860 +}
109861 +
109862 +/*
109863 + * 64bit variant of Bob Jenkins' public domain PRNG
109864 + * 256 bits of internal state
109865 + */
109866 +
109867 +typedef unsigned long long u64;
109868 +
109869 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
109870 +
109871 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
109872 +static u64 ranval(ranctx *x) {
109873 + u64 e = x->a - rot(x->b, 7);
109874 + x->a = x->b ^ rot(x->c, 13);
109875 + x->b = x->c + rot(x->d, 37);
109876 + x->c = x->d + e;
109877 + x->d = e + x->a;
109878 + return x->d;
109879 +}
109880 +
109881 +static void raninit(ranctx *x, u64 *seed) {
109882 + int i;
109883 +
109884 + x->a = seed[0];
109885 + x->b = seed[1];
109886 + x->c = seed[2];
109887 + x->d = seed[3];
109888 +
109889 + for (i=0; i < 30; ++i)
109890 + (void)ranval(x);
109891 +}
109892 +
109893 +static u64 shuffle_seed[4];
109894 +
109895 +struct partition_group {
109896 + tree tree_start;
109897 + unsigned long start;
109898 + unsigned long length;
109899 +};
109900 +
109901 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
109902 +{
109903 + unsigned long i;
109904 + unsigned long accum_size = 0;
109905 + unsigned long accum_length = 0;
109906 + unsigned long group_idx = 0;
109907 +
109908 + gcc_assert(length < INT_MAX);
109909 +
109910 + memset(size_groups, 0, sizeof(struct partition_group) * length);
109911 +
109912 + for (i = 0; i < length; i++) {
109913 + if (size_groups[group_idx].tree_start == NULL_TREE) {
109914 + size_groups[group_idx].tree_start = fields[i];
109915 + size_groups[group_idx].start = i;
109916 + accum_length = 0;
109917 + accum_size = 0;
109918 + }
109919 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
109920 + accum_length++;
109921 + if (accum_size >= 64) {
109922 + size_groups[group_idx].length = accum_length;
109923 + accum_length = 0;
109924 + group_idx++;
109925 + }
109926 + }
109927 +
109928 + if (size_groups[group_idx].tree_start != NULL_TREE &&
109929 + !size_groups[group_idx].length) {
109930 + size_groups[group_idx].length = accum_length;
109931 + group_idx++;
109932 + }
109933 +
109934 + *num_groups = group_idx;
109935 +}
109936 +
109937 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
109938 +{
109939 + unsigned long i, x;
109940 + struct partition_group size_group[length];
109941 + unsigned long num_groups = 0;
109942 + unsigned long randnum;
109943 +
109944 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
109945 + for (i = num_groups - 1; i > 0; i--) {
109946 + struct partition_group tmp;
109947 + randnum = ranval(prng_state) % (i + 1);
109948 + tmp = size_group[i];
109949 + size_group[i] = size_group[randnum];
109950 + size_group[randnum] = tmp;
109951 + }
109952 +
109953 + for (x = 0; x < num_groups; x++) {
109954 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
109955 + tree tmp;
109956 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
109957 + continue;
109958 + randnum = ranval(prng_state) % (i + 1);
109959 + // we could handle this case differently if desired
109960 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
109961 + continue;
109962 + tmp = newtree[i];
109963 + newtree[i] = newtree[randnum];
109964 + newtree[randnum] = tmp;
109965 + }
109966 + }
109967 +}
109968 +
109969 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
109970 +{
109971 + unsigned long i, randnum;
109972 +
109973 + for (i = length - 1; i > 0; i--) {
109974 + tree tmp;
109975 + randnum = ranval(prng_state) % (i + 1);
109976 + tmp = newtree[i];
109977 + newtree[i] = newtree[randnum];
109978 + newtree[randnum] = tmp;
109979 + }
109980 +}
109981 +
109982 +/* modern in-place Fisher-Yates shuffle */
109983 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
109984 +{
109985 + unsigned long i;
109986 + u64 seed[4];
109987 + ranctx prng_state;
109988 + const unsigned char *structname;
109989 +
109990 + if (length == 0)
109991 + return;
109992 +
109993 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
109994 +
109995 + structname = ORIG_TYPE_NAME(type);
109996 +
109997 +#ifdef __DEBUG_PLUGIN
109998 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
109999 +#ifdef __DEBUG_VERBOSE
110000 + debug_tree((tree)type);
110001 +#endif
110002 +#endif
110003 +
110004 + for (i = 0; i < 4; i++) {
110005 + seed[i] = shuffle_seed[i];
110006 + seed[i] ^= name_hash(structname);
110007 + }
110008 +
110009 + raninit(&prng_state, (u64 *)&seed);
110010 +
110011 + if (performance_mode)
110012 + performance_shuffle(newtree, length, &prng_state);
110013 + else
110014 + full_shuffle(newtree, length, &prng_state);
110015 +}
110016 +
110017 +static bool is_flexible_array(const_tree field)
110018 +{
110019 + const_tree fieldtype;
110020 + const_tree typesize;
110021 + const_tree elemtype;
110022 + const_tree elemsize;
110023 +
110024 + fieldtype = TREE_TYPE(field);
110025 + typesize = TYPE_SIZE(fieldtype);
110026 +
110027 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
110028 + return false;
110029 +
110030 + elemtype = TREE_TYPE(fieldtype);
110031 + elemsize = TYPE_SIZE(elemtype);
110032 +
110033 + /* size of type is represented in bits */
110034 +
110035 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
110036 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
110037 + return true;
110038 +
110039 + if (typesize != NULL_TREE &&
110040 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
110041 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
110042 + return true;
110043 +
110044 + return false;
110045 +}
110046 +
110047 +static int relayout_struct(tree type)
110048 +{
110049 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
110050 + unsigned long shuffle_length = num_fields;
110051 + tree field;
110052 + tree newtree[num_fields];
110053 + unsigned long i;
110054 + tree list;
110055 + tree variant;
110056 + expanded_location xloc;
110057 +
110058 + if (TYPE_FIELDS(type) == NULL_TREE)
110059 + return 0;
110060 +
110061 + if (num_fields < 2)
110062 + return 0;
110063 +
110064 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
110065 +
110066 + gcc_assert(num_fields < INT_MAX);
110067 +
110068 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
110069 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
110070 + return 0;
110071 +
110072 + /* throw out any structs in uapi */
110073 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
110074 +
110075 + if (strstr(xloc.file, "/uapi/"))
110076 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
110077 +
110078 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
110079 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
110080 + newtree[i] = field;
110081 + }
110082 +
110083 + /*
110084 + * enforce that we don't randomize the layout of the last
110085 + * element of a struct if it's a 0 or 1-length array
110086 + * or a proper flexible array
110087 + */
110088 + if (is_flexible_array(newtree[num_fields - 1]))
110089 + shuffle_length--;
110090 +
110091 + shuffle(type, (tree *)newtree, shuffle_length);
110092 +
110093 + /*
110094 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
110095 + * as gcc provides no other way to detect such code
110096 + */
110097 + list = make_node(FIELD_DECL);
110098 + TREE_CHAIN(list) = newtree[0];
110099 + TREE_TYPE(list) = void_type_node;
110100 + DECL_SIZE(list) = bitsize_zero_node;
110101 + DECL_NONADDRESSABLE_P(list) = 1;
110102 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
110103 + DECL_SIZE_UNIT(list) = size_zero_node;
110104 + DECL_FIELD_OFFSET(list) = size_zero_node;
110105 + // to satisfy the constify plugin
110106 + TREE_READONLY(list) = 1;
110107 +
110108 + for (i = 0; i < num_fields - 1; i++)
110109 + TREE_CHAIN(newtree[i]) = newtree[i+1];
110110 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
110111 +
110112 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
110113 + TYPE_FIELDS(variant) = list;
110114 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
110115 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
110116 + // force a re-layout
110117 + TYPE_SIZE(variant) = NULL_TREE;
110118 + layout_type(variant);
110119 + }
110120 +
110121 + return 1;
110122 +}
110123 +
110124 +/* from constify plugin */
110125 +static const_tree get_field_type(const_tree field)
110126 +{
110127 + return strip_array_types(TREE_TYPE(field));
110128 +}
110129 +
110130 +/* from constify plugin */
110131 +static bool is_fptr(const_tree fieldtype)
110132 +{
110133 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
110134 + return false;
110135 +
110136 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
110137 +}
110138 +
110139 +/* derived from constify plugin */
110140 +static int is_pure_ops_struct(const_tree node)
110141 +{
110142 + const_tree field;
110143 +
110144 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
110145 +
110146 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
110147 + const_tree fieldtype = get_field_type(field);
110148 + enum tree_code code = TREE_CODE(fieldtype);
110149 +
110150 + if (node == fieldtype)
110151 + continue;
110152 +
110153 + if (!is_fptr(fieldtype))
110154 + return 0;
110155 +
110156 + if (code != RECORD_TYPE && code != UNION_TYPE)
110157 + continue;
110158 +
110159 + if (!is_pure_ops_struct(fieldtype))
110160 + return 0;
110161 + }
110162 +
110163 + return 1;
110164 +}
110165 +
110166 +static void randomize_type(tree type)
110167 +{
110168 + tree variant;
110169 +
110170 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
110171 +
110172 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
110173 + return;
110174 +
110175 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
110176 + relayout_struct(type);
110177 +
110178 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
110179 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
110180 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
110181 + }
110182 +#ifdef __DEBUG_PLUGIN
110183 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
110184 +#ifdef __DEBUG_VERBOSE
110185 + debug_tree(type);
110186 +#endif
110187 +#endif
110188 +}
110189 +
110190 +static void randomize_layout_finish_decl(void *event_data, void *data)
110191 +{
110192 + tree decl = (tree)event_data;
110193 + tree type;
110194 +
110195 + if (decl == NULL_TREE || decl == error_mark_node)
110196 + return;
110197 +
110198 + type = TREE_TYPE(decl);
110199 +
110200 + if (TREE_CODE(decl) != VAR_DECL)
110201 + return;
110202 +
110203 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
110204 + return;
110205 +
110206 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
110207 + return;
110208 +
110209 + relayout_decl(decl);
110210 +}
110211 +
110212 +static void finish_type(void *event_data, void *data)
110213 +{
110214 + tree type = (tree)event_data;
110215 +
110216 + if (type == NULL_TREE || type == error_mark_node)
110217 + return;
110218 +
110219 + if (TREE_CODE(type) != RECORD_TYPE)
110220 + return;
110221 +
110222 + if (TYPE_FIELDS(type) == NULL_TREE)
110223 + return;
110224 +
110225 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
110226 + return;
110227 +
110228 +#ifdef __DEBUG_PLUGIN
110229 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
110230 +#endif
110231 +#ifdef __DEBUG_VERBOSE
110232 + debug_tree(type);
110233 +#endif
110234 + randomize_type(type);
110235 +
110236 + return;
110237 +}
110238 +
110239 +static struct attribute_spec randomize_layout_attr = {
110240 + .name = "randomize_layout",
110241 + // related to args
110242 + .min_length = 0,
110243 + .max_length = 0,
110244 + .decl_required = false,
110245 + // need type declaration
110246 + .type_required = true,
110247 + .function_type_required = false,
110248 + .handler = handle_randomize_layout_attr,
110249 +#if BUILDING_GCC_VERSION >= 4007
110250 + .affects_type_identity = true
110251 +#endif
110252 +};
110253 +
110254 +static struct attribute_spec no_randomize_layout_attr = {
110255 + .name = "no_randomize_layout",
110256 + // related to args
110257 + .min_length = 0,
110258 + .max_length = 0,
110259 + .decl_required = false,
110260 + // need type declaration
110261 + .type_required = true,
110262 + .function_type_required = false,
110263 + .handler = handle_randomize_layout_attr,
110264 +#if BUILDING_GCC_VERSION >= 4007
110265 + .affects_type_identity = true
110266 +#endif
110267 +};
110268 +
110269 +static struct attribute_spec randomize_considered_attr = {
110270 + .name = "randomize_considered",
110271 + // related to args
110272 + .min_length = 0,
110273 + .max_length = 0,
110274 + .decl_required = false,
110275 + // need type declaration
110276 + .type_required = true,
110277 + .function_type_required = false,
110278 + .handler = handle_randomize_considered_attr,
110279 +#if BUILDING_GCC_VERSION >= 4007
110280 + .affects_type_identity = false
110281 +#endif
110282 +};
110283 +
110284 +static struct attribute_spec randomize_performed_attr = {
110285 + .name = "randomize_performed",
110286 + // related to args
110287 + .min_length = 0,
110288 + .max_length = 0,
110289 + .decl_required = false,
110290 + // need type declaration
110291 + .type_required = true,
110292 + .function_type_required = false,
110293 + .handler = handle_randomize_performed_attr,
110294 +#if BUILDING_GCC_VERSION >= 4007
110295 + .affects_type_identity = false
110296 +#endif
110297 +};
110298 +
110299 +static void register_attributes(void *event_data, void *data)
110300 +{
110301 + register_attribute(&randomize_layout_attr);
110302 + register_attribute(&no_randomize_layout_attr);
110303 + register_attribute(&randomize_considered_attr);
110304 + register_attribute(&randomize_performed_attr);
110305 +}
110306 +
110307 +static void check_bad_casts_in_constructor(tree var, tree init)
110308 +{
110309 + unsigned HOST_WIDE_INT idx;
110310 + tree field, val;
110311 + tree field_type, val_type;
110312 +
110313 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
110314 + if (TREE_CODE(val) == CONSTRUCTOR) {
110315 + check_bad_casts_in_constructor(var, val);
110316 + continue;
110317 + }
110318 +
110319 + /* pipacs' plugin creates franken-arrays that differ from those produced by
110320 + normal code which all have valid 'field' trees. work around this */
110321 + if (field == NULL_TREE)
110322 + continue;
110323 + field_type = TREE_TYPE(field);
110324 + val_type = TREE_TYPE(val);
110325 +
110326 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
110327 + continue;
110328 +
110329 + if (field_type == val_type)
110330 + continue;
110331 +
110332 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
110333 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
110334 +
110335 + if (field_type == void_type_node)
110336 + continue;
110337 + if (field_type == val_type)
110338 + continue;
110339 + if (TREE_CODE(val_type) != RECORD_TYPE)
110340 + continue;
110341 +
110342 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
110343 + continue;
110344 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
110345 + }
110346 +}
110347 +
110348 +/* derived from the constify plugin */
110349 +static void check_global_variables(void *event_data, void *data)
110350 +{
110351 + struct varpool_node *node;
110352 + tree init;
110353 +
110354 + FOR_EACH_VARIABLE(node) {
110355 + tree var = NODE_DECL(node);
110356 + init = DECL_INITIAL(var);
110357 + if (init == NULL_TREE)
110358 + continue;
110359 +
110360 + if (TREE_CODE(init) != CONSTRUCTOR)
110361 + continue;
110362 +
110363 + check_bad_casts_in_constructor(var, init);
110364 + }
110365 +}
110366 +
110367 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
110368 +{
110369 + basic_block dom;
110370 + gimple dom_stmt;
110371 + gimple call_stmt;
110372 + const_tree dom_lhs;
110373 + const_tree poss_is_err_cond;
110374 + const_tree poss_is_err_func;
110375 + const_tree is_err_arg;
110376 +
110377 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
110378 + if (!dom)
110379 + return false;
110380 +
110381 + dom_stmt = last_stmt(dom);
110382 + if (!dom_stmt)
110383 + return false;
110384 +
110385 + if (gimple_code(dom_stmt) != GIMPLE_COND)
110386 + return false;
110387 +
110388 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
110389 + return false;
110390 +
110391 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
110392 + return false;
110393 +
110394 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
110395 +
110396 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
110397 + return false;
110398 +
110399 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
110400 +
110401 + if (gimple_code(call_stmt) != GIMPLE_CALL)
110402 + return false;
110403 +
110404 + dom_lhs = gimple_get_lhs(call_stmt);
110405 + poss_is_err_func = gimple_call_fndecl(call_stmt);
110406 + if (!poss_is_err_func)
110407 + return false;
110408 + if (dom_lhs != poss_is_err_cond)
110409 + return false;
110410 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
110411 + return false;
110412 +
110413 + is_err_arg = gimple_call_arg(call_stmt, 0);
110414 + if (!is_err_arg)
110415 + return false;
110416 +
110417 + if (is_err_arg != rhs)
110418 + return false;
110419 +
110420 + return true;
110421 +}
110422 +
110423 +static void handle_local_var_initializers(void)
110424 +{
110425 + tree var;
110426 + unsigned int i;
110427 +
110428 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
110429 + tree init = DECL_INITIAL(var);
110430 + if (!init)
110431 + continue;
110432 + if (TREE_CODE(init) != CONSTRUCTOR)
110433 + continue;
110434 + check_bad_casts_in_constructor(var, init);
110435 + }
110436 +}
110437 +
110438 +/*
110439 + * iterate over all statements to find "bad" casts:
110440 + * those where the address of the start of a structure is cast
110441 + * to a pointer of a structure of a different type, or a
110442 + * structure pointer type is cast to a different structure pointer type
110443 + */
110444 +static unsigned int find_bad_casts(void)
110445 +{
110446 + basic_block bb;
110447 +
110448 + handle_local_var_initializers();
110449 +
110450 + FOR_ALL_BB_FN(bb, cfun) {
110451 + gimple_stmt_iterator gsi;
110452 +
110453 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
110454 + gimple stmt;
110455 + const_tree lhs;
110456 + const_tree lhs_type;
110457 + const_tree rhs1;
110458 + const_tree rhs_type;
110459 + const_tree ptr_lhs_type;
110460 + const_tree ptr_rhs_type;
110461 + const_tree op0;
110462 + const_tree op0_type;
110463 + enum tree_code rhs_code;
110464 +
110465 + stmt = gsi_stmt(gsi);
110466 +
110467 +#ifdef __DEBUG_PLUGIN
110468 +#ifdef __DEBUG_VERBOSE
110469 + debug_gimple_stmt(stmt);
110470 + debug_tree(gimple_get_lhs(stmt));
110471 +#endif
110472 +#endif
110473 +
110474 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
110475 + continue;
110476 +
110477 +#ifdef __DEBUG_PLUGIN
110478 +#ifdef __DEBUG_VERBOSE
110479 + debug_tree(gimple_assign_rhs1(stmt));
110480 +#endif
110481 +#endif
110482 +
110483 + rhs_code = gimple_assign_rhs_code(stmt);
110484 +
110485 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
110486 + continue;
110487 +
110488 + lhs = gimple_get_lhs(stmt);
110489 + lhs_type = TREE_TYPE(lhs);
110490 + rhs1 = gimple_assign_rhs1(stmt);
110491 + rhs_type = TREE_TYPE(rhs1);
110492 +
110493 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
110494 + TREE_CODE(lhs_type) != POINTER_TYPE)
110495 + continue;
110496 +
110497 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
110498 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
110499 +
110500 + if (ptr_rhs_type == void_type_node)
110501 + continue;
110502 +
110503 + if (ptr_lhs_type == void_type_node)
110504 + continue;
110505 +
110506 + if (dominated_by_is_err(rhs1, bb))
110507 + continue;
110508 +
110509 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
110510 +#ifndef __DEBUG_PLUGIN
110511 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
110512 +#endif
110513 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
110514 + continue;
110515 + }
110516 +
110517 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
110518 + continue;
110519 +
110520 + if (rhs_code == ADDR_EXPR) {
110521 + op0 = TREE_OPERAND(rhs1, 0);
110522 +
110523 + if (op0 == NULL_TREE)
110524 + continue;
110525 +
110526 + if (TREE_CODE(op0) != VAR_DECL)
110527 + continue;
110528 +
110529 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
110530 + if (op0_type == ptr_lhs_type)
110531 + continue;
110532 +
110533 +#ifndef __DEBUG_PLUGIN
110534 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
110535 +#endif
110536 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
110537 + } else {
110538 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
110539 + /* skip bogus type casts introduced by container_of */
110540 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
110541 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
110542 + continue;
110543 +#ifndef __DEBUG_PLUGIN
110544 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
110545 +#endif
110546 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
110547 + }
110548 +
110549 + }
110550 + }
110551 + return 0;
110552 +}
110553 +
110554 +#if BUILDING_GCC_VERSION >= 4009
110555 +static const struct pass_data randomize_layout_bad_cast_data = {
110556 +#else
110557 +static struct gimple_opt_pass randomize_layout_bad_cast = {
110558 + .pass = {
110559 +#endif
110560 + .type = GIMPLE_PASS,
110561 + .name = "randomize_layout_bad_cast",
110562 +#if BUILDING_GCC_VERSION >= 4008
110563 + .optinfo_flags = OPTGROUP_NONE,
110564 +#endif
110565 +#if BUILDING_GCC_VERSION >= 4009
110566 + .has_gate = false,
110567 + .has_execute = true,
110568 +#else
110569 + .gate = NULL,
110570 + .execute = find_bad_casts,
110571 + .sub = NULL,
110572 + .next = NULL,
110573 + .static_pass_number = 0,
110574 +#endif
110575 + .tv_id = TV_NONE,
110576 + .properties_required = PROP_cfg,
110577 + .properties_provided = 0,
110578 + .properties_destroyed = 0,
110579 + .todo_flags_start = 0,
110580 + .todo_flags_finish = TODO_dump_func
110581 +#if BUILDING_GCC_VERSION < 4009
110582 + }
110583 +#endif
110584 +};
110585 +
110586 +#if BUILDING_GCC_VERSION >= 4009
110587 +namespace {
110588 +class randomize_layout_bad_cast : public gimple_opt_pass {
110589 +public:
110590 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
110591 + unsigned int execute() { return find_bad_casts(); }
110592 +};
110593 +}
110594 +#endif
110595 +
110596 +static struct opt_pass *make_randomize_layout_bad_cast(void)
110597 +{
110598 +#if BUILDING_GCC_VERSION >= 4009
110599 + return new randomize_layout_bad_cast();
110600 +#else
110601 + return &randomize_layout_bad_cast.pass;
110602 +#endif
110603 +}
110604 +
110605 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110606 +{
110607 + int i;
110608 + const char * const plugin_name = plugin_info->base_name;
110609 + const int argc = plugin_info->argc;
110610 + const struct plugin_argument * const argv = plugin_info->argv;
110611 + bool enable = true;
110612 + int obtained_seed = 0;
110613 + struct register_pass_info randomize_layout_bad_cast_info;
110614 +
110615 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
110616 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
110617 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
110618 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
110619 +
110620 + if (!plugin_default_version_check(version, &gcc_version)) {
110621 + error(G_("incompatible gcc/plugin versions"));
110622 + return 1;
110623 + }
110624 +
110625 + if (strcmp(lang_hooks.name, "GNU C")) {
110626 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
110627 + enable = false;
110628 + }
110629 +
110630 + for (i = 0; i < argc; ++i) {
110631 + if (!strcmp(argv[i].key, "disable")) {
110632 + enable = false;
110633 + continue;
110634 + }
110635 + if (!strcmp(argv[i].key, "performance-mode")) {
110636 + performance_mode = 1;
110637 + continue;
110638 + }
110639 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110640 + }
110641 +
110642 + if (strlen(randstruct_seed) != 64) {
110643 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
110644 + return 1;
110645 + }
110646 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
110647 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
110648 + if (obtained_seed != 4) {
110649 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
110650 + return 1;
110651 + }
110652 +
110653 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
110654 + if (enable) {
110655 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
110656 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
110657 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
110658 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
110659 + }
110660 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
110661 +
110662 + return 0;
110663 +}
110664 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
110665 new file mode 100644
110666 index 0000000..1f0214f
110667 --- /dev/null
110668 +++ b/tools/gcc/size_overflow_plugin/.gitignore
110669 @@ -0,0 +1,3 @@
110670 +randomize_layout_seed.h
110671 +size_overflow_hash.h
110672 +size_overflow_hash_aux.h
110673 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
110674 new file mode 100644
110675 index 0000000..1ae2ed5
110676 --- /dev/null
110677 +++ b/tools/gcc/size_overflow_plugin/Makefile
110678 @@ -0,0 +1,20 @@
110679 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
110680 +always := $($(HOSTLIBS)-y)
110681 +
110682 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
110683 +
110684 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
110685 +
110686 +quiet_cmd_build_size_overflow_hash = GENHASH $@
110687 + cmd_build_size_overflow_hash = \
110688 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
110689 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
110690 + $(call if_changed,build_size_overflow_hash)
110691 +
110692 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
110693 + cmd_build_size_overflow_hash_aux = \
110694 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
110695 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
110696 + $(call if_changed,build_size_overflow_hash_aux)
110697 +
110698 +targets += size_overflow_hash.h size_overflow_hash_aux.h
110699 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
110700 new file mode 100644
110701 index 0000000..12b1e3b
110702 --- /dev/null
110703 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
110704 @@ -0,0 +1,102 @@
110705 +#!/bin/bash
110706 +
110707 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
110708 +
110709 +header1="size_overflow_hash.h"
110710 +database="size_overflow_hash.data"
110711 +n=65536
110712 +hashtable_name="size_overflow_hash"
110713 +
110714 +usage() {
110715 +cat <<EOF
110716 +usage: $0 options
110717 +OPTIONS:
110718 + -h|--help help
110719 + -o header file
110720 + -d database file
110721 + -n hash array size
110722 + -s name of the hash table
110723 +EOF
110724 + return 0
110725 +}
110726 +
110727 +while true
110728 +do
110729 + case "$1" in
110730 + -h|--help) usage && exit 0;;
110731 + -n) n=$2; shift 2;;
110732 + -o) header1="$2"; shift 2;;
110733 + -d) database="$2"; shift 2;;
110734 + -s) hashtable_name="$2"; shift 2;;
110735 + --) shift 1; break ;;
110736 + *) break ;;
110737 + esac
110738 +done
110739 +
110740 +create_defines() {
110741 + for i in `seq 0 31`
110742 + do
110743 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
110744 + done
110745 + echo >> "$header1"
110746 +}
110747 +
110748 +create_structs() {
110749 + rm -f "$header1"
110750 +
110751 + create_defines
110752 +
110753 + cat "$database" | while read data
110754 + do
110755 + data_array=($data)
110756 + struct_hash_name="${data_array[0]}"
110757 + funcn="${data_array[1]}"
110758 + params="${data_array[2]}"
110759 + next="${data_array[4]}"
110760 +
110761 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
110762 +
110763 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
110764 + echo -en "\t.param\t= " >> "$header1"
110765 + line=
110766 + for param_num in ${params//-/ };
110767 + do
110768 + line="${line}PARAM"$param_num"|"
110769 + done
110770 +
110771 + echo -e "${line%?},\n};\n" >> "$header1"
110772 + done
110773 +}
110774 +
110775 +create_headers() {
110776 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
110777 +}
110778 +
110779 +create_array_elements() {
110780 + index=0
110781 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
110782 + do
110783 + data_array=($data)
110784 + i="${data_array[3]}"
110785 + hash="${data_array[0]}"
110786 + while [[ $index -lt $i ]]
110787 + do
110788 + echo -e "\t["$index"]\t= NULL," >> "$header1"
110789 + index=$(($index + 1))
110790 + done
110791 + index=$(($index + 1))
110792 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
110793 + done
110794 + echo '};' >> $header1
110795 +}
110796 +
110797 +size_overflow_plugin_dir=`dirname $header1`
110798 +if [ "$size_overflow_plugin_dir" != '.' ]; then
110799 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
110800 +fi
110801 +
110802 +create_structs
110803 +create_headers
110804 +create_array_elements
110805 +
110806 +exit 0
110807 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
110808 new file mode 100644
110809 index 0000000..3e8148c
110810 --- /dev/null
110811 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
110812 @@ -0,0 +1,790 @@
110813 +/*
110814 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
110815 + * Licensed under the GPL v2, or (at your option) v3
110816 + *
110817 + * Homepage:
110818 + * http://www.grsecurity.net/~ephox/overflow_plugin/
110819 + *
110820 + * Documentation:
110821 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
110822 + *
110823 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
110824 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
110825 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
110826 + *
110827 + * Usage:
110828 + * $ make
110829 + * $ make run
110830 + */
110831 +
110832 +#include "gcc-common.h"
110833 +#include "size_overflow.h"
110834 +
110835 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
110836 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
110837 +
110838 +// data for the size_overflow asm stmt
110839 +struct asm_data {
110840 + gimple def_stmt;
110841 + tree input;
110842 + tree output;
110843 +};
110844 +
110845 +#if BUILDING_GCC_VERSION <= 4007
110846 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
110847 +#else
110848 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
110849 +#endif
110850 +{
110851 + tree list;
110852 +#if BUILDING_GCC_VERSION <= 4007
110853 + VEC(tree, gc) *vec_list = NULL;
110854 +#else
110855 + vec<tree, va_gc> *vec_list = NULL;
110856 +#endif
110857 +
110858 + list = build_tree_list(NULL_TREE, string);
110859 + list = chainon(NULL_TREE, build_tree_list(list, io));
110860 +#if BUILDING_GCC_VERSION <= 4007
110861 + VEC_safe_push(tree, gc, vec_list, list);
110862 +#else
110863 + vec_safe_push(vec_list, list);
110864 +#endif
110865 + return vec_list;
110866 +}
110867 +
110868 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
110869 +{
110870 + gimple asm_stmt;
110871 + gimple_stmt_iterator gsi;
110872 +#if BUILDING_GCC_VERSION <= 4007
110873 + VEC(tree, gc) *input, *output = NULL;
110874 +#else
110875 + vec<tree, va_gc> *input, *output = NULL;
110876 +#endif
110877 +
110878 + input = create_asm_io_list(str_input, asm_data->input);
110879 +
110880 + if (asm_data->output)
110881 + output = create_asm_io_list(str_output, asm_data->output);
110882 +
110883 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
110884 + gsi = gsi_for_stmt(asm_data->def_stmt);
110885 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
110886 +
110887 + if (asm_data->output)
110888 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
110889 +}
110890 +
110891 +static void replace_call_lhs(const struct asm_data *asm_data)
110892 +{
110893 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
110894 + update_stmt(asm_data->def_stmt);
110895 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
110896 +}
110897 +
110898 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
110899 +{
110900 + enum mark cur_fndecl_attr;
110901 + gimple phi = get_def_stmt(result);
110902 + unsigned int i, n = gimple_phi_num_args(phi);
110903 +
110904 + pointer_set_insert(visited, phi);
110905 + for (i = 0; i < n; i++) {
110906 + tree arg = gimple_phi_arg_def(phi, i);
110907 +
110908 + cur_fndecl_attr = search_intentional(visited, arg);
110909 + if (cur_fndecl_attr != MARK_NO)
110910 + return cur_fndecl_attr;
110911 + }
110912 + return MARK_NO;
110913 +}
110914 +
110915 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
110916 +{
110917 + enum mark cur_fndecl_attr;
110918 + const_tree rhs1, rhs2;
110919 + gimple def_stmt = get_def_stmt(lhs);
110920 +
110921 + rhs1 = gimple_assign_rhs1(def_stmt);
110922 + rhs2 = gimple_assign_rhs2(def_stmt);
110923 +
110924 + cur_fndecl_attr = search_intentional(visited, rhs1);
110925 + if (cur_fndecl_attr != MARK_NO)
110926 + return cur_fndecl_attr;
110927 + return search_intentional(visited, rhs2);
110928 +}
110929 +
110930 +// Look up the intentional_overflow attribute on the caller and the callee functions.
110931 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
110932 +{
110933 + const_gimple def_stmt;
110934 +
110935 + if (TREE_CODE(lhs) != SSA_NAME)
110936 + return get_intentional_attr_type(lhs);
110937 +
110938 + def_stmt = get_def_stmt(lhs);
110939 + if (!def_stmt)
110940 + return MARK_NO;
110941 +
110942 + if (pointer_set_contains(visited, def_stmt))
110943 + return MARK_NO;
110944 +
110945 + switch (gimple_code(def_stmt)) {
110946 + case GIMPLE_NOP:
110947 + return search_intentional(visited, SSA_NAME_VAR(lhs));
110948 + case GIMPLE_ASM:
110949 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
110950 + return MARK_TURN_OFF;
110951 + return MARK_NO;
110952 + case GIMPLE_CALL:
110953 + return MARK_NO;
110954 + case GIMPLE_PHI:
110955 + return search_intentional_phi(visited, lhs);
110956 + case GIMPLE_ASSIGN:
110957 + switch (gimple_num_ops(def_stmt)) {
110958 + case 2:
110959 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
110960 + case 3:
110961 + return search_intentional_binary(visited, lhs);
110962 + }
110963 + case GIMPLE_RETURN:
110964 + return MARK_NO;
110965 + default:
110966 + debug_gimple_stmt((gimple)def_stmt);
110967 + error("%s: unknown gimple code", __func__);
110968 + gcc_unreachable();
110969 + }
110970 +}
110971 +
110972 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
110973 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
110974 +{
110975 + const_tree fndecl;
110976 + struct pointer_set_t *visited;
110977 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
110978 +
110979 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
110980 + if (is_end_intentional_intentional_attr(fndecl, argnum))
110981 + decl_attr = MARK_NOT_INTENTIONAL;
110982 + else if (is_yes_intentional_attr(fndecl, argnum))
110983 + decl_attr = MARK_YES;
110984 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
110985 + return MARK_TURN_OFF;
110986 + }
110987 +
110988 + visited = pointer_set_create();
110989 + cur_fndecl_attr = search_intentional(visited, arg);
110990 + pointer_set_destroy(visited);
110991 +
110992 + switch (cur_fndecl_attr) {
110993 + case MARK_NO:
110994 + case MARK_TURN_OFF:
110995 + return cur_fndecl_attr;
110996 + default:
110997 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
110998 + return MARK_YES;
110999 + }
111000 +}
111001 +
111002 +static void check_missing_size_overflow_attribute(tree var)
111003 +{
111004 + tree orig_fndecl;
111005 + unsigned int num;
111006 +
111007 + if (is_a_return_check(var))
111008 + orig_fndecl = DECL_ORIGIN(var);
111009 + else
111010 + orig_fndecl = DECL_ORIGIN(current_function_decl);
111011 +
111012 + num = get_function_num(var, orig_fndecl);
111013 + if (num == CANNOT_FIND_ARG)
111014 + return;
111015 +
111016 + is_missing_function(orig_fndecl, num);
111017 +}
111018 +
111019 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
111020 +{
111021 + gimple phi = get_def_stmt(result);
111022 + unsigned int i, n = gimple_phi_num_args(phi);
111023 +
111024 + pointer_set_insert(visited, phi);
111025 + for (i = 0; i < n; i++) {
111026 + tree arg = gimple_phi_arg_def(phi, i);
111027 +
111028 + search_size_overflow_attribute(visited, arg);
111029 + }
111030 +}
111031 +
111032 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
111033 +{
111034 + const_gimple def_stmt = get_def_stmt(lhs);
111035 + tree rhs1, rhs2;
111036 +
111037 + rhs1 = gimple_assign_rhs1(def_stmt);
111038 + rhs2 = gimple_assign_rhs2(def_stmt);
111039 +
111040 + search_size_overflow_attribute(visited, rhs1);
111041 + search_size_overflow_attribute(visited, rhs2);
111042 +}
111043 +
111044 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
111045 +{
111046 + const_gimple def_stmt;
111047 +
111048 + if (TREE_CODE(lhs) == PARM_DECL) {
111049 + check_missing_size_overflow_attribute(lhs);
111050 + return;
111051 + }
111052 +
111053 + def_stmt = get_def_stmt(lhs);
111054 + if (!def_stmt)
111055 + return;
111056 +
111057 + if (pointer_set_insert(visited, def_stmt))
111058 + return;
111059 +
111060 + switch (gimple_code(def_stmt)) {
111061 + case GIMPLE_NOP:
111062 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
111063 + case GIMPLE_ASM:
111064 + return;
111065 + case GIMPLE_CALL: {
111066 + tree fndecl = gimple_call_fndecl(def_stmt);
111067 +
111068 + if (fndecl == NULL_TREE)
111069 + return;
111070 + check_missing_size_overflow_attribute(fndecl);
111071 + return;
111072 + }
111073 + case GIMPLE_PHI:
111074 + return search_size_overflow_attribute_phi(visited, lhs);
111075 + case GIMPLE_ASSIGN:
111076 + switch (gimple_num_ops(def_stmt)) {
111077 + case 2:
111078 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
111079 + case 3:
111080 + return search_size_overflow_attribute_binary(visited, lhs);
111081 + }
111082 + default:
111083 + debug_gimple_stmt((gimple)def_stmt);
111084 + error("%s: unknown gimple code", __func__);
111085 + gcc_unreachable();
111086 + }
111087 +}
111088 +
111089 +// Search missing entries in the hash table (invoked from the gimple pass)
111090 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
111091 +{
111092 + tree fndecl = NULL_TREE;
111093 + tree lhs;
111094 + struct pointer_set_t *visited;
111095 +
111096 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
111097 + return;
111098 +
111099 + if (num == 0) {
111100 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
111101 + lhs = gimple_return_retval(stmt);
111102 + } else {
111103 + gcc_assert(is_gimple_call(stmt));
111104 + lhs = gimple_call_arg(stmt, num - 1);
111105 + fndecl = gimple_call_fndecl(stmt);
111106 + }
111107 +
111108 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
111109 + return;
111110 +
111111 + visited = pointer_set_create();
111112 + search_size_overflow_attribute(visited, lhs);
111113 + pointer_set_destroy(visited);
111114 +}
111115 +
111116 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
111117 +{
111118 + gimple_stmt_iterator gsi;
111119 + gimple assign;
111120 +
111121 + assign = gimple_build_assign(asm_data->input, asm_data->output);
111122 + gsi = gsi_for_stmt(stmt);
111123 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
111124 + asm_data->def_stmt = assign;
111125 +
111126 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
111127 + asm_data->output = make_ssa_name(asm_data->output, stmt);
111128 + if (gimple_code(stmt) == GIMPLE_RETURN)
111129 + gimple_return_set_retval(stmt, asm_data->output);
111130 + else
111131 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
111132 + update_stmt(stmt);
111133 +}
111134 +
111135 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
111136 +{
111137 + const char *fn_name;
111138 + char *asm_comment;
111139 + unsigned int len;
111140 +
111141 + if (argnum == 0)
111142 + fn_name = DECL_NAME_POINTER(current_function_decl);
111143 + else
111144 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
111145 +
111146 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
111147 + gcc_assert(len > 0);
111148 +
111149 + return asm_comment;
111150 +}
111151 +
111152 +static const char *convert_mark_to_str(enum mark mark)
111153 +{
111154 + switch (mark) {
111155 + case MARK_NO:
111156 + return OK_ASM_STR;
111157 + case MARK_YES:
111158 + case MARK_NOT_INTENTIONAL:
111159 + return YES_ASM_STR;
111160 + case MARK_TURN_OFF:
111161 + return TURN_OFF_ASM_STR;
111162 + }
111163 +
111164 + gcc_unreachable();
111165 +}
111166 +
111167 +/* Create the input of the size_overflow asm stmt.
111168 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
111169 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
111170 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
111171 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
111172 + */
111173 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
111174 +{
111175 + if (!asm_data->def_stmt) {
111176 + asm_data->input = NULL_TREE;
111177 + return;
111178 + }
111179 +
111180 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
111181 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
111182 +
111183 + switch (gimple_code(asm_data->def_stmt)) {
111184 + case GIMPLE_ASSIGN:
111185 + case GIMPLE_CALL:
111186 + replace_call_lhs(asm_data);
111187 + break;
111188 + case GIMPLE_PHI:
111189 + create_output_from_phi(stmt, argnum, asm_data);
111190 + break;
111191 + case GIMPLE_NOP: {
111192 + enum mark mark;
111193 + const char *mark_str;
111194 + char *asm_comment;
111195 +
111196 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
111197 +
111198 + asm_data->input = asm_data->output;
111199 + asm_data->output = NULL;
111200 + asm_data->def_stmt = stmt;
111201 +
111202 + mark_str = convert_mark_to_str(mark);
111203 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
111204 +
111205 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
111206 + free(asm_comment);
111207 + asm_data->input = NULL_TREE;
111208 + break;
111209 + }
111210 + case GIMPLE_ASM:
111211 + if (is_size_overflow_asm(asm_data->def_stmt)) {
111212 + asm_data->input = NULL_TREE;
111213 + break;
111214 + }
111215 + default:
111216 + debug_gimple_stmt(asm_data->def_stmt);
111217 + gcc_unreachable();
111218 + }
111219 +}
111220 +
111221 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
111222 + * is of the right kind create the appropriate size_overflow asm stmts:
111223 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
111224 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
111225 + */
111226 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
111227 +{
111228 + struct asm_data asm_data;
111229 + const char *mark_str;
111230 + char *asm_comment;
111231 + enum mark mark;
111232 +
111233 + if (is_gimple_constant(output_node))
111234 + return;
111235 +
111236 + asm_data.output = output_node;
111237 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
111238 + if (mark != MARK_TURN_OFF)
111239 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
111240 +
111241 + asm_data.def_stmt = get_def_stmt(asm_data.output);
111242 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
111243 + return;
111244 +
111245 + create_asm_input(stmt, argnum, &asm_data);
111246 + if (asm_data.input == NULL_TREE)
111247 + return;
111248 +
111249 + mark_str = convert_mark_to_str(mark);
111250 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
111251 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
111252 + free(asm_comment);
111253 +}
111254 +
111255 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
111256 +static bool create_mark_asm(gimple stmt, enum mark mark)
111257 +{
111258 + struct asm_data asm_data;
111259 + const char *asm_str;
111260 +
111261 + switch (mark) {
111262 + case MARK_TURN_OFF:
111263 + asm_str = TURN_OFF_ASM_STR;
111264 + break;
111265 + case MARK_NOT_INTENTIONAL:
111266 + case MARK_YES:
111267 + asm_str = YES_ASM_STR;
111268 + break;
111269 + default:
111270 + gcc_unreachable();
111271 + }
111272 +
111273 + asm_data.def_stmt = stmt;
111274 + asm_data.output = gimple_call_lhs(stmt);
111275 +
111276 + if (asm_data.output == NULL_TREE) {
111277 + asm_data.input = gimple_call_arg(stmt, 0);
111278 + if (is_gimple_constant(asm_data.input))
111279 + return false;
111280 + asm_data.output = NULL;
111281 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
111282 + return true;
111283 + }
111284 +
111285 + create_asm_input(stmt, 0, &asm_data);
111286 + gcc_assert(asm_data.input != NULL_TREE);
111287 +
111288 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
111289 + return true;
111290 +}
111291 +
111292 +static bool is_from_cast(const_tree node)
111293 +{
111294 + gimple def_stmt = get_def_stmt(node);
111295 +
111296 + if (!def_stmt)
111297 + return false;
111298 +
111299 + if (gimple_assign_cast_p(def_stmt))
111300 + return true;
111301 +
111302 + return false;
111303 +}
111304 +
111305 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
111306 +static bool skip_ptr_minus(gimple stmt)
111307 +{
111308 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
111309 +
111310 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
111311 + return false;
111312 +
111313 + rhs1 = gimple_assign_rhs1(stmt);
111314 + if (!is_from_cast(rhs1))
111315 + return false;
111316 +
111317 + rhs2 = gimple_assign_rhs2(stmt);
111318 + if (!is_from_cast(rhs2))
111319 + return false;
111320 +
111321 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
111322 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
111323 +
111324 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
111325 + return false;
111326 +
111327 + create_mark_asm(stmt, MARK_YES);
111328 + return true;
111329 +}
111330 +
111331 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
111332 +{
111333 + gimple def_stmt;
111334 +
111335 + def_stmt = get_def_stmt(lhs);
111336 + if (!def_stmt)
111337 + return;
111338 +
111339 + if (pointer_set_insert(visited, def_stmt))
111340 + return;
111341 +
111342 + switch (gimple_code(def_stmt)) {
111343 + case GIMPLE_NOP:
111344 + case GIMPLE_ASM:
111345 + case GIMPLE_CALL:
111346 + break;
111347 + case GIMPLE_PHI: {
111348 + unsigned int i, n = gimple_phi_num_args(def_stmt);
111349 +
111350 + pointer_set_insert(visited, def_stmt);
111351 +
111352 + for (i = 0; i < n; i++) {
111353 + tree arg = gimple_phi_arg_def(def_stmt, i);
111354 +
111355 + walk_use_def_ptr(visited, arg);
111356 + }
111357 + }
111358 + case GIMPLE_ASSIGN:
111359 + switch (gimple_num_ops(def_stmt)) {
111360 + case 2:
111361 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
111362 + return;
111363 + case 3:
111364 + if (skip_ptr_minus(def_stmt))
111365 + return;
111366 +
111367 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
111368 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
111369 + return;
111370 + default:
111371 + return;
111372 + }
111373 + default:
111374 + debug_gimple_stmt((gimple)def_stmt);
111375 + error("%s: unknown gimple code", __func__);
111376 + gcc_unreachable();
111377 + }
111378 +}
111379 +
111380 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
111381 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
111382 +{
111383 + struct pointer_set_t *visited;
111384 +
111385 + visited = pointer_set_create();
111386 + walk_use_def_ptr(visited, arg);
111387 + pointer_set_destroy(visited);
111388 +}
111389 +
111390 +// Determine the return value and insert the asm stmt to mark the return stmt.
111391 +static void insert_asm_ret(gimple stmt)
111392 +{
111393 + tree ret;
111394 +
111395 + ret = gimple_return_retval(stmt);
111396 + create_size_overflow_asm(stmt, ret, 0);
111397 +}
111398 +
111399 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
111400 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
111401 +{
111402 + tree arg;
111403 + unsigned int argnum;
111404 +
111405 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
111406 + gcc_assert(argnum != 0);
111407 + if (argnum == CANNOT_FIND_ARG)
111408 + return;
111409 +
111410 + arg = gimple_call_arg(stmt, argnum - 1);
111411 + gcc_assert(arg != NULL_TREE);
111412 +
111413 + // skip all ptr - ptr expressions
111414 + insert_mark_not_intentional_asm_at_ptr(arg);
111415 +
111416 + create_size_overflow_asm(stmt, arg, argnum);
111417 +}
111418 +
111419 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
111420 +static void set_argnum_attribute(const_tree attr, bool *argnums)
111421 +{
111422 + unsigned int argnum;
111423 + tree attr_value;
111424 +
111425 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
111426 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
111427 + argnums[argnum] = true;
111428 + }
111429 +}
111430 +
111431 +// If a function arg or the return value is in the hash table then set its index in the array.
111432 +static void set_argnum_hash(tree fndecl, bool *argnums)
111433 +{
111434 + unsigned int num;
111435 + const struct size_overflow_hash *hash;
111436 +
111437 + hash = get_function_hash(DECL_ORIGIN(fndecl));
111438 + if (!hash)
111439 + return;
111440 +
111441 + for (num = 0; num <= MAX_PARAM; num++) {
111442 + if (!(hash->param & (1U << num)))
111443 + continue;
111444 +
111445 + argnums[num] = true;
111446 + }
111447 +}
111448 +
111449 +static bool is_all_the_argnums_empty(bool *argnums)
111450 +{
111451 + unsigned int i;
111452 +
111453 + for (i = 0; i <= MAX_PARAM; i++)
111454 + if (argnums[i])
111455 + return false;
111456 + return true;
111457 +}
111458 +
111459 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
111460 +static void search_interesting_args(tree fndecl, bool *argnums)
111461 +{
111462 + const_tree attr;
111463 +
111464 + set_argnum_hash(fndecl, argnums);
111465 + if (!is_all_the_argnums_empty(argnums))
111466 + return;
111467 +
111468 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
111469 + if (attr && TREE_VALUE(attr))
111470 + set_argnum_attribute(attr, argnums);
111471 +}
111472 +
111473 +/*
111474 + * Look up the intentional_overflow attribute that turns off ipa based duplication
111475 + * on the callee function.
111476 + */
111477 +static bool is_mark_turn_off_attribute(gimple stmt)
111478 +{
111479 + enum mark mark;
111480 + const_tree fndecl = gimple_call_fndecl(stmt);
111481 +
111482 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
111483 + if (mark == MARK_TURN_OFF)
111484 + return true;
111485 + return false;
111486 +}
111487 +
111488 +// 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
111489 +static void handle_interesting_function(gimple stmt)
111490 +{
111491 + unsigned int argnum;
111492 + tree fndecl;
111493 + bool orig_argnums[MAX_PARAM + 1] = {false};
111494 +
111495 + if (gimple_call_num_args(stmt) == 0)
111496 + return;
111497 + fndecl = gimple_call_fndecl(stmt);
111498 + if (fndecl == NULL_TREE)
111499 + return;
111500 + fndecl = DECL_ORIGIN(fndecl);
111501 +
111502 + if (is_mark_turn_off_attribute(stmt)) {
111503 + create_mark_asm(stmt, MARK_TURN_OFF);
111504 + return;
111505 + }
111506 +
111507 + search_interesting_args(fndecl, orig_argnums);
111508 +
111509 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
111510 + if (orig_argnums[argnum])
111511 + insert_asm_arg(stmt, argnum);
111512 +}
111513 +
111514 +// 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
111515 +static void handle_interesting_ret(gimple stmt)
111516 +{
111517 + bool orig_argnums[MAX_PARAM + 1] = {false};
111518 +
111519 + search_interesting_args(current_function_decl, orig_argnums);
111520 +
111521 + if (orig_argnums[0])
111522 + insert_asm_ret(stmt);
111523 +}
111524 +
111525 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
111526 +static unsigned int search_interesting_functions(void)
111527 +{
111528 + basic_block bb;
111529 +
111530 + FOR_ALL_BB_FN(bb, cfun) {
111531 + gimple_stmt_iterator gsi;
111532 +
111533 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111534 + gimple stmt = gsi_stmt(gsi);
111535 +
111536 + if (is_size_overflow_asm(stmt))
111537 + continue;
111538 +
111539 + if (is_gimple_call(stmt))
111540 + handle_interesting_function(stmt);
111541 + else if (gimple_code(stmt) == GIMPLE_RETURN)
111542 + handle_interesting_ret(stmt);
111543 + }
111544 + }
111545 + return 0;
111546 +}
111547 +
111548 +/*
111549 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
111550 + * this pass inserts asm stmts to mark the interesting args
111551 + * that the ipa pass will detect and insert the size overflow checks for.
111552 + */
111553 +#if BUILDING_GCC_VERSION >= 4009
111554 +static const struct pass_data insert_size_overflow_asm_pass_data = {
111555 +#else
111556 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
111557 + .pass = {
111558 +#endif
111559 + .type = GIMPLE_PASS,
111560 + .name = "insert_size_overflow_asm",
111561 +#if BUILDING_GCC_VERSION >= 4008
111562 + .optinfo_flags = OPTGROUP_NONE,
111563 +#endif
111564 +#if BUILDING_GCC_VERSION >= 4009
111565 + .has_gate = false,
111566 + .has_execute = true,
111567 +#else
111568 + .gate = NULL,
111569 + .execute = search_interesting_functions,
111570 + .sub = NULL,
111571 + .next = NULL,
111572 + .static_pass_number = 0,
111573 +#endif
111574 + .tv_id = TV_NONE,
111575 + .properties_required = PROP_cfg,
111576 + .properties_provided = 0,
111577 + .properties_destroyed = 0,
111578 + .todo_flags_start = 0,
111579 + .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
111580 +#if BUILDING_GCC_VERSION < 4009
111581 + }
111582 +#endif
111583 +};
111584 +
111585 +#if BUILDING_GCC_VERSION >= 4009
111586 +namespace {
111587 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
111588 +public:
111589 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
111590 + unsigned int execute() { return search_interesting_functions(); }
111591 +};
111592 +}
111593 +#endif
111594 +
111595 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
111596 +{
111597 +#if BUILDING_GCC_VERSION >= 4009
111598 + return new insert_size_overflow_asm_pass();
111599 +#else
111600 + return &insert_size_overflow_asm_pass.pass;
111601 +#endif
111602 +}
111603 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
111604 new file mode 100644
111605 index 0000000..88469e9
111606 --- /dev/null
111607 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
111608 @@ -0,0 +1,902 @@
111609 +/*
111610 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
111611 + * Licensed under the GPL v2, or (at your option) v3
111612 + *
111613 + * Homepage:
111614 + * http://www.grsecurity.net/~ephox/overflow_plugin/
111615 + *
111616 + * Documentation:
111617 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
111618 + *
111619 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
111620 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
111621 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
111622 + *
111623 + * Usage:
111624 + * $ make
111625 + * $ make run
111626 + */
111627 +
111628 +#include "gcc-common.h"
111629 +#include "size_overflow.h"
111630 +
111631 +#define MIN_CHECK true
111632 +#define MAX_CHECK false
111633 +
111634 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
111635 +{
111636 + const_tree type;
111637 + tree new_type;
111638 +
111639 + gcc_assert(node != NULL_TREE);
111640 +
111641 + type = TREE_TYPE(node);
111642 +
111643 + if (pointer_set_contains(visited->my_stmts, stmt))
111644 + return TREE_TYPE(node);
111645 +
111646 + switch (TYPE_MODE(type)) {
111647 + case QImode:
111648 + new_type = size_overflow_type_HI;
111649 + break;
111650 + case HImode:
111651 + new_type = size_overflow_type_SI;
111652 + break;
111653 + case SImode:
111654 + new_type = size_overflow_type_DI;
111655 + break;
111656 + case DImode:
111657 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
111658 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
111659 + else
111660 + new_type = size_overflow_type_TI;
111661 + break;
111662 + case TImode:
111663 + gcc_assert(!TYPE_UNSIGNED(type));
111664 + new_type = size_overflow_type_TI;
111665 + break;
111666 + default:
111667 + debug_tree((tree)node);
111668 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
111669 + gcc_unreachable();
111670 + }
111671 +
111672 + if (TYPE_QUALS(type) != 0)
111673 + return build_qualified_type(new_type, TYPE_QUALS(type));
111674 + return new_type;
111675 +}
111676 +
111677 +static tree get_lhs(const_gimple stmt)
111678 +{
111679 + switch (gimple_code(stmt)) {
111680 + case GIMPLE_ASSIGN:
111681 + case GIMPLE_CALL:
111682 + return gimple_get_lhs(stmt);
111683 + case GIMPLE_PHI:
111684 + return gimple_phi_result(stmt);
111685 + default:
111686 + return NULL_TREE;
111687 + }
111688 +}
111689 +
111690 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
111691 +{
111692 + gimple_stmt_iterator gsi;
111693 + tree lhs;
111694 + gimple new_stmt;
111695 +
111696 + if (rhs == NULL_TREE)
111697 + return NULL_TREE;
111698 +
111699 + gsi = gsi_for_stmt(stmt);
111700 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
111701 + pointer_set_insert(visited->my_stmts, new_stmt);
111702 +
111703 + lhs = get_lhs(new_stmt);
111704 + gcc_assert(lhs != NULL_TREE);
111705 + return lhs;
111706 +}
111707 +
111708 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
111709 +{
111710 + tree lhs, dst_type;
111711 + gimple_stmt_iterator gsi;
111712 +
111713 + if (rhs1 == NULL_TREE) {
111714 + debug_gimple_stmt(oldstmt);
111715 + error("%s: rhs1 is NULL_TREE", __func__);
111716 + gcc_unreachable();
111717 + }
111718 +
111719 + switch (gimple_code(oldstmt)) {
111720 + case GIMPLE_ASM:
111721 + lhs = rhs1;
111722 + break;
111723 + case GIMPLE_CALL:
111724 + case GIMPLE_ASSIGN:
111725 + lhs = gimple_get_lhs(oldstmt);
111726 + break;
111727 + default:
111728 + debug_gimple_stmt(oldstmt);
111729 + gcc_unreachable();
111730 + }
111731 +
111732 + gsi = gsi_for_stmt(oldstmt);
111733 + pointer_set_insert(visited->stmts, oldstmt);
111734 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
111735 + basic_block next_bb, cur_bb;
111736 + const_edge e;
111737 +
111738 + gcc_assert(before == false);
111739 + gcc_assert(stmt_can_throw_internal(oldstmt));
111740 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
111741 + gcc_assert(!gsi_end_p(gsi));
111742 +
111743 + cur_bb = gimple_bb(oldstmt);
111744 + next_bb = cur_bb->next_bb;
111745 + e = find_edge(cur_bb, next_bb);
111746 + gcc_assert(e != NULL);
111747 + gcc_assert(e->flags & EDGE_FALLTHRU);
111748 +
111749 + gsi = gsi_after_labels(next_bb);
111750 + gcc_assert(!gsi_end_p(gsi));
111751 +
111752 + before = true;
111753 + oldstmt = gsi_stmt(gsi);
111754 + }
111755 +
111756 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
111757 +
111758 + if (is_gimple_constant(rhs1))
111759 + return cast_a_tree(dst_type, rhs1);
111760 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
111761 +}
111762 +
111763 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
111764 +{
111765 + gimple stmt;
111766 + gimple_stmt_iterator gsi;
111767 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
111768 +
111769 + if (pointer_set_contains(visited->my_stmts, oldstmt))
111770 + return lhs;
111771 +
111772 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
111773 + rhs1 = gimple_assign_rhs1(oldstmt);
111774 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
111775 + }
111776 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
111777 + rhs2 = gimple_assign_rhs2(oldstmt);
111778 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
111779 + }
111780 +
111781 + stmt = gimple_copy(oldstmt);
111782 + gimple_set_location(stmt, gimple_location(oldstmt));
111783 + pointer_set_insert(visited->my_stmts, stmt);
111784 +
111785 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
111786 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
111787 +
111788 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
111789 +
111790 + new_var = create_new_var(size_overflow_type);
111791 + new_var = make_ssa_name(new_var, stmt);
111792 + gimple_assign_set_lhs(stmt, new_var);
111793 +
111794 + if (rhs1 != NULL_TREE)
111795 + gimple_assign_set_rhs1(stmt, rhs1);
111796 +
111797 + if (rhs2 != NULL_TREE)
111798 + gimple_assign_set_rhs2(stmt, rhs2);
111799 +#if BUILDING_GCC_VERSION >= 4006
111800 + if (rhs3 != NULL_TREE)
111801 + gimple_assign_set_rhs3(stmt, rhs3);
111802 +#endif
111803 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
111804 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
111805 +
111806 + gsi = gsi_for_stmt(oldstmt);
111807 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
111808 + update_stmt(stmt);
111809 + pointer_set_insert(visited->stmts, oldstmt);
111810 + return gimple_assign_lhs(stmt);
111811 +}
111812 +
111813 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
111814 +{
111815 + gimple assign;
111816 + gimple_stmt_iterator gsi;
111817 + basic_block first_bb;
111818 +
111819 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
111820 +
111821 + if (bb->index == 0) {
111822 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
111823 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
111824 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
111825 + bb = first_bb;
111826 + }
111827 +
111828 + gsi = gsi_after_labels(bb);
111829 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
111830 + pointer_set_insert(visited->my_stmts, assign);
111831 +
111832 + return gimple_assign_lhs(assign);
111833 +}
111834 +
111835 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
111836 +{
111837 + gimple_stmt_iterator gsi;
111838 + gimple assign, def_stmt = get_def_stmt(new_arg);
111839 +
111840 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
111841 + gsi = gsi_after_labels(gimple_bb(def_stmt));
111842 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
111843 + } else {
111844 + gsi = gsi_for_stmt(def_stmt);
111845 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
111846 + }
111847 +
111848 + pointer_set_insert(visited->my_stmts, assign);
111849 + return gimple_assign_lhs(assign);
111850 +}
111851 +
111852 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
111853 +{
111854 + basic_block bb;
111855 + gimple_stmt_iterator gsi;
111856 + const_gimple def_stmt;
111857 + gimple assign;
111858 +
111859 + def_stmt = get_def_stmt(arg);
111860 + bb = gimple_bb(def_stmt);
111861 + gcc_assert(bb->index != 0);
111862 + gsi = gsi_after_labels(bb);
111863 +
111864 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
111865 + pointer_set_insert(visited->my_stmts, assign);
111866 + return gimple_assign_lhs(assign);
111867 +}
111868 +
111869 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
111870 +{
111871 + tree size_overflow_type;
111872 + tree arg;
111873 + const_gimple def_stmt;
111874 +
111875 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
111876 + return new_arg;
111877 +
111878 + arg = gimple_phi_arg_def(oldstmt, i);
111879 + def_stmt = get_def_stmt(arg);
111880 + gcc_assert(def_stmt != NULL);
111881 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
111882 +
111883 + switch (gimple_code(def_stmt)) {
111884 + case GIMPLE_PHI:
111885 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
111886 + case GIMPLE_NOP: {
111887 + basic_block bb;
111888 +
111889 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
111890 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
111891 + }
111892 + case GIMPLE_ASM: {
111893 + gimple_stmt_iterator gsi;
111894 + gimple assign, stmt = get_def_stmt(arg);
111895 +
111896 + gsi = gsi_for_stmt(stmt);
111897 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
111898 + pointer_set_insert(visited->my_stmts, assign);
111899 + return gimple_assign_lhs(assign);
111900 + }
111901 + default:
111902 + gcc_assert(new_arg != NULL_TREE);
111903 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
111904 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
111905 + }
111906 +}
111907 +
111908 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
111909 +{
111910 + basic_block bb;
111911 + gimple phi;
111912 + gimple_seq seq;
111913 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
111914 +
111915 + bb = gsi_bb(gsi);
111916 +
111917 + if (result == NULL_TREE) {
111918 + tree old_result = gimple_phi_result(oldstmt);
111919 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
111920 +
111921 + result = create_new_var(size_overflow_type);
111922 + }
111923 +
111924 + phi = create_phi_node(result, bb);
111925 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
111926 + seq = phi_nodes(bb);
111927 + gsi = gsi_last(seq);
111928 + gsi_remove(&gsi, false);
111929 +
111930 + gsi = gsi_for_stmt(oldstmt);
111931 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
111932 + gimple_set_bb(phi, bb);
111933 + return phi;
111934 +}
111935 +
111936 +#if BUILDING_GCC_VERSION <= 4007
111937 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
111938 +#else
111939 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
111940 +#endif
111941 +{
111942 + gimple new_phi;
111943 + unsigned int i;
111944 + tree arg, result;
111945 + location_t loc = gimple_location(oldstmt);
111946 +
111947 +#if BUILDING_GCC_VERSION <= 4007
111948 + gcc_assert(!VEC_empty(tree, *args));
111949 +#else
111950 + gcc_assert(!args->is_empty());
111951 +#endif
111952 +
111953 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
111954 + result = gimple_phi_result(new_phi);
111955 + ssa_name_var = SSA_NAME_VAR(result);
111956 +
111957 +#if BUILDING_GCC_VERSION <= 4007
111958 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
111959 +#else
111960 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
111961 +#endif
111962 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
111963 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
111964 + }
111965 +
111966 +#if BUILDING_GCC_VERSION <= 4007
111967 + VEC_free(tree, heap, *args);
111968 +#else
111969 + vec_free(args);
111970 +#endif
111971 + update_stmt(new_phi);
111972 + pointer_set_insert(visited->my_stmts, new_phi);
111973 + return result;
111974 +}
111975 +
111976 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
111977 +{
111978 + tree ssa_name_var = NULL_TREE;
111979 +#if BUILDING_GCC_VERSION <= 4007
111980 + VEC(tree, heap) *args = NULL;
111981 +#else
111982 + vec<tree, va_heap, vl_embed> *args = NULL;
111983 +#endif
111984 + gimple oldstmt = get_def_stmt(orig_result);
111985 + unsigned int i, len = gimple_phi_num_args(oldstmt);
111986 +
111987 + pointer_set_insert(visited->stmts, oldstmt);
111988 + for (i = 0; i < len; i++) {
111989 + tree arg, new_arg;
111990 +
111991 + arg = gimple_phi_arg_def(oldstmt, i);
111992 + new_arg = expand(visited, caller_node, arg);
111993 +
111994 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
111995 + ssa_name_var = SSA_NAME_VAR(new_arg);
111996 +
111997 + if (is_gimple_constant(arg)) {
111998 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
111999 +
112000 + new_arg = cast_a_tree(size_overflow_type, arg);
112001 + }
112002 +
112003 +#if BUILDING_GCC_VERSION <= 4007
112004 + VEC_safe_push(tree, heap, args, new_arg);
112005 +#else
112006 + vec_safe_push(args, new_arg);
112007 +#endif
112008 + }
112009 +
112010 +#if BUILDING_GCC_VERSION <= 4007
112011 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
112012 +#else
112013 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
112014 +#endif
112015 +}
112016 +
112017 +static tree create_cast_assign(struct visited *visited, gimple stmt)
112018 +{
112019 + tree rhs1 = gimple_assign_rhs1(stmt);
112020 + tree lhs = gimple_assign_lhs(stmt);
112021 + const_tree rhs1_type = TREE_TYPE(rhs1);
112022 + const_tree lhs_type = TREE_TYPE(lhs);
112023 +
112024 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
112025 + return create_assign(visited, stmt, lhs, AFTER_STMT);
112026 +
112027 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
112028 +}
112029 +
112030 +static bool skip_lhs_cast_check(const_gimple stmt)
112031 +{
112032 + const_tree rhs = gimple_assign_rhs1(stmt);
112033 + const_gimple def_stmt = get_def_stmt(rhs);
112034 +
112035 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
112036 + if (gimple_code(def_stmt) == GIMPLE_ASM)
112037 + return true;
112038 +
112039 + if (is_const_plus_unsigned_signed_truncation(rhs))
112040 + return true;
112041 +
112042 + return false;
112043 +}
112044 +
112045 +static tree create_string_param(tree string)
112046 +{
112047 + tree i_type, a_type;
112048 + const int length = TREE_STRING_LENGTH(string);
112049 +
112050 + gcc_assert(length > 0);
112051 +
112052 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
112053 + a_type = build_array_type(char_type_node, i_type);
112054 +
112055 + TREE_TYPE(string) = a_type;
112056 + TREE_CONSTANT(string) = 1;
112057 + TREE_READONLY(string) = 1;
112058 +
112059 + return build1(ADDR_EXPR, ptr_type_node, string);
112060 +}
112061 +
112062 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
112063 +{
112064 + gimple cond_stmt;
112065 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
112066 +
112067 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
112068 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
112069 + update_stmt(cond_stmt);
112070 +}
112071 +
112072 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
112073 +{
112074 + gimple func_stmt;
112075 + const_gimple def_stmt;
112076 + const_tree loc_line;
112077 + tree loc_file, ssa_name, current_func;
112078 + expanded_location xloc;
112079 + char *ssa_name_buf;
112080 + int len;
112081 + struct cgraph_edge *edge;
112082 + struct cgraph_node *callee_node;
112083 + int frequency;
112084 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
112085 +
112086 + def_stmt = get_def_stmt(arg);
112087 + xloc = expand_location(gimple_location(def_stmt));
112088 +
112089 + if (!gimple_has_location(def_stmt)) {
112090 + xloc = expand_location(gimple_location(stmt));
112091 + if (!gimple_has_location(stmt))
112092 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
112093 + }
112094 +
112095 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
112096 +
112097 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
112098 + loc_file = create_string_param(loc_file);
112099 +
112100 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
112101 + current_func = create_string_param(current_func);
112102 +
112103 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
112104 + call_count++;
112105 + 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);
112106 + gcc_assert(len > 0);
112107 + ssa_name = build_string(len + 1, ssa_name_buf);
112108 + free(ssa_name_buf);
112109 + ssa_name = create_string_param(ssa_name);
112110 +
112111 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
112112 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
112113 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
112114 +
112115 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
112116 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
112117 +
112118 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
112119 + gcc_assert(edge != NULL);
112120 +}
112121 +
112122 +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)
112123 +{
112124 + basic_block cond_bb, join_bb, bb_true;
112125 + edge e;
112126 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
112127 +
112128 + cond_bb = gimple_bb(stmt);
112129 + if (before)
112130 + gsi_prev(&gsi);
112131 + if (gsi_end_p(gsi))
112132 + e = split_block_after_labels(cond_bb);
112133 + else
112134 + e = split_block(cond_bb, gsi_stmt(gsi));
112135 + cond_bb = e->src;
112136 + join_bb = e->dest;
112137 + e->flags = EDGE_FALSE_VALUE;
112138 + e->probability = REG_BR_PROB_BASE;
112139 +
112140 + bb_true = create_empty_bb(cond_bb);
112141 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
112142 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
112143 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
112144 +
112145 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
112146 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
112147 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
112148 +
112149 + if (current_loops != NULL) {
112150 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
112151 + add_bb_to_loop(bb_true, cond_bb->loop_father);
112152 + }
112153 +
112154 + insert_cond(cond_bb, arg, cond_code, type_value);
112155 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
112156 +
112157 +// print_the_code_insertions(stmt);
112158 +}
112159 +
112160 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
112161 +{
112162 + const_tree rhs_type = TREE_TYPE(rhs);
112163 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
112164 +
112165 + gcc_assert(rhs_type != NULL_TREE);
112166 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
112167 + return;
112168 +
112169 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
112170 +
112171 + if (is_const_plus_unsigned_signed_truncation(rhs))
112172 + return;
112173 +
112174 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
112175 + // typemax (-1) < typemin (0)
112176 + if (TREE_OVERFLOW(type_max))
112177 + return;
112178 +
112179 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
112180 +
112181 + cast_rhs_type = TREE_TYPE(cast_rhs);
112182 + type_max_type = TREE_TYPE(type_max);
112183 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
112184 +
112185 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
112186 +
112187 + // special case: get_size_overflow_type(), 32, u64->s
112188 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
112189 + return;
112190 +
112191 + type_min_type = TREE_TYPE(type_min);
112192 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
112193 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
112194 +}
112195 +
112196 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
112197 +{
112198 + bool cast_lhs, cast_rhs;
112199 + tree lhs = gimple_assign_lhs(stmt);
112200 + tree rhs = gimple_assign_rhs1(stmt);
112201 + const_tree lhs_type = TREE_TYPE(lhs);
112202 + const_tree rhs_type = TREE_TYPE(rhs);
112203 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
112204 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
112205 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
112206 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
112207 +
112208 + static bool check_lhs[3][4] = {
112209 + // ss su us uu
112210 + { false, true, true, false }, // lhs > rhs
112211 + { false, false, false, false }, // lhs = rhs
112212 + { true, true, true, true }, // lhs < rhs
112213 + };
112214 +
112215 + static bool check_rhs[3][4] = {
112216 + // ss su us uu
112217 + { true, false, true, true }, // lhs > rhs
112218 + { true, false, true, true }, // lhs = rhs
112219 + { true, false, true, true }, // lhs < rhs
112220 + };
112221 +
112222 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
112223 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
112224 + return create_assign(visited, stmt, lhs, AFTER_STMT);
112225 +
112226 + if (lhs_size > rhs_size) {
112227 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
112228 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
112229 + } else if (lhs_size == rhs_size) {
112230 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
112231 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
112232 + } else {
112233 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
112234 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
112235 + }
112236 +
112237 + if (!cast_lhs && !cast_rhs)
112238 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
112239 +
112240 + if (cast_lhs && !skip_lhs_cast_check(stmt))
112241 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
112242 +
112243 + if (cast_rhs)
112244 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
112245 +
112246 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
112247 +}
112248 +
112249 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
112250 +{
112251 + enum tree_code rhs_code;
112252 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
112253 +
112254 + if (pointer_set_contains(visited->my_stmts, stmt))
112255 + return lhs;
112256 +
112257 + rhs1 = gimple_assign_rhs1(stmt);
112258 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
112259 + return create_assign(visited, stmt, lhs, AFTER_STMT);
112260 +
112261 + new_rhs1 = expand(visited, caller_node, rhs1);
112262 +
112263 + if (new_rhs1 == NULL_TREE)
112264 + return create_cast_assign(visited, stmt);
112265 +
112266 + if (pointer_set_contains(visited->no_cast_check, stmt))
112267 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
112268 +
112269 + rhs_code = gimple_assign_rhs_code(stmt);
112270 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
112271 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
112272 +
112273 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
112274 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
112275 + return create_assign(visited, stmt, lhs, AFTER_STMT);
112276 + }
112277 +
112278 + if (!gimple_assign_cast_p(stmt))
112279 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
112280 +
112281 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
112282 +}
112283 +
112284 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
112285 +{
112286 + tree rhs1, lhs = gimple_assign_lhs(stmt);
112287 + gimple def_stmt = get_def_stmt(lhs);
112288 +
112289 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
112290 + rhs1 = gimple_assign_rhs1(def_stmt);
112291 +
112292 + if (is_gimple_constant(rhs1))
112293 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112294 +
112295 + switch (TREE_CODE(rhs1)) {
112296 + case SSA_NAME: {
112297 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
112298 +
112299 + if (gimple_assign_cast_p(stmt))
112300 + unsigned_signed_cast_intentional_overflow(visited, stmt);
112301 + return ret;
112302 + }
112303 + case ARRAY_REF:
112304 + case BIT_FIELD_REF:
112305 + case ADDR_EXPR:
112306 + case COMPONENT_REF:
112307 + case INDIRECT_REF:
112308 +#if BUILDING_GCC_VERSION >= 4006
112309 + case MEM_REF:
112310 +#endif
112311 + case TARGET_MEM_REF:
112312 + case VIEW_CONVERT_EXPR:
112313 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112314 + case PARM_DECL:
112315 + case VAR_DECL:
112316 + return create_assign(visited, stmt, lhs, AFTER_STMT);
112317 +
112318 + default:
112319 + debug_gimple_stmt(def_stmt);
112320 + debug_tree(rhs1);
112321 + gcc_unreachable();
112322 + }
112323 +}
112324 +
112325 +static void __unused print_the_code_insertions(const_gimple stmt)
112326 +{
112327 + location_t loc = gimple_location(stmt);
112328 +
112329 + inform(loc, "Integer size_overflow check applied here.");
112330 +}
112331 +
112332 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
112333 +{
112334 + enum intentional_overflow_type res;
112335 + tree rhs1, rhs2, new_lhs;
112336 + gimple def_stmt = get_def_stmt(lhs);
112337 + tree new_rhs1 = NULL_TREE;
112338 + tree new_rhs2 = NULL_TREE;
112339 +
112340 + rhs1 = gimple_assign_rhs1(def_stmt);
112341 + rhs2 = gimple_assign_rhs2(def_stmt);
112342 +
112343 + /* no DImode/TImode division in the 32/64 bit kernel */
112344 + switch (gimple_assign_rhs_code(def_stmt)) {
112345 + case RDIV_EXPR:
112346 + case TRUNC_DIV_EXPR:
112347 + case CEIL_DIV_EXPR:
112348 + case FLOOR_DIV_EXPR:
112349 + case ROUND_DIV_EXPR:
112350 + case TRUNC_MOD_EXPR:
112351 + case CEIL_MOD_EXPR:
112352 + case FLOOR_MOD_EXPR:
112353 + case ROUND_MOD_EXPR:
112354 + case EXACT_DIV_EXPR:
112355 + case POINTER_PLUS_EXPR:
112356 + case BIT_AND_EXPR:
112357 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112358 + default:
112359 + break;
112360 + }
112361 +
112362 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
112363 + if (new_lhs != NULL_TREE)
112364 + return new_lhs;
112365 +
112366 + if (TREE_CODE(rhs1) == SSA_NAME)
112367 + new_rhs1 = expand(visited, caller_node, rhs1);
112368 + if (TREE_CODE(rhs2) == SSA_NAME)
112369 + new_rhs2 = expand(visited, caller_node, rhs2);
112370 +
112371 + res = add_mul_intentional_overflow(def_stmt);
112372 + if (res != NO_INTENTIONAL_OVERFLOW) {
112373 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
112374 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
112375 + return new_lhs;
112376 + }
112377 +
112378 + if (skip_expr_on_double_type(def_stmt)) {
112379 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
112380 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
112381 + return new_lhs;
112382 + }
112383 +
112384 + if (is_a_neg_overflow(def_stmt, rhs2))
112385 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
112386 + if (is_a_neg_overflow(def_stmt, rhs1))
112387 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
112388 +
112389 +
112390 + if (is_a_constant_overflow(def_stmt, rhs2))
112391 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
112392 + if (is_a_constant_overflow(def_stmt, rhs1))
112393 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
112394 +
112395 + // the const is between 0 and (signed) MAX
112396 + if (is_gimple_constant(rhs1))
112397 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
112398 + if (is_gimple_constant(rhs2))
112399 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
112400 +
112401 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
112402 +}
112403 +
112404 +#if BUILDING_GCC_VERSION >= 4006
112405 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
112406 +{
112407 + if (is_gimple_constant(rhs))
112408 + return cast_a_tree(size_overflow_type, rhs);
112409 + if (TREE_CODE(rhs) != SSA_NAME)
112410 + return NULL_TREE;
112411 + return expand(visited, caller_node, rhs);
112412 +}
112413 +
112414 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
112415 +{
112416 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
112417 + gimple def_stmt = get_def_stmt(lhs);
112418 +
112419 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
112420 +
112421 + rhs1 = gimple_assign_rhs1(def_stmt);
112422 + rhs2 = gimple_assign_rhs2(def_stmt);
112423 + rhs3 = gimple_assign_rhs3(def_stmt);
112424 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
112425 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
112426 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
112427 +
112428 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
112429 +}
112430 +#endif
112431 +
112432 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
112433 +{
112434 + gimple_stmt_iterator gsi;
112435 + gimple next_stmt = NULL;
112436 +
112437 + gsi = gsi_for_stmt(stmt);
112438 +
112439 + do {
112440 + gsi_next(&gsi);
112441 + next_stmt = gsi_stmt(gsi);
112442 +
112443 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
112444 + return NULL_TREE;
112445 +
112446 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
112447 + break;
112448 +
112449 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
112450 + } while (!gsi_end_p(gsi));
112451 +
112452 + gcc_assert(next_stmt);
112453 + return get_lhs(next_stmt);
112454 +}
112455 +
112456 +static tree expand_visited(struct visited *visited, gimple def_stmt)
112457 +{
112458 + gimple_stmt_iterator gsi;
112459 + enum gimple_code code = gimple_code(def_stmt);
112460 +
112461 + if (code == GIMPLE_ASM)
112462 + return NULL_TREE;
112463 +
112464 + gsi = gsi_for_stmt(def_stmt);
112465 + gsi_next(&gsi);
112466 +
112467 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
112468 + return NULL_TREE;
112469 + return get_my_stmt_lhs(visited, def_stmt);
112470 +}
112471 +
112472 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
112473 +{
112474 + gimple def_stmt;
112475 +
112476 + def_stmt = get_def_stmt(lhs);
112477 +
112478 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
112479 + return NULL_TREE;
112480 +
112481 + if (pointer_set_contains(visited->my_stmts, def_stmt))
112482 + return lhs;
112483 +
112484 + if (pointer_set_contains(visited->stmts, def_stmt))
112485 + return expand_visited(visited, def_stmt);
112486 +
112487 + switch (gimple_code(def_stmt)) {
112488 + case GIMPLE_PHI:
112489 + return handle_phi(visited, caller_node, lhs);
112490 + case GIMPLE_CALL:
112491 + case GIMPLE_ASM:
112492 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112493 + case GIMPLE_ASSIGN:
112494 + switch (gimple_num_ops(def_stmt)) {
112495 + case 2:
112496 + return handle_unary_ops(visited, caller_node, def_stmt);
112497 + case 3:
112498 + return handle_binary_ops(visited, caller_node, lhs);
112499 +#if BUILDING_GCC_VERSION >= 4006
112500 + case 4:
112501 + return handle_ternary_ops(visited, caller_node, lhs);
112502 +#endif
112503 + }
112504 + default:
112505 + debug_gimple_stmt(def_stmt);
112506 + error("%s: unknown gimple code", __func__);
112507 + gcc_unreachable();
112508 + }
112509 +}
112510 +
112511 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
112512 new file mode 100644
112513 index 0000000..715a590
112514 --- /dev/null
112515 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
112516 @@ -0,0 +1,1141 @@
112517 +/*
112518 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
112519 + * Licensed under the GPL v2, or (at your option) v3
112520 + *
112521 + * Homepage:
112522 + * http://www.grsecurity.net/~ephox/overflow_plugin/
112523 + *
112524 + * Documentation:
112525 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
112526 + *
112527 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
112528 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
112529 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
112530 + *
112531 + * Usage:
112532 + * $ make
112533 + * $ make run
112534 + */
112535 +
112536 +#include "gcc-common.h"
112537 +#include "size_overflow.h"
112538 +
112539 +#define VEC_LEN 128
112540 +#define RET_CHECK NULL_TREE
112541 +#define WRONG_NODE 32
112542 +#define NOT_INTENTIONAL_ASM NULL
112543 +
112544 +unsigned int call_count;
112545 +
112546 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
112547 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
112548 +
112549 +struct visited_fns {
112550 + struct visited_fns *next;
112551 + const_tree fndecl;
112552 + unsigned int num;
112553 + const_gimple first_stmt;
112554 +};
112555 +
112556 +struct next_cgraph_node {
112557 + struct next_cgraph_node *next;
112558 + struct cgraph_node *current_function;
112559 + tree callee_fndecl;
112560 + unsigned int num;
112561 +};
112562 +
112563 +// Don't want to duplicate entries in next_cgraph_node
112564 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
112565 +{
112566 + const_tree new_callee_fndecl;
112567 + struct next_cgraph_node *cur_node;
112568 +
112569 + if (fndecl == RET_CHECK)
112570 + new_callee_fndecl = NODE_DECL(node);
112571 + else
112572 + new_callee_fndecl = fndecl;
112573 +
112574 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
112575 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
112576 + continue;
112577 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
112578 + continue;
112579 + if (num == cur_node->num)
112580 + return true;
112581 + }
112582 + return false;
112583 +}
112584 +
112585 +/* Add a next_cgraph_node into the list for handle_function().
112586 + * handle_function() iterates over all the next cgraph nodes and
112587 + * starts the overflow check insertion process.
112588 + */
112589 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
112590 +{
112591 + struct next_cgraph_node *new_node;
112592 +
112593 + if (is_in_next_cgraph_node(head, node, fndecl, num))
112594 + return head;
112595 +
112596 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
112597 + new_node->current_function = node;
112598 + new_node->next = NULL;
112599 + new_node->num = num;
112600 + if (fndecl == RET_CHECK)
112601 + new_node->callee_fndecl = NODE_DECL(node);
112602 + else
112603 + new_node->callee_fndecl = fndecl;
112604 +
112605 + if (!head)
112606 + return new_node;
112607 +
112608 + new_node->next = head;
112609 + return new_node;
112610 +}
112611 +
112612 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
112613 +{
112614 + struct cgraph_edge *e;
112615 +
112616 + if (num == 0)
112617 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
112618 +
112619 + for (e = node->callers; e; e = e->next_caller) {
112620 + tree fndecl = gimple_call_fndecl(e->call_stmt);
112621 +
112622 + gcc_assert(fndecl != NULL_TREE);
112623 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
112624 + }
112625 +
112626 + return head;
112627 +}
112628 +
112629 +struct missing_functions {
112630 + struct missing_functions *next;
112631 + const_tree node;
112632 + tree fndecl;
112633 +};
112634 +
112635 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
112636 +{
112637 + struct missing_functions *new_function;
112638 +
112639 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
112640 + new_function->node = node;
112641 + new_function->next = NULL;
112642 +
112643 + if (TREE_CODE(node) == FUNCTION_DECL)
112644 + new_function->fndecl = node;
112645 + else
112646 + new_function->fndecl = current_function_decl;
112647 + gcc_assert(new_function->fndecl);
112648 +
112649 + if (!missing_fn_head)
112650 + return new_function;
112651 +
112652 + new_function->next = missing_fn_head;
112653 + return new_function;
112654 +}
112655 +
112656 +/* If the function is missing from the hash table and it is a static function
112657 + * then create a next_cgraph_node from it for handle_function()
112658 + */
112659 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
112660 +{
112661 + unsigned int num;
112662 + const_tree orig_fndecl;
112663 + struct cgraph_node *next_node = NULL;
112664 +
112665 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
112666 +
112667 + num = get_function_num(missing_fn_head->node, orig_fndecl);
112668 + if (num == CANNOT_FIND_ARG)
112669 + return cnodes;
112670 +
112671 + if (!is_missing_function(orig_fndecl, num))
112672 + return cnodes;
112673 +
112674 + next_node = cgraph_get_node(missing_fn_head->fndecl);
112675 + if (next_node && next_node->local.local)
112676 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
112677 + return cnodes;
112678 +}
112679 +
112680 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
112681 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
112682 + */
112683 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
112684 +{
112685 + unsigned int i;
112686 + tree node;
112687 + struct missing_functions *cur, *missing_fn_head = NULL;
112688 +
112689 +#if BUILDING_GCC_VERSION <= 4007
112690 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
112691 +#else
112692 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
112693 +#endif
112694 + switch (TREE_CODE(node)) {
112695 + case PARM_DECL:
112696 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
112697 + break;
112698 + case FUNCTION_DECL:
112699 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
112700 + break;
112701 + default:
112702 + break;
112703 + }
112704 + }
112705 +
112706 + while (missing_fn_head) {
112707 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
112708 +
112709 + cur = missing_fn_head->next;
112710 + free(missing_fn_head);
112711 + missing_fn_head = cur;
112712 + }
112713 +
112714 + return cnodes;
112715 +}
112716 +
112717 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
112718 +{
112719 + gimple phi = get_def_stmt(result);
112720 + unsigned int i, n = gimple_phi_num_args(phi);
112721 +
112722 + pointer_set_insert(visited, phi);
112723 + for (i = 0; i < n; i++) {
112724 + const_tree arg = gimple_phi_arg_def(phi, i);
112725 +
112726 + set_conditions(visited, interesting_conditions, arg);
112727 + }
112728 +}
112729 +
112730 +enum conditions {
112731 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
112732 +};
112733 +
112734 +// Search for constants, cast assignments and binary/ternary assignments
112735 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
112736 +{
112737 + gimple def_stmt = get_def_stmt(lhs);
112738 +
112739 + if (is_gimple_constant(lhs)) {
112740 + interesting_conditions[FROM_CONST] = true;
112741 + return;
112742 + }
112743 +
112744 + if (!def_stmt)
112745 + return;
112746 +
112747 + if (pointer_set_contains(visited, def_stmt))
112748 + return;
112749 +
112750 + switch (gimple_code(def_stmt)) {
112751 + case GIMPLE_CALL:
112752 + if (lhs == gimple_return_retval(def_stmt))
112753 + interesting_conditions[RET] = true;
112754 + return;
112755 + case GIMPLE_NOP:
112756 + case GIMPLE_ASM:
112757 + return;
112758 + case GIMPLE_PHI:
112759 + interesting_conditions[PHI] = true;
112760 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
112761 + case GIMPLE_ASSIGN:
112762 + if (gimple_num_ops(def_stmt) == 2) {
112763 + const_tree rhs = gimple_assign_rhs1(def_stmt);
112764 +
112765 + if (gimple_assign_cast_p(def_stmt))
112766 + interesting_conditions[CAST] = true;
112767 +
112768 + return set_conditions(visited, interesting_conditions, rhs);
112769 + } else {
112770 + interesting_conditions[NOT_UNARY] = true;
112771 + return;
112772 + }
112773 + default:
112774 + debug_gimple_stmt(def_stmt);
112775 + gcc_unreachable();
112776 + }
112777 +}
112778 +
112779 +// determine whether duplication will be necessary or not.
112780 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
112781 +{
112782 + struct pointer_set_t *visited;
112783 +
112784 + if (gimple_assign_cast_p(cur_node->first_stmt))
112785 + interesting_conditions[CAST] = true;
112786 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
112787 + interesting_conditions[NOT_UNARY] = true;
112788 +
112789 + visited = pointer_set_create();
112790 + set_conditions(visited, interesting_conditions, cur_node->node);
112791 + pointer_set_destroy(visited);
112792 +}
112793 +
112794 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
112795 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
112796 +{
112797 + gimple assign;
112798 + gimple_stmt_iterator gsi;
112799 +
112800 + // already removed
112801 + if (gimple_bb(asm_stmt) == NULL)
112802 + return;
112803 + gsi = gsi_for_stmt(asm_stmt);
112804 +
112805 + assign = gimple_build_assign(lhs, rhs);
112806 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
112807 + SSA_NAME_DEF_STMT(lhs) = assign;
112808 +
112809 + gsi_remove(&gsi, true);
112810 +}
112811 +
112812 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
112813 + * stmt is a return otherwise it is the callee function.
112814 + */
112815 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
112816 +{
112817 + const_tree fndecl;
112818 +
112819 + if (argnum == 0)
112820 + fndecl = current_function_decl;
112821 + else
112822 + fndecl = gimple_call_fndecl(stmt);
112823 +
112824 + if (fndecl == NULL_TREE)
112825 + return NULL_TREE;
112826 +
112827 + return DECL_ORIGIN(fndecl);
112828 +}
112829 +
112830 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
112831 +static bool skip_asm(const_tree arg)
112832 +{
112833 + gimple def_stmt = get_def_stmt(arg);
112834 +
112835 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
112836 + return false;
112837 +
112838 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
112839 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
112840 +}
112841 +
112842 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
112843 +{
112844 + gimple phi = get_def_stmt(result);
112845 + unsigned int i, n = gimple_phi_num_args(phi);
112846 +
112847 + pointer_set_insert(visited, phi);
112848 + for (i = 0; i < n; i++) {
112849 + tree arg = gimple_phi_arg_def(phi, i);
112850 +
112851 + walk_use_def(visited, cur_node, arg);
112852 + }
112853 +}
112854 +
112855 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
112856 +{
112857 + gimple def_stmt = get_def_stmt(lhs);
112858 + tree rhs1, rhs2;
112859 +
112860 + rhs1 = gimple_assign_rhs1(def_stmt);
112861 + rhs2 = gimple_assign_rhs2(def_stmt);
112862 +
112863 + walk_use_def(visited, cur_node, rhs1);
112864 + walk_use_def(visited, cur_node, rhs2);
112865 +}
112866 +
112867 +static void insert_last_node(struct interesting_node *cur_node, tree node)
112868 +{
112869 + unsigned int i;
112870 + tree element;
112871 + enum tree_code code;
112872 +
112873 + gcc_assert(node != NULL_TREE);
112874 +
112875 + if (is_gimple_constant(node))
112876 + return;
112877 +
112878 + code = TREE_CODE(node);
112879 + if (code == VAR_DECL) {
112880 + node = DECL_ORIGIN(node);
112881 + code = TREE_CODE(node);
112882 + }
112883 +
112884 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
112885 + return;
112886 +
112887 +#if BUILDING_GCC_VERSION <= 4007
112888 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
112889 +#else
112890 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
112891 +#endif
112892 + if (operand_equal_p(node, element, 0))
112893 + return;
112894 + }
112895 +
112896 +#if BUILDING_GCC_VERSION <= 4007
112897 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
112898 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
112899 +#else
112900 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
112901 + vec_safe_push(cur_node->last_nodes, node);
112902 +#endif
112903 +}
112904 +
112905 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
112906 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
112907 +{
112908 + if (!is_size_overflow_asm(stmt))
112909 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
112910 +}
112911 +
112912 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
112913 + * and component refs (for checking the intentional_overflow attribute).
112914 + */
112915 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
112916 +{
112917 + const_gimple def_stmt;
112918 +
112919 + if (TREE_CODE(lhs) != SSA_NAME) {
112920 + insert_last_node(cur_node, lhs);
112921 + return;
112922 + }
112923 +
112924 + def_stmt = get_def_stmt(lhs);
112925 + if (!def_stmt)
112926 + return;
112927 +
112928 + if (pointer_set_insert(visited, def_stmt))
112929 + return;
112930 +
112931 + switch (gimple_code(def_stmt)) {
112932 + case GIMPLE_NOP:
112933 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
112934 + case GIMPLE_ASM:
112935 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
112936 + case GIMPLE_CALL: {
112937 + tree fndecl = gimple_call_fndecl(def_stmt);
112938 +
112939 + if (fndecl == NULL_TREE)
112940 + return;
112941 + insert_last_node(cur_node, fndecl);
112942 + return;
112943 + }
112944 + case GIMPLE_PHI:
112945 + return walk_use_def_phi(visited, cur_node, lhs);
112946 + case GIMPLE_ASSIGN:
112947 + switch (gimple_num_ops(def_stmt)) {
112948 + case 2:
112949 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
112950 + case 3:
112951 + return walk_use_def_binary(visited, cur_node, lhs);
112952 + }
112953 + default:
112954 + debug_gimple_stmt((gimple)def_stmt);
112955 + error("%s: unknown gimple code", __func__);
112956 + gcc_unreachable();
112957 + }
112958 +}
112959 +
112960 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
112961 +static void set_last_nodes(struct interesting_node *cur_node)
112962 +{
112963 + struct pointer_set_t *visited;
112964 +
112965 + visited = pointer_set_create();
112966 + walk_use_def(visited, cur_node, cur_node->node);
112967 + pointer_set_destroy(visited);
112968 +}
112969 +
112970 +enum precond {
112971 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
112972 +};
112973 +
112974 +/* 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.
112975 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
112976 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
112977 + * It skips the possible error codes too.
112978 + */
112979 +static enum precond check_preconditions(struct interesting_node *cur_node)
112980 +{
112981 + bool interesting_conditions[5] = {false, false, false, false, false};
112982 +
112983 + set_last_nodes(cur_node);
112984 +
112985 + check_intentional_attribute_ipa(cur_node);
112986 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
112987 + return NO_ATTRIBUTE_SEARCH;
112988 +
112989 + search_interesting_conditions(cur_node, interesting_conditions);
112990 +
112991 + // error code: a phi, unary assign (not cast) and returns only
112992 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
112993 + return NO_ATTRIBUTE_SEARCH;
112994 +
112995 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
112996 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
112997 + return NO_ATTRIBUTE_SEARCH;
112998 +
112999 + // unnecessary overflow check
113000 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
113001 + return NO_CHECK_INSERT;
113002 +
113003 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
113004 + return NO_CHECK_INSERT;
113005 +
113006 + return NONE;
113007 +}
113008 +
113009 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
113010 +{
113011 + const_gimple assign;
113012 + tree orig_type = TREE_TYPE(orig_node);
113013 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113014 +
113015 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113016 + return gimple_assign_lhs(assign);
113017 +}
113018 +
113019 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
113020 +{
113021 + void (*set_rhs)(gimple, tree);
113022 + gimple stmt = cur_node->first_stmt;
113023 + const_tree orig_node = cur_node->node;
113024 +
113025 + switch (gimple_code(stmt)) {
113026 + case GIMPLE_RETURN:
113027 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
113028 + break;
113029 + case GIMPLE_CALL:
113030 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
113031 + break;
113032 + case GIMPLE_ASSIGN:
113033 + switch (cur_node->num) {
113034 + case 1:
113035 + set_rhs = &gimple_assign_set_rhs1;
113036 + break;
113037 + case 2:
113038 + set_rhs = &gimple_assign_set_rhs2;
113039 + break;
113040 +#if BUILDING_GCC_VERSION >= 4006
113041 + case 3:
113042 + set_rhs = &gimple_assign_set_rhs3;
113043 + break;
113044 +#endif
113045 + default:
113046 + gcc_unreachable();
113047 + }
113048 +
113049 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
113050 + break;
113051 + default:
113052 + debug_gimple_stmt(stmt);
113053 + gcc_unreachable();
113054 + }
113055 +
113056 + update_stmt(stmt);
113057 +}
113058 +
113059 +static struct visited *create_visited(void)
113060 +{
113061 + struct visited *new_node;
113062 +
113063 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
113064 + new_node->stmts = pointer_set_create();
113065 + new_node->my_stmts = pointer_set_create();
113066 + new_node->skip_expr_casts = pointer_set_create();
113067 + new_node->no_cast_check = pointer_set_create();
113068 + return new_node;
113069 +}
113070 +
113071 +static void free_visited(struct visited *visited)
113072 +{
113073 + pointer_set_destroy(visited->stmts);
113074 + pointer_set_destroy(visited->my_stmts);
113075 + pointer_set_destroy(visited->skip_expr_casts);
113076 + pointer_set_destroy(visited->no_cast_check);
113077 +
113078 + free(visited);
113079 +}
113080 +
113081 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
113082 + * 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
113083 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
113084 + */
113085 +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)
113086 +{
113087 + enum precond ret;
113088 + tree new_node, orig_node = cur_node->node;
113089 +
113090 + ret = check_preconditions(cur_node);
113091 + if (ret == NO_ATTRIBUTE_SEARCH)
113092 + return cnodes;
113093 +
113094 + cnodes = search_overflow_attribute(cnodes, cur_node);
113095 +
113096 + if (ret == NO_CHECK_INSERT)
113097 + return cnodes;
113098 +
113099 + new_node = expand(visited, caller_node, orig_node);
113100 + if (new_node == NULL_TREE)
113101 + return cnodes;
113102 +
113103 + change_orig_node(visited, cur_node, new_node);
113104 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
113105 +
113106 + return cnodes;
113107 +}
113108 +
113109 +// Check visited_fns interesting nodes.
113110 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
113111 +{
113112 + struct interesting_node *cur;
113113 +
113114 + for (cur = head; cur; cur = cur->next) {
113115 + if (!operand_equal_p(node, cur->node, 0))
113116 + continue;
113117 + if (num != cur->num)
113118 + continue;
113119 + if (first_stmt == cur->first_stmt)
113120 + return true;
113121 + }
113122 + return false;
113123 +}
113124 +
113125 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
113126 + 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
113127 + 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
113128 + the intentional_overflow attribute check. They are collected by set_last_nodes().
113129 + num: arg count of a call stmt or 0 when it is a ret
113130 + node: the recursion starts from here, it is a call arg or a return value
113131 + 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.
113132 + intentional_attr_decl: intentional_overflow attribute of the callee function
113133 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
113134 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
113135 + */
113136 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
113137 +{
113138 + struct interesting_node *new_node;
113139 + tree fndecl;
113140 + enum gimple_code code;
113141 +
113142 + gcc_assert(node != NULL_TREE);
113143 + code = gimple_code(first_stmt);
113144 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
113145 +
113146 + if (num == CANNOT_FIND_ARG)
113147 + return head;
113148 +
113149 + if (skip_types(node))
113150 + return head;
113151 +
113152 + if (skip_asm(node))
113153 + return head;
113154 +
113155 + if (is_gimple_call(first_stmt))
113156 + fndecl = gimple_call_fndecl(first_stmt);
113157 + else
113158 + fndecl = current_function_decl;
113159 +
113160 + if (fndecl == NULL_TREE)
113161 + return head;
113162 +
113163 + if (is_in_interesting_node(head, first_stmt, node, num))
113164 + return head;
113165 +
113166 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
113167 +
113168 + new_node->next = NULL;
113169 + new_node->first_stmt = first_stmt;
113170 +#if BUILDING_GCC_VERSION <= 4007
113171 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
113172 +#else
113173 + vec_alloc(new_node->last_nodes, VEC_LEN);
113174 +#endif
113175 + new_node->num = num;
113176 + new_node->node = node;
113177 + new_node->fndecl = fndecl;
113178 + new_node->intentional_attr_decl = MARK_NO;
113179 + new_node->intentional_attr_cur_fndecl = MARK_NO;
113180 + new_node->intentional_mark_from_gimple = asm_stmt;
113181 +
113182 + if (!head)
113183 + return new_node;
113184 +
113185 + new_node->next = head;
113186 + return new_node;
113187 +}
113188 +
113189 +/* 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).
113190 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
113191 + */
113192 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
113193 +{
113194 + struct next_cgraph_node *cur_node;
113195 + tree ret = gimple_return_retval(stmt);
113196 +
113197 + if (ret == NULL_TREE)
113198 + return head;
113199 +
113200 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
113201 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
113202 + continue;
113203 + if (cur_node->num == 0)
113204 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
113205 + }
113206 +
113207 + return head;
113208 +}
113209 +
113210 +/* 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).
113211 + * If the call stmt is in the next cgraph node list then it's an interesting call.
113212 + */
113213 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
113214 +{
113215 + unsigned int argnum;
113216 + tree arg;
113217 + const_tree fndecl;
113218 + struct next_cgraph_node *cur_node;
113219 +
113220 + fndecl = gimple_call_fndecl(stmt);
113221 + if (fndecl == NULL_TREE)
113222 + return head;
113223 +
113224 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
113225 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
113226 + continue;
113227 + argnum = get_correct_arg_count(cur_node->num, fndecl);
113228 + gcc_assert(argnum != CANNOT_FIND_ARG);
113229 + if (argnum == 0)
113230 + continue;
113231 +
113232 + arg = gimple_call_arg(stmt, argnum - 1);
113233 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
113234 + }
113235 +
113236 + return head;
113237 +}
113238 +
113239 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
113240 +{
113241 + if (!operand_equal_p(orig_node, node, 0))
113242 + return WRONG_NODE;
113243 + if (skip_types(node))
113244 + return WRONG_NODE;
113245 + return ret_count;
113246 +}
113247 +
113248 +// Get the index of the rhs node in an assignment
113249 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
113250 +{
113251 + const_tree rhs1, rhs2;
113252 + unsigned int ret;
113253 +
113254 + gcc_assert(stmt);
113255 + gcc_assert(is_gimple_assign(stmt));
113256 +
113257 + rhs1 = gimple_assign_rhs1(stmt);
113258 + gcc_assert(rhs1 != NULL_TREE);
113259 +
113260 + switch (gimple_num_ops(stmt)) {
113261 + case 2:
113262 + return check_ops(node, rhs1, 1);
113263 + case 3:
113264 + ret = check_ops(node, rhs1, 1);
113265 + if (ret != WRONG_NODE)
113266 + return ret;
113267 +
113268 + rhs2 = gimple_assign_rhs2(stmt);
113269 + gcc_assert(rhs2 != NULL_TREE);
113270 + return check_ops(node, rhs2, 2);
113271 + default:
113272 + gcc_unreachable();
113273 + }
113274 +}
113275 +
113276 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
113277 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
113278 +{
113279 + unsigned int i;
113280 +
113281 + if (gimple_call_fndecl(stmt) == NULL_TREE)
113282 + return CANNOT_FIND_ARG;
113283 +
113284 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
113285 + tree node;
113286 +
113287 + node = gimple_call_arg(stmt, i);
113288 + if (!operand_equal_p(arg, node, 0))
113289 + continue;
113290 + if (!skip_types(node))
113291 + return i + 1;
113292 + }
113293 +
113294 + return CANNOT_FIND_ARG;
113295 +}
113296 +
113297 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
113298 + * any of return, call or assignment stmts (because of inlining).
113299 + */
113300 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
113301 +{
113302 + use_operand_p use_p;
113303 + imm_use_iterator imm_iter;
113304 + unsigned int argnum;
113305 +
113306 + gcc_assert(TREE_CODE(node) == SSA_NAME);
113307 +
113308 + if (pointer_set_insert(visited, node))
113309 + return head;
113310 +
113311 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
113312 + gimple stmt = USE_STMT(use_p);
113313 +
113314 + if (stmt == NULL)
113315 + return head;
113316 + if (is_gimple_debug(stmt))
113317 + continue;
113318 +
113319 + switch (gimple_code(stmt)) {
113320 + case GIMPLE_CALL:
113321 + argnum = find_arg_number_gimple(node, stmt);
113322 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
113323 + break;
113324 + case GIMPLE_RETURN:
113325 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
113326 + break;
113327 + case GIMPLE_ASSIGN:
113328 + argnum = get_assign_ops_count(stmt, node);
113329 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
113330 + break;
113331 + case GIMPLE_PHI: {
113332 + tree result = gimple_phi_result(stmt);
113333 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
113334 + break;
113335 + }
113336 + case GIMPLE_ASM:
113337 + if (gimple_asm_noutputs(stmt) != 0)
113338 + break;
113339 + if (!is_size_overflow_asm(stmt))
113340 + break;
113341 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
113342 + break;
113343 + case GIMPLE_COND:
113344 + case GIMPLE_SWITCH:
113345 + break;
113346 + default:
113347 + debug_gimple_stmt(stmt);
113348 + gcc_unreachable();
113349 + break;
113350 + }
113351 + }
113352 + return head;
113353 +}
113354 +
113355 +static void remove_size_overflow_asm(gimple stmt)
113356 +{
113357 + gimple_stmt_iterator gsi;
113358 + tree input, output;
113359 +
113360 + if (!is_size_overflow_asm(stmt))
113361 + return;
113362 +
113363 + if (gimple_asm_noutputs(stmt) == 0) {
113364 + gsi = gsi_for_stmt(stmt);
113365 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
113366 + gsi_remove(&gsi, true);
113367 + return;
113368 + }
113369 +
113370 + input = gimple_asm_input_op(stmt, 0);
113371 + output = gimple_asm_output_op(stmt, 0);
113372 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
113373 +}
113374 +
113375 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
113376 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
113377 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
113378 + */
113379 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
113380 +{
113381 + const_tree output;
113382 + struct pointer_set_t *visited;
113383 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
113384 +
113385 + if (!is_size_overflow_asm(stmt))
113386 + return head;
113387 +
113388 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
113389 + intentional_asm = stmt;
113390 +
113391 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
113392 +
113393 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
113394 + return head;
113395 +
113396 + if (gimple_asm_noutputs(stmt) == 0) {
113397 + const_tree input;
113398 +
113399 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
113400 + return head;
113401 +
113402 + input = gimple_asm_input_op(stmt, 0);
113403 + remove_size_overflow_asm(stmt);
113404 + if (is_gimple_constant(TREE_VALUE(input)))
113405 + return head;
113406 + visited = pointer_set_create();
113407 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
113408 + pointer_set_destroy(visited);
113409 + return head;
113410 + }
113411 +
113412 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
113413 + remove_size_overflow_asm(stmt);
113414 +
113415 + visited = pointer_set_create();
113416 + output = gimple_asm_output_op(stmt, 0);
113417 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
113418 + pointer_set_destroy(visited);
113419 + return head;
113420 +}
113421 +
113422 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
113423 + * or a call stmt or a return stmt and store them in the interesting_node list
113424 + */
113425 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
113426 +{
113427 + basic_block bb;
113428 + struct interesting_node *head = NULL;
113429 +
113430 + FOR_ALL_BB_FN(bb, cfun) {
113431 + gimple_stmt_iterator gsi;
113432 +
113433 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
113434 + enum gimple_code code;
113435 + gimple stmt = gsi_stmt(gsi);
113436 +
113437 + code = gimple_code(stmt);
113438 +
113439 + if (code == GIMPLE_ASM)
113440 + head = handle_stmt_by_size_overflow_asm(stmt, head);
113441 +
113442 + if (!next_node)
113443 + continue;
113444 + if (code == GIMPLE_CALL)
113445 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
113446 + if (code == GIMPLE_RETURN)
113447 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
113448 + }
113449 + }
113450 + return head;
113451 +}
113452 +
113453 +static void free_interesting_node(struct interesting_node *head)
113454 +{
113455 + struct interesting_node *cur;
113456 +
113457 + while (head) {
113458 + cur = head->next;
113459 +#if BUILDING_GCC_VERSION <= 4007
113460 + VEC_free(tree, gc, head->last_nodes);
113461 +#else
113462 + vec_free(head->last_nodes);
113463 +#endif
113464 + free(head);
113465 + head = cur;
113466 + }
113467 +}
113468 +
113469 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
113470 +{
113471 + struct visited_fns *new_visited_fns;
113472 +
113473 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
113474 + new_visited_fns->fndecl = cur_node->fndecl;
113475 + new_visited_fns->num = cur_node->num;
113476 + new_visited_fns->first_stmt = cur_node->first_stmt;
113477 + new_visited_fns->next = NULL;
113478 +
113479 + if (!head)
113480 + return new_visited_fns;
113481 +
113482 + new_visited_fns->next = head;
113483 + return new_visited_fns;
113484 +}
113485 +
113486 +/* 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
113487 + * it is a visited_fns function.
113488 + */
113489 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
113490 +{
113491 + struct visited_fns *cur;
113492 +
113493 + if (!head)
113494 + return false;
113495 +
113496 + for (cur = head; cur; cur = cur->next) {
113497 + if (cur_node->first_stmt != cur->first_stmt)
113498 + continue;
113499 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
113500 + continue;
113501 + if (cur_node->num == cur->num)
113502 + return true;
113503 + }
113504 + return false;
113505 +}
113506 +
113507 +static void free_next_cgraph_node(struct next_cgraph_node *head)
113508 +{
113509 + struct next_cgraph_node *cur;
113510 +
113511 + while (head) {
113512 + cur = head->next;
113513 + free(head);
113514 + head = cur;
113515 + }
113516 +}
113517 +
113518 +static void remove_all_size_overflow_asm(void)
113519 +{
113520 + basic_block bb;
113521 +
113522 + FOR_ALL_BB_FN(bb, cfun) {
113523 + gimple_stmt_iterator si;
113524 +
113525 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
113526 + remove_size_overflow_asm(gsi_stmt(si));
113527 + }
113528 +}
113529 +
113530 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
113531 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
113532 + * the newly collected interesting functions (they are interesting if there is control flow between
113533 + * the interesting stmts and them).
113534 + */
113535 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
113536 +{
113537 + struct visited *visited;
113538 + struct interesting_node *head, *cur_node;
113539 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
113540 +
113541 + set_current_function_decl(NODE_DECL(node));
113542 + call_count = 0;
113543 +
113544 + head = collect_interesting_stmts(next_node);
113545 +
113546 + visited = create_visited();
113547 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
113548 + if (is_visited_fns_function(visited_fns, cur_node))
113549 + continue;
113550 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
113551 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
113552 + }
113553 +
113554 + free_visited(visited);
113555 + free_interesting_node(head);
113556 + remove_all_size_overflow_asm();
113557 + unset_current_function_decl();
113558 +
113559 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
113560 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
113561 +
113562 + free_next_cgraph_node(cnodes_head);
113563 + return visited_fns;
113564 +}
113565 +
113566 +static void free_visited_fns(struct visited_fns *head)
113567 +{
113568 + struct visited_fns *cur;
113569 +
113570 + while (head) {
113571 + cur = head->next;
113572 + free(head);
113573 + head = cur;
113574 + }
113575 +}
113576 +
113577 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
113578 +unsigned int search_function(void)
113579 +{
113580 + struct cgraph_node *node;
113581 + struct visited_fns *visited_fns = NULL;
113582 +
113583 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
113584 + gcc_assert(cgraph_function_flags_ready);
113585 +#if BUILDING_GCC_VERSION <= 4007
113586 + gcc_assert(node->reachable);
113587 +#endif
113588 +
113589 + visited_fns = handle_function(node, NULL, visited_fns);
113590 + }
113591 +
113592 + free_visited_fns(visited_fns);
113593 + return 0;
113594 +}
113595 +
113596 +#if BUILDING_GCC_VERSION >= 4009
113597 +static const struct pass_data insert_size_overflow_check_data = {
113598 +#else
113599 +static struct ipa_opt_pass_d insert_size_overflow_check = {
113600 + .pass = {
113601 +#endif
113602 + .type = SIMPLE_IPA_PASS,
113603 + .name = "size_overflow",
113604 +#if BUILDING_GCC_VERSION >= 4008
113605 + .optinfo_flags = OPTGROUP_NONE,
113606 +#endif
113607 +#if BUILDING_GCC_VERSION >= 4009
113608 + .has_gate = false,
113609 + .has_execute = true,
113610 +#else
113611 + .gate = NULL,
113612 + .execute = search_function,
113613 + .sub = NULL,
113614 + .next = NULL,
113615 + .static_pass_number = 0,
113616 +#endif
113617 + .tv_id = TV_NONE,
113618 + .properties_required = 0,
113619 + .properties_provided = 0,
113620 + .properties_destroyed = 0,
113621 + .todo_flags_start = 0,
113622 + .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,
113623 +#if BUILDING_GCC_VERSION < 4009
113624 + },
113625 + .generate_summary = NULL,
113626 + .write_summary = NULL,
113627 + .read_summary = NULL,
113628 +#if BUILDING_GCC_VERSION >= 4006
113629 + .write_optimization_summary = NULL,
113630 + .read_optimization_summary = NULL,
113631 +#endif
113632 + .stmt_fixup = NULL,
113633 + .function_transform_todo_flags_start = 0,
113634 + .function_transform = NULL,
113635 + .variable_transform = NULL,
113636 +#endif
113637 +};
113638 +
113639 +#if BUILDING_GCC_VERSION >= 4009
113640 +namespace {
113641 +class insert_size_overflow_check : public ipa_opt_pass_d {
113642 +public:
113643 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
113644 + unsigned int execute() { return search_function(); }
113645 +};
113646 +}
113647 +#endif
113648 +
113649 +struct opt_pass *make_insert_size_overflow_check(void)
113650 +{
113651 +#if BUILDING_GCC_VERSION >= 4009
113652 + return new insert_size_overflow_check();
113653 +#else
113654 + return &insert_size_overflow_check.pass;
113655 +#endif
113656 +}
113657 +
113658 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
113659 new file mode 100644
113660 index 0000000..38904bc
113661 --- /dev/null
113662 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
113663 @@ -0,0 +1,733 @@
113664 +/*
113665 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113666 + * Licensed under the GPL v2, or (at your option) v3
113667 + *
113668 + * Homepage:
113669 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113670 + *
113671 + * Documentation:
113672 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
113673 + *
113674 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
113675 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
113676 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
113677 + *
113678 + * Usage:
113679 + * $ make
113680 + * $ make run
113681 + */
113682 +
113683 +#include "gcc-common.h"
113684 +#include "size_overflow.h"
113685 +
113686 +/* Get the param of the intentional_overflow attribute.
113687 + * * 0: MARK_NOT_INTENTIONAL
113688 + * * 1..MAX_PARAM: MARK_YES
113689 + * * -1: MARK_TURN_OFF
113690 + */
113691 +static tree get_attribute_param(const_tree decl)
113692 +{
113693 + const_tree attr;
113694 +
113695 + if (decl == NULL_TREE)
113696 + return NULL_TREE;
113697 +
113698 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
113699 + if (!attr || !TREE_VALUE(attr))
113700 + return NULL_TREE;
113701 +
113702 + return TREE_VALUE(attr);
113703 +}
113704 +
113705 +// MARK_TURN_OFF
113706 +bool is_turn_off_intentional_attr(const_tree decl)
113707 +{
113708 + const_tree param_head;
113709 +
113710 + param_head = get_attribute_param(decl);
113711 + if (param_head == NULL_TREE)
113712 + return false;
113713 +
113714 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
113715 + return true;
113716 + return false;
113717 +}
113718 +
113719 +// MARK_NOT_INTENTIONAL
113720 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
113721 +{
113722 + const_tree param_head;
113723 +
113724 + if (argnum == 0)
113725 + return false;
113726 +
113727 + param_head = get_attribute_param(decl);
113728 + if (param_head == NULL_TREE)
113729 + return false;
113730 +
113731 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
113732 + return true;
113733 + return false;
113734 +}
113735 +
113736 +// MARK_YES
113737 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
113738 +{
113739 + tree param, param_head;
113740 +
113741 + if (argnum == 0)
113742 + return false;
113743 +
113744 + param_head = get_attribute_param(decl);
113745 + for (param = param_head; param; param = TREE_CHAIN(param))
113746 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
113747 + return true;
113748 + return false;
113749 +}
113750 +
113751 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
113752 +{
113753 + location_t loc;
113754 +
113755 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
113756 + return;
113757 +
113758 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
113759 + return;
113760 +
113761 + loc = DECL_SOURCE_LOCATION(decl);
113762 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
113763 +}
113764 +
113765 +// Get the field decl of a component ref for intentional_overflow checking
113766 +static const_tree search_field_decl(const_tree comp_ref)
113767 +{
113768 + const_tree field = NULL_TREE;
113769 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
113770 +
113771 + for (i = 0; i < len; i++) {
113772 + field = TREE_OPERAND(comp_ref, i);
113773 + if (TREE_CODE(field) == FIELD_DECL)
113774 + break;
113775 + }
113776 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
113777 + return field;
113778 +}
113779 +
113780 +/* Get the type of the intentional_overflow attribute of a node
113781 + * * MARK_TURN_OFF
113782 + * * MARK_YES
113783 + * * MARK_NO
113784 + * * MARK_NOT_INTENTIONAL
113785 + */
113786 +enum mark get_intentional_attr_type(const_tree node)
113787 +{
113788 + const_tree cur_decl;
113789 +
113790 + if (node == NULL_TREE)
113791 + return MARK_NO;
113792 +
113793 + switch (TREE_CODE(node)) {
113794 + case COMPONENT_REF:
113795 + cur_decl = search_field_decl(node);
113796 + if (is_turn_off_intentional_attr(cur_decl))
113797 + return MARK_TURN_OFF;
113798 + if (is_end_intentional_intentional_attr(cur_decl, 1))
113799 + return MARK_YES;
113800 + break;
113801 + case PARM_DECL: {
113802 + unsigned int argnum;
113803 +
113804 + cur_decl = DECL_ORIGIN(current_function_decl);
113805 + argnum = find_arg_number_tree(node, cur_decl);
113806 + if (argnum == CANNOT_FIND_ARG)
113807 + return MARK_NO;
113808 + if (is_yes_intentional_attr(cur_decl, argnum))
113809 + return MARK_YES;
113810 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
113811 + return MARK_NOT_INTENTIONAL;
113812 + break;
113813 + }
113814 + case FUNCTION_DECL:
113815 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
113816 + return MARK_TURN_OFF;
113817 + break;
113818 + default:
113819 + break;
113820 + }
113821 + return MARK_NO;
113822 +}
113823 +
113824 +// Search for the intentional_overflow attribute on the last nodes
113825 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
113826 +{
113827 + unsigned int i;
113828 + tree last_node;
113829 + enum mark mark = MARK_NO;
113830 +
113831 +#if BUILDING_GCC_VERSION <= 4007
113832 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
113833 +#else
113834 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
113835 +#endif
113836 + mark = get_intentional_attr_type(last_node);
113837 + if (mark != MARK_NO)
113838 + break;
113839 + }
113840 + return mark;
113841 +}
113842 +
113843 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
113844 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
113845 + */
113846 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
113847 +{
113848 + if (!cur_node->intentional_mark_from_gimple)
113849 + return false;
113850 +
113851 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
113852 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
113853 + else
113854 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
113855 +
113856 + // skip param decls
113857 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
113858 + return true;
113859 + return true;
113860 +}
113861 +
113862 +/* Search intentional_overflow attribute on caller and on callee too.
113863 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
113864 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
113865 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
113866 +*/
113867 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
113868 +{
113869 + const_tree fndecl;
113870 +
113871 + if (is_intentional_attribute_from_gimple(cur_node))
113872 + return;
113873 +
113874 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
113875 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
113876 + return;
113877 + }
113878 +
113879 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
113880 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
113881 + return;
113882 + }
113883 +
113884 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
113885 + return;
113886 +
113887 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
113888 + if (is_turn_off_intentional_attr(fndecl)) {
113889 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
113890 + return;
113891 + }
113892 +
113893 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
113894 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
113895 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
113896 + cur_node->intentional_attr_decl = MARK_YES;
113897 +
113898 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
113899 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
113900 +}
113901 +
113902 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
113903 +{
113904 + const_tree rhs1, lhs, rhs1_type, lhs_type;
113905 + enum machine_mode lhs_mode, rhs_mode;
113906 + gimple def_stmt = get_def_stmt(no_const_rhs);
113907 +
113908 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113909 + return false;
113910 +
113911 + rhs1 = gimple_assign_rhs1(def_stmt);
113912 + lhs = gimple_assign_lhs(def_stmt);
113913 + rhs1_type = TREE_TYPE(rhs1);
113914 + lhs_type = TREE_TYPE(lhs);
113915 + rhs_mode = TYPE_MODE(rhs1_type);
113916 + lhs_mode = TYPE_MODE(lhs_type);
113917 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
113918 + return false;
113919 +
113920 + return true;
113921 +}
113922 +
113923 +static unsigned int uses_num(tree node)
113924 +{
113925 + imm_use_iterator imm_iter;
113926 + use_operand_p use_p;
113927 + unsigned int num = 0;
113928 +
113929 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
113930 + gimple use_stmt = USE_STMT(use_p);
113931 +
113932 + if (use_stmt == NULL)
113933 + return num;
113934 + if (is_gimple_debug(use_stmt))
113935 + continue;
113936 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
113937 + continue;
113938 + num++;
113939 + }
113940 + return num;
113941 +}
113942 +
113943 +static bool no_uses(tree node)
113944 +{
113945 + return !uses_num(node);
113946 +}
113947 +
113948 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
113949 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
113950 +{
113951 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
113952 + gimple def_stmt = get_def_stmt(lhs);
113953 +
113954 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113955 + return false;
113956 +
113957 + rhs1 = gimple_assign_rhs1(def_stmt);
113958 + rhs_type = TREE_TYPE(rhs1);
113959 + lhs_type = TREE_TYPE(lhs);
113960 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
113961 + return false;
113962 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
113963 + return false;
113964 +
113965 + def_stmt = get_def_stmt(rhs1);
113966 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
113967 + return false;
113968 +
113969 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
113970 + return false;
113971 +
113972 + rhs1 = gimple_assign_rhs1(def_stmt);
113973 + rhs2 = gimple_assign_rhs2(def_stmt);
113974 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
113975 + return false;
113976 +
113977 + if (is_gimple_constant(rhs2))
113978 + not_const_rhs = rhs1;
113979 + else
113980 + not_const_rhs = rhs2;
113981 +
113982 + return no_uses(not_const_rhs);
113983 +}
113984 +
113985 +static bool is_lt_signed_type_max(const_tree rhs)
113986 +{
113987 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
113988 +
113989 + if (!TYPE_UNSIGNED(type))
113990 + return true;
113991 +
113992 + switch (TYPE_MODE(type)) {
113993 + case QImode:
113994 + new_type = intQI_type_node;
113995 + break;
113996 + case HImode:
113997 + new_type = intHI_type_node;
113998 + break;
113999 + case SImode:
114000 + new_type = intSI_type_node;
114001 + break;
114002 + case DImode:
114003 + new_type = intDI_type_node;
114004 + break;
114005 + default:
114006 + debug_tree((tree)type);
114007 + gcc_unreachable();
114008 + }
114009 +
114010 + type_max = TYPE_MAX_VALUE(new_type);
114011 + if (!tree_int_cst_lt(type_max, rhs))
114012 + return true;
114013 +
114014 + return false;
114015 +}
114016 +
114017 +static bool is_gt_zero(const_tree rhs)
114018 +{
114019 + const_tree type = TREE_TYPE(rhs);
114020 +
114021 + if (TYPE_UNSIGNED(type))
114022 + return true;
114023 +
114024 + if (!tree_int_cst_lt(rhs, integer_zero_node))
114025 + return true;
114026 +
114027 + return false;
114028 +}
114029 +
114030 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
114031 +{
114032 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
114033 + return false;
114034 + if (!is_gimple_constant(rhs))
114035 + return false;
114036 +
114037 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
114038 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
114039 + return false;
114040 +
114041 + return true;
114042 +}
114043 +
114044 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
114045 +{
114046 + gimple assign;
114047 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114048 + tree origtype = TREE_TYPE(orig_rhs);
114049 +
114050 + gcc_assert(is_gimple_assign(stmt));
114051 +
114052 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114053 + pointer_set_insert(visited->my_stmts, assign);
114054 + return gimple_assign_lhs(assign);
114055 +}
114056 +
114057 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
114058 +{
114059 + tree new_rhs, orig_rhs;
114060 + void (*gimple_assign_set_rhs)(gimple, tree);
114061 + tree rhs1 = gimple_assign_rhs1(stmt);
114062 + tree rhs2 = gimple_assign_rhs2(stmt);
114063 + tree lhs = gimple_assign_lhs(stmt);
114064 +
114065 + if (!check_overflow)
114066 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114067 +
114068 + if (change_rhs == NULL_TREE)
114069 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114070 +
114071 + if (new_rhs2 == NULL_TREE) {
114072 + orig_rhs = rhs1;
114073 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
114074 + } else {
114075 + orig_rhs = rhs2;
114076 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
114077 + }
114078 +
114079 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
114080 +
114081 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
114082 + gimple_assign_set_rhs(stmt, new_rhs);
114083 + update_stmt(stmt);
114084 +
114085 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114086 +}
114087 +
114088 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
114089 +{
114090 + gimple rhs1_def_stmt, rhs2_def_stmt;
114091 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
114092 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
114093 + const_tree rhs1 = gimple_assign_rhs1(stmt);
114094 + const_tree rhs2 = gimple_assign_rhs2(stmt);
114095 +
114096 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
114097 + return false;
114098 +
114099 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
114100 +
114101 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
114102 + return false;
114103 +
114104 + rhs1_def_stmt = get_def_stmt(rhs1);
114105 + rhs2_def_stmt = get_def_stmt(rhs2);
114106 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
114107 + return false;
114108 +
114109 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
114110 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
114111 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
114112 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
114113 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
114114 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
114115 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
114116 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
114117 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
114118 + return false;
114119 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
114120 + return false;
114121 +
114122 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
114123 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
114124 + return true;
114125 +}
114126 +
114127 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
114128 +{
114129 + gimple assign;
114130 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114131 + tree type = TREE_TYPE(rhs1);
114132 + tree lhs = create_new_var(type);
114133 +
114134 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
114135 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
114136 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
114137 +
114138 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
114139 + update_stmt(assign);
114140 + pointer_set_insert(visited->my_stmts, assign);
114141 + return assign;
114142 +}
114143 +
114144 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
114145 +{
114146 + gimple_stmt_iterator gsi;
114147 + gimple cast_stmt;
114148 + tree type = TREE_TYPE(node);
114149 +
114150 + if (types_compatible_p(type, intTI_type_node))
114151 + return node;
114152 +
114153 + gsi = gsi_for_stmt(stmt);
114154 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114155 + pointer_set_insert(visited->my_stmts, cast_stmt);
114156 + return gimple_assign_lhs(cast_stmt);
114157 +}
114158 +
114159 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
114160 +{
114161 + tree rhs1, def_stmt_rhs1;
114162 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
114163 +
114164 + def_stmt = get_def_stmt(var);
114165 + if (!gimple_assign_cast_p(def_stmt))
114166 + return NULL_TREE;
114167 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
114168 +
114169 + rhs1 = gimple_assign_rhs1(def_stmt);
114170 + rhs1_def_stmt = get_def_stmt(rhs1);
114171 + if (!gimple_assign_cast_p(rhs1_def_stmt))
114172 + return rhs1;
114173 +
114174 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
114175 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
114176 +
114177 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
114178 + case GIMPLE_CALL:
114179 + case GIMPLE_NOP:
114180 + case GIMPLE_ASM:
114181 + case GIMPLE_PHI:
114182 + return def_stmt_rhs1;
114183 + case GIMPLE_ASSIGN:
114184 + return rhs1;
114185 + default:
114186 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
114187 + gcc_unreachable();
114188 + }
114189 +}
114190 +
114191 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
114192 +{
114193 + tree new_rhs1, new_rhs2;
114194 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
114195 + gimple assign, stmt = get_def_stmt(lhs);
114196 + tree rhs1 = gimple_assign_rhs1(stmt);
114197 + tree rhs2 = gimple_assign_rhs2(stmt);
114198 +
114199 + if (!is_subtraction_special(visited, stmt))
114200 + return NULL_TREE;
114201 +
114202 + new_rhs1 = expand(visited, caller_node, rhs1);
114203 + new_rhs2 = expand(visited, caller_node, rhs2);
114204 +
114205 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
114206 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
114207 +
114208 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
114209 + return NULL_TREE;
114210 +
114211 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
114212 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
114213 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
114214 + }
114215 +
114216 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
114217 + new_lhs = gimple_assign_lhs(assign);
114218 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
114219 +
114220 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
114221 +}
114222 +
114223 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
114224 +{
114225 + const_gimple def_stmt;
114226 +
114227 + if (TREE_CODE(rhs) != SSA_NAME)
114228 + return false;
114229 +
114230 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
114231 + return false;
114232 +
114233 + def_stmt = get_def_stmt(rhs);
114234 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
114235 + return false;
114236 +
114237 + return true;
114238 +}
114239 +
114240 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
114241 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
114242 + * fffffff * 16 > signed max -> truncate
114243 + */
114244 +static bool look_for_mult_and_add(const_gimple stmt)
114245 +{
114246 + const_tree res;
114247 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
114248 + const_gimple def_stmt;
114249 +
114250 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
114251 + return false;
114252 + if (!is_gimple_assign(stmt))
114253 + return false;
114254 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
114255 + return false;
114256 +
114257 + rhs1 = gimple_assign_rhs1(stmt);
114258 + rhs2 = gimple_assign_rhs2(stmt);
114259 + if (is_gimple_constant(rhs1)) {
114260 + const_rhs = rhs1;
114261 + def_stmt = get_def_stmt(rhs2);
114262 + } else if (is_gimple_constant(rhs2)) {
114263 + const_rhs = rhs2;
114264 + def_stmt = get_def_stmt(rhs1);
114265 + } else
114266 + return false;
114267 +
114268 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
114269 + return false;
114270 +
114271 + def_rhs1 = gimple_assign_rhs1(def_stmt);
114272 + def_rhs2 = gimple_assign_rhs2(def_stmt);
114273 + if (is_gimple_constant(def_rhs1))
114274 + def_const_rhs = def_rhs1;
114275 + else if (is_gimple_constant(def_rhs2))
114276 + def_const_rhs = def_rhs2;
114277 + else
114278 + return false;
114279 +
114280 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
114281 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
114282 + return false;
114283 + return true;
114284 +}
114285 +
114286 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
114287 +{
114288 + const_gimple def_stmt_1, def_stmt_2;
114289 + const_tree rhs1, rhs2;
114290 + bool add_mul_rhs1, add_mul_rhs2;
114291 +
114292 + rhs1 = gimple_assign_rhs1(stmt);
114293 + def_stmt_1 = get_def_stmt(rhs1);
114294 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
114295 +
114296 + rhs2 = gimple_assign_rhs2(stmt);
114297 + def_stmt_2 = get_def_stmt(rhs2);
114298 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
114299 +
114300 + if (add_mul_rhs1)
114301 + return RHS1_INTENTIONAL_OVERFLOW;
114302 + if (add_mul_rhs2)
114303 + return RHS2_INTENTIONAL_OVERFLOW;
114304 + return NO_INTENTIONAL_OVERFLOW;
114305 +}
114306 +
114307 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
114308 +{
114309 + gimple my_stmt;
114310 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114311 +
114312 + gsi_next(&gsi);
114313 + my_stmt = gsi_stmt(gsi);
114314 +
114315 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
114316 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
114317 +
114318 + return my_stmt;
114319 +}
114320 +
114321 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
114322 + * unsigned type cast to signed type, unsigned type: no more uses
114323 + * e.g., lib/vsprintf.c:simple_strtol()
114324 + * _10 = (unsigned long int) _9
114325 + * _11 = -_10;
114326 + * _12 = (long int) _11; (_11_ no more uses)
114327 + */
114328 +static bool is_call_or_cast(gimple stmt)
114329 +{
114330 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
114331 +}
114332 +
114333 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
114334 +{
114335 + const_tree rhs;
114336 + gimple def_stmt;
114337 +
114338 + if (node == NULL_TREE)
114339 + return true;
114340 + if (is_gimple_constant(node))
114341 + return true;
114342 +
114343 + def_stmt = get_def_stmt(node);
114344 + if (!def_stmt)
114345 + return false;
114346 +
114347 + if (is_call_or_cast(def_stmt))
114348 + return true;
114349 +
114350 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
114351 + return false;
114352 + rhs = gimple_assign_rhs1(def_stmt);
114353 + def_stmt = get_def_stmt(rhs);
114354 + if (!def_stmt)
114355 + return false;
114356 + return is_call_or_cast(def_stmt);
114357 +}
114358 +
114359 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
114360 +{
114361 + unsigned int use_num;
114362 + gimple so_stmt;
114363 + const_gimple def_stmt;
114364 + const_tree rhs1, rhs2;
114365 + tree rhs = gimple_assign_rhs1(stmt);
114366 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
114367 + const_tree rhs_type = TREE_TYPE(rhs);
114368 +
114369 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
114370 + return;
114371 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
114372 + return;
114373 + use_num = uses_num(rhs);
114374 + if (use_num != 1)
114375 + return;
114376 +
114377 + def_stmt = get_def_stmt(rhs);
114378 + if (!def_stmt)
114379 + return;
114380 + if (!is_gimple_assign(def_stmt))
114381 + return;
114382 +
114383 + rhs1 = gimple_assign_rhs1(def_stmt);
114384 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
114385 + return;
114386 +
114387 + rhs2 = gimple_assign_rhs2(def_stmt);
114388 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
114389 + return;
114390 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
114391 + return;
114392 +
114393 + so_stmt = get_dup_stmt(visited, stmt);
114394 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
114395 +}
114396 +
114397 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
114398 new file mode 100644
114399 index 0000000..4bddad2
114400 --- /dev/null
114401 +++ b/tools/gcc/size_overflow_plugin/misc.c
114402 @@ -0,0 +1,203 @@
114403 +/*
114404 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114405 + * Licensed under the GPL v2, or (at your option) v3
114406 + *
114407 + * Homepage:
114408 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114409 + *
114410 + * Documentation:
114411 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114412 + *
114413 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114414 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114415 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114416 + *
114417 + * Usage:
114418 + * $ make
114419 + * $ make run
114420 + */
114421 +
114422 +#include "gcc-common.h"
114423 +#include "size_overflow.h"
114424 +
114425 +void set_current_function_decl(tree fndecl)
114426 +{
114427 + gcc_assert(fndecl != NULL_TREE);
114428 +
114429 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
114430 + calculate_dominance_info(CDI_DOMINATORS);
114431 + current_function_decl = fndecl;
114432 +}
114433 +
114434 +void unset_current_function_decl(void)
114435 +{
114436 + free_dominance_info(CDI_DOMINATORS);
114437 + pop_cfun();
114438 + current_function_decl = NULL_TREE;
114439 +}
114440 +
114441 +static bool is_bool(const_tree node)
114442 +{
114443 + const_tree type;
114444 +
114445 + if (node == NULL_TREE)
114446 + return false;
114447 +
114448 + type = TREE_TYPE(node);
114449 + if (!INTEGRAL_TYPE_P(type))
114450 + return false;
114451 + if (TREE_CODE(type) == BOOLEAN_TYPE)
114452 + return true;
114453 + if (TYPE_PRECISION(type) == 1)
114454 + return true;
114455 + return false;
114456 +}
114457 +
114458 +bool skip_types(const_tree var)
114459 +{
114460 + tree type;
114461 + enum tree_code code;
114462 +
114463 + if (is_gimple_constant(var))
114464 + return true;
114465 +
114466 + switch (TREE_CODE(var)) {
114467 + case ADDR_EXPR:
114468 +#if BUILDING_GCC_VERSION >= 4006
114469 + case MEM_REF:
114470 +#endif
114471 + case ARRAY_REF:
114472 + case BIT_FIELD_REF:
114473 + case INDIRECT_REF:
114474 + case TARGET_MEM_REF:
114475 + case COMPONENT_REF:
114476 + case VAR_DECL:
114477 + case VIEW_CONVERT_EXPR:
114478 + return true;
114479 + default:
114480 + break;
114481 + }
114482 +
114483 + code = TREE_CODE(var);
114484 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
114485 +
114486 + type = TREE_TYPE(var);
114487 + switch (TREE_CODE(type)) {
114488 + case INTEGER_TYPE:
114489 + case ENUMERAL_TYPE:
114490 + return false;
114491 + case BOOLEAN_TYPE:
114492 + return is_bool(var);
114493 + default:
114494 + return true;
114495 + }
114496 +}
114497 +
114498 +gimple get_def_stmt(const_tree node)
114499 +{
114500 + gcc_assert(node != NULL_TREE);
114501 +
114502 + if (skip_types(node))
114503 + return NULL;
114504 +
114505 + if (TREE_CODE(node) != SSA_NAME)
114506 + return NULL;
114507 + return SSA_NAME_DEF_STMT(node);
114508 +}
114509 +
114510 +tree create_new_var(tree type)
114511 +{
114512 + tree new_var = create_tmp_var(type, "cicus");
114513 +
114514 + add_referenced_var(new_var);
114515 + return new_var;
114516 +}
114517 +
114518 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
114519 +{
114520 + const_gimple def_stmt = get_def_stmt(rhs);
114521 +
114522 + if (force)
114523 + return false;
114524 +
114525 + if (is_gimple_constant(rhs))
114526 + return false;
114527 +
114528 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
114529 + return false;
114530 +
114531 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
114532 + return false;
114533 +
114534 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
114535 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114536 + return false;
114537 +
114538 + return true;
114539 +}
114540 +
114541 +tree cast_a_tree(tree type, tree var)
114542 +{
114543 + gcc_assert(type != NULL_TREE);
114544 + gcc_assert(var != NULL_TREE);
114545 + gcc_assert(fold_convertible_p(type, var));
114546 +
114547 + return fold_convert(type, var);
114548 +}
114549 +
114550 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
114551 +{
114552 + gimple assign, def_stmt;
114553 +
114554 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
114555 + gcc_assert(!is_gimple_constant(rhs));
114556 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
114557 + gcc_unreachable();
114558 +
114559 + def_stmt = get_def_stmt(rhs);
114560 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
114561 + return def_stmt;
114562 +
114563 + if (lhs == CREATE_NEW_VAR)
114564 + lhs = create_new_var(dst_type);
114565 +
114566 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
114567 +
114568 + if (!gsi_end_p(*gsi)) {
114569 + location_t loc = gimple_location(gsi_stmt(*gsi));
114570 + gimple_set_location(assign, loc);
114571 + }
114572 +
114573 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
114574 +
114575 + if (before)
114576 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
114577 + else
114578 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
114579 + update_stmt(assign);
114580 + return assign;
114581 +}
114582 +
114583 +bool is_size_overflow_type(const_tree var)
114584 +{
114585 + const char *name;
114586 + const_tree type_name, type;
114587 +
114588 + if (var == NULL_TREE)
114589 + return false;
114590 +
114591 + type = TREE_TYPE(var);
114592 + type_name = TYPE_NAME(type);
114593 + if (type_name == NULL_TREE)
114594 + return false;
114595 +
114596 + if (DECL_P(type_name))
114597 + name = DECL_NAME_POINTER(type_name);
114598 + else
114599 + name = IDENTIFIER_POINTER(type_name);
114600 +
114601 + if (!strncmp(name, "size_overflow_type", 18))
114602 + return true;
114603 + return false;
114604 +}
114605 +
114606 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
114607 new file mode 100644
114608 index 0000000..7c9e6d1
114609 --- /dev/null
114610 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
114611 @@ -0,0 +1,138 @@
114612 +/*
114613 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114614 + * Licensed under the GPL v2, or (at your option) v3
114615 + *
114616 + * Homepage:
114617 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114618 + *
114619 + * Documentation:
114620 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114621 + *
114622 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114623 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114624 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114625 + *
114626 + * Usage:
114627 + * $ make
114628 + * $ make run
114629 + */
114630 +
114631 +#include "gcc-common.h"
114632 +#include "size_overflow.h"
114633 +
114634 +bool skip_expr_on_double_type(const_gimple stmt)
114635 +{
114636 + enum tree_code code = gimple_assign_rhs_code(stmt);
114637 +
114638 + switch (code) {
114639 + case RSHIFT_EXPR:
114640 + case TRUNC_DIV_EXPR:
114641 + case CEIL_DIV_EXPR:
114642 + case FLOOR_DIV_EXPR:
114643 + case ROUND_DIV_EXPR:
114644 + case EXACT_DIV_EXPR:
114645 + case RDIV_EXPR:
114646 + case TRUNC_MOD_EXPR:
114647 + case CEIL_MOD_EXPR:
114648 + case FLOOR_MOD_EXPR:
114649 + case ROUND_MOD_EXPR:
114650 + return true;
114651 + default:
114652 + return false;
114653 + }
114654 +}
114655 +
114656 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
114657 +{
114658 + const_tree orig_rhs1;
114659 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
114660 + gimple down_cast, up_cast;
114661 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
114662 +
114663 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114664 + down_lhs = gimple_assign_lhs(down_cast);
114665 +
114666 + gsi = gsi_for_stmt(use_stmt);
114667 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114668 + new_lhs = gimple_assign_lhs(up_cast);
114669 +
114670 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
114671 + if (operand_equal_p(orig_rhs1, rhs, 0))
114672 + gimple_assign_set_rhs1(use_stmt, new_lhs);
114673 + else
114674 + gimple_assign_set_rhs2(use_stmt, new_lhs);
114675 + update_stmt(use_stmt);
114676 +
114677 + pointer_set_insert(visited->my_stmts, up_cast);
114678 + pointer_set_insert(visited->my_stmts, down_cast);
114679 + pointer_set_insert(visited->skip_expr_casts, up_cast);
114680 + pointer_set_insert(visited->skip_expr_casts, down_cast);
114681 +}
114682 +
114683 +static tree get_proper_unsigned_half_type(const_tree node)
114684 +{
114685 + tree new_type, type;
114686 +
114687 + gcc_assert(is_size_overflow_type(node));
114688 +
114689 + type = TREE_TYPE(node);
114690 + switch (TYPE_MODE(type)) {
114691 + case HImode:
114692 + new_type = unsigned_intQI_type_node;
114693 + break;
114694 + case SImode:
114695 + new_type = unsigned_intHI_type_node;
114696 + break;
114697 + case DImode:
114698 + new_type = unsigned_intSI_type_node;
114699 + break;
114700 + case TImode:
114701 + new_type = unsigned_intDI_type_node;
114702 + break;
114703 + default:
114704 + gcc_unreachable();
114705 + }
114706 +
114707 + if (TYPE_QUALS(type) != 0)
114708 + return build_qualified_type(new_type, TYPE_QUALS(type));
114709 + return new_type;
114710 +}
114711 +
114712 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
114713 +{
114714 + tree type;
114715 +
114716 + if (rhs == NULL_TREE)
114717 + return;
114718 + if (!is_size_overflow_type(rhs))
114719 + return;
114720 +
114721 + type = get_proper_unsigned_half_type(rhs);
114722 + if (is_gimple_constant(rhs))
114723 + return;
114724 + create_up_and_down_cast(visited, stmt, type, rhs);
114725 +}
114726 +
114727 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
114728 +{
114729 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
114730 + return;
114731 + gcc_assert(is_size_overflow_type(rhs));
114732 + insert_cast_rhs(visited, stmt, rhs);
114733 +}
114734 +
114735 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
114736 +{
114737 + tree rhs1, rhs2;
114738 +
114739 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
114740 + rhs1 = gimple_assign_rhs1(stmt);
114741 + insert_cast(visited, stmt, rhs1);
114742 + }
114743 +
114744 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
114745 + rhs2 = gimple_assign_rhs2(stmt);
114746 + insert_cast(visited, stmt, rhs2);
114747 + }
114748 +}
114749 +
114750 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
114751 new file mode 100644
114752 index 0000000..e5b4e50
114753 --- /dev/null
114754 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
114755 @@ -0,0 +1,127 @@
114756 +#ifndef SIZE_OVERFLOW_H
114757 +#define SIZE_OVERFLOW_H
114758 +
114759 +#define CREATE_NEW_VAR NULL_TREE
114760 +#define CANNOT_FIND_ARG 32
114761 +#define MAX_PARAM 31
114762 +#define BEFORE_STMT true
114763 +#define AFTER_STMT false
114764 +
114765 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
114766 +#define YES_ASM_STR "# size_overflow MARK_YES "
114767 +#define OK_ASM_STR "# size_overflow "
114768 +
114769 +enum mark {
114770 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
114771 +};
114772 +
114773 +enum intentional_overflow_type {
114774 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
114775 +};
114776 +
114777 +struct visited {
114778 + struct pointer_set_t *stmts;
114779 + struct pointer_set_t *my_stmts;
114780 + struct pointer_set_t *skip_expr_casts;
114781 + struct pointer_set_t *no_cast_check;
114782 +};
114783 +
114784 +// size_overflow_plugin.c
114785 +extern tree report_size_overflow_decl;
114786 +extern tree size_overflow_type_HI;
114787 +extern tree size_overflow_type_SI;
114788 +extern tree size_overflow_type_DI;
114789 +extern tree size_overflow_type_TI;
114790 +
114791 +
114792 +// size_overflow_plugin_hash.c
114793 +struct size_overflow_hash {
114794 + const struct size_overflow_hash * const next;
114795 + const char * const name;
114796 + const unsigned int param;
114797 +};
114798 +
114799 +struct interesting_node {
114800 + struct interesting_node *next;
114801 + gimple first_stmt;
114802 + const_tree fndecl;
114803 + tree node;
114804 +#if BUILDING_GCC_VERSION <= 4007
114805 + VEC(tree, gc) *last_nodes;
114806 +#else
114807 + vec<tree, va_gc> *last_nodes;
114808 +#endif
114809 + unsigned int num;
114810 + enum mark intentional_attr_decl;
114811 + enum mark intentional_attr_cur_fndecl;
114812 + gimple intentional_mark_from_gimple;
114813 +};
114814 +
114815 +extern bool is_size_overflow_asm(const_gimple stmt);
114816 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
114817 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
114818 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
114819 +extern bool is_a_return_check(const_tree node);
114820 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
114821 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
114822 +
114823 +
114824 +// size_overflow_debug.c
114825 +extern struct opt_pass *make_dump_pass(void);
114826 +
114827 +
114828 +// intentional_overflow.c
114829 +extern enum mark get_intentional_attr_type(const_tree node);
114830 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
114831 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
114832 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
114833 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
114834 +extern bool is_turn_off_intentional_attr(const_tree decl);
114835 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
114836 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
114837 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
114838 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
114839 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
114840 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
114841 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
114842 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
114843 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
114844 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
114845 +
114846 +
114847 +// insert_size_overflow_check_ipa.c
114848 +extern unsigned int search_function(void);
114849 +extern unsigned int call_count;
114850 +extern struct opt_pass *make_insert_size_overflow_check(void);
114851 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
114852 +
114853 +
114854 +// insert_size_overflow_asm.c
114855 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
114856 +
114857 +
114858 +// misc.c
114859 +extern void set_current_function_decl(tree fndecl);
114860 +extern void unset_current_function_decl(void);
114861 +extern gimple get_def_stmt(const_tree node);
114862 +extern tree create_new_var(tree type);
114863 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
114864 +extern bool skip_types(const_tree var);
114865 +extern tree cast_a_tree(tree type, tree var);
114866 +extern bool is_size_overflow_type(const_tree var);
114867 +
114868 +
114869 +// insert_size_overflow_check_core.c
114870 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
114871 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
114872 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
114873 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
114874 +
114875 +
114876 +// remove_unnecessary_dup.c
114877 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
114878 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
114879 +extern bool skip_expr_on_double_type(const_gimple stmt);
114880 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
114881 +
114882 +#endif
114883 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
114884 new file mode 100644
114885 index 0000000..4378111
114886 --- /dev/null
114887 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
114888 @@ -0,0 +1,116 @@
114889 +/*
114890 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114891 + * Licensed under the GPL v2, or (at your option) v3
114892 + *
114893 + * Homepage:
114894 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114895 + *
114896 + * Documentation:
114897 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114898 + *
114899 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114900 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114901 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114902 + *
114903 + * Usage:
114904 + * $ make
114905 + * $ make run
114906 + */
114907 +
114908 +#include "gcc-common.h"
114909 +
114910 +static unsigned int dump_functions(void)
114911 +{
114912 + struct cgraph_node *node;
114913 +
114914 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
114915 + basic_block bb;
114916 +
114917 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
114918 + current_function_decl = NODE_DECL(node);
114919 +
114920 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
114921 +
114922 + FOR_ALL_BB_FN(bb, cfun) {
114923 + gimple_stmt_iterator si;
114924 +
114925 + fprintf(stderr, "<bb %u>:\n", bb->index);
114926 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
114927 + debug_gimple_stmt(gsi_stmt(si));
114928 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
114929 + debug_gimple_stmt(gsi_stmt(si));
114930 + fprintf(stderr, "\n");
114931 + }
114932 +
114933 + fprintf(stderr, "-------------------------------------------------------------------------\n");
114934 +
114935 + pop_cfun();
114936 + current_function_decl = NULL_TREE;
114937 + }
114938 +
114939 + fprintf(stderr, "###############################################################################\n");
114940 +
114941 + return 0;
114942 +}
114943 +
114944 +#if BUILDING_GCC_VERSION >= 4009
114945 +static const struct pass_data dump_pass_data = {
114946 +#else
114947 +static struct ipa_opt_pass_d dump_pass = {
114948 + .pass = {
114949 +#endif
114950 + .type = SIMPLE_IPA_PASS,
114951 + .name = "dump",
114952 +#if BUILDING_GCC_VERSION >= 4008
114953 + .optinfo_flags = OPTGROUP_NONE,
114954 +#endif
114955 +#if BUILDING_GCC_VERSION >= 4009
114956 + .has_gate = false,
114957 + .has_execute = true,
114958 +#else
114959 + .gate = NULL,
114960 + .execute = dump_functions,
114961 + .sub = NULL,
114962 + .next = NULL,
114963 + .static_pass_number = 0,
114964 +#endif
114965 + .tv_id = TV_NONE,
114966 + .properties_required = 0,
114967 + .properties_provided = 0,
114968 + .properties_destroyed = 0,
114969 + .todo_flags_start = 0,
114970 + .todo_flags_finish = 0,
114971 +#if BUILDING_GCC_VERSION < 4009
114972 + },
114973 + .generate_summary = NULL,
114974 + .write_summary = NULL,
114975 + .read_summary = NULL,
114976 +#if BUILDING_GCC_VERSION >= 4006
114977 + .write_optimization_summary = NULL,
114978 + .read_optimization_summary = NULL,
114979 +#endif
114980 + .stmt_fixup = NULL,
114981 + .function_transform_todo_flags_start = 0,
114982 + .function_transform = NULL,
114983 + .variable_transform = NULL,
114984 +#endif
114985 +};
114986 +
114987 +#if BUILDING_GCC_VERSION >= 4009
114988 +namespace {
114989 +class dump_pass : public ipa_opt_pass_d {
114990 +public:
114991 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
114992 + unsigned int execute() { return dump_functions(); }
114993 +};
114994 +}
114995 +#endif
114996 +
114997 +struct opt_pass *make_dump_pass(void)
114998 +{
114999 +#if BUILDING_GCC_VERSION >= 4009
115000 + return new dump_pass();
115001 +#else
115002 + return &dump_pass.pass;
115003 +#endif
115004 +}
115005 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
115006 new file mode 100644
115007 index 0000000..386792a
115008 --- /dev/null
115009 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
115010 @@ -0,0 +1,5808 @@
115011 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
115012 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
115013 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
115014 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
115015 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
115016 +padzero_55 padzero 1 55 &sel_read_policyvers_55
115017 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
115018 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
115019 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
115020 +load_msg_95 load_msg 2 95 NULL
115021 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
115022 +init_q_132 init_q 4 132 NULL
115023 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
115024 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
115025 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
115026 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL nohasharray
115027 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 &tracing_trace_options_write_153
115028 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
115029 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
115030 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
115031 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
115032 +br_port_info_size_268 br_port_info_size 0 268 NULL
115033 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
115034 +SYSC_connect_304 SYSC_connect 3 304 NULL
115035 +syslog_print_307 syslog_print 2 307 NULL
115036 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
115037 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
115038 +aio_read_events_ring_410 aio_read_events_ring 3 410 NULL
115039 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
115040 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
115041 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
115042 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
115043 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
115044 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
115045 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
115046 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
115047 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
115048 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
115049 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
115050 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
115051 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
115052 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
115053 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
115054 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
115055 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
115056 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
115057 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
115058 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
115059 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
115060 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
115061 +unlink_queued_645 unlink_queued 4 645 NULL
115062 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
115063 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
115064 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
115065 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
115066 +dvb_video_write_754 dvb_video_write 3 754 NULL
115067 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
115068 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
115069 +snd_pcm_drain_811 snd_pcm_drain 0 811 NULL
115070 +if_writecmd_815 if_writecmd 2 815 NULL
115071 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
115072 +error_state_read_859 error_state_read 6 859 NULL
115073 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
115074 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
115075 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
115076 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
115077 +__nodes_weight_956 __nodes_weight 0 956 NULL
115078 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
115079 +mnt_want_write_975 mnt_want_write 0 975 NULL
115080 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
115081 +memcmp_990 memcmp 0 990 NULL
115082 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
115083 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
115084 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
115085 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
115086 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
115087 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
115088 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
115089 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
115090 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
115091 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
115092 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
115093 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
115094 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
115095 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
115096 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
115097 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
115098 +fsync_buffers_list_1219 fsync_buffers_list 0 1219 NULL
115099 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
115100 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
115101 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
115102 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
115103 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
115104 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
115105 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
115106 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
115107 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
115108 +ffs_1322 ffs 0 1322 NULL
115109 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
115110 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
115111 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
115112 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
115113 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
115114 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
115115 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
115116 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
115117 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
115118 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
115119 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
115120 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
115121 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
115122 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
115123 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
115124 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
115125 +fpregs_set_1497 fpregs_set 4 1497 NULL
115126 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
115127 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
115128 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
115129 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
115130 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
115131 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
115132 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
115133 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
115134 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
115135 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
115136 +rmap_add_1677 rmap_add 3 1677 NULL
115137 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
115138 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
115139 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
115140 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
115141 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
115142 +internal_create_group_1733 internal_create_group 0 1733 NULL
115143 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
115144 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
115145 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
115146 +cosa_write_1774 cosa_write 3 1774 NULL
115147 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
115148 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
115149 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
115150 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
115151 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
115152 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
115153 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
115154 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
115155 +bdev_erase_1933 bdev_erase 3 1933 NULL
115156 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
115157 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
115158 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
115159 +__assign_irq_vector_1961 __assign_irq_vector 0 1961 NULL
115160 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
115161 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
115162 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
115163 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
115164 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
115165 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
115166 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
115167 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
115168 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
115169 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
115170 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
115171 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
115172 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
115173 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
115174 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
115175 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
115176 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
115177 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
115178 +enable_read_2117 enable_read 3 2117 NULL
115179 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
115180 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
115181 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
115182 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
115183 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
115184 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
115185 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
115186 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
115187 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
115188 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
115189 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
115190 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
115191 +do_update_counters_2259 do_update_counters 4 2259 NULL
115192 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
115193 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
115194 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
115195 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
115196 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
115197 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL nohasharray
115198 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 &picolcd_fb_write_2318
115199 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
115200 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
115201 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
115202 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
115203 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
115204 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
115205 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
115206 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
115207 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
115208 +raid1_size_2419 raid1_size 0-2 2419 NULL
115209 +arch_msi_check_device_2449 arch_msi_check_device 0 2449 NULL
115210 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
115211 +wiphy_new_2482 wiphy_new 2 2482 NULL
115212 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
115213 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
115214 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
115215 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
115216 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
115217 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
115218 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
115219 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
115220 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
115221 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
115222 +slot_bytes_2609 slot_bytes 0 2609 NULL
115223 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
115224 +switch_status_2629 switch_status 5 2629 NULL
115225 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
115226 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
115227 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
115228 +oti6858_write_2692 oti6858_write 4 2692 NULL
115229 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
115230 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
115231 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
115232 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
115233 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
115234 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
115235 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
115236 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
115237 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
115238 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
115239 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL nohasharray
115240 +snd_pcm_reset_2829 snd_pcm_reset 0 2829 &vb2_dc_get_userptr_2829
115241 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
115242 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
115243 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
115244 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
115245 +nla_padlen_2883 nla_padlen 1 2883 NULL
115246 +cmm_write_2896 cmm_write 3 2896 NULL
115247 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
115248 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
115249 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
115250 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
115251 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
115252 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
115253 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
115254 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
115255 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
115256 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
115257 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
115258 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
115259 +depth_write_3021 depth_write 3 3021 NULL
115260 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
115261 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
115262 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
115263 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
115264 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
115265 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
115266 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
115267 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
115268 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
115269 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
115270 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
115271 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
115272 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
115273 +rb_alloc_3102 rb_alloc 1 3102 NULL
115274 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
115275 +print_time_3132 print_time 0 3132 NULL
115276 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
115277 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
115278 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
115279 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
115280 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
115281 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
115282 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
115283 +alloc_context_3194 alloc_context 1 3194 NULL
115284 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
115285 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
115286 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
115287 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
115288 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
115289 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
115290 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
115291 +key_key_read_3241 key_key_read 3 3241 NULL
115292 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
115293 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
115294 +cgroup_name_3300 cgroup_name 3 3300 NULL
115295 +__set_extent_bit_3305 __set_extent_bit 0 3305 NULL
115296 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 4-3-0 3314 NULL
115297 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
115298 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
115299 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
115300 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
115301 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
115302 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
115303 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
115304 +scnprintf_3360 scnprintf 0-2 3360 NULL
115305 +sr_read_3366 sr_read 3 3366 NULL
115306 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
115307 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
115308 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
115309 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
115310 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
115311 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
115312 +softsynth_write_3455 softsynth_write 3 3455 NULL
115313 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
115314 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
115315 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
115316 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
115317 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
115318 +SyS_readv_3539 SyS_readv 3 3539 NULL
115319 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
115320 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
115321 +evtchn_read_3569 evtchn_read 3 3569 NULL
115322 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
115323 +vc_resize_3585 vc_resize 3-2 3585 NULL
115324 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
115325 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
115326 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
115327 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
115328 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
115329 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
115330 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
115331 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
115332 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
115333 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
115334 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
115335 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
115336 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
115337 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
115338 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
115339 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
115340 +get_fd_set_3866 get_fd_set 1 3866 NULL
115341 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
115342 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
115343 +nvram_write_3894 nvram_write 3 3894 NULL
115344 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
115345 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
115346 +vcs_write_3910 vcs_write 3 3910 NULL
115347 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
115348 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
115349 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
115350 +do_add_counters_3992 do_add_counters 3 3992 NULL
115351 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
115352 +userspace_status_4004 userspace_status 4 4004 NULL
115353 +mei_write_4005 mei_write 3 4005 NULL nohasharray
115354 +xfs_check_block_4005 xfs_check_block 4 4005 &mei_write_4005
115355 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
115356 +blk_end_request_4024 blk_end_request 3 4024 NULL
115357 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
115358 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
115359 +read_file_queues_4078 read_file_queues 3 4078 NULL
115360 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
115361 +tm6000_read_4151 tm6000_read 3 4151 NULL
115362 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
115363 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
115364 +get_alua_req_4166 get_alua_req 3 4166 NULL
115365 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
115366 +read_file_bool_4180 read_file_bool 3 4180 NULL
115367 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
115368 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
115369 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
115370 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
115371 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
115372 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
115373 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
115374 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
115375 +count_strings_4315 count_strings 0 4315 NULL
115376 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
115377 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
115378 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
115379 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3-0 4365 NULL
115380 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
115381 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL nohasharray
115382 +access_process_vm_4412 access_process_vm 0 4412 &cxacru_cm_get_array_4412
115383 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
115384 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
115385 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
115386 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
115387 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 0-5 4481 NULL
115388 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
115389 +set_link_security_4502 set_link_security 4 4502 NULL
115390 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
115391 +tty_register_device_4544 tty_register_device 2 4544 NULL
115392 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
115393 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
115394 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
115395 +bch_alloc_4593 bch_alloc 1 4593 NULL
115396 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
115397 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
115398 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
115399 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
115400 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
115401 +kone_receive_4690 kone_receive 4 4690 NULL
115402 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
115403 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
115404 +show_header_4722 show_header 3 4722 NULL nohasharray
115405 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 &show_header_4722
115406 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
115407 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
115408 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
115409 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
115410 +create_subvol_4791 create_subvol 4 4791 NULL
115411 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
115412 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
115413 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
115414 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
115415 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
115416 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
115417 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
115418 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
115419 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
115420 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
115421 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
115422 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
115423 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
115424 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
115425 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
115426 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
115427 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
115428 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
115429 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 2-3 5066 NULL
115430 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
115431 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
115432 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
115433 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
115434 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
115435 +sound_write_5102 sound_write 3 5102 NULL
115436 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
115437 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
115438 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
115439 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
115440 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
115441 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
115442 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
115443 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
115444 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
115445 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
115446 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
115447 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
115448 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
115449 +cq_free_res_5355 cq_free_res 5 5355 NULL
115450 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
115451 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
115452 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
115453 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
115454 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
115455 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
115456 +pci_enable_msix_exact_5482 pci_enable_msix_exact 3-0 5482 NULL
115457 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
115458 +tty_write_5494 tty_write 3 5494 NULL
115459 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
115460 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
115461 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
115462 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
115463 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
115464 +le_readq_5557 le_readq 0 5557 NULL
115465 +inw_5558 inw 0 5558 NULL
115466 +bioset_create_5580 bioset_create 1 5580 NULL
115467 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
115468 +__remove_suid_5618 __remove_suid 0 5618 NULL
115469 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
115470 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
115471 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
115472 +get_arg_5694 get_arg 3 5694 NULL
115473 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
115474 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
115475 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
115476 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
115477 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
115478 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
115479 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
115480 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
115481 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
115482 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
115483 +setup_req_5848 setup_req 3 5848 NULL
115484 +ria_page_count_5849 ria_page_count 0 5849 NULL
115485 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
115486 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
115487 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
115488 +port_show_regs_5904 port_show_regs 3 5904 NULL
115489 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
115490 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
115491 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
115492 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
115493 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
115494 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
115495 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
115496 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
115497 +SyS_semop_5980 SyS_semop 3 5980 NULL
115498 +alloc_msg_6072 alloc_msg 1 6072 NULL
115499 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
115500 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
115501 +__mnt_want_write_6091 __mnt_want_write 0 6091 NULL
115502 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
115503 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
115504 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
115505 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
115506 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
115507 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
115508 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
115509 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
115510 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
115511 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
115512 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
115513 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
115514 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
115515 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
115516 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
115517 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
115518 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
115519 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
115520 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
115521 +serial_port_in_6291 serial_port_in 0 6291 NULL
115522 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
115523 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
115524 +SyS_mincore_6329 SyS_mincore 1-2 6329 &hfa384x_inw_6329
115525 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
115526 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
115527 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
115528 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
115529 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
115530 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
115531 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
115532 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
115533 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
115534 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
115535 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
115536 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
115537 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
115538 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
115539 +mei_read_6507 mei_read 3 6507 NULL
115540 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
115541 +wdm_read_6549 wdm_read 3 6549 NULL
115542 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
115543 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
115544 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
115545 +snd_pcm_hw_refine_old_user_6586 snd_pcm_hw_refine_old_user 0 6586 NULL
115546 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
115547 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
115548 +pvscsi_allocate_rings_6689 pvscsi_allocate_rings 0 6689 NULL
115549 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
115550 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
115551 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
115552 +mpeg_read_6708 mpeg_read 3 6708 NULL
115553 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
115554 +video_proc_write_6724 video_proc_write 3 6724 NULL
115555 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
115556 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
115557 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
115558 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
115559 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
115560 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
115561 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
115562 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
115563 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
115564 +calc_pages_for_6838 calc_pages_for 0-2-1 6838 NULL
115565 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
115566 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
115567 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
115568 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
115569 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
115570 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
115571 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
115572 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
115573 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
115574 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
115575 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
115576 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
115577 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
115578 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
115579 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
115580 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
115581 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
115582 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
115583 +request_key_async_6990 request_key_async 4 6990 NULL
115584 +tpl_write_6998 tpl_write 3 6998 NULL
115585 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
115586 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
115587 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
115588 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
115589 +wimax_msg_7030 wimax_msg 4 7030 NULL
115590 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
115591 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
115592 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
115593 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
115594 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
115595 +event_enable_read_7074 event_enable_read 3 7074 NULL
115596 +tipc_send_packet_7091 tipc_send_packet 4 7091 NULL nohasharray
115597 +beacon_interval_read_7091 beacon_interval_read 3 7091 &tipc_send_packet_7091
115598 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
115599 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
115600 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
115601 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
115602 +qlcnic_enable_msix_7144 qlcnic_enable_msix 2 7144 NULL
115603 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
115604 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
115605 +security_inode_need_killpriv_7322 security_inode_need_killpriv 0 7322 NULL
115606 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
115607 +mgmt_control_7349 mgmt_control 3 7349 NULL
115608 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
115609 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
115610 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
115611 +hweight_long_7388 hweight_long 0 7388 NULL
115612 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
115613 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
115614 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
115615 +readb_7401 readb 0 7401 NULL
115616 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
115617 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
115618 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
115619 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
115620 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
115621 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
115622 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
115623 +garp_request_join_7471 garp_request_join 4 7471 NULL
115624 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
115625 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
115626 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
115627 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
115628 +sk_convert_filter_7541 sk_convert_filter 2 7541 NULL
115629 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
115630 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
115631 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
115632 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
115633 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
115634 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
115635 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
115636 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
115637 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
115638 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
115639 +dev_write_7708 dev_write 3 7708 NULL
115640 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
115641 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
115642 +ubi_io_read_vid_hdr_7766 ubi_io_read_vid_hdr 0 7766 NULL
115643 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
115644 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
115645 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
115646 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
115647 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 NULL nohasharray
115648 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 &lustre_packed_msg_size_7792
115649 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
115650 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
115651 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
115652 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
115653 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
115654 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
115655 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
115656 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
115657 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
115658 +vcs_read_8017 vcs_read 3 8017 NULL
115659 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
115660 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
115661 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
115662 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
115663 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
115664 +venus_lookup_8121 venus_lookup 4 8121 NULL
115665 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
115666 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
115667 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
115668 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
115669 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
115670 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
115671 +play_iframe_8219 play_iframe 3 8219 NULL
115672 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
115673 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
115674 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
115675 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
115676 +init_cdev_8274 init_cdev 1 8274 NULL
115677 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
115678 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
115679 +snd_pcm_update_state_8320 snd_pcm_update_state 0 8320 NULL
115680 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
115681 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
115682 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
115683 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
115684 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
115685 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
115686 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
115687 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
115688 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
115689 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
115690 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
115691 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
115692 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
115693 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
115694 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
115695 +dev_config_8506 dev_config 3 8506 NULL
115696 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
115697 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
115698 +user_on_off_8552 user_on_off 2 8552 NULL
115699 +profile_remove_8556 profile_remove 3 8556 NULL
115700 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL nohasharray
115701 +pci_msi_check_device_8570 pci_msi_check_device 0 8570 &cache_slow_downcall_8570
115702 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
115703 +tower_write_8580 tower_write 3 8580 NULL
115704 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
115705 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
115706 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
115707 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
115708 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
115709 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
115710 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
115711 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
115712 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
115713 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
115714 +arcfb_write_8702 arcfb_write 3 8702 NULL
115715 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
115716 +init_header_8703 init_header 0 8703 &i_size_read_8703
115717 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
115718 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
115719 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
115720 +__create_irqs_8733 __create_irqs 2 8733 NULL
115721 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
115722 +compound_order_8750 compound_order 0 8750 NULL
115723 +yurex_write_8761 yurex_write 3 8761 NULL
115724 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
115725 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
115726 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
115727 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
115728 +__bitmap_weight_8796 __bitmap_weight 0 8796 NULL
115729 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
115730 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
115731 +extent_read_full_page_8826 extent_read_full_page 0 8826 NULL
115732 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
115733 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
115734 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
115735 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
115736 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
115737 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
115738 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
115739 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
115740 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
115741 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
115742 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
115743 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
115744 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
115745 +write_file_ani_8918 write_file_ani 3 8918 NULL
115746 +layout_commit_8926 layout_commit 3 8926 NULL
115747 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
115748 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
115749 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
115750 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
115751 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
115752 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
115753 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
115754 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
115755 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
115756 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
115757 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
115758 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
115759 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
115760 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
115761 +nla_put_9042 nla_put 3 9042 NULL
115762 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
115763 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
115764 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
115765 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
115766 +create_queues_9088 create_queues 2-3 9088 NULL
115767 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
115768 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
115769 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
115770 +gfn_to_rmap_9110 gfn_to_rmap 2-3 9110 &caif_stream_sendmsg_9110
115771 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
115772 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
115773 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
115774 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
115775 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
115776 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
115777 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
115778 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
115779 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
115780 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
115781 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
115782 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
115783 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
115784 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
115785 +flakey_status_9274 flakey_status 5 9274 NULL
115786 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
115787 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
115788 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
115789 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
115790 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
115791 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
115792 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
115793 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
115794 +read_9397 read 3 9397 NULL
115795 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
115796 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
115797 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
115798 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
115799 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
115800 +get_registers_9470 get_registers 4 9470 NULL nohasharray
115801 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
115802 +crypt_status_9492 crypt_status 5 9492 NULL
115803 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
115804 +lp_write_9511 lp_write 3 9511 NULL
115805 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
115806 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
115807 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
115808 +read_file_dma_9530 read_file_dma 3 9530 NULL
115809 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
115810 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
115811 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
115812 +fw_node_create_9559 fw_node_create 2 9559 NULL
115813 +kobj_map_9566 kobj_map 2-3 9566 NULL
115814 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
115815 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
115816 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
115817 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
115818 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
115819 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
115820 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
115821 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
115822 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
115823 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
115824 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
115825 +dns_query_9676 dns_query 3 9676 NULL
115826 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
115827 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
115828 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
115829 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
115830 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
115831 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
115832 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
115833 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
115834 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
115835 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
115836 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
115837 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
115838 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
115839 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
115840 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
115841 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
115842 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
115843 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
115844 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
115845 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
115846 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
115847 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
115848 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
115849 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
115850 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
115851 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
115852 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
115853 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
115854 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
115855 +read_file_misc_9948 read_file_misc 3 9948 NULL
115856 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
115857 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
115858 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
115859 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
115860 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
115861 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
115862 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
115863 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
115864 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
115865 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
115866 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
115867 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
115868 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
115869 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
115870 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
115871 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
115872 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
115873 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
115874 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
115875 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
115876 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
115877 +ubi_leb_change_10289 ubi_leb_change 0 10289 NULL
115878 +read_emulate_10310 read_emulate 2-4 10310 NULL
115879 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
115880 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
115881 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
115882 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
115883 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
115884 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
115885 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
115886 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
115887 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
115888 +led_classdev_register_10384 led_classdev_register 0 10384 NULL
115889 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
115890 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
115891 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
115892 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
115893 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
115894 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
115895 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
115896 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
115897 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
115898 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
115899 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
115900 +snd_pcm_hw_params_user_10520 snd_pcm_hw_params_user 0 10520 NULL
115901 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
115902 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
115903 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
115904 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
115905 +otp_read_10594 otp_read 2-4-5 10594 NULL
115906 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
115907 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
115908 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
115909 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL nohasharray
115910 +ubi_io_write_vid_hdr_10660 ubi_io_write_vid_hdr 0 10660 &nfs_idmap_lookup_id_10660
115911 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
115912 +parport_write_10669 parport_write 0 10669 NULL
115913 +edge_write_10692 edge_write 4 10692 NULL
115914 +ubi_wl_get_peb_10699 ubi_wl_get_peb 0 10699 NULL
115915 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
115916 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
115917 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
115918 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
115919 +spi_sync_10731 spi_sync 0 10731 NULL
115920 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
115921 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
115922 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
115923 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
115924 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
115925 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
115926 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
115927 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
115928 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
115929 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
115930 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
115931 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
115932 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
115933 +get_scq_10897 get_scq 2 10897 NULL
115934 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
115935 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
115936 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
115937 +kobject_add_10919 kobject_add 0 10919 NULL
115938 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
115939 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
115940 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
115941 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
115942 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
115943 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
115944 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
115945 +pci_msi_vec_count_11046 pci_msi_vec_count 0 11046 NULL
115946 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
115947 +qlcnic_83xx_calculate_msix_vector_11063 qlcnic_83xx_calculate_msix_vector 0 11063 NULL nohasharray
115948 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 &qlcnic_83xx_calculate_msix_vector_11063
115949 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
115950 +snd_pcm_delay_11081 snd_pcm_delay 0 11081 NULL
115951 +count_argc_11083 count_argc 0 11083 NULL
115952 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
115953 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
115954 +page_offset_11120 page_offset 0 11120 NULL
115955 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 NULL nohasharray
115956 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 &cea_db_payload_len_11124
115957 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
115958 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
115959 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
115960 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
115961 +of_irq_count_11253 of_irq_count 0 11253 NULL
115962 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
115963 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
115964 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
115965 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
115966 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
115967 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
115968 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
115969 +construct_key_11329 construct_key 3 11329 NULL nohasharray
115970 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
115971 +next_segment_11330 next_segment 0-2-1 11330 NULL
115972 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
115973 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
115974 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
115975 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
115976 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
115977 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
115978 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
115979 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
115980 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
115981 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
115982 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
115983 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
115984 +str_to_user_11411 str_to_user 2 11411 NULL
115985 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
115986 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
115987 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
115988 +trace_options_read_11419 trace_options_read 3 11419 NULL
115989 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
115990 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
115991 +bttv_read_11432 bttv_read 3 11432 NULL
115992 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
115993 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
115994 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
115995 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
115996 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
115997 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
115998 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
115999 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
116000 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
116001 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
116002 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
116003 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
116004 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
116005 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
116006 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
116007 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
116008 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
116009 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
116010 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
116011 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
116012 +slab_ksize_11664 slab_ksize 0 11664 NULL
116013 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
116014 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
116015 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
116016 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
116017 +split_11691 split 2 11691 NULL
116018 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
116019 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
116020 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
116021 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
116022 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
116023 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
116024 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
116025 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
116026 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
116027 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
116028 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
116029 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
116030 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
116031 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
116032 +pci_enable_msix_range_11852 pci_enable_msix_range 0-4 11852 NULL
116033 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
116034 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
116035 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
116036 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
116037 +ti_write_11916 ti_write 4 11916 NULL
116038 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
116039 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
116040 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
116041 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
116042 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
116043 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
116044 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
116045 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
116046 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
116047 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
116048 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
116049 +set_powered_12129 set_powered 4 12129 NULL
116050 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
116051 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
116052 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
116053 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
116054 +get_idx_gc_leb_12148 get_idx_gc_leb 0 12148 NULL
116055 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
116056 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
116057 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
116058 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
116059 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
116060 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
116061 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
116062 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
116063 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
116064 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
116065 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
116066 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
116067 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
116068 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
116069 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
116070 +SYSC_vm86_12279 SYSC_vm86 2 12279 NULL
116071 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
116072 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
116073 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
116074 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
116075 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
116076 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
116077 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
116078 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
116079 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
116080 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
116081 +populate_dir_12391 populate_dir 0 12391 &write_file_dump_12391
116082 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
116083 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
116084 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
116085 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
116086 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
116087 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
116088 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
116089 +write_inode_now_12565 write_inode_now 0 12565 NULL
116090 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
116091 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
116092 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
116093 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
116094 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
116095 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
116096 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
116097 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
116098 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
116099 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
116100 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
116101 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
116102 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
116103 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
116104 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
116105 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
116106 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
116107 +ivtv_write_12721 ivtv_write 3 12721 NULL
116108 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
116109 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
116110 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
116111 +listxattr_12769 listxattr 3 12769 NULL
116112 +sctp_ssnmap_init_12772 sctp_ssnmap_init 3-2 12772 NULL
116113 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
116114 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
116115 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
116116 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
116117 +spidev_sync_12842 spidev_sync 0 12842 NULL
116118 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
116119 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
116120 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
116121 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
116122 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
116123 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
116124 +bm_status_write_12964 bm_status_write 3 12964 NULL
116125 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
116126 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
116127 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
116128 +__btrfs_direct_write_13007 __btrfs_direct_write 4-0 13007 NULL
116129 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
116130 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
116131 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
116132 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
116133 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
116134 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
116135 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
116136 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
116137 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
116138 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
116139 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
116140 +blk_update_request_13146 blk_update_request 3 13146 NULL
116141 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
116142 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
116143 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
116144 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
116145 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
116146 +comedi_read_13199 comedi_read 3 13199 NULL
116147 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
116148 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
116149 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
116150 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
116151 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
116152 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
116153 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
116154 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
116155 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
116156 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
116157 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
116158 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
116159 +sd_major_13294 sd_major 0-1 13294 NULL
116160 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
116161 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
116162 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
116163 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
116164 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
116165 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
116166 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
116167 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
116168 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
116169 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
116170 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
116171 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
116172 +data_read_13494 data_read 3 13494 NULL
116173 +core_status_13515 core_status 4 13515 NULL
116174 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
116175 +bm_init_13529 bm_init 2 13529 NULL
116176 +request_any_context_irq_13530 request_any_context_irq 0 13530 NULL
116177 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
116178 +SyS_vm86_13557 SyS_vm86 2 13557 NULL
116179 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
116180 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
116181 +ubifs_get_idx_gc_leb_13566 ubifs_get_idx_gc_leb 0 13566 NULL
116182 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
116183 +cache_write_13589 cache_write 3 13589 NULL
116184 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
116185 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
116186 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
116187 +packet_snd_13634 packet_snd 3 13634 NULL
116188 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
116189 +cache_downcall_13666 cache_downcall 3 13666 NULL
116190 +ext3_xattr_list_entries_13682 ext3_xattr_list_entries 0 13682 NULL
116191 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
116192 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
116193 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
116194 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
116195 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
116196 +random_read_13815 random_read 3 13815 NULL
116197 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
116198 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
116199 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
116200 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
116201 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
116202 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
116203 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
116204 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
116205 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
116206 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
116207 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
116208 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
116209 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
116210 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
116211 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL nohasharray
116212 +pagecache_write_end_13950 pagecache_write_end 0 13950 &lpfc_idiag_queacc_read_13950
116213 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
116214 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
116215 +qcam_read_13977 qcam_read 3 13977 NULL
116216 +dsp_read_13980 dsp_read 2 13980 NULL
116217 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
116218 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
116219 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
116220 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
116221 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
116222 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
116223 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
116224 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
116225 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
116226 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
116227 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
116228 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
116229 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
116230 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
116231 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
116232 +em_canid_change_14150 em_canid_change 3 14150 NULL
116233 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
116234 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
116235 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
116236 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
116237 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
116238 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
116239 +alloc_async_14208 alloc_async 1 14208 NULL
116240 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
116241 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
116242 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
116243 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
116244 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
116245 +rr_status_14293 rr_status 5 14293 NULL
116246 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
116247 +oo_objects_14319 oo_objects 0 14319 NULL
116248 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
116249 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
116250 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
116251 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
116252 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
116253 +lowpan_read_14369 lowpan_read 3 14369 NULL
116254 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
116255 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
116256 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
116257 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
116258 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
116259 +block_size_14443 block_size 0 14443 NULL
116260 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
116261 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
116262 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
116263 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
116264 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
116265 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
116266 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
116267 +split_state_14491 split_state 0 14491 NULL
116268 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
116269 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
116270 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
116271 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
116272 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
116273 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
116274 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
116275 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
116276 +dbJoin_14644 dbJoin 0 14644 NULL
116277 +profile_replace_14652 profile_replace 3 14652 NULL
116278 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
116279 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
116280 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
116281 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
116282 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
116283 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
116284 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
116285 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
116286 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
116287 +vfd_write_14717 vfd_write 3 14717 NULL
116288 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
116289 +raid1_resize_14740 raid1_resize 2 14740 NULL
116290 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
116291 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
116292 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
116293 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
116294 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
116295 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
116296 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
116297 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
116298 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
116299 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
116300 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
116301 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
116302 +lcd_write_14857 lcd_write 3 14857 NULL
116303 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
116304 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
116305 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
116306 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
116307 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
116308 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
116309 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
116310 +queue_cnt_14951 queue_cnt 0 14951 NULL
116311 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
116312 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
116313 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
116314 +setkey_14987 setkey 3 14987 NULL nohasharray
116315 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
116316 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
116317 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
116318 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
116319 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
116320 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
116321 +ntfs_copy_from_user_15072 ntfs_copy_from_user 0-5-3 15072 NULL
116322 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
116323 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
116324 +btrfs_readpage_15094 btrfs_readpage 0 15094 NULL
116325 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
116326 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
116327 +start_port_15124 start_port 0 15124 NULL
116328 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
116329 +self_check_not_bad_15175 self_check_not_bad 0 15175 NULL
116330 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
116331 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
116332 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
116333 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
116334 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
116335 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
116336 +simple_strtol_15273 simple_strtol 0 15273 NULL
116337 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
116338 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
116339 +ioread16_15342 ioread16 0 15342 NULL
116340 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
116341 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
116342 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
116343 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
116344 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
116345 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
116346 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
116347 +get_modalias_15406 get_modalias 2 15406 NULL
116348 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
116349 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
116350 +rtw_cfg80211_rx_action_p2p_15432 rtw_cfg80211_rx_action_p2p 3 15432 NULL
116351 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
116352 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
116353 +insert_old_idx_znode_15500 insert_old_idx_znode 0 15500 NULL
116354 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
116355 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
116356 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
116357 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
116358 +snd_pcm_channel_info_15572 snd_pcm_channel_info 0 15572 NULL
116359 +persistent_status_15574 persistent_status 4 15574 NULL
116360 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
116361 +vme_user_write_15587 vme_user_write 3 15587 NULL
116362 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
116363 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
116364 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
116365 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
116366 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
116367 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
116368 +fs_path_add_15648 fs_path_add 3 15648 NULL
116369 +__do_readpage_15652 __do_readpage 0 15652 NULL
116370 +xsd_read_15653 xsd_read 3 15653 NULL
116371 +unix_bind_15668 unix_bind 3 15668 NULL
116372 +dm_read_15674 dm_read 3 15674 NULL nohasharray
116373 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
116374 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
116375 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
116376 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
116377 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
116378 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
116379 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
116380 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
116381 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
116382 +table_size_15851 table_size 0-1-2 15851 NULL
116383 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
116384 +media_entity_init_15870 media_entity_init 2-4 15870 NULL nohasharray
116385 +ubi_io_write_15870 ubi_io_write 0 15870 &media_entity_init_15870
116386 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
116387 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
116388 +power_read_15939 power_read 3 15939 NULL
116389 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
116390 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
116391 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
116392 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
116393 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
116394 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
116395 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
116396 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
116397 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
116398 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
116399 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
116400 +fsm_init_16134 fsm_init 2 16134 NULL
116401 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
116402 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
116403 +mapping_level_16188 mapping_level 2-0 16188 NULL
116404 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
116405 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
116406 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
116407 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
116408 +create_table_16213 create_table 2 16213 NULL
116409 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
116410 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
116411 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
116412 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
116413 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
116414 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
116415 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
116416 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
116417 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
116418 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
116419 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
116420 +account_16283 account 0-4-2 16283 NULL nohasharray
116421 +mirror_status_16283 mirror_status 5 16283 &account_16283
116422 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
116423 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
116424 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
116425 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
116426 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
116427 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
116428 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
116429 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
116430 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
116431 +i8042_create_kbd_port_16379 i8042_create_kbd_port 0 16379 NULL
116432 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
116433 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
116434 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
116435 +cmdline_store_16442 cmdline_store 4 16442 NULL
116436 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
116437 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
116438 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
116439 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
116440 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
116441 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
116442 +raid10_resize_16537 raid10_resize 2 16537 NULL
116443 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
116444 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
116445 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
116446 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
116447 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
116448 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
116449 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
116450 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
116451 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
116452 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
116453 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
116454 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
116455 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
116456 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
116457 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
116458 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
116459 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
116460 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
116461 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
116462 +st_write_16874 st_write 3 16874 NULL
116463 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
116464 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
116465 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
116466 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
116467 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
116468 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
116469 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
116470 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
116471 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
116472 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
116473 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
116474 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
116475 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
116476 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
116477 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
116478 +entry_length_17093 entry_length 0 17093 NULL
116479 +write_mem_17114 write_mem 3 17114 NULL
116480 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
116481 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
116482 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
116483 +sep_read_17161 sep_read 3 17161 NULL
116484 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
116485 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
116486 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
116487 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
116488 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
116489 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
116490 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
116491 +sync_request_17208 sync_request 2 17208 NULL
116492 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
116493 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
116494 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
116495 +alloc_ep_17269 alloc_ep 1 17269 NULL
116496 +pg_read_17276 pg_read 3 17276 NULL
116497 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
116498 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
116499 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
116500 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
116501 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
116502 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
116503 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
116504 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
116505 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
116506 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
116507 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
116508 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
116509 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
116510 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
116511 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
116512 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
116513 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
116514 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
116515 +qp_free_res_17541 qp_free_res 5 17541 NULL
116516 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
116517 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
116518 +snd_pcm_action_lock_irq_17569 snd_pcm_action_lock_irq 0 17569 NULL
116519 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
116520 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
116521 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
116522 +osst_execute_17607 osst_execute 7-6 17607 NULL
116523 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
116524 +dma_map_page_17628 dma_map_page 0 17628 NULL
116525 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
116526 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
116527 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL nohasharray
116528 +ubi_io_read_data_17662 ubi_io_read_data 0 17662 &packet_setsockopt_17662
116529 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
116530 +filemap_fdatawait_17688 filemap_fdatawait 0 17688 NULL
116531 +venus_rename_17707 venus_rename 4-5 17707 NULL
116532 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
116533 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
116534 +ubifs_leb_change_17789 ubifs_leb_change 0 17789 NULL
116535 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
116536 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
116537 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
116538 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
116539 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
116540 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
116541 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
116542 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
116543 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
116544 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
116545 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
116546 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
116547 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
116548 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
116549 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
116550 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
116551 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
116552 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
116553 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
116554 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
116555 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
116556 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
116557 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
116558 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
116559 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
116560 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
116561 +cpufreq_add_dev_symlink_18028 cpufreq_add_dev_symlink 0 18028 NULL
116562 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
116563 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
116564 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
116565 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
116566 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
116567 +fpregs_get_18066 fpregs_get 4 18066 NULL
116568 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
116569 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
116570 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
116571 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
116572 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
116573 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
116574 +svc_getnl_18120 svc_getnl 0 18120 NULL
116575 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
116576 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
116577 +is_idx_node_in_use_18165 is_idx_node_in_use 0 18165 NULL
116578 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
116579 +snd_pcm_hw_refine_user_18204 snd_pcm_hw_refine_user 0 18204 NULL
116580 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
116581 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
116582 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
116583 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
116584 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
116585 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
116586 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
116587 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
116588 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
116589 +find_dirty_idx_leb_18280 find_dirty_idx_leb 0 18280 NULL
116590 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
116591 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
116592 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
116593 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
116594 +um_idi_write_18293 um_idi_write 3 18293 NULL
116595 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
116596 +vga_r_18310 vga_r 0 18310 NULL
116597 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
116598 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
116599 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
116600 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
116601 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
116602 +copy_page_to_iter_18345 copy_page_to_iter 3-0 18345 NULL
116603 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
116604 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
116605 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
116606 +ep_io_18367 ep_io 0 18367 NULL
116607 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
116608 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
116609 +ci_role_write_18388 ci_role_write 3 18388 NULL
116610 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
116611 +rtl8169_rx_fill_18416 rtl8169_rx_fill 0 18416 NULL
116612 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
116613 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
116614 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
116615 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
116616 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
116617 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
116618 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
116619 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
116620 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
116621 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
116622 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
116623 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
116624 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
116625 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
116626 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
116627 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
116628 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
116629 +debug_output_18575 debug_output 3 18575 NULL
116630 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
116631 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
116632 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
116633 +from_buffer_18625 from_buffer 3 18625 NULL
116634 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
116635 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
116636 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
116637 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
116638 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
116639 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
116640 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
116641 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
116642 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
116643 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
116644 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
116645 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
116646 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
116647 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
116648 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
116649 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
116650 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
116651 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
116652 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
116653 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
116654 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
116655 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
116656 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
116657 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
116658 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
116659 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
116660 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
116661 +find_dirtiest_idx_leb_19001 find_dirtiest_idx_leb 0 19001 NULL
116662 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
116663 +huge_page_size_19008 huge_page_size 0 19008 NULL
116664 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
116665 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
116666 +revalidate_19043 revalidate 2 19043 NULL
116667 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
116668 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL nohasharray
116669 +do_vm86_irq_handling_19056 do_vm86_irq_handling 2 19056 &osc_pinger_recov_seq_write_19056
116670 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
116671 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
116672 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
116673 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
116674 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
116675 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
116676 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
116677 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
116678 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
116679 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
116680 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
116681 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
116682 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
116683 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
116684 +snd_pcm_capture_rewind_19229 snd_pcm_capture_rewind 0-2 19229 NULL
116685 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
116686 +ucma_query_19260 ucma_query 4 19260 NULL
116687 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
116688 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
116689 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
116690 +qc_capture_19298 qc_capture 3 19298 NULL
116691 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 3-4 19303 NULL
116692 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
116693 +debug_read_19322 debug_read 3 19322 NULL
116694 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL nohasharray
116695 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 &cfg80211_inform_bss_19332
116696 +closure_sub_19359 closure_sub 2 19359 NULL
116697 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
116698 +read_zero_19366 read_zero 3 19366 NULL
116699 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
116700 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
116701 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
116702 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
116703 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
116704 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
116705 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
116706 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
116707 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
116708 +sky2_read16_19475 sky2_read16 0 19475 NULL
116709 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
116710 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
116711 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
116712 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
116713 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
116714 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
116715 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
116716 +nfsd_read_19568 nfsd_read 5 19568 NULL
116717 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
116718 +mnt_want_write_file_19579 mnt_want_write_file 0 19579 NULL
116719 +bm_status_read_19583 bm_status_read 3 19583 NULL
116720 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
116721 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
116722 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
116723 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
116724 +ocfs2_control_get_this_node_19721 ocfs2_control_get_this_node 0 19721 NULL
116725 +read_reg_19723 read_reg 0 19723 NULL
116726 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
116727 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
116728 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
116729 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
116730 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
116731 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
116732 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
116733 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
116734 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
116735 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
116736 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
116737 +__nla_put_19857 __nla_put 3 19857 NULL
116738 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
116739 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
116740 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
116741 +mangle_name_19923 mangle_name 0 19923 NULL
116742 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
116743 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
116744 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
116745 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
116746 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
116747 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
116748 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
116749 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL nohasharray
116750 +i40e_reserve_msix_vectors_19989 i40e_reserve_msix_vectors 2 19989 &rtw_set_wps_probe_resp_19989
116751 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
116752 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
116753 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
116754 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
116755 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
116756 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
116757 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
116758 +target_message_20072 target_message 2 20072 NULL
116759 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
116760 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
116761 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
116762 +team_options_register_20091 team_options_register 3 20091 NULL
116763 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
116764 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
116765 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
116766 +self_check_vid_hdr_20131 self_check_vid_hdr 0 20131 NULL
116767 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
116768 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
116769 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
116770 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
116771 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
116772 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
116773 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
116774 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
116775 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
116776 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
116777 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
116778 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
116779 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
116780 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
116781 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
116782 +snd_pcm_stop_20376 snd_pcm_stop 0 20376 NULL
116783 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
116784 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
116785 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
116786 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
116787 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
116788 +read_buf_20469 read_buf 2 20469 NULL
116789 +bio_trim_20472 bio_trim 2 20472 NULL
116790 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
116791 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
116792 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
116793 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
116794 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
116795 +venus_create_20555 venus_create 4 20555 NULL
116796 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
116797 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
116798 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
116799 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
116800 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
116801 +lirc_write_20604 lirc_write 3 20604 NULL
116802 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
116803 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
116804 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
116805 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
116806 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
116807 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
116808 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
116809 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL nohasharray
116810 +btrfs_qgroup_reserve_20676 btrfs_qgroup_reserve 0 20676 &snd_hdsp_playback_copy_20676
116811 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
116812 +cpumask_size_20683 cpumask_size 0 20683 NULL
116813 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
116814 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
116815 +__maestro_read_20700 __maestro_read 0 20700 NULL
116816 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
116817 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
116818 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
116819 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
116820 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
116821 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
116822 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
116823 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL nohasharray
116824 +mnt_clone_write_20763 mnt_clone_write 0 20763 &brcmf_p2p_escan_20763
116825 +ubi_io_read_20767 ubi_io_read 0 20767 NULL
116826 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
116827 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
116828 +lowpan_write_20800 lowpan_write 3 20800 NULL
116829 +strndup_user_20819 strndup_user 2 20819 NULL
116830 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
116831 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
116832 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
116833 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
116834 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
116835 +get_name_20855 get_name 4 20855 NULL
116836 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
116837 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
116838 +srq_free_res_20868 srq_free_res 5 20868 NULL
116839 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
116840 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
116841 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
116842 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
116843 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
116844 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
116845 +htable_bits_20933 htable_bits 0 20933 NULL
116846 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
116847 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
116848 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
116849 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
116850 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
116851 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
116852 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
116853 +btrfs_dirty_pages_21019 btrfs_dirty_pages 0 21019 NULL
116854 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
116855 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
116856 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
116857 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
116858 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
116859 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
116860 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
116861 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
116862 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
116863 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
116864 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
116865 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
116866 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
116867 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
116868 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
116869 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
116870 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
116871 +__generic_file_aio_write_21201 __generic_file_aio_write 0 21201 NULL
116872 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
116873 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
116874 +get_numpages_21227 get_numpages 0-2-1 21227 NULL
116875 +input_ff_create_21240 input_ff_create 2 21240 NULL
116876 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
116877 +fru_length_21257 fru_length 0 21257 NULL
116878 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
116879 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
116880 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
116881 +add_res_range_21310 add_res_range 4 21310 NULL
116882 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
116883 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
116884 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
116885 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
116886 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
116887 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
116888 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
116889 +insert_ptr_21386 insert_ptr 6 21386 NULL
116890 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
116891 +__clone_and_map_simple_bio_21404 __clone_and_map_simple_bio 4 21404 NULL
116892 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
116893 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
116894 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
116895 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
116896 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
116897 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
116898 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
116899 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
116900 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
116901 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
116902 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
116903 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
116904 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
116905 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
116906 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
116907 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
116908 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
116909 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
116910 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
116911 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
116912 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
116913 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
116914 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
116915 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
116916 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
116917 +update_time_21719 update_time 0 21719 NULL
116918 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
116919 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
116920 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
116921 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
116922 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
116923 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
116924 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
116925 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
116926 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
116927 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
116928 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
116929 +msix_capability_init_21870 msix_capability_init 0 21870 NULL
116930 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
116931 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
116932 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
116933 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
116934 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
116935 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
116936 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
116937 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3-0 22001 NULL nohasharray
116938 +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
116939 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
116940 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
116941 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
116942 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
116943 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
116944 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
116945 +mem_rw_22085 mem_rw 3 22085 NULL
116946 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
116947 +snd_pcm_xrun_22088 snd_pcm_xrun 0 22088 NULL
116948 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
116949 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
116950 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
116951 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
116952 +pci_request_region_22164 pci_request_region 0 22164 NULL
116953 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
116954 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
116955 +mem_write_22232 mem_write 3 22232 NULL
116956 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
116957 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
116958 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
116959 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
116960 +add_res_tree_22263 add_res_tree 7 22263 NULL
116961 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
116962 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 NULL nohasharray
116963 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 &pci_vpd_srdt_size_22300
116964 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
116965 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
116966 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
116967 +atomic_read_22342 atomic_read 0 22342 NULL
116968 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
116969 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
116970 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
116971 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
116972 +zoran_write_22404 zoran_write 3 22404 NULL
116973 +queue_reply_22416 queue_reply 3 22416 NULL
116974 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
116975 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
116976 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
116977 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
116978 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
116979 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
116980 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
116981 +ntb_setup_bwd_msix_22549 ntb_setup_bwd_msix 2-0 22549 NULL
116982 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
116983 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
116984 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
116985 +snapshot_read_22601 snapshot_read 3 22601 NULL
116986 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
116987 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
116988 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
116989 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
116990 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
116991 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
116992 +fill_gap_22681 fill_gap 0 22681 NULL nohasharray
116993 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 &fill_gap_22681
116994 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
116995 +reg_umr_22686 reg_umr 5 22686 NULL
116996 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
116997 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
116998 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
116999 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
117000 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
117001 +__writeback_single_inode_22739 __writeback_single_inode 0 22739 NULL
117002 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
117003 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
117004 +print_frame_22769 print_frame 0 22769 NULL
117005 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
117006 +__break_lease_22777 __break_lease 0 22777 NULL
117007 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
117008 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
117009 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
117010 +create_attr_set_22861 create_attr_set 1 22861 NULL
117011 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
117012 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
117013 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
117014 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
117015 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
117016 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
117017 +__set_xattr_22923 __set_xattr 0 22923 NULL
117018 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
117019 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
117020 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
117021 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
117022 +vme_get_size_22964 vme_get_size 0 22964 NULL
117023 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
117024 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
117025 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
117026 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
117027 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
117028 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
117029 +st_status_23032 st_status 5 23032 NULL
117030 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
117031 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
117032 +security_inode_killpriv_23060 security_inode_killpriv 0 23060 NULL
117033 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
117034 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
117035 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
117036 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
117037 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
117038 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
117039 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
117040 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
117041 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
117042 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
117043 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
117044 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
117045 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
117046 +__clear_user_23118 __clear_user 0-2 23118 NULL
117047 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
117048 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
117049 +read_file_ani_23161 read_file_ani 3 23161 NULL
117050 +usblp_write_23178 usblp_write 3 23178 NULL
117051 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
117052 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
117053 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
117054 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
117055 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
117056 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
117057 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
117058 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
117059 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
117060 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
117061 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
117062 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
117063 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
117064 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
117065 +page_readlink_23346 page_readlink 3 23346 NULL
117066 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
117067 +get_dst_timing_23358 get_dst_timing 0 23358 NULL nohasharray
117068 +write_inode_23358 write_inode 0 23358 &get_dst_timing_23358
117069 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
117070 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
117071 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
117072 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
117073 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
117074 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
117075 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
117076 +sync_mapping_buffers_23485 sync_mapping_buffers 0 23485 &linear_conf_23485
117077 +event_filter_read_23494 event_filter_read 3 23494 NULL
117078 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
117079 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
117080 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
117081 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
117082 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
117083 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
117084 +dbg_leb_change_23555 dbg_leb_change 0 23555 NULL
117085 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
117086 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
117087 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
117088 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
117089 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
117090 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
117091 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
117092 +sInW_23663 sInW 0 23663 NULL
117093 +SyS_connect_23669 SyS_connect 3 23669 NULL
117094 +cx18_read_23699 cx18_read 3 23699 NULL
117095 +at_get_23708 at_get 0 23708 NULL
117096 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
117097 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
117098 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
117099 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
117100 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
117101 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
117102 +map_write_23795 map_write 3 23795 NULL
117103 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
117104 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
117105 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
117106 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 0-3-4 23829 NULL
117107 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
117108 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
117109 +p54_init_common_23850 p54_init_common 1 23850 NULL
117110 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
117111 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
117112 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
117113 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 NULL nohasharray
117114 +writeback_single_inode_23881 writeback_single_inode 0 23881 &nouveau_clock_create__23881
117115 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
117116 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
117117 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
117118 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
117119 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
117120 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
117121 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
117122 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
117123 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
117124 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
117125 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
117126 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
117127 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
117128 +give_pages_24021 give_pages 3 24021 NULL
117129 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
117130 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
117131 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
117132 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
117133 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
117134 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
117135 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
117136 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
117137 +lov_brw_24122 lov_brw 4 24122 NULL
117138 +mpu401_read_24126 mpu401_read 3 24126 NULL
117139 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
117140 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
117141 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
117142 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
117143 +adu_read_24177 adu_read 3 24177 NULL
117144 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
117145 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
117146 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
117147 +efx_vf_size_24213 efx_vf_size 0 24213 NULL
117148 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
117149 +mei_amthif_read_24224 mei_amthif_read 4 24224 NULL nohasharray
117150 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 &mei_amthif_read_24224
117151 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
117152 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
117153 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
117154 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
117155 +thin_status_24278 thin_status 5 24278 NULL
117156 +msg_size_24288 msg_size 0 24288 NULL
117157 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
117158 +reserve_metadata_bytes_24313 reserve_metadata_bytes 0 24313 NULL
117159 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
117160 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
117161 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
117162 +prepare_pages_24349 prepare_pages 0 24349 NULL
117163 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
117164 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
117165 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
117166 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
117167 +igetword_24373 igetword 0 24373 NULL nohasharray
117168 +break_deleg_24373 break_deleg 0 24373 &igetword_24373
117169 +max_io_len_24384 max_io_len 0-1 24384 NULL
117170 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
117171 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
117172 +getxattr_24398 getxattr 4 24398 NULL nohasharray
117173 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
117174 +populate_msi_sysfs_24399 populate_msi_sysfs 0 24399 NULL
117175 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
117176 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
117177 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
117178 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
117179 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
117180 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
117181 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
117182 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 NULL nohasharray
117183 +smk_user_access_24440 smk_user_access 3 24440 &rtw_set_wps_assoc_resp_24440
117184 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
117185 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
117186 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
117187 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
117188 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
117189 +pd_video_read_24510 pd_video_read 3 24510 NULL
117190 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
117191 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
117192 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
117193 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
117194 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
117195 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
117196 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
117197 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
117198 +SyS_poll_24620 SyS_poll 2 24620 NULL
117199 +context_alloc_24645 context_alloc 3 24645 NULL
117200 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
117201 +btrfs_check_data_free_space_24692 btrfs_check_data_free_space 0 24692 NULL
117202 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
117203 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
117204 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
117205 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
117206 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
117207 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
117208 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
117209 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
117210 +cache_read_24790 cache_read 3 24790 NULL
117211 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
117212 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
117213 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
117214 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
117215 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
117216 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
117217 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
117218 +queues_read_24877 queues_read 3 24877 NULL
117219 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
117220 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL nohasharray
117221 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 &v4l2_ctrl_new_24927
117222 +ocfs2_fiemap_24949 ocfs2_fiemap 3-4 24949 NULL
117223 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
117224 +security_inode_rename_24971 security_inode_rename 0 24971 NULL
117225 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
117226 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
117227 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
117228 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
117229 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
117230 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
117231 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
117232 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
117233 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
117234 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
117235 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
117236 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
117237 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
117238 +_iwl_dbgfs_reduced_txp_write_25169 _iwl_dbgfs_reduced_txp_write 3 25169 NULL nohasharray
117239 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 &_iwl_dbgfs_reduced_txp_write_25169
117240 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
117241 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
117242 +stripe_status_25259 stripe_status 5 25259 NULL
117243 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
117244 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
117245 +vfs_writev_25278 vfs_writev 3 25278 NULL
117246 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
117247 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
117248 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
117249 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
117250 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
117251 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
117252 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
117253 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
117254 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
117255 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
117256 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
117257 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
117258 +sb_permission_25523 sb_permission 0 25523 NULL
117259 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
117260 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
117261 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
117262 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
117263 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
117264 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
117265 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
117266 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
117267 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
117268 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
117269 +__direct_map_25647 __direct_map 5-6 25647 NULL
117270 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
117271 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
117272 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
117273 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
117274 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
117275 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
117276 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
117277 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
117278 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
117279 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
117280 +sg_read_25799 sg_read 3 25799 NULL
117281 +system_enable_read_25815 system_enable_read 3 25815 NULL
117282 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
117283 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
117284 +parport_read_25855 parport_read 0 25855 NULL
117285 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
117286 +key_attr_size_25865 key_attr_size 0 25865 NULL
117287 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
117288 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
117289 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
117290 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
117291 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
117292 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
117293 +rcname_read_25919 rcname_read 3 25919 NULL
117294 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
117295 +key_flags_read_25931 key_flags_read 3 25931 NULL
117296 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
117297 +flush_25957 flush 2 25957 NULL
117298 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
117299 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
117300 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
117301 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
117302 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
117303 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
117304 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
117305 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
117306 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
117307 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
117308 +read_sb_page_26119 read_sb_page 5 26119 NULL
117309 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
117310 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
117311 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
117312 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
117313 +disk_devt_26180 disk_devt 0 26180 NULL
117314 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
117315 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
117316 +mce_write_26201 mce_write 3 26201 NULL
117317 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
117318 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
117319 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
117320 +simple_setattr_26234 simple_setattr 0 26234 NULL
117321 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
117322 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
117323 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
117324 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
117325 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
117326 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
117327 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
117328 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
117329 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
117330 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
117331 +ntty_write_26404 ntty_write 3 26404 NULL
117332 +firmware_store_26408 firmware_store 4 26408 NULL
117333 +pagemap_read_26441 pagemap_read 3 26441 NULL
117334 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 NULL nohasharray
117335 +tower_read_26461 tower_read 3 26461 &enc_pools_add_pages_26461
117336 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
117337 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
117338 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
117339 +read_vmcore_26501 read_vmcore 3 26501 NULL
117340 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
117341 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
117342 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
117343 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
117344 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
117345 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
117346 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
117347 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
117348 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
117349 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
117350 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
117351 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
117352 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
117353 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
117354 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
117355 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
117356 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
117357 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
117358 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
117359 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
117360 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
117361 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
117362 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
117363 +smk_write_load_26829 smk_write_load 3 26829 NULL
117364 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
117365 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
117366 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
117367 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
117368 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
117369 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
117370 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
117371 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
117372 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
117373 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
117374 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
117375 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
117376 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
117377 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
117378 +extract_entropy_user_26952 extract_entropy_user 3 26952 NULL nohasharray
117379 +do_trimming_26952 do_trimming 3 26952 &extract_entropy_user_26952
117380 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
117381 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
117382 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
117383 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
117384 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
117385 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
117386 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
117387 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
117388 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
117389 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
117390 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
117391 +pms_capture_27142 pms_capture 4 27142 NULL
117392 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
117393 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
117394 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
117395 +write_kmem_27225 write_kmem 3 27225 NULL
117396 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
117397 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
117398 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
117399 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
117400 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
117401 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
117402 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
117403 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
117404 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
117405 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
117406 +seq_read_27411 seq_read 3 27411 NULL
117407 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
117408 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
117409 +cypress_write_27423 cypress_write 4 27423 NULL
117410 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
117411 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
117412 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
117413 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
117414 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
117415 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
117416 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
117417 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
117418 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
117419 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
117420 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
117421 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
117422 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
117423 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
117424 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
117425 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642 nohasharray
117426 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &nl80211_send_connect_result_27642
117427 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
117428 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
117429 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
117430 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
117431 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
117432 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
117433 +evm_write_key_27715 evm_write_key 3 27715 NULL
117434 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
117435 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
117436 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
117437 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
117438 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
117439 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
117440 +SyS_readv_27804 SyS_readv 3 27804 NULL
117441 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
117442 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
117443 +init_header_complete_27833 init_header_complete 0 27833 NULL
117444 +read_profile_27859 read_profile 3 27859 NULL
117445 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
117446 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
117447 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
117448 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
117449 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
117450 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL nohasharray
117451 +bio_next_split_27961 bio_next_split 2 27961 &tracing_clock_write_27961
117452 +security_path_chown_27966 security_path_chown 0 27966 NULL
117453 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
117454 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
117455 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
117456 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
117457 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
117458 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
117459 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
117460 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
117461 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
117462 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
117463 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
117464 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
117465 +pool_status_28055 pool_status 5 28055 NULL
117466 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
117467 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
117468 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
117469 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
117470 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
117471 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
117472 +video_read_28148 video_read 3 28148 NULL
117473 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
117474 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
117475 +vread_28173 vread 0-3 28173 NULL
117476 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
117477 +counter_free_res_28187 counter_free_res 5 28187 NULL
117478 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
117479 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
117480 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
117481 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
117482 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
117483 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
117484 +usemap_size_28281 usemap_size 0 28281 NULL
117485 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
117486 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
117487 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
117488 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
117489 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
117490 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
117491 +security_inode_link_28327 security_inode_link 0 28327 NULL
117492 +generic_write_checks_28329 generic_write_checks 0 28329 NULL
117493 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
117494 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
117495 +snapshot_write_28351 snapshot_write 3 28351 NULL
117496 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
117497 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
117498 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
117499 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
117500 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
117501 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
117502 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
117503 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
117504 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
117505 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
117506 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
117507 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
117508 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
117509 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
117510 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
117511 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
117512 +aio_read_events_28545 aio_read_events 3 28545 &mptctl_getiocinfo_28545 nohasharray
117513 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &aio_read_events_28545
117514 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
117515 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
117516 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
117517 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
117518 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
117519 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
117520 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
117521 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 3-5 28622 NULL
117522 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
117523 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
117524 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
117525 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
117526 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
117527 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
117528 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
117529 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
117530 +spi_execute_28736 spi_execute 5 28736 NULL
117531 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
117532 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
117533 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
117534 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
117535 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
117536 +sel_write_member_28800 sel_write_member 3 28800 NULL
117537 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
117538 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
117539 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
117540 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
117541 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
117542 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
117543 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
117544 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
117545 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
117546 +push_rx_28939 push_rx 3 28939 NULL
117547 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
117548 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
117549 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
117550 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
117551 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
117552 +bin_uuid_28999 bin_uuid 3 28999 NULL
117553 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
117554 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
117555 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
117556 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
117557 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
117558 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
117559 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
117560 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
117561 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
117562 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
117563 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
117564 +snprintf_29125 snprintf 0 29125 NULL
117565 +iov_shorten_29130 iov_shorten 0 29130 NULL
117566 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
117567 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
117568 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
117569 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
117570 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
117571 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
117572 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
117573 +recover_peb_29238 recover_peb 0 29238 NULL
117574 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
117575 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
117576 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
117577 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
117578 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
117579 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
117580 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
117581 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
117582 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
117583 +tun_put_user_29337 tun_put_user 5 29337 NULL
117584 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
117585 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
117586 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
117587 +mempool_create_29437 mempool_create 1 29437 NULL
117588 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
117589 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
117590 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
117591 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
117592 +do_register_entry_29478 do_register_entry 4 29478 NULL
117593 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
117594 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
117595 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
117596 +i2c_add_adapter_29507 i2c_add_adapter 0 29507 NULL
117597 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
117598 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
117599 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
117600 +pci_enable_msix_29524 pci_enable_msix 0 29524 NULL
117601 +ftrace_write_29551 ftrace_write 3 29551 NULL
117602 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
117603 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
117604 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
117605 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
117606 +security_path_chmod_29578 security_path_chmod 0 29578 NULL
117607 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
117608 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
117609 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
117610 +slots_per_page_29601 slots_per_page 0 29601 NULL
117611 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
117612 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
117613 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
117614 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
117615 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
117616 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
117617 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
117618 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
117619 +probes_write_29711 probes_write 3 29711 NULL
117620 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
117621 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
117622 +std_nic_write_29752 std_nic_write 3 29752 NULL
117623 +tg3_irq_count_29786 tg3_irq_count 0 29786 NULL
117624 +dbAlloc_29794 dbAlloc 0 29794 NULL
117625 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
117626 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
117627 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
117628 +count_partial_29850 count_partial 0 29850 NULL
117629 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
117630 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
117631 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
117632 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
117633 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
117634 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
117635 +write_file_queue_29922 write_file_queue 3 29922 NULL
117636 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
117637 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
117638 +arch_setup_dmar_msi_29992 arch_setup_dmar_msi 0 29992 NULL
117639 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
117640 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
117641 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
117642 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
117643 +drp_wmove_30043 drp_wmove 4 30043 NULL
117644 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
117645 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
117646 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
117647 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
117648 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
117649 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
117650 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
117651 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
117652 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
117653 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
117654 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
117655 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
117656 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
117657 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
117658 +snd_pcm_playback_forward_30201 snd_pcm_playback_forward 0-2 30201 NULL
117659 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
117660 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
117661 +SyS_semop_30227 SyS_semop 3 30227 NULL
117662 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
117663 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
117664 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL nohasharray
117665 +try_break_deleg_30271 try_break_deleg 0 30271 &isr_pci_pm_read_30271
117666 +compat_readv_30273 compat_readv 3 30273 NULL
117667 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
117668 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
117669 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
117670 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
117671 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
117672 +i8254_read_30330 i8254_read 0 30330 NULL
117673 +resource_from_user_30341 resource_from_user 3 30341 NULL
117674 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
117675 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
117676 +pagecache_write_begin_30364 pagecache_write_begin 0 30364 NULL
117677 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
117678 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
117679 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
117680 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
117681 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
117682 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
117683 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
117684 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
117685 +enable_write_30456 enable_write 3 30456 NULL
117686 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
117687 +urandom_read_30462 urandom_read 3 30462 NULL
117688 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
117689 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
117690 +adu_write_30487 adu_write 3 30487 NULL
117691 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
117692 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
117693 +__send_duplicate_bios_30498 __send_duplicate_bios 4 30498 NULL
117694 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
117695 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
117696 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
117697 +ixgbevf_acquire_msix_vectors_30559 ixgbevf_acquire_msix_vectors 2 30559 NULL
117698 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
117699 +set_le_30581 set_le 4 30581 NULL
117700 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
117701 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
117702 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
117703 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
117704 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
117705 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
117706 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
117707 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
117708 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
117709 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
117710 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
117711 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
117712 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
117713 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 3-4 30727 NULL
117714 +snapshot_status_30744 snapshot_status 5 30744 NULL
117715 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
117716 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
117717 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
117718 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
117719 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
117720 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
117721 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
117722 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
117723 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
117724 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
117725 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
117726 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
117727 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
117728 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
117729 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
117730 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
117731 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
117732 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
117733 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
117734 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
117735 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
117736 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
117737 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
117738 +depth_read_31112 depth_read 3 31112 NULL
117739 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
117740 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
117741 +size_inside_page_31141 size_inside_page 0 31141 NULL
117742 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
117743 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
117744 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
117745 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
117746 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
117747 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
117748 +__read_reg_31216 __read_reg 0 31216 NULL
117749 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
117750 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
117751 +cyy_readb_31240 cyy_readb 0 31240 NULL
117752 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
117753 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
117754 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
117755 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
117756 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
117757 +command_file_write_31318 command_file_write 3 31318 NULL
117758 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
117759 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
117760 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
117761 +outlen_write_31358 outlen_write 3 31358 NULL
117762 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
117763 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
117764 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
117765 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
117766 +inb_31388 inb 0 31388 NULL
117767 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
117768 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
117769 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
117770 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
117771 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
117772 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
117773 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
117774 +alg_setkey_31485 alg_setkey 3 31485 NULL
117775 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
117776 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
117777 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
117778 +hidraw_write_31536 hidraw_write 3 31536 NULL
117779 +usbvision_read_31555 usbvision_read 3 31555 NULL
117780 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
117781 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
117782 +osst_write_31581 osst_write 3 31581 NULL
117783 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
117784 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
117785 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL nohasharray
117786 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 &arvo_sysfs_read_31617
117787 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
117788 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
117789 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
117790 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
117791 +__lgread_31668 __lgread 4 31668 NULL
117792 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
117793 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
117794 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
117795 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
117796 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
117797 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
117798 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
117799 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
117800 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
117801 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
117802 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
117803 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
117804 +osync_buffers_list_31789 osync_buffers_list 0 31789 NULL
117805 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
117806 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
117807 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
117808 +data_write_31805 data_write 3 31805 NULL
117809 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
117810 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
117811 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
117812 +clone_bio_31854 clone_bio 4-3 31854 NULL
117813 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
117814 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
117815 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
117816 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
117817 +xattr_permission_31907 xattr_permission 0 31907 NULL
117818 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
117819 +new_dir_31919 new_dir 3 31919 NULL
117820 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
117821 +era_status_31934 era_status 5 31934 NULL
117822 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
117823 +read_mem_31942 read_mem 3 31942 NULL nohasharray
117824 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
117825 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
117826 +vb2_write_31948 vb2_write 3 31948 NULL
117827 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
117828 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
117829 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
117830 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
117831 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
117832 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
117833 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
117834 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
117835 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
117836 +calc_hmac_32010 calc_hmac 3 32010 NULL
117837 +aead_len_32021 aead_len 0 32021 NULL nohasharray
117838 +aer_init_32021 aer_init 0 32021 &aead_len_32021
117839 +stk_read_32038 stk_read 3 32038 NULL
117840 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
117841 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
117842 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
117843 +bio_alloc_32095 bio_alloc 2 32095 NULL
117844 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
117845 +disk_status_32120 disk_status 4 32120 NULL
117846 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
117847 +venus_link_32165 venus_link 5 32165 NULL
117848 +do_writepages_32173 do_writepages 0 32173 NULL
117849 +del_ptr_32197 del_ptr 4 32197 NULL
117850 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
117851 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
117852 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
117853 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
117854 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
117855 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
117856 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
117857 +SyS_select_32319 SyS_select 1 32319 NULL
117858 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
117859 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
117860 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
117861 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
117862 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
117863 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
117864 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
117865 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
117866 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
117867 +snd_pcm_sync_ptr_32461 snd_pcm_sync_ptr 0 32461 NULL
117868 +cache_status_32462 cache_status 5 32462 NULL
117869 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
117870 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
117871 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
117872 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
117873 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
117874 +disconnect_32521 disconnect 4 32521 NULL
117875 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
117876 +ilo_read_32531 ilo_read 3 32531 NULL
117877 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
117878 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
117879 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
117880 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
117881 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
117882 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
117883 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
117884 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
117885 +__pci_request_region_32618 __pci_request_region 0 32618 NULL
117886 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
117887 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
117888 +kvmalloc_32646 kvmalloc 1 32646 NULL
117889 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
117890 +generic_readlink_32654 generic_readlink 3 32654 NULL
117891 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
117892 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
117893 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
117894 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
117895 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
117896 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
117897 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
117898 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
117899 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
117900 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
117901 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
117902 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
117903 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
117904 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
117905 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
117906 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
117907 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
117908 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
117909 +compat_filldir_32999 compat_filldir 3 32999 NULL
117910 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
117911 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
117912 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
117913 +snd_pcm_prepare_33036 snd_pcm_prepare 0 33036 NULL
117914 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
117915 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
117916 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
117917 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
117918 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
117919 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
117920 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
117921 +alloc_tio_33077 alloc_tio 3 33077 NULL
117922 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
117923 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
117924 +notify_change_33143 notify_change 0 33143 NULL
117925 +SyS_poll_33152 SyS_poll 2 33152 NULL
117926 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
117927 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
117928 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
117929 +pp_read_33210 pp_read 3 33210 NULL
117930 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
117931 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
117932 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
117933 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
117934 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
117935 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
117936 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
117937 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
117938 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
117939 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
117940 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
117941 +pvscsi_allocate_sg_33357 pvscsi_allocate_sg 0 33357 NULL
117942 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
117943 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
117944 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
117945 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
117946 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 2-3 33394 NULL
117947 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
117948 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
117949 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
117950 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
117951 +message_stats_list_33440 message_stats_list 5 33440 NULL
117952 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
117953 +create_entry_33479 create_entry 2 33479 NULL
117954 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
117955 +res_counter_read_33499 res_counter_read 4 33499 NULL
117956 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
117957 +fb_read_33506 fb_read 3 33506 NULL
117958 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
117959 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
117960 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
117961 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
117962 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
117963 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
117964 +count_subheaders_33591 count_subheaders 0 33591 NULL
117965 +scsi_execute_33596 scsi_execute 5 33596 NULL
117966 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
117967 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
117968 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
117969 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
117970 +stride_page_count_33641 stride_page_count 2 33641 NULL
117971 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
117972 +inw_p_33668 inw_p 0 33668 NULL
117973 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
117974 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
117975 +submit_one_bio_33683 submit_one_bio 0 33683 NULL
117976 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
117977 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
117978 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
117979 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
117980 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
117981 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
117982 +rtw_cbuf_alloc23a_33740 rtw_cbuf_alloc23a 1 33740 NULL
117983 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
117984 +hashtab_create_33769 hashtab_create 3 33769 NULL
117985 +i8042_create_aux_port_33777 i8042_create_aux_port 0 33777 NULL
117986 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
117987 +filter_write_33819 filter_write 3 33819 NULL
117988 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
117989 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
117990 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
117991 +snd_pcm_action_nonatomic_33844 snd_pcm_action_nonatomic 0 33844 NULL
117992 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
117993 +get_user_pages_33908 get_user_pages 0 33908 NULL
117994 +sg_nents_33909 sg_nents 0 33909 NULL
117995 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
117996 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
117997 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
117998 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
117999 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
118000 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
118001 +btrfs_delalloc_reserve_metadata_33963 btrfs_delalloc_reserve_metadata 0 33963 NULL
118002 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
118003 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
118004 +ppp_write_34034 ppp_write 3 34034 NULL
118005 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
118006 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
118007 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
118008 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
118009 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
118010 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
118011 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
118012 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
118013 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
118014 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
118015 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
118016 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL
118017 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
118018 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
118019 +device_private_init_34279 device_private_init 0 34279 NULL
118020 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
118021 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
118022 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
118023 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
118024 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
118025 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
118026 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 NULL nohasharray
118027 +ea_read_34378 ea_read 0 34378 &_iwl_dbgfs_low_latency_write_34378
118028 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
118029 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
118030 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
118031 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
118032 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
118033 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
118034 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
118035 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
118036 +__extent_read_full_page_34437 __extent_read_full_page 0 34437 NULL
118037 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
118038 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
118039 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
118040 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
118041 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
118042 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
118043 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
118044 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
118045 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL nohasharray
118046 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 &tracing_stats_read_34537
118047 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
118048 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
118049 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL nohasharray
118050 +self_check_peb_ec_hdr_34564 self_check_peb_ec_hdr 0 34564 &alloc_ieee80211_rsl_34564
118051 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
118052 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
118053 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
118054 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
118055 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
118056 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
118057 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL nohasharray
118058 +mtd_write_34609 mtd_write 0 34609 &__jffs2_ref_totlen_34609
118059 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
118060 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
118061 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
118062 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
118063 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
118064 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
118065 +port_print_34704 port_print 3 34704 NULL
118066 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
118067 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
118068 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
118069 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
118070 +bootmode_store_34762 bootmode_store 4 34762 NULL
118071 +device_add_34766 device_add 0 34766 NULL
118072 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
118073 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
118074 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
118075 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
118076 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
118077 +file_page_index_34820 file_page_index 0-2 34820 NULL
118078 +bio_segments_34832 bio_segments 0 34832 NULL
118079 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
118080 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
118081 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
118082 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
118083 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
118084 +msg_print_text_34889 msg_print_text 0 34889 NULL
118085 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
118086 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
118087 +__inode_permission_34925 __inode_permission 0 34925 NULL nohasharray
118088 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 &__inode_permission_34925
118089 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
118090 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
118091 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
118092 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
118093 +schedule_erase_34996 schedule_erase 0 34996 NULL
118094 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
118095 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
118096 +rtw_cfg80211_rx_p2p_action_public_35010 rtw_cfg80211_rx_p2p_action_public 3 35010 NULL
118097 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
118098 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
118099 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
118100 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
118101 +capi_write_35104 capi_write 3 35104 NULL nohasharray
118102 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
118103 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
118104 +message_stats_print_35158 message_stats_print 6 35158 NULL
118105 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
118106 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
118107 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
118108 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
118109 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 NULL nohasharray
118110 +striped_read_35218 striped_read 0-2 35218 &security_key_getsecurity_35218
118111 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
118112 +set_fd_set_35249 set_fd_set 1 35249 NULL
118113 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
118114 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
118115 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
118116 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
118117 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
118118 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
118119 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3-0 35311 NULL nohasharray
118120 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
118121 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
118122 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
118123 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
118124 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
118125 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
118126 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
118127 +read_kmem_35372 read_kmem 3 35372 NULL
118128 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
118129 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
118130 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
118131 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
118132 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
118133 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
118134 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
118135 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
118136 +async_setkey_35521 async_setkey 3 35521 NULL
118137 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
118138 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
118139 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
118140 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
118141 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
118142 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
118143 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
118144 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
118145 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
118146 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
118147 +kernel_readv_35617 kernel_readv 3 35617 NULL
118148 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
118149 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
118150 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
118151 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
118152 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
118153 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
118154 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
118155 +md_super_write_35703 md_super_write 4 35703 NULL
118156 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
118157 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
118158 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
118159 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
118160 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
118161 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
118162 +fls64_35862 fls64 0 35862 NULL
118163 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
118164 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
118165 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
118166 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
118167 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
118168 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
118169 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
118170 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
118171 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
118172 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
118173 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
118174 +acl_alloc_35979 acl_alloc 1 35979 NULL
118175 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
118176 +kuc_alloc_35998 kuc_alloc 1 35998 NULL nohasharray
118177 +write_file_antenna_35998 write_file_antenna 3 35998 &kuc_alloc_35998
118178 +scsi_transfer_length_36011 scsi_transfer_length 0 36011 NULL
118179 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
118180 +ubi_eba_write_leb_36029 ubi_eba_write_leb 0 36029 NULL
118181 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
118182 +account_shadowed_36048 account_shadowed 2 36048 NULL
118183 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
118184 +snd_pcm_playback_hw_avail_36061 snd_pcm_playback_hw_avail 0 36061 NULL
118185 +write_emulate_36065 write_emulate 2-4 36065 NULL
118186 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
118187 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
118188 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
118189 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
118190 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
118191 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
118192 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
118193 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
118194 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
118195 +twl_set_36154 twl_set 2 36154 NULL
118196 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
118197 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
118198 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
118199 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
118200 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
118201 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
118202 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
118203 +rtw_cfg80211_set_wpa_ie_36236 rtw_cfg80211_set_wpa_ie 3 36236 NULL
118204 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
118205 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
118206 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
118207 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
118208 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL nohasharray
118209 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 &cfs_hash_buckets_realloc_36276
118210 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
118211 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
118212 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
118213 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
118214 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
118215 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 NULL nohasharray
118216 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 &__compat_sys_pwritev64_36328
118217 +lc_create_36332 lc_create 4 36332 NULL
118218 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
118219 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
118220 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
118221 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
118222 +to_sector_36361 to_sector 0-1 36361 NULL
118223 +tunables_read_36385 tunables_read 3 36385 NULL
118224 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
118225 +sierra_write_36402 sierra_write 4 36402 NULL
118226 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
118227 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
118228 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
118229 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
118230 +lock_and_cleanup_extent_if_need_36480 lock_and_cleanup_extent_if_need 0 36480 NULL
118231 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
118232 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
118233 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
118234 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
118235 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
118236 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
118237 +get_param_l_36518 get_param_l 0 36518 NULL
118238 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
118239 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
118240 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
118241 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
118242 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
118243 +__erst_read_36579 __erst_read 0 36579 NULL
118244 +put_cmsg_36589 put_cmsg 4 36589 NULL
118245 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
118246 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
118247 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
118248 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
118249 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
118250 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
118251 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
118252 +xillybus_read_36678 xillybus_read 3 36678 NULL
118253 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
118254 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
118255 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
118256 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
118257 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
118258 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
118259 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
118260 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
118261 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
118262 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
118263 +cm_write_36858 cm_write 3 36858 NULL
118264 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
118265 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
118266 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
118267 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
118268 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
118269 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
118270 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
118271 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
118272 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
118273 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
118274 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
118275 +setxattr_37006 setxattr 4 37006 NULL
118276 +command_file_read_37038 command_file_read 3 37038 NULL
118277 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
118278 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
118279 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
118280 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
118281 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
118282 +parse_command_37079 parse_command 2 37079 NULL
118283 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
118284 +tun_get_user_37094 tun_get_user 5 37094 NULL
118285 +has_wrprotected_page_37123 has_wrprotected_page 2-3 37123 NULL
118286 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
118287 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
118288 +msg_word_37164 msg_word 0 37164 NULL
118289 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
118290 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
118291 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
118292 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
118293 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 4-0 37212 &crypto_shash_descsize_37212
118294 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
118295 +__do_replace_37227 __do_replace 5 37227 NULL
118296 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
118297 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
118298 +prot_queue_del_37258 prot_queue_del 0 37258 NULL
118299 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
118300 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
118301 +request_threaded_irq_37303 request_threaded_irq 0 37303 NULL
118302 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
118303 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
118304 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
118305 +tipc_send_37315 tipc_send 3 37315 NULL
118306 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
118307 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
118308 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
118309 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
118310 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
118311 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
118312 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
118313 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
118314 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
118315 +fru_alloc_37442 fru_alloc 1 37442 NULL
118316 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
118317 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
118318 +get_est_timing_37484 get_est_timing 0 37484 NULL
118319 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
118320 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
118321 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
118322 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
118323 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
118324 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
118325 +hdr_size_37536 hdr_size 0 37536 NULL
118326 +extent_map_end_37550 extent_map_end 0 37550 NULL
118327 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
118328 +fat_cont_expand_37552 fat_cont_expand 0 37552 NULL
118329 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
118330 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
118331 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
118332 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
118333 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
118334 +may_delete_37656 may_delete 0 37656 NULL
118335 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
118336 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
118337 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
118338 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
118339 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
118340 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
118341 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
118342 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
118343 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
118344 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
118345 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
118346 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
118347 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
118348 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
118349 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
118350 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
118351 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
118352 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
118353 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
118354 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
118355 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
118356 +set_registers_37883 set_registers 4 37883 NULL
118357 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
118358 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
118359 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
118360 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
118361 +write_file_bool_37957 write_file_bool 3 37957 NULL
118362 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
118363 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
118364 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
118365 +vfs_readv_38011 vfs_readv 3 38011 NULL
118366 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
118367 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
118368 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
118369 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
118370 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
118371 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
118372 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
118373 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
118374 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 NULL nohasharray
118375 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 &wcn36xx_smd_rsp_process_38081
118376 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
118377 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
118378 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
118379 +ep0_read_38095 ep0_read 3 38095 NULL
118380 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
118381 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
118382 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
118383 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
118384 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
118385 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 4-3-0 38153 NULL
118386 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
118387 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
118388 +cdev_add_38176 cdev_add 2-3 38176 NULL
118389 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
118390 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
118391 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
118392 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
118393 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
118394 +snd_pcm_playback_rewind_38249 snd_pcm_playback_rewind 0-2 38249 NULL
118395 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
118396 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268
118397 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
118398 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
118399 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
118400 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
118401 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
118402 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
118403 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
118404 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
118405 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
118406 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
118407 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
118408 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
118409 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
118410 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
118411 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
118412 +dev_names_read_38509 dev_names_read 3 38509 NULL
118413 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
118414 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
118415 +set_queue_count_38519 set_queue_count 0 38519 NULL
118416 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
118417 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
118418 +kuc_len_38557 kuc_len 0-1 38557 NULL
118419 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
118420 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
118421 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
118422 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 3-5 38567 NULL
118423 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
118424 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
118425 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
118426 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
118427 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
118428 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
118429 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
118430 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
118431 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
118432 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
118433 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
118434 +validate_vid_hdr_38699 validate_vid_hdr 0 38699 NULL
118435 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
118436 +udf_readpages_38761 udf_readpages 4 38761 NULL
118437 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
118438 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
118439 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
118440 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
118441 +err_decode_38804 err_decode 2 38804 NULL
118442 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
118443 +direct_entry_38836 direct_entry 3 38836 NULL
118444 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
118445 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
118446 +interfaces_38859 interfaces 2 38859 NULL
118447 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
118448 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
118449 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
118450 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
118451 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
118452 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
118453 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
118454 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
118455 +get_nodes_39012 get_nodes 3 39012 NULL
118456 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
118457 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
118458 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
118459 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
118460 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
118461 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
118462 +leb_write_lock_39111 leb_write_lock 0 39111 NULL
118463 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
118464 +ea_foreach_39133 ea_foreach 0 39133 NULL
118465 +generic_permission_39150 generic_permission 0 39150 NULL
118466 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
118467 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
118468 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
118469 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
118470 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
118471 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
118472 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
118473 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
118474 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 0-2 39248 NULL
118475 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
118476 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
118477 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
118478 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
118479 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
118480 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
118481 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
118482 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
118483 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
118484 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
118485 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
118486 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
118487 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
118488 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
118489 +__send_to_port_39386 __send_to_port 3 39386 NULL
118490 +user_power_read_39414 user_power_read 3 39414 NULL
118491 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
118492 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
118493 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
118494 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
118495 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
118496 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
118497 +int_proc_write_39542 int_proc_write 3 39542 NULL
118498 +ext4_alloc_file_blocks_39551 ext4_alloc_file_blocks 3 39551 NULL
118499 +pp_write_39554 pp_write 3 39554 NULL
118500 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
118501 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
118502 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
118503 +ext_depth_39607 ext_depth 0 39607 NULL
118504 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
118505 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
118506 +sdio_readb_39618 sdio_readb 0 39618 NULL
118507 +prepare_uptodate_page_39622 prepare_uptodate_page 0 39622 NULL
118508 +set_dev_class_39645 set_dev_class 4 39645 NULL
118509 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
118510 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
118511 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
118512 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
118513 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
118514 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
118515 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
118516 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
118517 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
118518 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
118519 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
118520 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
118521 +pkt_add_39897 pkt_add 3 39897 NULL
118522 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
118523 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
118524 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
118525 +__mnt_want_write_file_39917 __mnt_want_write_file 0 39917 NULL
118526 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
118527 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
118528 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
118529 +__spi_async_39932 __spi_async 0 39932 NULL
118530 +__get_order_39935 __get_order 0 39935 NULL
118531 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
118532 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
118533 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
118534 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
118535 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
118536 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
118537 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
118538 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
118539 +server_name2svname_39998 server_name2svname 4 39998 NULL
118540 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
118541 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
118542 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
118543 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
118544 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
118545 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
118546 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
118547 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
118548 +snd_pcm_sw_params_user_40095 snd_pcm_sw_params_user 0 40095 NULL
118549 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
118550 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
118551 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
118552 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
118553 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
118554 +pt_write_40159 pt_write 3 40159 NULL
118555 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
118556 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
118557 +allocate_probes_40204 allocate_probes 1 40204 NULL
118558 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
118559 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
118560 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
118561 +osst_read_40237 osst_read 3 40237 NULL
118562 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
118563 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4 40248 NULL
118564 +of_get_child_count_40254 of_get_child_count 0 40254 NULL
118565 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
118566 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
118567 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
118568 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
118569 +SyS_bind_40303 SyS_bind 3 40303 NULL
118570 +ubi_io_write_data_40305 ubi_io_write_data 0 40305 NULL
118571 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
118572 +mmio_read_40348 mmio_read 4 40348 NULL
118573 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
118574 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 2-3 40365 NULL
118575 +get_chars_40373 get_chars 3 40373 NULL
118576 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
118577 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
118578 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
118579 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
118580 +SyS_writev_40467 SyS_writev 3 40467 NULL
118581 +SyS_select_40473 SyS_select 1 40473 NULL
118582 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
118583 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
118584 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
118585 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
118586 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
118587 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
118588 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
118589 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
118590 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
118591 +i2c_register_adapter_40660 i2c_register_adapter 0 40660 NULL
118592 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
118593 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
118594 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
118595 +fops_read_40672 fops_read 3 40672 NULL
118596 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
118597 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
118598 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
118599 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
118600 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
118601 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
118602 +set_extent_bit_40719 set_extent_bit 0 40719 NULL
118603 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
118604 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
118605 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
118606 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
118607 +card_send_command_40757 card_send_command 3 40757 NULL
118608 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
118609 +pg_write_40766 pg_write 3 40766 NULL
118610 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
118611 +show_list_40775 show_list 3-0 40775 NULL
118612 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
118613 +bitmap_weight_40791 bitmap_weight 0 40791 NULL
118614 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
118615 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
118616 +add_action_40811 add_action 4 40811 NULL
118617 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
118618 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
118619 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
118620 +read_file_queue_40895 read_file_queue 3 40895 NULL
118621 +waiters_read_40902 waiters_read 3 40902 NULL
118622 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
118623 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
118624 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
118625 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
118626 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
118627 +insert_old_idx_40987 insert_old_idx 0 40987 NULL
118628 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
118629 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
118630 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
118631 +mtd_block_isbad_41015 mtd_block_isbad 0 41015 NULL
118632 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
118633 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
118634 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
118635 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
118636 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
118637 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
118638 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
118639 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
118640 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
118641 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
118642 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
118643 +dma_attach_41094 dma_attach 5-6 41094 NULL
118644 +provide_user_output_41105 provide_user_output 3 41105 NULL
118645 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
118646 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
118647 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
118648 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
118649 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
118650 +netif_get_num_default_rss_queues_41187 netif_get_num_default_rss_queues 0 41187 NULL
118651 +request_irq_41192 request_irq 0 41192 NULL
118652 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
118653 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
118654 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
118655 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
118656 +erst_read_41260 erst_read 0 41260 NULL
118657 +alloc_context_41283 alloc_context 1 41283 NULL
118658 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
118659 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
118660 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
118661 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
118662 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
118663 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
118664 +kmp_init_41373 kmp_init 2 41373 NULL
118665 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
118666 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
118667 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
118668 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
118669 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
118670 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
118671 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
118672 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
118673 +se_io_cb_41461 se_io_cb 3 41461 NULL
118674 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
118675 +snd_pcm_status_41472 snd_pcm_status 0 41472 NULL
118676 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
118677 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
118678 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
118679 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
118680 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
118681 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
118682 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
118683 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
118684 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
118685 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
118686 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
118687 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
118688 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
118689 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
118690 +vga_io_r_41609 vga_io_r 0 41609 NULL
118691 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
118692 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 NULL nohasharray
118693 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 &usb_endpoint_maxp_41613
118694 +a2mp_send_41615 a2mp_send 4 41615 NULL
118695 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
118696 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
118697 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
118698 +get_std_timing_41654 get_std_timing 0 41654 NULL
118699 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
118700 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
118701 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
118702 +fillonedir_41746 fillonedir 3 41746 NULL
118703 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
118704 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
118705 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
118706 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
118707 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
118708 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
118709 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
118710 +pci_map_single_41869 pci_map_single 0 41869 NULL
118711 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
118712 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
118713 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
118714 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
118715 +read_gssp_41947 read_gssp 3 41947 NULL
118716 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
118717 +portnames_read_41958 portnames_read 3 41958 NULL
118718 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 0 41959 NULL
118719 +dst_mtu_41969 dst_mtu 0 41969 NULL
118720 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
118721 +ubi_io_is_bad_41983 ubi_io_is_bad 0 41983 NULL
118722 +pool_allocate_42012 pool_allocate 3 42012 NULL
118723 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
118724 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
118725 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
118726 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
118727 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
118728 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
118729 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
118730 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
118731 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
118732 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
118733 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
118734 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
118735 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
118736 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
118737 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
118738 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
118739 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
118740 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
118741 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
118742 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
118743 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
118744 +find_last_bit_42260 find_last_bit 0 42260 NULL
118745 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
118746 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
118747 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
118748 +__cpus_weight_42299 __cpus_weight 0 42299 NULL
118749 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
118750 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
118751 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
118752 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
118753 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
118754 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
118755 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
118756 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
118757 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
118758 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
118759 +krng_get_random_42420 krng_get_random 3 42420 NULL
118760 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
118761 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
118762 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
118763 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
118764 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
118765 +kuc_free_42455 kuc_free 2 42455 NULL
118766 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
118767 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
118768 +bypass_write_42498 bypass_write 3 42498 NULL
118769 +SyS_mincore_42511 SyS_mincore 2-1 42511 NULL
118770 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
118771 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
118772 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
118773 +self_check_ec_hdr_42528 self_check_ec_hdr 0 42528 NULL
118774 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
118775 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
118776 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
118777 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
118778 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
118779 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
118780 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
118781 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
118782 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
118783 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
118784 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
118785 +vb2_read_42703 vb2_read 3 42703 NULL
118786 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
118787 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
118788 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
118789 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
118790 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
118791 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
118792 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
118793 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
118794 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
118795 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
118796 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
118797 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
118798 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
118799 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
118800 +set_arg_42824 set_arg 3 42824 NULL
118801 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
118802 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
118803 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
118804 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
118805 +hd_end_request_42904 hd_end_request 2 42904 NULL
118806 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
118807 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
118808 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
118809 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
118810 +ntb_setup_snb_msix_42971 ntb_setup_snb_msix 2-0 42971 NULL
118811 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
118812 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
118813 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
118814 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
118815 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
118816 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
118817 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
118818 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
118819 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
118820 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
118821 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
118822 +e1000_request_msix_43134 e1000_request_msix 0 43134 NULL
118823 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
118824 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
118825 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
118826 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
118827 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
118828 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
118829 +uio_write_43202 uio_write 3 43202 NULL
118830 +iso_callback_43208 iso_callback 3 43208 NULL
118831 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
118832 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
118833 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
118834 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
118835 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
118836 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
118837 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
118838 +evtchn_write_43278 evtchn_write 3 43278 NULL
118839 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
118840 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
118841 +mmu_set_spte_43327 mmu_set_spte 6-7 43327 NULL
118842 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
118843 +xenfb_write_43412 xenfb_write 3 43412 NULL
118844 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
118845 +msi_capability_init_43423 msi_capability_init 0 43423 &__alloc_bootmem_low_43423
118846 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
118847 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
118848 +usb_string_43443 usb_string 0 43443 NULL nohasharray
118849 +usemap_size_43443 usemap_size 0-1-2 43443 &usb_string_43443
118850 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
118851 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
118852 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
118853 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
118854 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
118855 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
118856 +read_events_43534 read_events 3 43534 NULL
118857 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
118858 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
118859 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
118860 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
118861 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
118862 +proc_read_43614 proc_read 3 43614 NULL
118863 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
118864 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
118865 +random_write_43656 random_write 3 43656 NULL
118866 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
118867 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
118868 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
118869 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
118870 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
118871 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
118872 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
118873 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
118874 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
118875 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
118876 +generic_file_direct_write_43770 generic_file_direct_write 0 43770 NULL
118877 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
118878 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
118879 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1-0 43806 NULL
118880 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
118881 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
118882 +read_flush_43851 read_flush 3 43851 NULL
118883 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
118884 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
118885 +SendString_43928 SendString 3 43928 NULL
118886 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
118887 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
118888 +nla_reserve_43984 nla_reserve 3 43984 NULL
118889 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
118890 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
118891 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992 nohasharray
118892 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &bcm_recvmsg_43992
118893 +ulist_add_43994 ulist_add 0 43994 NULL
118894 +emit_flags_44006 emit_flags 4-3 44006 NULL
118895 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
118896 +fru_strlen_44046 fru_strlen 0 44046 NULL
118897 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
118898 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
118899 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
118900 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
118901 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
118902 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL nohasharray
118903 +file_remove_suid_44122 file_remove_suid 0 44122 &tracing_set_trace_read_44122
118904 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
118905 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
118906 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
118907 +ubifs_find_dirty_idx_leb_44169 ubifs_find_dirty_idx_leb 0 44169 NULL
118908 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
118909 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
118910 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
118911 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
118912 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
118913 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
118914 +device_create_file_44285 device_create_file 0 44285 NULL
118915 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
118916 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
118917 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
118918 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
118919 +rs_init_44327 rs_init 1 44327 NULL
118920 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
118921 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
118922 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
118923 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
118924 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
118925 +strlcpy_44400 strlcpy 3 44400 NULL
118926 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
118927 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
118928 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
118929 +write_file_debug_44476 write_file_debug 3 44476 NULL
118930 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
118931 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
118932 +bio_advance_44496 bio_advance 2 44496 NULL
118933 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
118934 +ac_register_board_44504 ac_register_board 3 44504 NULL
118935 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
118936 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
118937 +spidev_write_44510 spidev_write 3 44510 NULL
118938 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
118939 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
118940 +comm_write_44537 comm_write 3 44537 NULL
118941 +snd_pcm_drop_44542 snd_pcm_drop 0 44542 NULL
118942 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
118943 +btrfs_set_extent_delalloc_44587 btrfs_set_extent_delalloc 0 44587 NULL
118944 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
118945 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
118946 +mpi_resize_44674 mpi_resize 2 44674 NULL
118947 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
118948 +ts_read_44687 ts_read 3 44687 NULL
118949 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
118950 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
118951 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
118952 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
118953 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
118954 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
118955 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
118956 +efx_wanted_parallelism_44732 efx_wanted_parallelism 0 44732 NULL
118957 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
118958 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
118959 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
118960 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
118961 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
118962 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
118963 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
118964 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
118965 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
118966 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
118967 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
118968 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
118969 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
118970 +sisusb_write_44834 sisusb_write 3 44834 NULL
118971 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
118972 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
118973 +copydesc_user_44855 copydesc_user 3 44855 NULL
118974 +set_advertising_44870 set_advertising 4 44870 NULL
118975 +init_rs_44873 init_rs 1 44873 NULL
118976 +skb_availroom_44883 skb_availroom 0 44883 NULL
118977 +do_tty_write_44896 do_tty_write 5 44896 NULL
118978 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
118979 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
118980 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
118981 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
118982 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
118983 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
118984 +sel_write_user_45060 sel_write_user 3 45060 NULL
118985 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
118986 +snd_card_new_45104 snd_card_new 5 45104 NULL
118987 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
118988 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
118989 +usbdev_read_45114 usbdev_read 3 45114 NULL
118990 +send_to_tty_45141 send_to_tty 3 45141 NULL
118991 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
118992 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
118993 +device_write_45156 device_write 3 45156 NULL nohasharray
118994 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3 45156 &device_write_45156
118995 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
118996 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
118997 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 NULL nohasharray
118998 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 &sctp_pack_cookie_45190
118999 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
119000 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
119001 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
119002 +event_enable_write_45238 event_enable_write 3 45238 NULL
119003 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
119004 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
119005 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
119006 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
119007 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
119008 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
119009 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
119010 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
119011 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
119012 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
119013 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
119014 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
119015 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
119016 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
119017 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
119018 +snd_pcm_hwsync_45479 snd_pcm_hwsync 0 45479 NULL
119019 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
119020 +copy_macs_45534 copy_macs 4 45534 NULL
119021 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
119022 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
119023 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
119024 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
119025 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
119026 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
119027 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
119028 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
119029 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
119030 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
119031 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
119032 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
119033 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
119034 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
119035 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
119036 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
119037 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
119038 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
119039 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
119040 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
119041 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
119042 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
119043 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
119044 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
119045 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
119046 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
119047 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
119048 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
119049 +insert_state_45848 insert_state 0 45848 NULL
119050 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
119051 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
119052 +isdn_write_45863 isdn_write 3 45863 NULL
119053 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
119054 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
119055 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
119056 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
119057 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
119058 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
119059 +alloc_mr_45935 alloc_mr 1 45935 NULL
119060 +copy_to_45969 copy_to 3 45969 NULL
119061 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
119062 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
119063 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
119064 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
119065 +get_free_entries_46030 get_free_entries 1 46030 NULL nohasharray
119066 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 &get_free_entries_46030
119067 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
119068 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
119069 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
119070 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
119071 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
119072 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
119073 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
119074 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
119075 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
119076 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
119077 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
119078 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
119079 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
119080 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
119081 +fq_resize_46195 fq_resize 2 46195 NULL
119082 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
119083 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
119084 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
119085 +dsp_write_46218 dsp_write 2 46218 NULL
119086 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
119087 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
119088 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
119089 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
119090 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
119091 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 NULL nohasharray
119092 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 &compat_SyS_readv_46328
119093 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
119094 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
119095 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
119096 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
119097 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
119098 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
119099 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
119100 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
119101 +filldir64_46469 filldir64 3 46469 NULL
119102 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
119103 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
119104 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
119105 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 NULL nohasharray
119106 +kmsg_read_46514 kmsg_read 3 46514 &nouveau_drm_ioctl_46514
119107 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
119108 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
119109 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
119110 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
119111 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
119112 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
119113 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
119114 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
119115 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
119116 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
119117 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
119118 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
119119 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
119120 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
119121 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
119122 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
119123 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
119124 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
119125 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
119126 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
119127 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
119128 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
119129 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
119130 +spi_async_46857 spi_async 0 46857 NULL
119131 +vsnprintf_46863 vsnprintf 0 46863 NULL
119132 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
119133 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
119134 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
119135 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
119136 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
119137 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
119138 +wlcore_alloc_hw_46917 wlcore_alloc_hw 3-1 46917 NULL
119139 +fb_write_46924 fb_write 3 46924 NULL
119140 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
119141 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
119142 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
119143 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
119144 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
119145 +strlcat_46985 strlcat 3 46985 NULL
119146 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
119147 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
119148 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
119149 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
119150 +fs_path_len_47060 fs_path_len 0 47060 NULL
119151 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
119152 +ext4_xattr_list_entries_47070 ext4_xattr_list_entries 0 47070 NULL
119153 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
119154 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
119155 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
119156 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
119157 +mousedev_read_47123 mousedev_read 3 47123 NULL
119158 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
119159 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
119160 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
119161 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
119162 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
119163 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
119164 +options_write_47243 options_write 3 47243 NULL
119165 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
119166 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
119167 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
119168 +vsnprintf_47291 vsnprintf 0 47291 NULL
119169 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
119170 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
119171 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
119172 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
119173 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
119174 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
119175 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
119176 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
119177 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
119178 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
119179 +nametbl_list_47391 nametbl_list 2 47391 NULL
119180 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
119181 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
119182 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
119183 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
119184 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
119185 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
119186 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
119187 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
119188 +newpart_47485 newpart 6-4 47485 NULL
119189 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
119190 +core_sys_select_47494 core_sys_select 1 47494 NULL
119191 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
119192 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
119193 +unlink_simple_47506 unlink_simple 3 47506 NULL
119194 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
119195 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
119196 +snd_pcm_resume_47530 snd_pcm_resume 0 47530 NULL
119197 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
119198 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
119199 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
119200 +rtw_cfg80211_set_assoc_resp_wpsp2pie_47558 rtw_cfg80211_set_assoc_resp_wpsp2pie 3 47558 NULL
119201 +read_ldt_47570 read_ldt 2 47570 NULL
119202 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
119203 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
119204 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
119205 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
119206 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
119207 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
119208 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
119209 +get_size_47644 get_size 1-2 47644 NULL
119210 +snd_pcm_info_47699 snd_pcm_info 0 47699 NULL
119211 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
119212 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
119213 +save_microcode_47717 save_microcode 3 47717 NULL
119214 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
119215 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
119216 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
119217 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
119218 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
119219 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
119220 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
119221 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
119222 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
119223 +lov_packmd_47810 lov_packmd 0 47810 NULL
119224 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
119225 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
119226 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
119227 +vhci_read_47878 vhci_read 3 47878 NULL
119228 +ubi_wl_put_peb_47886 ubi_wl_put_peb 0 47886 NULL
119229 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
119230 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
119231 +comedi_write_47926 comedi_write 3 47926 NULL
119232 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
119233 +arch_setup_msi_irq_47959 arch_setup_msi_irq 0 47959 NULL
119234 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
119235 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
119236 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
119237 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
119238 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
119239 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
119240 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
119241 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
119242 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
119243 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
119244 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
119245 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
119246 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
119247 +disc_write_48070 disc_write 3 48070 NULL
119248 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
119249 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
119250 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
119251 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
119252 +set_discoverable_48141 set_discoverable 4 48141 NULL
119253 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
119254 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
119255 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
119256 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
119257 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
119258 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
119259 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
119260 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
119261 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
119262 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
119263 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
119264 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
119265 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
119266 +read_file_recv_48232 read_file_recv 3 48232 NULL
119267 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
119268 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
119269 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
119270 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
119271 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
119272 +trace_options_write_48275 trace_options_write 3 48275 NULL
119273 +send_set_info_48288 send_set_info 7 48288 NULL
119274 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
119275 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
119276 +hash_setkey_48310 hash_setkey 3 48310 NULL
119277 +skb_add_data_48363 skb_add_data 3 48363 NULL
119278 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
119279 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
119280 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
119281 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
119282 +snd_power_wait_48422 snd_power_wait 0 48422 NULL
119283 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
119284 +print_filtered_48442 print_filtered 2-0 48442 NULL
119285 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
119286 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
119287 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
119288 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
119289 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
119290 +send_control_msg_48498 send_control_msg 6 48498 NULL
119291 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
119292 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
119293 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
119294 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
119295 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
119296 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
119297 +llog_data_len_48607 llog_data_len 1 48607 NULL
119298 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
119299 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
119300 +mtd_read_48655 mtd_read 0 48655 NULL
119301 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
119302 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
119303 +ubi_eba_unmap_leb_48671 ubi_eba_unmap_leb 0 48671 NULL
119304 +security_inode_setattr_48689 security_inode_setattr 0 48689 NULL
119305 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
119306 +altera_drscan_48698 altera_drscan 2 48698 NULL
119307 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
119308 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
119309 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
119310 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
119311 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
119312 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
119313 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
119314 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
119315 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
119316 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
119317 +azx_get_position_48841 azx_get_position 0 48841 NULL
119318 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
119319 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
119320 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
119321 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
119322 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
119323 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
119324 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
119325 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
119326 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
119327 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
119328 +snd_pcm_update_hw_ptr_48925 snd_pcm_update_hw_ptr 0 48925 NULL
119329 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
119330 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
119331 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
119332 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
119333 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
119334 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
119335 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
119336 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
119337 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
119338 +transient_status_49027 transient_status 4 49027 NULL
119339 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
119340 +scsi_register_49094 scsi_register 2 49094 NULL
119341 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
119342 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
119343 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
119344 +pt_read_49136 pt_read 3 49136 NULL nohasharray
119345 +netxen_setup_msi_interrupts_49136 netxen_setup_msi_interrupts 2 49136 &pt_read_49136
119346 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
119347 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
119348 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
119349 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
119350 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
119351 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
119352 +print_queue_49191 print_queue 0-4 49191 NULL
119353 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
119354 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
119355 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
119356 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
119357 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
119358 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
119359 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
119360 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
119361 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
119362 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
119363 +uio_read_49300 uio_read 3 49300 NULL
119364 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
119365 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
119366 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
119367 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
119368 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
119369 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
119370 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
119371 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
119372 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
119373 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
119374 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
119375 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
119376 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
119377 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
119378 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
119379 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
119380 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
119381 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
119382 +smk_write_access_49561 smk_write_access 3 49561 NULL
119383 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
119384 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
119385 +evm_inode_setattr_49594 evm_inode_setattr 0 49594 NULL
119386 +tap_write_49595 tap_write 3 49595 NULL
119387 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
119388 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
119389 +heap_init_49617 heap_init 2 49617 NULL
119390 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
119391 +port_fops_read_49626 port_fops_read 3 49626 NULL
119392 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
119393 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
119394 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
119395 +__setup_irq_49696 __setup_irq 0 49696 NULL
119396 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
119397 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
119398 +write_pool_49718 write_pool 3 49718 NULL
119399 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
119400 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
119401 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
119402 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
119403 +fuse_wr_pages_49753 fuse_wr_pages 0-2-1 49753 NULL
119404 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
119405 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
119406 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
119407 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
119408 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
119409 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 6-3-0 49829 NULL
119410 +add_uuid_49831 add_uuid 4 49831 NULL
119411 +twl4030_write_49846 twl4030_write 2 49846 NULL
119412 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
119413 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
119414 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
119415 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
119416 +osc_brw_49896 osc_brw 4 49896 NULL
119417 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
119418 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
119419 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
119420 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
119421 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
119422 +isdn_read_50021 isdn_read 3 50021 NULL
119423 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
119424 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
119425 +ioread8_50049 ioread8 0 50049 NULL
119426 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
119427 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
119428 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
119429 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
119430 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
119431 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
119432 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
119433 +read_file_slot_50111 read_file_slot 3 50111 NULL
119434 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
119435 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
119436 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
119437 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
119438 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
119439 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
119440 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
119441 +odev_update_50169 odev_update 2 50169 NULL
119442 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
119443 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
119444 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
119445 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
119446 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
119447 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
119448 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
119449 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
119450 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
119451 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
119452 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
119453 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
119454 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
119455 +do_launder_page_50329 do_launder_page 0 50329 NULL
119456 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
119457 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
119458 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
119459 +tpm_read_50344 tpm_read 3 50344 NULL
119460 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
119461 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
119462 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
119463 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
119464 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
119465 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
119466 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
119467 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
119468 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
119469 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
119470 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
119471 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
119472 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
119473 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
119474 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
119475 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
119476 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
119477 +self_check_peb_vid_hdr_50563 self_check_peb_vid_hdr 0 50563 NULL
119478 +fat_readpages_50582 fat_readpages 4 50582 NULL
119479 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
119480 +xillybus_write_50605 xillybus_write 3 50605 NULL
119481 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
119482 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
119483 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
119484 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
119485 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
119486 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
119487 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
119488 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
119489 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
119490 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
119491 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
119492 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
119493 +bio_alloc_map_data_50782 bio_alloc_map_data 2 50782 NULL
119494 +ixgbe_acquire_msix_vectors_50789 ixgbe_acquire_msix_vectors 2 50789 NULL
119495 +tpm_write_50798 tpm_write 3 50798 NULL
119496 +tun_do_read_50800 tun_do_read 4 50800 NULL
119497 +write_flush_50803 write_flush 3 50803 NULL
119498 +dvb_play_50814 dvb_play 3 50814 NULL
119499 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
119500 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
119501 +SetArea_50835 SetArea 4 50835 NULL
119502 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
119503 +self_check_write_50856 self_check_write 0 50856 NULL
119504 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
119505 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
119506 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
119507 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
119508 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
119509 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
119510 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
119511 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
119512 +show_device_status_50947 show_device_status 0 50947 NULL
119513 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
119514 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
119515 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
119516 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
119517 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
119518 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
119519 +timeout_write_50991 timeout_write 3 50991 NULL
119520 +proc_write_51003 proc_write 3 51003 NULL
119521 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
119522 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
119523 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
119524 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
119525 +dump_midi_51040 dump_midi 3 51040 NULL
119526 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
119527 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
119528 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
119529 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
119530 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
119531 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
119532 +ti_recv_51110 ti_recv 3 51110 NULL
119533 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
119534 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
119535 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
119536 +snd_pcm_unlink_51210 snd_pcm_unlink 0 51210 NULL
119537 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
119538 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
119539 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
119540 +drm_property_create_51239 drm_property_create 4 51239 NULL
119541 +st_read_51251 st_read 3 51251 NULL
119542 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
119543 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
119544 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
119545 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
119546 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
119547 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
119548 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
119549 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
119550 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
119551 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
119552 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
119553 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
119554 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
119555 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
119556 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
119557 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
119558 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
119559 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
119560 +vmxnet3_acquire_msix_vectors_51462 vmxnet3_acquire_msix_vectors 2 51462 NULL
119561 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
119562 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
119563 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
119564 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
119565 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
119566 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
119567 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
119568 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
119569 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
119570 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
119571 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
119572 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
119573 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
119574 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
119575 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
119576 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
119577 +sel_write_access_51704 sel_write_access 3 51704 NULL
119578 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
119579 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
119580 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
119581 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
119582 +cm4040_read_51732 cm4040_read 3 51732 NULL
119583 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
119584 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
119585 +if_write_51756 if_write 3 51756 NULL
119586 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
119587 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
119588 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
119589 +ioread32_51847 ioread32 0 51847 NULL nohasharray
119590 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
119591 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
119592 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
119593 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
119594 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
119595 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
119596 +user_read_51881 user_read 3 51881 NULL
119597 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
119598 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
119599 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
119600 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
119601 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
119602 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
119603 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
119604 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
119605 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
119606 +get_zone_51981 get_zone 0-1 51981 NULL
119607 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
119608 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
119609 +scsi_sysfs_add_host_52010 scsi_sysfs_add_host 0 52010 NULL
119610 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
119611 +rdmalt_52022 rdmalt 0 52022 NULL
119612 +override_release_52032 override_release 2 52032 NULL
119613 +end_port_52042 end_port 0 52042 NULL
119614 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
119615 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
119616 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
119617 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
119618 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
119619 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
119620 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
119621 +ulist_add_merge_52096 ulist_add_merge 0 52096 NULL
119622 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
119623 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
119624 +retry_count_read_52129 retry_count_read 3 52129 NULL
119625 +snd_pcm_channel_info_user_52135 snd_pcm_channel_info_user 0 52135 NULL
119626 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
119627 +sub_alloc_52140 sub_alloc 0 52140 NULL
119628 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
119629 +htable_size_52148 htable_size 0-1 52148 NULL
119630 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
119631 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
119632 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
119633 +print_prefix_52176 print_prefix 0 52176 NULL
119634 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
119635 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
119636 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
119637 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
119638 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
119639 +shrink_slab_52261 shrink_slab 2 52261 NULL
119640 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
119641 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
119642 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
119643 +read_file_reset_52310 read_file_reset 3 52310 NULL
119644 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
119645 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
119646 +hwflags_read_52318 hwflags_read 3 52318 NULL
119647 +snd_pcm_hw_free_52327 snd_pcm_hw_free 0 52327 NULL
119648 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
119649 +hur_len_52339 hur_len 0 52339 NULL
119650 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL nohasharray
119651 +cap_inode_killpriv_52362 cap_inode_killpriv 0 52362 &bytes_to_frames_52362
119652 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
119653 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
119654 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
119655 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
119656 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
119657 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
119658 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
119659 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
119660 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
119661 +delay_status_52431 delay_status 5 52431 NULL
119662 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
119663 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
119664 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
119665 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
119666 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
119667 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
119668 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
119669 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
119670 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
119671 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
119672 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
119673 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
119674 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
119675 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
119676 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
119677 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
119678 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
119679 +snd_pcm_sw_params_52594 snd_pcm_sw_params 0 52594 NULL
119680 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
119681 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
119682 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
119683 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
119684 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
119685 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
119686 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
119687 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
119688 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
119689 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
119690 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
119691 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
119692 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
119693 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
119694 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
119695 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
119696 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
119697 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
119698 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
119699 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
119700 +twlreg_write_52880 twlreg_write 3 52880 NULL
119701 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
119702 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
119703 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
119704 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
119705 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
119706 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
119707 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
119708 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
119709 +num_node_state_52989 num_node_state 0 52989 NULL
119710 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
119711 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
119712 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
119713 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
119714 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
119715 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
119716 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
119717 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
119718 +vmci_check_host_caps_53087 vmci_check_host_caps 0 53087 NULL
119719 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
119720 +verity_status_53120 verity_status 5 53120 NULL
119721 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
119722 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL nohasharray
119723 +inode_newsize_ok_53140 inode_newsize_ok 0 53140 &ps_poll_ps_poll_max_ap_turn_read_53140
119724 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
119725 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
119726 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
119727 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
119728 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
119729 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
119730 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
119731 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
119732 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
119733 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
119734 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
119735 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
119736 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
119737 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
119738 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
119739 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
119740 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
119741 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
119742 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
119743 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
119744 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
119745 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
119746 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
119747 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
119748 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
119749 +force_sc_support_write_53512 force_sc_support_write 3 53512 NULL nohasharray
119750 +check_acl_53512 check_acl 0 53512 &force_sc_support_write_53512
119751 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
119752 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
119753 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
119754 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
119755 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
119756 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
119757 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
119758 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
119759 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
119760 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4-0 53682 NULL
119761 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
119762 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
119763 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
119764 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
119765 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
119766 +wdm_write_53735 wdm_write 3 53735 NULL
119767 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL nohasharray
119768 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 &lpfc_idiag_queacc_read_qe_53755
119769 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
119770 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
119771 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
119772 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
119773 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
119774 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
119775 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
119776 +setup_data_read_53822 setup_data_read 3 53822 NULL
119777 +pms_read_53873 pms_read 3 53873 NULL
119778 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
119779 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
119780 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
119781 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
119782 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
119783 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
119784 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
119785 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
119786 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
119787 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
119788 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
119789 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
119790 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
119791 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
119792 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
119793 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
119794 +_malloc_54077 _malloc 1 54077 NULL
119795 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 NULL nohasharray
119796 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 &lustre_posix_acl_xattr_filter_54103
119797 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
119798 +strn_len_54122 strn_len 0 54122 NULL
119799 +isku_receive_54130 isku_receive 4 54130 NULL
119800 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
119801 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
119802 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
119803 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
119804 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
119805 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
119806 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
119807 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
119808 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
119809 +reada_add_block_54247 reada_add_block 2 54247 NULL
119810 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
119811 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
119812 +audio_write_54261 audio_write 4 54261 NULL nohasharray
119813 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
119814 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
119815 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
119816 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
119817 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
119818 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
119819 +sprintf_54306 sprintf 0 54306 NULL
119820 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
119821 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
119822 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
119823 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
119824 +readlink_copy_54366 readlink_copy 2 54366 NULL
119825 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
119826 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
119827 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
119828 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
119829 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
119830 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
119831 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
119832 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
119833 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
119834 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
119835 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
119836 +sst_byt_get_dsp_position_54513 sst_byt_get_dsp_position 0-3 54513 NULL
119837 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
119838 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
119839 +viacam_read_54526 viacam_read 3 54526 NULL
119840 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
119841 +setsockopt_54539 setsockopt 5 54539 NULL
119842 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
119843 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
119844 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
119845 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
119846 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
119847 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
119848 +port_fops_write_54627 port_fops_write 3 54627 NULL
119849 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
119850 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
119851 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
119852 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
119853 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
119854 +bus_add_device_54665 bus_add_device 0 54665 NULL
119855 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
119856 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
119857 +evm_read_key_54674 evm_read_key 3 54674 NULL
119858 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
119859 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
119860 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
119861 +kzalloc_54740 kzalloc 1 54740 NULL
119862 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
119863 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
119864 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
119865 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
119866 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
119867 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
119868 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
119869 +nfsd_write_54809 nfsd_write 6 54809 NULL
119870 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
119871 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
119872 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
119873 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
119874 +generic_perform_write_54832 generic_perform_write 3-0 54832 NULL
119875 +write_rio_54837 write_rio 3 54837 NULL
119876 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
119877 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
119878 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
119879 +printer_read_54851 printer_read 3 54851 NULL
119880 +assign_irq_vector_54852 assign_irq_vector 0 54852 NULL
119881 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
119882 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
119883 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
119884 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
119885 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
119886 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
119887 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
119888 +add_port_54941 add_port 2 54941 NULL
119889 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
119890 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
119891 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
119892 +c4_add_card_54968 c4_add_card 3 54968 NULL
119893 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
119894 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
119895 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
119896 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
119897 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
119898 +snd_pcm_capture_hw_avail_55086 snd_pcm_capture_hw_avail 0 55086 NULL
119899 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
119900 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
119901 +filldir_55137 filldir 3 55137 NULL
119902 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
119903 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
119904 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
119905 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
119906 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
119907 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
119908 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
119909 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
119910 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
119911 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
119912 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
119913 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
119914 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
119915 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
119916 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
119917 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
119918 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
119919 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
119920 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
119921 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
119922 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
119923 +vme_user_read_55338 vme_user_read 3 55338 NULL
119924 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
119925 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
119926 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
119927 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
119928 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
119929 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
119930 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
119931 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
119932 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
119933 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
119934 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
119935 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
119936 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
119937 +ea_get_55522 ea_get 3-0 55522 NULL
119938 +buffer_size_55534 buffer_size 0 55534 NULL
119939 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
119940 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
119941 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
119942 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
119943 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
119944 +add_partition_55588 add_partition 2 55588 NULL
119945 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
119946 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
119947 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
119948 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
119949 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
119950 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
119951 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
119952 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
119953 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
119954 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
119955 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
119956 +get_info_55681 get_info 3 55681 NULL
119957 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
119958 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
119959 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
119960 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
119961 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
119962 +set_local_name_55757 set_local_name 4 55757 NULL
119963 +strlen_55778 strlen 0 55778 NULL nohasharray
119964 +is_idx_node_in_tnc_55778 is_idx_node_in_tnc 0 55778 &strlen_55778
119965 +set_spte_55783 set_spte 5-4 55783 NULL
119966 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
119967 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
119968 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
119969 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
119970 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
119971 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
119972 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
119973 +hsc_write_55875 hsc_write 3 55875 NULL
119974 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
119975 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
119976 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
119977 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
119978 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
119979 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
119980 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
119981 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
119982 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
119983 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
119984 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
119985 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
119986 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
119987 +rtl8169_init_ring_56028 rtl8169_init_ring 0 56028 NULL
119988 +usb_ocp_write_56047 usb_ocp_write 4 56047 NULL
119989 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
119990 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
119991 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
119992 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
119993 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
119994 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
119995 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
119996 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
119997 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
119998 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
119999 +fd_copyin_56247 fd_copyin 3 56247 NULL
120000 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
120001 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
120002 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
120003 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
120004 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
120005 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
120006 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
120007 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
120008 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
120009 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
120010 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
120011 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
120012 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
120013 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
120014 +dev_read_56369 dev_read 3 56369 NULL
120015 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
120016 +snd_pcm_common_ioctl1_56382 snd_pcm_common_ioctl1 0 56382 NULL
120017 +write_gssp_56404 write_gssp 3 56404 NULL
120018 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
120019 +store_msg_56417 store_msg 3 56417 NULL
120020 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
120021 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
120022 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 NULL
120023 +fl_create_56435 fl_create 5 56435 NULL
120024 +gnttab_map_56439 gnttab_map 2 56439 NULL
120025 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
120026 +set_connectable_56458 set_connectable 4 56458 NULL
120027 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
120028 +putused_user_56467 putused_user 3 56467 NULL
120029 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
120030 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
120031 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
120032 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
120033 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
120034 +init_map_ip_56508 init_map_ip 5 56508 NULL
120035 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
120036 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
120037 +ip_options_get_56538 ip_options_get 4 56538 NULL
120038 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
120039 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
120040 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
120041 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
120042 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
120043 +event_filter_write_56609 event_filter_write 3 56609 NULL
120044 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
120045 +gather_array_56641 gather_array 3 56641 NULL
120046 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
120047 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
120048 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
120049 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
120050 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
120051 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
120052 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
120053 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
120054 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
120055 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
120056 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
120057 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
120058 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
120059 +do_syslog_56807 do_syslog 3 56807 NULL
120060 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
120061 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
120062 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
120063 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
120064 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
120065 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
120066 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL nohasharray
120067 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 &batadv_tt_update_changes_56895
120068 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
120069 +strcspn_56913 strcspn 0 56913 NULL
120070 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
120071 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
120072 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
120073 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
120074 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
120075 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
120076 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
120077 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
120078 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
120079 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
120080 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
120081 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
120082 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
120083 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
120084 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
120085 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
120086 +altera_get_note_57099 altera_get_note 6 57099 NULL
120087 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
120088 +snd_pcm_hw_params_old_user_57108 snd_pcm_hw_params_old_user 0 57108 NULL
120089 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
120090 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
120091 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
120092 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
120093 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
120094 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
120095 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
120096 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
120097 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
120098 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
120099 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
120100 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
120101 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
120102 +flush_space_57241 flush_space 0 57241 NULL
120103 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
120104 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
120105 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
120106 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
120107 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
120108 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
120109 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
120110 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
120111 +write_file_regval_57313 write_file_regval 3 57313 NULL
120112 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
120113 +usblp_read_57342 usblp_read 3 57342 NULL
120114 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
120115 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
120116 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
120117 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
120118 +read_file_blob_57406 read_file_blob 3 57406 NULL
120119 +enclosure_register_57412 enclosure_register 3 57412 NULL
120120 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
120121 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
120122 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
120123 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
120124 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
120125 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
120126 +skb_headlen_57501 skb_headlen 0 57501 NULL
120127 +copy_in_user_57502 copy_in_user 3 57502 NULL
120128 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
120129 +init_tag_map_57515 init_tag_map 3 57515 NULL
120130 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
120131 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
120132 +cmm_read_57520 cmm_read 3 57520 NULL
120133 +inode_permission_57531 inode_permission 0 57531 NULL
120134 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
120135 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
120136 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
120137 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
120138 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
120139 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
120140 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
120141 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
120142 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
120143 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
120144 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
120145 +mem_read_57631 mem_read 3 57631 NULL
120146 +pci_enable_msi_block_57632 pci_enable_msi_block 0 57632 NULL
120147 +msi_compose_msg_57637 msi_compose_msg 0 57637 NULL
120148 +r3964_write_57662 r3964_write 4 57662 NULL
120149 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
120150 +__lgwrite_57669 __lgwrite 4 57669 NULL
120151 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
120152 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
120153 +vm_find_vqs_57729 vm_find_vqs 0 57729 NULL
120154 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
120155 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
120156 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
120157 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
120158 +security_inode_unlink_57791 security_inode_unlink 0 57791 NULL
120159 +ld2_57794 ld2 0 57794 NULL
120160 +ivtv_read_57796 ivtv_read 3 57796 NULL
120161 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
120162 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
120163 +copy_to_user_57835 copy_to_user 0-3 57835 NULL
120164 +flash_read_57843 flash_read 3 57843 NULL
120165 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
120166 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
120167 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
120168 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
120169 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
120170 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
120171 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
120172 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
120173 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
120174 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
120175 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
120176 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
120177 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
120178 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
120179 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
120180 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
120181 +mce_async_out_58056 mce_async_out 3 58056 NULL
120182 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
120183 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
120184 +cm4040_write_58079 cm4040_write 3 58079 NULL
120185 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
120186 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
120187 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
120188 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
120189 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
120190 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
120191 +read_file_debug_58256 read_file_debug 3 58256 NULL
120192 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
120193 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
120194 +profile_load_58267 profile_load 3 58267 NULL
120195 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
120196 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
120197 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
120198 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
120199 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
120200 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
120201 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
120202 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
120203 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
120204 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
120205 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 NULL
120206 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
120207 +capabilities_read_58457 capabilities_read 3 58457 NULL
120208 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
120209 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
120210 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
120211 +nv_rd08_58472 nv_rd08 0 58472 NULL
120212 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
120213 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
120214 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
120215 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3-0 58498 NULL
120216 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
120217 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
120218 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
120219 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
120220 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
120221 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
120222 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
120223 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
120224 +xip_file_read_58592 xip_file_read 3 58592 NULL
120225 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
120226 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
120227 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
120228 +filemap_fdatawrite_range_58630 filemap_fdatawrite_range 0 58630 NULL
120229 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
120230 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
120231 +find_zero_58685 find_zero 0-1 58685 NULL
120232 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
120233 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
120234 +scsi_setup_command_freelist_58703 scsi_setup_command_freelist 0 58703 NULL
120235 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
120236 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
120237 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
120238 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
120239 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
120240 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
120241 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
120242 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
120243 +ep_read_58813 ep_read 3 58813 NULL
120244 +command_write_58841 command_write 3 58841 NULL
120245 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
120246 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
120247 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
120248 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
120249 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
120250 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
120251 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
120252 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
120253 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
120254 +init_list_set_59005 init_list_set 3 59005 NULL
120255 +ep_write_59008 ep_write 3 59008 NULL
120256 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
120257 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
120258 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
120259 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
120260 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
120261 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL nohasharray
120262 +i8042_enable_kbd_port_59049 i8042_enable_kbd_port 0 59049 &regmap_bulk_write_59049
120263 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
120264 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
120265 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
120266 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
120267 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
120268 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
120269 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
120270 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
120271 +ksize_59176 ksize 0 59176 NULL
120272 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
120273 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
120274 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
120275 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
120276 +dt3155_read_59226 dt3155_read 3 59226 NULL
120277 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-2-1 59229 NULL
120278 +nla_len_59258 nla_len 0 59258 NULL
120279 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
120280 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
120281 +fd_copyout_59323 fd_copyout 3 59323 NULL
120282 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
120283 +set_state_private_59336 set_state_private 0 59336 NULL
120284 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
120285 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
120286 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
120287 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
120288 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
120289 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
120290 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
120291 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
120292 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
120293 +snd_pcm_tstamp_59431 snd_pcm_tstamp 0 59431 NULL
120294 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
120295 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
120296 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
120297 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
120298 +rtw_cfg80211_set_mgnt_wpsp2pie_59497 rtw_cfg80211_set_mgnt_wpsp2pie 3 59497 NULL
120299 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
120300 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
120301 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
120302 +msix_setup_entries_59545 msix_setup_entries 0 59545 NULL nohasharray
120303 +idr_alloc_59545 idr_alloc 0 59545 &msix_setup_entries_59545
120304 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
120305 +tunables_write_59563 tunables_write 3 59563 NULL
120306 +bio_split_59564 bio_split 2 59564 NULL
120307 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
120308 +memdup_user_59590 memdup_user 2 59590 NULL
120309 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
120310 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
120311 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
120312 +mtrr_write_59622 mtrr_write 3 59622 NULL
120313 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
120314 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
120315 +file_update_time_59647 file_update_time 0 59647 NULL
120316 +hidraw_read_59650 hidraw_read 3 59650 NULL
120317 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
120318 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
120319 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
120320 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
120321 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
120322 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
120323 +snd_pcm_info_user_59711 snd_pcm_info_user 0 59711 NULL
120324 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
120325 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
120326 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
120327 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
120328 +strnlen_59746 strnlen 0 59746 NULL
120329 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
120330 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL nohasharray
120331 +cap_inode_need_killpriv_59766 cap_inode_need_killpriv 0 59766 &long_retry_limit_read_59766
120332 +venus_remove_59781 venus_remove 4 59781 NULL
120333 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
120334 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
120335 +ipw_write_59807 ipw_write 3 59807 NULL
120336 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
120337 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
120338 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
120339 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
120340 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
120341 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
120342 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
120343 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
120344 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
120345 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
120346 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
120347 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
120348 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
120349 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
120350 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
120351 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
120352 +copy_items_60009 copy_items 7 60009 NULL
120353 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
120354 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
120355 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
120356 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
120357 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
120358 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
120359 +vcs_size_60050 vcs_size 0 60050 NULL
120360 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
120361 +compat_writev_60063 compat_writev 3 60063 NULL
120362 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
120363 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
120364 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
120365 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
120366 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
120367 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
120368 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
120369 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
120370 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
120371 +init_state_60165 init_state 2 60165 NULL
120372 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
120373 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
120374 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
120375 +arch_setup_msi_irqs_60193 arch_setup_msi_irqs 0 60193 NULL nohasharray
120376 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 &arch_setup_msi_irqs_60193
120377 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
120378 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
120379 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
120380 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
120381 +printer_write_60276 printer_write 3 60276 NULL
120382 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
120383 +getDataLength_60301 getDataLength 0 60301 NULL
120384 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
120385 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
120386 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
120387 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
120388 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 0 60379 NULL
120389 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
120390 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
120391 +driver_names_read_60399 driver_names_read 3 60399 NULL
120392 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
120393 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
120394 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
120395 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
120396 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
120397 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
120398 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
120399 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
120400 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
120401 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
120402 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
120403 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
120404 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
120405 +inode_change_ok_60614 inode_change_ok 0 60614 NULL
120406 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
120407 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
120408 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
120409 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
120410 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
120411 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
120412 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
120413 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
120414 +raid_status_60755 raid_status 5 60755 NULL
120415 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
120416 +opticon_write_60775 opticon_write 4 60775 NULL
120417 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
120418 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
120419 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
120420 +__clone_and_map_data_bio_60861 __clone_and_map_data_bio 3-4 60861 NULL
120421 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
120422 +generic_writepages_60871 generic_writepages 0 60871 NULL
120423 +ubifs_read_one_lp_60882 ubifs_read_one_lp 0 60882 NULL
120424 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
120425 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
120426 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
120427 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
120428 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
120429 +pti_char_write_60960 pti_char_write 3 60960 NULL
120430 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
120431 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
120432 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
120433 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
120434 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
120435 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
120436 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
120437 +symtab_init_61050 symtab_init 2 61050 NULL
120438 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
120439 +snd_pcm_pause_61054 snd_pcm_pause 0 61054 NULL
120440 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 2-0 61062 NULL
120441 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
120442 +snd_pcm_update_hw_ptr0_61084 snd_pcm_update_hw_ptr0 0 61084 NULL
120443 +get_derived_key_61100 get_derived_key 4 61100 NULL
120444 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
120445 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
120446 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
120447 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
120448 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
120449 +pair_device_61175 pair_device 4 61175 NULL nohasharray
120450 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
120451 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
120452 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
120453 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
120454 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
120455 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
120456 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
120457 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270 nohasharray
120458 +ifalias_store_61270 ifalias_store 4 61270 &find_get_pages_tag_61270
120459 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
120460 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
120461 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
120462 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
120463 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
120464 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
120465 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
120466 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
120467 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
120468 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
120469 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
120470 +system_enable_write_61396 system_enable_write 3 61396 NULL
120471 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
120472 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
120473 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
120474 +erst_errno_61526 erst_errno 0 61526 NULL
120475 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
120476 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
120477 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
120478 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
120479 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
120480 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
120481 +seq_open_private_61589 seq_open_private 3 61589 NULL
120482 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-2-1 61591 NULL
120483 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
120484 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
120485 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
120486 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
120487 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
120488 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
120489 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
120490 +resize_stripes_61650 resize_stripes 2 61650 NULL
120491 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
120492 +insert_one_name_61668 insert_one_name 7 61668 NULL
120493 +snd_pcm_playback_avail_61671 snd_pcm_playback_avail 0 61671 NULL
120494 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
120495 +lock_loop_61681 lock_loop 1 61681 NULL
120496 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
120497 +filter_read_61692 filter_read 3 61692 NULL
120498 +iov_length_61716 iov_length 0 61716 NULL
120499 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
120500 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
120501 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
120502 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
120503 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
120504 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
120505 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
120506 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
120507 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
120508 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
120509 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
120510 +get_fw_name_61874 get_fw_name 3 61874 NULL
120511 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
120512 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
120513 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
120514 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
120515 +kernfs_name_61910 kernfs_name 3 61910 NULL
120516 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
120517 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
120518 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
120519 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
120520 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
120521 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
120522 +fix_read_error_61965 fix_read_error 4 61965 NULL
120523 +cow_file_range_61979 cow_file_range 3 61979 NULL
120524 +set_extent_delalloc_61982 set_extent_delalloc 0 61982 NULL
120525 +dequeue_event_62000 dequeue_event 3 62000 NULL
120526 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
120527 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
120528 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
120529 +SYSC_select_62024 SYSC_select 1 62024 NULL
120530 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
120531 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
120532 +do_pselect_62061 do_pselect 1 62061 NULL
120533 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
120534 +fat_setattr_62084 fat_setattr 0 62084 NULL
120535 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
120536 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
120537 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
120538 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
120539 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
120540 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
120541 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
120542 +ql_status_62135 ql_status 5 62135 NULL nohasharray
120543 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
120544 +video_usercopy_62151 video_usercopy 2 62151 NULL
120545 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
120546 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
120547 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
120548 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
120549 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
120550 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
120551 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
120552 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
120553 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
120554 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
120555 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
120556 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
120557 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
120558 +subseq_list_62332 subseq_list 3-0 62332 NULL
120559 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
120560 +flash_write_62354 flash_write 3 62354 NULL
120561 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
120562 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
120563 +altera_irscan_62396 altera_irscan 2 62396 NULL
120564 +set_ssp_62411 set_ssp 4 62411 NULL
120565 +udf_expand_file_adinicb_62470 udf_expand_file_adinicb 0 62470 NULL
120566 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
120567 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
120568 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
120569 +debugfs_read_62535 debugfs_read 3 62535 NULL
120570 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
120571 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
120572 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
120573 +get_subdir_62581 get_subdir 3 62581 NULL
120574 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
120575 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
120576 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
120577 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
120578 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
120579 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
120580 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
120581 +rdm_62719 rdm 0 62719 NULL
120582 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
120583 +key_replays_read_62746 key_replays_read 3 62746 NULL
120584 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
120585 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
120586 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
120587 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
120588 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
120589 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
120590 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
120591 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
120592 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
120593 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
120594 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
120595 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
120596 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
120597 +aoechr_write_62883 aoechr_write 3 62883 NULL
120598 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
120599 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
120600 +getdqbuf_62908 getdqbuf 1 62908 NULL
120601 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
120602 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
120603 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
120604 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
120605 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
120606 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
120607 +unlink1_63059 unlink1 3 63059 NULL
120608 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
120609 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
120610 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
120611 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
120612 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
120613 +snd_pcm_status_user_63140 snd_pcm_status_user 0 63140 NULL
120614 +ubifs_change_one_lp_63157 ubifs_change_one_lp 0 63157 NULL
120615 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
120616 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
120617 +vme_master_read_63221 vme_master_read 0 63221 NULL
120618 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
120619 +ptp_read_63251 ptp_read 4 63251 NULL
120620 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
120621 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
120622 +raid5_resize_63306 raid5_resize 2 63306 NULL
120623 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
120624 +proc_info_read_63344 proc_info_read 3 63344 NULL
120625 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
120626 +idmouse_read_63374 idmouse_read 3 63374 NULL
120627 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
120628 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
120629 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
120630 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
120631 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
120632 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
120633 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
120634 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
120635 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
120636 +read_kcore_63488 read_kcore 3 63488 NULL
120637 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
120638 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
120639 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
120640 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL nohasharray
120641 +generic_cont_expand_simple_63534 generic_cont_expand_simple 0 63534 &ubi_more_leb_change_data_63534
120642 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
120643 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
120644 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
120645 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
120646 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
120647 +write_debug_level_63613 write_debug_level 3 63613 NULL
120648 +__spi_validate_63618 __spi_validate 0 63618 NULL
120649 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
120650 +hid_report_len_63637 hid_report_len 0 63637 NULL
120651 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
120652 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
120653 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
120654 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
120655 +vbi_read_63673 vbi_read 3 63673 NULL
120656 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
120657 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
120658 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
120659 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
120660 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
120661 +snd_pcm_link_63772 snd_pcm_link 0 63772 NULL
120662 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
120663 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
120664 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
120665 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
120666 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
120667 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL
120668 +sel_write_load_63830 sel_write_load 3 63830 NULL
120669 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
120670 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
120671 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
120672 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
120673 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
120674 +__team_options_register_63941 __team_options_register 3 63941 NULL
120675 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
120676 +set_bredr_63975 set_bredr 4 63975 NULL
120677 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
120678 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
120679 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
120680 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
120681 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
120682 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
120683 +get_u8_64076 get_u8 0 64076 NULL
120684 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
120685 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
120686 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
120687 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
120688 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
120689 +to_bytes_64103 to_bytes 0-1 64103 NULL
120690 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
120691 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
120692 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
120693 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
120694 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
120695 +init_bch_64130 init_bch 1-2 64130 NULL
120696 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
120697 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
120698 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
120699 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
120700 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
120701 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
120702 +read_pulse_64227 read_pulse 0-3 64227 NULL
120703 +ea_len_64229 ea_len 0 64229 NULL
120704 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
120705 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
120706 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
120707 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
120708 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
120709 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
120710 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
120711 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
120712 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
120713 +ts_write_64336 ts_write 3 64336 NULL
120714 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
120715 +qlcnic_82xx_calculate_msix_vector_64354 qlcnic_82xx_calculate_msix_vector 0 64354 NULL
120716 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
120717 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
120718 +reg_create_64372 reg_create 5 64372 NULL nohasharray
120719 +bnx2_enable_msix_64372 bnx2_enable_msix 2 64372 &reg_create_64372
120720 +ilo_write_64378 ilo_write 3 64378 NULL
120721 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
120722 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
120723 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
120724 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
120725 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
120726 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
120727 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
120728 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
120729 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
120730 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
120731 +__i2c_add_numbered_adapter_64445 __i2c_add_numbered_adapter 0 64445 NULL
120732 +single_open_size_64483 single_open_size 4 64483 NULL
120733 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
120734 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
120735 +remove_uuid_64505 remove_uuid 4 64505 NULL
120736 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
120737 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
120738 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
120739 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
120740 +SyS_bind_64544 SyS_bind 3 64544 NULL
120741 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
120742 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
120743 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
120744 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
120745 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
120746 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
120747 +do_erase_64574 do_erase 4 64574 NULL
120748 +fanotify_write_64623 fanotify_write 3 64623 NULL
120749 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
120750 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
120751 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL nohasharray
120752 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 &tlbflush_read_file_64661
120753 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
120754 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
120755 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
120756 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
120757 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
120758 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
120759 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
120760 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
120761 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
120762 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
120763 +message_for_md_64777 message_for_md 5 64777 NULL
120764 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
120765 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
120766 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
120767 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
120768 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
120769 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
120770 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
120771 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
120772 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
120773 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
120774 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
120775 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
120776 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
120777 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
120778 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
120779 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
120780 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
120781 +insert_dent_65034 insert_dent 7 65034 NULL
120782 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
120783 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
120784 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
120785 +make_idx_node_65068 make_idx_node 0 65068 NULL
120786 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
120787 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
120788 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
120789 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
120790 +scsi_add_host_with_dma_65093 scsi_add_host_with_dma 0 65093 NULL
120791 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
120792 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
120793 +print_endpoint_stat_65232 print_endpoint_stat 0-3-4 65232 NULL
120794 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
120795 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
120796 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
120797 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
120798 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
120799 +get_var_len_65304 get_var_len 0 65304 NULL
120800 +unpack_array_65318 unpack_array 0 65318 NULL
120801 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
120802 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
120803 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
120804 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
120805 +SyS_writev_65372 SyS_writev 3 65372 NULL
120806 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
120807 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
120808 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
120809 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
120810 +device_add_groups_65423 device_add_groups 0 65423 NULL
120811 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
120812 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
120813 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
120814 +clear_user_65470 clear_user 2 65470 NULL
120815 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
120816 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
120817 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
120818 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
120819 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
120820 new file mode 100644
120821 index 0000000..560cd7b
120822 --- /dev/null
120823 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
120824 @@ -0,0 +1,92 @@
120825 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
120826 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
120827 +mappedread_2627 mappedread 2 2627 NULL
120828 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
120829 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
120830 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
120831 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
120832 +dmu_write_6048 dmu_write 4-3 6048 NULL
120833 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
120834 +update_pages_6225 update_pages 2-3 6225 NULL
120835 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
120836 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
120837 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
120838 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
120839 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
120840 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
120841 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
120842 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
120843 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
120844 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
120845 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
120846 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
120847 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
120848 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
120849 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
120850 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
120851 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
120852 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
120853 +uiocopy_18680 uiocopy 2 18680 NULL
120854 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
120855 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
120856 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
120857 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
120858 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
120859 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
120860 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
120861 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
120862 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
120863 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
120864 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
120865 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
120866 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
120867 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
120868 +splat_write_30943 splat_write 3 30943 NULL
120869 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
120870 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
120871 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
120872 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
120873 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
120874 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
120875 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
120876 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
120877 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
120878 +copyinstr_36980 copyinstr 3 36980 NULL
120879 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
120880 +splat_read_38116 splat_read 3 38116 NULL
120881 +sa_setup_38756 sa_setup 4 38756 NULL
120882 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
120883 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
120884 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
120885 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
120886 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
120887 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
120888 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
120889 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
120890 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
120891 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
120892 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
120893 +kcopy_write_43683 kcopy_write 3 43683 NULL
120894 +uiomove_44355 uiomove 2 44355 NULL
120895 +dmu_read_44418 dmu_read 4-3 44418 NULL
120896 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
120897 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
120898 +copyin_45945 copyin 3 45945 NULL
120899 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
120900 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
120901 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
120902 +spa_history_write_49650 spa_history_write 3 49650 NULL
120903 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
120904 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
120905 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
120906 +copyout_51409 copyout 3 51409 NULL
120907 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
120908 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
120909 +get_nvlist_56685 get_nvlist 2 56685 NULL
120910 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
120911 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
120912 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
120913 +zpios_write_61823 zpios_write 3 61823 NULL
120914 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
120915 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
120916 +zpios_read_64734 zpios_read 3 64734 NULL
120917 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
120918 new file mode 100644
120919 index 0000000..a15328d
120920 --- /dev/null
120921 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
120922 @@ -0,0 +1,259 @@
120923 +/*
120924 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
120925 + * Licensed under the GPL v2, or (at your option) v3
120926 + *
120927 + * Homepage:
120928 + * http://www.grsecurity.net/~ephox/overflow_plugin/
120929 + *
120930 + * Documentation:
120931 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
120932 + *
120933 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
120934 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
120935 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
120936 + *
120937 + * Usage:
120938 + * $ make
120939 + * $ make run
120940 + */
120941 +
120942 +#include "gcc-common.h"
120943 +#include "size_overflow.h"
120944 +
120945 +int plugin_is_GPL_compatible;
120946 +
120947 +tree report_size_overflow_decl;
120948 +
120949 +tree size_overflow_type_HI;
120950 +tree size_overflow_type_SI;
120951 +tree size_overflow_type_DI;
120952 +tree size_overflow_type_TI;
120953 +
120954 +static struct plugin_info size_overflow_plugin_info = {
120955 + .version = "20140713",
120956 + .help = "no-size-overflow\tturn off size overflow checking\n",
120957 +};
120958 +
120959 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
120960 +{
120961 + unsigned int arg_count;
120962 + enum tree_code code = TREE_CODE(*node);
120963 +
120964 + switch (code) {
120965 + case FUNCTION_DECL:
120966 + arg_count = type_num_arguments(TREE_TYPE(*node));
120967 + break;
120968 + case FUNCTION_TYPE:
120969 + case METHOD_TYPE:
120970 + arg_count = type_num_arguments(*node);
120971 + break;
120972 + default:
120973 + *no_add_attrs = true;
120974 + error("%s: %qE attribute only applies to functions", __func__, name);
120975 + return NULL_TREE;
120976 + }
120977 +
120978 + for (; args; args = TREE_CHAIN(args)) {
120979 + tree position = TREE_VALUE(args);
120980 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
120981 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
120982 + *no_add_attrs = true;
120983 + }
120984 + }
120985 + return NULL_TREE;
120986 +}
120987 +
120988 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
120989 +{
120990 + unsigned int arg_count;
120991 + enum tree_code code = TREE_CODE(*node);
120992 +
120993 + switch (code) {
120994 + case FUNCTION_DECL:
120995 + arg_count = type_num_arguments(TREE_TYPE(*node));
120996 + break;
120997 + case FUNCTION_TYPE:
120998 + case METHOD_TYPE:
120999 + arg_count = type_num_arguments(*node);
121000 + break;
121001 + case FIELD_DECL:
121002 + return NULL_TREE;
121003 + default:
121004 + *no_add_attrs = true;
121005 + error("%qE attribute only applies to functions", name);
121006 + return NULL_TREE;
121007 + }
121008 +
121009 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
121010 + return NULL_TREE;
121011 +
121012 + for (; args; args = TREE_CHAIN(args)) {
121013 + tree position = TREE_VALUE(args);
121014 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
121015 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
121016 + *no_add_attrs = true;
121017 + }
121018 + }
121019 + return NULL_TREE;
121020 +}
121021 +
121022 +static struct attribute_spec size_overflow_attr = {
121023 + .name = "size_overflow",
121024 + .min_length = 1,
121025 + .max_length = -1,
121026 + .decl_required = true,
121027 + .type_required = false,
121028 + .function_type_required = false,
121029 + .handler = handle_size_overflow_attribute,
121030 +#if BUILDING_GCC_VERSION >= 4007
121031 + .affects_type_identity = false
121032 +#endif
121033 +};
121034 +
121035 +static struct attribute_spec intentional_overflow_attr = {
121036 + .name = "intentional_overflow",
121037 + .min_length = 1,
121038 + .max_length = -1,
121039 + .decl_required = true,
121040 + .type_required = false,
121041 + .function_type_required = false,
121042 + .handler = handle_intentional_overflow_attribute,
121043 +#if BUILDING_GCC_VERSION >= 4007
121044 + .affects_type_identity = false
121045 +#endif
121046 +};
121047 +
121048 +static void register_attributes(void __unused *event_data, void __unused *data)
121049 +{
121050 + register_attribute(&size_overflow_attr);
121051 + register_attribute(&intentional_overflow_attr);
121052 +}
121053 +
121054 +static tree create_typedef(tree type, const char* ident)
121055 +{
121056 + tree new_type, decl;
121057 +
121058 + new_type = build_variant_type_copy(type);
121059 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
121060 + DECL_ORIGINAL_TYPE(decl) = type;
121061 + TYPE_NAME(new_type) = decl;
121062 + return new_type;
121063 +}
121064 +
121065 +// Create the noreturn report_size_overflow() function decl.
121066 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
121067 +{
121068 + tree const_char_ptr_type_node;
121069 + tree fntype;
121070 +
121071 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
121072 +
121073 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
121074 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
121075 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
121076 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
121077 +
121078 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
121079 + fntype = build_function_type_list(void_type_node,
121080 + const_char_ptr_type_node,
121081 + unsigned_type_node,
121082 + const_char_ptr_type_node,
121083 + const_char_ptr_type_node,
121084 + NULL_TREE);
121085 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
121086 +
121087 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
121088 + TREE_PUBLIC(report_size_overflow_decl) = 1;
121089 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
121090 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
121091 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
121092 +}
121093 +
121094 +
121095 +extern struct gimple_opt_pass pass_dce;
121096 +
121097 +static struct opt_pass *make_dce_pass(void)
121098 +{
121099 +#if BUILDING_GCC_VERSION >= 4009
121100 + return make_pass_dce(g);
121101 +#else
121102 + return &pass_dce.pass;
121103 +#endif
121104 +}
121105 +
121106 +
121107 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
121108 +{
121109 + int i;
121110 + const char * const plugin_name = plugin_info->base_name;
121111 + const int argc = plugin_info->argc;
121112 + const struct plugin_argument * const argv = plugin_info->argv;
121113 + bool enable = true;
121114 + struct register_pass_info insert_size_overflow_asm_pass_info;
121115 + struct register_pass_info __unused dump_before_pass_info;
121116 + struct register_pass_info __unused dump_after_pass_info;
121117 + struct register_pass_info insert_size_overflow_check_info;
121118 + struct register_pass_info dce_pass_info;
121119 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
121120 + {
121121 + .base = &report_size_overflow_decl,
121122 + .nelt = 1,
121123 + .stride = sizeof(report_size_overflow_decl),
121124 + .cb = &gt_ggc_mx_tree_node,
121125 + .pchw = &gt_pch_nx_tree_node
121126 + },
121127 + LAST_GGC_ROOT_TAB
121128 + };
121129 +
121130 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
121131 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
121132 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
121133 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
121134 +
121135 + dump_before_pass_info.pass = make_dump_pass();
121136 + dump_before_pass_info.reference_pass_name = "increase_alignment";
121137 + dump_before_pass_info.ref_pass_instance_number = 1;
121138 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
121139 +
121140 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
121141 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
121142 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
121143 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
121144 +
121145 + dump_after_pass_info.pass = make_dump_pass();
121146 + dump_after_pass_info.reference_pass_name = "increase_alignment";
121147 + dump_after_pass_info.ref_pass_instance_number = 1;
121148 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
121149 +
121150 + dce_pass_info.pass = make_dce_pass();
121151 + dce_pass_info.reference_pass_name = "vrp";
121152 + dce_pass_info.ref_pass_instance_number = 1;
121153 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
121154 +
121155 + if (!plugin_default_version_check(version, &gcc_version)) {
121156 + error(G_("incompatible gcc/plugin versions"));
121157 + return 1;
121158 + }
121159 +
121160 + for (i = 0; i < argc; ++i) {
121161 + if (!strcmp(argv[i].key, "no-size-overflow")) {
121162 + enable = false;
121163 + continue;
121164 + }
121165 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121166 + }
121167 +
121168 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
121169 + if (enable) {
121170 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
121171 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
121172 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
121173 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
121174 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
121175 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
121176 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
121177 + }
121178 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
121179 +
121180 + return 0;
121181 +}
121182 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
121183 new file mode 100644
121184 index 0000000..0888f6c
121185 --- /dev/null
121186 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
121187 @@ -0,0 +1,364 @@
121188 +/*
121189 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
121190 + * Licensed under the GPL v2, or (at your option) v3
121191 + *
121192 + * Homepage:
121193 + * http://www.grsecurity.net/~ephox/overflow_plugin/
121194 + *
121195 + * Documentation:
121196 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
121197 + *
121198 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
121199 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
121200 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
121201 + *
121202 + * Usage:
121203 + * $ make
121204 + * $ make run
121205 + */
121206 +
121207 +#include "gcc-common.h"
121208 +#include "size_overflow.h"
121209 +
121210 +#include "size_overflow_hash.h"
121211 +#include "size_overflow_hash_aux.h"
121212 +
121213 +#define CODES_LIMIT 32
121214 +
121215 +static unsigned char get_tree_code(const_tree type)
121216 +{
121217 + switch (TREE_CODE(type)) {
121218 + case ARRAY_TYPE:
121219 + return 0;
121220 + case BOOLEAN_TYPE:
121221 + return 1;
121222 + case ENUMERAL_TYPE:
121223 + return 2;
121224 + case FUNCTION_TYPE:
121225 + return 3;
121226 + case INTEGER_TYPE:
121227 + return 4;
121228 + case POINTER_TYPE:
121229 + return 5;
121230 + case RECORD_TYPE:
121231 + return 6;
121232 + case UNION_TYPE:
121233 + return 7;
121234 + case VOID_TYPE:
121235 + return 8;
121236 + case REAL_TYPE:
121237 + return 9;
121238 + case VECTOR_TYPE:
121239 + return 10;
121240 + case REFERENCE_TYPE:
121241 + return 11;
121242 + case OFFSET_TYPE:
121243 + return 12;
121244 + case COMPLEX_TYPE:
121245 + return 13;
121246 + default:
121247 + debug_tree((tree)type);
121248 + gcc_unreachable();
121249 + }
121250 +}
121251 +
121252 +struct function_hash {
121253 + size_t tree_codes_len;
121254 + unsigned char tree_codes[CODES_LIMIT];
121255 + const_tree fndecl;
121256 + unsigned int hash;
121257 +};
121258 +
121259 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
121260 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
121261 +{
121262 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
121263 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
121264 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
121265 +
121266 + unsigned int m = 0x57559429;
121267 + unsigned int n = 0x5052acdb;
121268 + const unsigned int *key4 = (const unsigned int *)key;
121269 + unsigned int h = len;
121270 + unsigned int k = len + seed + n;
121271 + unsigned long long p;
121272 +
121273 + while (len >= 8) {
121274 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
121275 + len -= 8;
121276 + }
121277 + if (len >= 4) {
121278 + cwmixb(key4[0]) key4 += 1;
121279 + len -= 4;
121280 + }
121281 + if (len)
121282 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
121283 + cwmixb(h ^ (k + n));
121284 + return k ^ h;
121285 +
121286 +#undef cwfold
121287 +#undef cwmixa
121288 +#undef cwmixb
121289 +}
121290 +
121291 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
121292 +{
121293 + unsigned int fn, codes, seed = 0;
121294 +
121295 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
121296 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
121297 +
121298 + fn_hash_data->hash = fn ^ codes;
121299 +}
121300 +
121301 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
121302 +{
121303 + gcc_assert(type != NULL_TREE);
121304 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
121305 +
121306 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
121307 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
121308 + fn_hash_data->tree_codes_len++;
121309 + type = TREE_TYPE(type);
121310 + }
121311 +}
121312 +
121313 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
121314 +{
121315 + const_tree result;
121316 +
121317 + gcc_assert(node != NULL_TREE);
121318 +
121319 + if (DECL_P(node)) {
121320 + result = DECL_RESULT(node);
121321 + if (result != NULL_TREE)
121322 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
121323 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
121324 + }
121325 +
121326 + gcc_assert(TYPE_P(node));
121327 +
121328 + if (TREE_CODE(node) == FUNCTION_TYPE)
121329 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
121330 +
121331 + return set_node_codes(node, fn_hash_data);
121332 +}
121333 +
121334 +static void set_function_codes(struct function_hash *fn_hash_data)
121335 +{
121336 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
121337 + enum tree_code code = TREE_CODE(type);
121338 +
121339 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
121340 +
121341 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
121342 +
121343 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
121344 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
121345 +}
121346 +
121347 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
121348 +{
121349 + while (entry) {
121350 + if (!strcmp(entry->name, func_name))
121351 + return entry;
121352 + entry = entry->next;
121353 + }
121354 + return NULL;
121355 +}
121356 +
121357 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
121358 +{
121359 + const struct size_overflow_hash *entry;
121360 + struct function_hash fn_hash_data;
121361 + const char *func_name;
121362 +
121363 + // skip builtins __builtin_constant_p
121364 + if (DECL_BUILT_IN(fndecl))
121365 + return NULL;
121366 +
121367 + fn_hash_data.fndecl = fndecl;
121368 + fn_hash_data.tree_codes_len = 0;
121369 +
121370 + set_function_codes(&fn_hash_data);
121371 + gcc_assert(fn_hash_data.tree_codes_len != 0);
121372 +
121373 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
121374 + set_hash(func_name, &fn_hash_data);
121375 +
121376 + entry = size_overflow_hash[fn_hash_data.hash];
121377 + entry = get_proper_hash_chain(entry, func_name);
121378 + if (entry)
121379 + return entry;
121380 + entry = size_overflow_hash_aux[fn_hash_data.hash];
121381 + return get_proper_hash_chain(entry, func_name);
121382 +}
121383 +
121384 +static void print_missing_msg(const_tree func, unsigned int argnum)
121385 +{
121386 + location_t loc;
121387 + const char *curfunc;
121388 + struct function_hash fn_hash_data;
121389 +
121390 + fn_hash_data.fndecl = DECL_ORIGIN(func);
121391 + fn_hash_data.tree_codes_len = 0;
121392 +
121393 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
121394 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
121395 +
121396 + set_function_codes(&fn_hash_data);
121397 + set_hash(curfunc, &fn_hash_data);
121398 +
121399 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
121400 +}
121401 +
121402 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
121403 +{
121404 + tree var;
121405 + unsigned int argnum = 1;
121406 +
121407 + if (TREE_CODE(arg) == SSA_NAME)
121408 + arg = SSA_NAME_VAR(arg);
121409 +
121410 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
121411 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
121412 + continue;
121413 + if (!skip_types(var))
121414 + return argnum;
121415 + }
121416 +
121417 + return CANNOT_FIND_ARG;
121418 +}
121419 +
121420 +static const char *get_asm_string(const_gimple stmt)
121421 +{
121422 + if (!stmt)
121423 + return NULL;
121424 + if (gimple_code(stmt) != GIMPLE_ASM)
121425 + return NULL;
121426 +
121427 + return gimple_asm_string(stmt);
121428 +}
121429 +
121430 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
121431 +{
121432 + const char *str;
121433 +
121434 + str = get_asm_string(stmt);
121435 + if (!str)
121436 + return false;
121437 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
121438 +}
121439 +
121440 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
121441 +{
121442 + const char *str;
121443 +
121444 + str = get_asm_string(stmt);
121445 + if (!str)
121446 + return false;
121447 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
121448 +}
121449 +
121450 +bool is_size_overflow_asm(const_gimple stmt)
121451 +{
121452 + const char *str;
121453 +
121454 + str = get_asm_string(stmt);
121455 + if (!str)
121456 + return false;
121457 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
121458 +}
121459 +
121460 +bool is_a_return_check(const_tree node)
121461 +{
121462 + if (TREE_CODE(node) == FUNCTION_DECL)
121463 + return true;
121464 +
121465 + gcc_assert(TREE_CODE(node) == PARM_DECL);
121466 + return false;
121467 +}
121468 +
121469 +// Get the argnum of a function decl, if node is a return then the argnum is 0
121470 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
121471 +{
121472 + if (is_a_return_check(node))
121473 + return 0;
121474 + else
121475 + return find_arg_number_tree(node, orig_fndecl);
121476 +}
121477 +
121478 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
121479 +{
121480 + const struct size_overflow_hash *hash;
121481 + unsigned int new_argnum;
121482 + tree arg;
121483 + const_tree origarg;
121484 +
121485 + if (argnum == 0)
121486 + return argnum;
121487 +
121488 + hash = get_function_hash(fndecl);
121489 + if (hash && hash->param & (1U << argnum))
121490 + return argnum;
121491 +
121492 + if (DECL_EXTERNAL(fndecl))
121493 + return argnum;
121494 +
121495 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
121496 + argnum--;
121497 + while (origarg && argnum) {
121498 + origarg = TREE_CHAIN(origarg);
121499 + argnum--;
121500 + }
121501 + gcc_assert(argnum == 0);
121502 + gcc_assert(origarg != NULL_TREE);
121503 +
121504 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
121505 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
121506 + return new_argnum;
121507 +
121508 + return CANNOT_FIND_ARG;
121509 +}
121510 +
121511 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
121512 +{
121513 + const struct size_overflow_hash *hash;
121514 +
121515 + hash = get_function_hash(fndecl);
121516 + if (hash && (hash->param & (1U << num)))
121517 + return true;
121518 + return false;
121519 +}
121520 +
121521 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
121522 + * If the function is missing everywhere then print the missing message into stderr.
121523 + */
121524 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
121525 +{
121526 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
121527 +#if BUILDING_GCC_VERSION >= 4008
121528 + case BUILT_IN_BSWAP16:
121529 +#endif
121530 + case BUILT_IN_BSWAP32:
121531 + case BUILT_IN_BSWAP64:
121532 + case BUILT_IN_EXPECT:
121533 + case BUILT_IN_MEMCMP:
121534 + return false;
121535 + default:
121536 + break;
121537 + }
121538 +
121539 + // skip test.c
121540 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
121541 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
121542 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
121543 + }
121544 +
121545 + if (is_in_hash_table(orig_fndecl, num))
121546 + return false;
121547 +
121548 + print_missing_msg(orig_fndecl, num);
121549 + return true;
121550 +}
121551 +
121552 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
121553 new file mode 100644
121554 index 0000000..dd94983
121555 --- /dev/null
121556 +++ b/tools/gcc/stackleak_plugin.c
121557 @@ -0,0 +1,376 @@
121558 +/*
121559 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
121560 + * Licensed under the GPL v2
121561 + *
121562 + * Note: the choice of the license means that the compilation process is
121563 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
121564 + * but for the kernel it doesn't matter since it doesn't link against
121565 + * any of the gcc libraries
121566 + *
121567 + * gcc plugin to help implement various PaX features
121568 + *
121569 + * - track lowest stack pointer
121570 + *
121571 + * TODO:
121572 + * - initialize all local variables
121573 + *
121574 + * BUGS:
121575 + * - none known
121576 + */
121577 +
121578 +#include "gcc-common.h"
121579 +
121580 +int plugin_is_GPL_compatible;
121581 +
121582 +static int track_frame_size = -1;
121583 +static const char track_function[] = "pax_track_stack";
121584 +static const char check_function[] = "pax_check_alloca";
121585 +static tree track_function_decl, check_function_decl;
121586 +static bool init_locals;
121587 +
121588 +static struct plugin_info stackleak_plugin_info = {
121589 + .version = "201402131920",
121590 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
121591 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
121592 +};
121593 +
121594 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
121595 +{
121596 + gimple check_alloca;
121597 + tree alloca_size;
121598 +
121599 + // insert call to void pax_check_alloca(unsigned long size)
121600 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
121601 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
121602 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
121603 +}
121604 +
121605 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
121606 +{
121607 + gimple track_stack;
121608 +
121609 + // insert call to void pax_track_stack(void)
121610 + track_stack = gimple_build_call(track_function_decl, 0);
121611 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
121612 +}
121613 +
121614 +static bool is_alloca(gimple stmt)
121615 +{
121616 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
121617 + return true;
121618 +
121619 +#if BUILDING_GCC_VERSION >= 4007
121620 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
121621 + return true;
121622 +#endif
121623 +
121624 + return false;
121625 +}
121626 +
121627 +static unsigned int execute_stackleak_tree_instrument(void)
121628 +{
121629 + basic_block bb, entry_bb;
121630 + bool prologue_instrumented = false, is_leaf = true;
121631 +
121632 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
121633 +
121634 + // 1. loop through BBs and GIMPLE statements
121635 + FOR_EACH_BB_FN(bb, cfun) {
121636 + gimple_stmt_iterator gsi;
121637 +
121638 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
121639 + gimple stmt;
121640 +
121641 + stmt = gsi_stmt(gsi);
121642 +
121643 + if (is_gimple_call(stmt))
121644 + is_leaf = false;
121645 +
121646 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
121647 + if (!is_alloca(stmt))
121648 + continue;
121649 +
121650 + // 2. insert stack overflow check before each __builtin_alloca call
121651 + stackleak_check_alloca(&gsi);
121652 +
121653 + // 3. insert track call after each __builtin_alloca call
121654 + stackleak_add_instrumentation(&gsi);
121655 + if (bb == entry_bb)
121656 + prologue_instrumented = true;
121657 + }
121658 + }
121659 +
121660 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
121661 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
121662 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
121663 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
121664 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
121665 + return 0;
121666 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
121667 + return 0;
121668 +
121669 + // 4. insert track call at the beginning
121670 + if (!prologue_instrumented) {
121671 + gimple_stmt_iterator gsi;
121672 +
121673 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
121674 + if (dom_info_available_p(CDI_DOMINATORS))
121675 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
121676 + gsi = gsi_start_bb(bb);
121677 + stackleak_add_instrumentation(&gsi);
121678 + }
121679 +
121680 + return 0;
121681 +}
121682 +
121683 +static unsigned int execute_stackleak_final(void)
121684 +{
121685 + rtx insn, next;
121686 +
121687 + if (cfun->calls_alloca)
121688 + return 0;
121689 +
121690 + // keep calls only if function frame is big enough
121691 + if (get_frame_size() >= track_frame_size)
121692 + return 0;
121693 +
121694 + // 1. find pax_track_stack calls
121695 + for (insn = get_insns(); insn; insn = next) {
121696 + // 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))
121697 + rtx body;
121698 +
121699 + next = NEXT_INSN(insn);
121700 + if (!CALL_P(insn))
121701 + continue;
121702 + body = PATTERN(insn);
121703 + if (GET_CODE(body) != CALL)
121704 + continue;
121705 + body = XEXP(body, 0);
121706 + if (GET_CODE(body) != MEM)
121707 + continue;
121708 + body = XEXP(body, 0);
121709 + if (GET_CODE(body) != SYMBOL_REF)
121710 + continue;
121711 +// if (strcmp(XSTR(body, 0), track_function))
121712 + if (SYMBOL_REF_DECL(body) != track_function_decl)
121713 + continue;
121714 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
121715 + // 2. delete call
121716 + delete_insn_and_edges(insn);
121717 +#if BUILDING_GCC_VERSION >= 4007
121718 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
121719 + insn = next;
121720 + next = NEXT_INSN(insn);
121721 + delete_insn_and_edges(insn);
121722 + }
121723 +#endif
121724 + }
121725 +
121726 +// print_simple_rtl(stderr, get_insns());
121727 +// print_rtl(stderr, get_insns());
121728 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
121729 +
121730 + return 0;
121731 +}
121732 +
121733 +static bool gate_stackleak_track_stack(void)
121734 +{
121735 + return track_frame_size >= 0;
121736 +}
121737 +
121738 +static void stackleak_start_unit(void *gcc_data, void *user_data)
121739 +{
121740 + tree fntype;
121741 +
121742 + // void pax_track_stack(void)
121743 + fntype = build_function_type_list(void_type_node, NULL_TREE);
121744 + track_function_decl = build_fn_decl(track_function, fntype);
121745 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
121746 + TREE_PUBLIC(track_function_decl) = 1;
121747 + DECL_EXTERNAL(track_function_decl) = 1;
121748 + DECL_ARTIFICIAL(track_function_decl) = 1;
121749 +
121750 + // void pax_check_alloca(unsigned long)
121751 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
121752 + check_function_decl = build_fn_decl(check_function, fntype);
121753 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
121754 + TREE_PUBLIC(check_function_decl) = 1;
121755 + DECL_EXTERNAL(check_function_decl) = 1;
121756 + DECL_ARTIFICIAL(check_function_decl) = 1;
121757 +}
121758 +
121759 +#if BUILDING_GCC_VERSION >= 4009
121760 +static const struct pass_data stackleak_tree_instrument_pass_data = {
121761 +#else
121762 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
121763 + .pass = {
121764 +#endif
121765 + .type = GIMPLE_PASS,
121766 + .name = "stackleak_tree_instrument",
121767 +#if BUILDING_GCC_VERSION >= 4008
121768 + .optinfo_flags = OPTGROUP_NONE,
121769 +#endif
121770 +#if BUILDING_GCC_VERSION >= 4009
121771 + .has_gate = true,
121772 + .has_execute = true,
121773 +#else
121774 + .gate = gate_stackleak_track_stack,
121775 + .execute = execute_stackleak_tree_instrument,
121776 + .sub = NULL,
121777 + .next = NULL,
121778 + .static_pass_number = 0,
121779 +#endif
121780 + .tv_id = TV_NONE,
121781 + .properties_required = PROP_gimple_leh | PROP_cfg,
121782 + .properties_provided = 0,
121783 + .properties_destroyed = 0,
121784 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
121785 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
121786 +#if BUILDING_GCC_VERSION < 4009
121787 + }
121788 +#endif
121789 +};
121790 +
121791 +#if BUILDING_GCC_VERSION >= 4009
121792 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
121793 +#else
121794 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
121795 + .pass = {
121796 +#endif
121797 + .type = RTL_PASS,
121798 + .name = "stackleak_final",
121799 +#if BUILDING_GCC_VERSION >= 4008
121800 + .optinfo_flags = OPTGROUP_NONE,
121801 +#endif
121802 +#if BUILDING_GCC_VERSION >= 4009
121803 + .has_gate = true,
121804 + .has_execute = true,
121805 +#else
121806 + .gate = gate_stackleak_track_stack,
121807 + .execute = execute_stackleak_final,
121808 + .sub = NULL,
121809 + .next = NULL,
121810 + .static_pass_number = 0,
121811 +#endif
121812 + .tv_id = TV_NONE,
121813 + .properties_required = 0,
121814 + .properties_provided = 0,
121815 + .properties_destroyed = 0,
121816 + .todo_flags_start = 0,
121817 + .todo_flags_finish = TODO_dump_func
121818 +#if BUILDING_GCC_VERSION < 4009
121819 + }
121820 +#endif
121821 +};
121822 +
121823 +#if BUILDING_GCC_VERSION >= 4009
121824 +namespace {
121825 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
121826 +public:
121827 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
121828 + bool gate() { return gate_stackleak_track_stack(); }
121829 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
121830 +};
121831 +
121832 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
121833 +public:
121834 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
121835 + bool gate() { return gate_stackleak_track_stack(); }
121836 + unsigned int execute() { return execute_stackleak_final(); }
121837 +};
121838 +}
121839 +
121840 +static opt_pass *make_stackleak_tree_instrument_pass(void)
121841 +{
121842 + return new stackleak_tree_instrument_pass();
121843 +}
121844 +
121845 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
121846 +{
121847 + return new stackleak_final_rtl_opt_pass();
121848 +}
121849 +#else
121850 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
121851 +{
121852 + return &stackleak_tree_instrument_pass.pass;
121853 +}
121854 +
121855 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
121856 +{
121857 + return &stackleak_final_rtl_opt_pass.pass;
121858 +}
121859 +#endif
121860 +
121861 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
121862 +{
121863 + const char * const plugin_name = plugin_info->base_name;
121864 + const int argc = plugin_info->argc;
121865 + const struct plugin_argument * const argv = plugin_info->argv;
121866 + int i;
121867 + struct register_pass_info stackleak_tree_instrument_pass_info;
121868 + struct register_pass_info stackleak_final_pass_info;
121869 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
121870 + {
121871 + .base = &track_function_decl,
121872 + .nelt = 1,
121873 + .stride = sizeof(track_function_decl),
121874 + .cb = &gt_ggc_mx_tree_node,
121875 + .pchw = &gt_pch_nx_tree_node
121876 + },
121877 + {
121878 + .base = &check_function_decl,
121879 + .nelt = 1,
121880 + .stride = sizeof(check_function_decl),
121881 + .cb = &gt_ggc_mx_tree_node,
121882 + .pchw = &gt_pch_nx_tree_node
121883 + },
121884 + LAST_GGC_ROOT_TAB
121885 + };
121886 +
121887 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
121888 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
121889 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
121890 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
121891 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
121892 +
121893 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
121894 + stackleak_final_pass_info.reference_pass_name = "final";
121895 + stackleak_final_pass_info.ref_pass_instance_number = 1;
121896 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
121897 +
121898 + if (!plugin_default_version_check(version, &gcc_version)) {
121899 + error(G_("incompatible gcc/plugin versions"));
121900 + return 1;
121901 + }
121902 +
121903 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
121904 +
121905 + for (i = 0; i < argc; ++i) {
121906 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
121907 + if (!argv[i].value) {
121908 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121909 + continue;
121910 + }
121911 + track_frame_size = atoi(argv[i].value);
121912 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
121913 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
121914 + continue;
121915 + }
121916 + if (!strcmp(argv[i].key, "initialize-locals")) {
121917 + if (argv[i].value) {
121918 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
121919 + continue;
121920 + }
121921 + init_locals = true;
121922 + continue;
121923 + }
121924 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121925 + }
121926 +
121927 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
121928 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
121929 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
121930 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
121931 +
121932 + return 0;
121933 +}
121934 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
121935 new file mode 100644
121936 index 0000000..4ee2231
121937 --- /dev/null
121938 +++ b/tools/gcc/structleak_plugin.c
121939 @@ -0,0 +1,274 @@
121940 +/*
121941 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
121942 + * Licensed under the GPL v2
121943 + *
121944 + * Note: the choice of the license means that the compilation process is
121945 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
121946 + * but for the kernel it doesn't matter since it doesn't link against
121947 + * any of the gcc libraries
121948 + *
121949 + * gcc plugin to forcibly initialize certain local variables that could
121950 + * otherwise leak kernel stack to userland if they aren't properly initialized
121951 + * by later code
121952 + *
121953 + * Homepage: http://pax.grsecurity.net/
121954 + *
121955 + * Usage:
121956 + * $ # for 4.5/4.6/C based 4.7
121957 + * $ 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
121958 + * $ # for C++ based 4.7/4.8+
121959 + * $ 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
121960 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
121961 + *
121962 + * TODO: eliminate redundant initializers
121963 + * increase type coverage
121964 + */
121965 +
121966 +#include "gcc-common.h"
121967 +
121968 +// unused C type flag in all versions 4.5-4.9
121969 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
121970 +
121971 +int plugin_is_GPL_compatible;
121972 +
121973 +static struct plugin_info structleak_plugin_info = {
121974 + .version = "201401260140",
121975 + .help = "disable\tdo not activate plugin\n",
121976 +};
121977 +
121978 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
121979 +{
121980 + *no_add_attrs = true;
121981 +
121982 + // check for types? for now accept everything linux has to offer
121983 + if (TREE_CODE(*node) != FIELD_DECL)
121984 + return NULL_TREE;
121985 +
121986 + *no_add_attrs = false;
121987 + return NULL_TREE;
121988 +}
121989 +
121990 +static struct attribute_spec user_attr = {
121991 + .name = "user",
121992 + .min_length = 0,
121993 + .max_length = 0,
121994 + .decl_required = false,
121995 + .type_required = false,
121996 + .function_type_required = false,
121997 + .handler = handle_user_attribute,
121998 +#if BUILDING_GCC_VERSION >= 4007
121999 + .affects_type_identity = true
122000 +#endif
122001 +};
122002 +
122003 +static void register_attributes(void *event_data, void *data)
122004 +{
122005 + register_attribute(&user_attr);
122006 +// register_attribute(&force_attr);
122007 +}
122008 +
122009 +static tree get_field_type(tree field)
122010 +{
122011 + return strip_array_types(TREE_TYPE(field));
122012 +}
122013 +
122014 +static bool is_userspace_type(tree type)
122015 +{
122016 + tree field;
122017 +
122018 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
122019 + tree fieldtype = get_field_type(field);
122020 + enum tree_code code = TREE_CODE(fieldtype);
122021 +
122022 + if (code == RECORD_TYPE || code == UNION_TYPE)
122023 + if (is_userspace_type(fieldtype))
122024 + return true;
122025 +
122026 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
122027 + return true;
122028 + }
122029 + return false;
122030 +}
122031 +
122032 +static void finish_type(void *event_data, void *data)
122033 +{
122034 + tree type = (tree)event_data;
122035 +
122036 + if (TYPE_USERSPACE(type))
122037 + return;
122038 +
122039 + if (is_userspace_type(type))
122040 + TYPE_USERSPACE(type) = 1;
122041 +}
122042 +
122043 +static void initialize(tree var)
122044 +{
122045 + basic_block bb;
122046 + gimple_stmt_iterator gsi;
122047 + tree initializer;
122048 + gimple init_stmt;
122049 +
122050 + // this is the original entry bb before the forced split
122051 + // TODO: check further BBs in case more splits occured before us
122052 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
122053 +
122054 + // first check if the variable is already initialized, warn otherwise
122055 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
122056 + gimple stmt = gsi_stmt(gsi);
122057 + tree rhs1;
122058 +
122059 + // we're looking for an assignment of a single rhs...
122060 + if (!gimple_assign_single_p(stmt))
122061 + continue;
122062 + rhs1 = gimple_assign_rhs1(stmt);
122063 +#if BUILDING_GCC_VERSION >= 4007
122064 + // ... of a non-clobbering expression...
122065 + if (TREE_CLOBBER_P(rhs1))
122066 + continue;
122067 +#endif
122068 + // ... to our variable...
122069 + if (gimple_get_lhs(stmt) != var)
122070 + continue;
122071 + // if it's an initializer then we're good
122072 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
122073 + return;
122074 + }
122075 +
122076 + // these aren't the 0days you're looking for
122077 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
122078 +
122079 + // build the initializer expression
122080 + initializer = build_constructor(TREE_TYPE(var), NULL);
122081 +
122082 + // build the initializer stmt
122083 + init_stmt = gimple_build_assign(var, initializer);
122084 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
122085 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
122086 + update_stmt(init_stmt);
122087 +}
122088 +
122089 +static unsigned int handle_function(void)
122090 +{
122091 + basic_block bb;
122092 + unsigned int ret = 0;
122093 + tree var;
122094 + unsigned int i;
122095 +
122096 + // split the first bb where we can put the forced initializers
122097 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
122098 + if (dom_info_available_p(CDI_DOMINATORS))
122099 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
122100 +
122101 + // enumarate all local variables and forcibly initialize our targets
122102 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
122103 + tree type = TREE_TYPE(var);
122104 +
122105 + gcc_assert(DECL_P(var));
122106 + if (!auto_var_in_fn_p(var, current_function_decl))
122107 + continue;
122108 +
122109 + // only care about structure types
122110 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
122111 + continue;
122112 +
122113 + // if the type is of interest, examine the variable
122114 + if (TYPE_USERSPACE(type))
122115 + initialize(var);
122116 + }
122117 +
122118 + return ret;
122119 +}
122120 +
122121 +#if BUILDING_GCC_VERSION >= 4009
122122 +static const struct pass_data structleak_pass_data = {
122123 +#else
122124 +static struct gimple_opt_pass structleak_pass = {
122125 + .pass = {
122126 +#endif
122127 + .type = GIMPLE_PASS,
122128 + .name = "structleak",
122129 +#if BUILDING_GCC_VERSION >= 4008
122130 + .optinfo_flags = OPTGROUP_NONE,
122131 +#endif
122132 +#if BUILDING_GCC_VERSION >= 4009
122133 + .has_gate = false,
122134 + .has_execute = true,
122135 +#else
122136 + .gate = NULL,
122137 + .execute = handle_function,
122138 + .sub = NULL,
122139 + .next = NULL,
122140 + .static_pass_number = 0,
122141 +#endif
122142 + .tv_id = TV_NONE,
122143 + .properties_required = PROP_cfg,
122144 + .properties_provided = 0,
122145 + .properties_destroyed = 0,
122146 + .todo_flags_start = 0,
122147 + .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
122148 +#if BUILDING_GCC_VERSION < 4009
122149 + }
122150 +#endif
122151 +};
122152 +
122153 +#if BUILDING_GCC_VERSION >= 4009
122154 +namespace {
122155 +class structleak_pass : public gimple_opt_pass {
122156 +public:
122157 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
122158 + unsigned int execute() { return handle_function(); }
122159 +};
122160 +}
122161 +
122162 +static opt_pass *make_structleak_pass(void)
122163 +{
122164 + return new structleak_pass();
122165 +}
122166 +#else
122167 +static struct opt_pass *make_structleak_pass(void)
122168 +{
122169 + return &structleak_pass.pass;
122170 +}
122171 +#endif
122172 +
122173 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
122174 +{
122175 + int i;
122176 + const char * const plugin_name = plugin_info->base_name;
122177 + const int argc = plugin_info->argc;
122178 + const struct plugin_argument * const argv = plugin_info->argv;
122179 + bool enable = true;
122180 + struct register_pass_info structleak_pass_info;
122181 +
122182 + structleak_pass_info.pass = make_structleak_pass();
122183 + structleak_pass_info.reference_pass_name = "ssa";
122184 + structleak_pass_info.ref_pass_instance_number = 1;
122185 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
122186 +
122187 + if (!plugin_default_version_check(version, &gcc_version)) {
122188 + error(G_("incompatible gcc/plugin versions"));
122189 + return 1;
122190 + }
122191 +
122192 + if (strcmp(lang_hooks.name, "GNU C")) {
122193 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
122194 + enable = false;
122195 + }
122196 +
122197 + for (i = 0; i < argc; ++i) {
122198 + if (!strcmp(argv[i].key, "disable")) {
122199 + enable = false;
122200 + continue;
122201 + }
122202 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
122203 + }
122204 +
122205 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
122206 + if (enable) {
122207 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
122208 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
122209 + }
122210 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
122211 +
122212 + return 0;
122213 +}
122214 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
122215 index fbc6665..5e9ce79 100644
122216 --- a/tools/include/linux/compiler.h
122217 +++ b/tools/include/linux/compiler.h
122218 @@ -35,4 +35,12 @@
122219 # define unlikely(x) __builtin_expect(!!(x), 0)
122220 #endif
122221
122222 +#ifndef __size_overflow
122223 +# define __size_overflow(...)
122224 +#endif
122225 +
122226 +#ifndef __intentional_overflow
122227 +# define __intentional_overflow(...)
122228 +#endif
122229 +
122230 #endif /* _TOOLS_LINUX_COMPILER_H */
122231 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
122232 index ce00f7e..0aca5e4 100644
122233 --- a/tools/lib/api/Makefile
122234 +++ b/tools/lib/api/Makefile
122235 @@ -16,7 +16,7 @@ LIB_OBJS += $(OUTPUT)fs/fs.o
122236
122237 LIBFILE = libapikfs.a
122238
122239 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
122240 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
122241 EXTLIBS = -lelf -lpthread -lrt -lm
122242 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
122243 ALL_LDFLAGS = $(LDFLAGS)
122244 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
122245 index 6789d788..4afd019e 100644
122246 --- a/tools/perf/util/include/asm/alternative-asm.h
122247 +++ b/tools/perf/util/include/asm/alternative-asm.h
122248 @@ -5,4 +5,7 @@
122249
122250 #define altinstruction_entry #
122251
122252 + .macro pax_force_retaddr rip=0, reload=0
122253 + .endm
122254 +
122255 #endif
122256 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
122257 index 0a578fe..b81f62d 100644
122258 --- a/tools/virtio/linux/uaccess.h
122259 +++ b/tools/virtio/linux/uaccess.h
122260 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
122261 ({ \
122262 typeof(ptr) __pu_ptr = (ptr); \
122263 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
122264 - ACCESS_ONCE(*(__pu_ptr)) = x; \
122265 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
122266 0; \
122267 })
122268
122269 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
122270 index 56baae8..2c889c2 100644
122271 --- a/virt/kvm/kvm_main.c
122272 +++ b/virt/kvm/kvm_main.c
122273 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
122274
122275 static cpumask_var_t cpus_hardware_enabled;
122276 static int kvm_usage_count = 0;
122277 -static atomic_t hardware_enable_failed;
122278 +static atomic_unchecked_t hardware_enable_failed;
122279
122280 struct kmem_cache *kvm_vcpu_cache;
122281 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
122282
122283 -static __read_mostly struct preempt_ops kvm_preempt_ops;
122284 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
122285 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
122286 +static struct preempt_ops kvm_preempt_ops = {
122287 + .sched_in = kvm_sched_in,
122288 + .sched_out = kvm_sched_out,
122289 +};
122290
122291 struct dentry *kvm_debugfs_dir;
122292
122293 @@ -755,7 +760,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
122294 /* We can read the guest memory with __xxx_user() later on. */
122295 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
122296 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
122297 - !access_ok(VERIFY_WRITE,
122298 + !access_ok_noprefault(VERIFY_WRITE,
122299 (void __user *)(unsigned long)mem->userspace_addr,
122300 mem->memory_size)))
122301 goto out;
122302 @@ -1612,9 +1617,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
122303
122304 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
122305 {
122306 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
122307 + int r;
122308 + unsigned long addr;
122309
122310 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
122311 + addr = gfn_to_hva(kvm, gfn);
122312 + if (kvm_is_error_hva(addr))
122313 + return -EFAULT;
122314 + r = __clear_user((void __user *)addr + offset, len);
122315 + if (r)
122316 + return -EFAULT;
122317 + mark_page_dirty(kvm, gfn);
122318 + return 0;
122319 }
122320 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
122321
122322 @@ -1864,7 +1877,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
122323 return 0;
122324 }
122325
122326 -static struct file_operations kvm_vcpu_fops = {
122327 +static file_operations_no_const kvm_vcpu_fops __read_only = {
122328 .release = kvm_vcpu_release,
122329 .unlocked_ioctl = kvm_vcpu_ioctl,
122330 #ifdef CONFIG_COMPAT
122331 @@ -2534,7 +2547,7 @@ out:
122332 }
122333 #endif
122334
122335 -static struct file_operations kvm_vm_fops = {
122336 +static file_operations_no_const kvm_vm_fops __read_only = {
122337 .release = kvm_vm_release,
122338 .unlocked_ioctl = kvm_vm_ioctl,
122339 #ifdef CONFIG_COMPAT
122340 @@ -2634,7 +2647,7 @@ out:
122341 return r;
122342 }
122343
122344 -static struct file_operations kvm_chardev_ops = {
122345 +static file_operations_no_const kvm_chardev_ops __read_only = {
122346 .unlocked_ioctl = kvm_dev_ioctl,
122347 .compat_ioctl = kvm_dev_ioctl,
122348 .llseek = noop_llseek,
122349 @@ -2660,7 +2673,7 @@ static void hardware_enable_nolock(void *junk)
122350
122351 if (r) {
122352 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
122353 - atomic_inc(&hardware_enable_failed);
122354 + atomic_inc_unchecked(&hardware_enable_failed);
122355 printk(KERN_INFO "kvm: enabling virtualization on "
122356 "CPU%d failed\n", cpu);
122357 }
122358 @@ -2716,10 +2729,10 @@ static int hardware_enable_all(void)
122359
122360 kvm_usage_count++;
122361 if (kvm_usage_count == 1) {
122362 - atomic_set(&hardware_enable_failed, 0);
122363 + atomic_set_unchecked(&hardware_enable_failed, 0);
122364 on_each_cpu(hardware_enable_nolock, NULL, 1);
122365
122366 - if (atomic_read(&hardware_enable_failed)) {
122367 + if (atomic_read_unchecked(&hardware_enable_failed)) {
122368 hardware_disable_all_nolock();
122369 r = -EBUSY;
122370 }
122371 @@ -3123,7 +3136,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
122372 kvm_arch_vcpu_put(vcpu);
122373 }
122374
122375 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122376 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122377 struct module *module)
122378 {
122379 int r;
122380 @@ -3170,7 +3183,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122381 if (!vcpu_align)
122382 vcpu_align = __alignof__(struct kvm_vcpu);
122383 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
122384 - 0, NULL);
122385 + SLAB_USERCOPY, NULL);
122386 if (!kvm_vcpu_cache) {
122387 r = -ENOMEM;
122388 goto out_free_3;
122389 @@ -3180,9 +3193,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122390 if (r)
122391 goto out_free;
122392
122393 + pax_open_kernel();
122394 kvm_chardev_ops.owner = module;
122395 kvm_vm_fops.owner = module;
122396 kvm_vcpu_fops.owner = module;
122397 + pax_close_kernel();
122398
122399 r = misc_register(&kvm_dev);
122400 if (r) {
122401 @@ -3192,9 +3207,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122402
122403 register_syscore_ops(&kvm_syscore_ops);
122404
122405 - kvm_preempt_ops.sched_in = kvm_sched_in;
122406 - kvm_preempt_ops.sched_out = kvm_sched_out;
122407 -
122408 r = kvm_init_debug();
122409 if (r) {
122410 printk(KERN_ERR "kvm: create debugfs files failed\n");